From patchwork Tue Jul 31 03:29:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dehao Chen X-Patchwork-Id: 174138 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id EFCC32C008C for ; Tue, 31 Jul 2012 13:29:30 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1344310171; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: MIME-Version:Received:Received:Date:Message-ID:Subject:From:To: Cc:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=rfizhHG GT1f9jF1bWva1MOCP3K0=; b=L9y6si/ptkD+rLxhxxogWscYw7BirMTzA1EyotR Ib4wi0SqmuLpmeS5RFUTFT1uNogVU4w7raVlUJfbxhmvhg/meYnRLpnobj6OMz4X 4NKjDcz7JsL2m2XUh7WoTQd/LEGxPEjDDOsD5nVDgZp3hMhg/7RsO0CRVBj4XtRt nWbs= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:Received:MIME-Version:Received:Received:Date:Message-ID:Subject:From:To:Cc:Content-Type:X-System-Of-Record:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Z+FEpHFpHzvOesoPc/e8OroQewfuU76PSn/MfsxqBXv0rtYHzQ69/JWllmPlls y1AGs7GtCeHfTJEgo2cQQYG4Fn8peSM1kLdcX7RY99Xen6lO/cHVWmikULbemG6U CAVCoEpUb3ZaeEO5bBIJm4aYfvQbMVGvkfmwS1OheGtN0=; Received: (qmail 28101 invoked by alias); 31 Jul 2012 03:29:27 -0000 Received: (qmail 28093 invoked by uid 22791); 31 Jul 2012 03:29:26 -0000 X-SWARE-Spam-Status: No, hits=-4.7 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, TW_TM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-pb0-f47.google.com (HELO mail-pb0-f47.google.com) (209.85.160.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 31 Jul 2012 03:29:13 +0000 Received: by pbbrq2 with SMTP id rq2so10634148pbb.20 for ; Mon, 30 Jul 2012 20:29:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc:content-type :x-system-of-record:x-gm-message-state; bh=1wOmwa9XWaky8aW07NfcTai5njqtM4xuD12xrSKbrVs=; b=GE8Zm8y4ZkTMQ0k2D3UjPzuweXm0ri9wWlYU6b9PsX58bugQUY6krc26NruEX5Ff9d dFciwJxcX/a6vMst8S7rUZ0W+/WReo+Kt67+hi9v1wY5FCfXCss0Bfy5htlWanRa45Ex 2Rt7BOPkCDlwaW0F7Tk/Z4Nl3/nX33MtmQd7guoMEsbXPTBHNMq5b0iIz4cqgT0uzrsz 9TIGWc89ZtmwnWcVlg6ovHe5q1yYTzQcV6EqRMK5K4M/zWjfPZH0c643cp1Mq7fkbu/6 rGXQ9ruSWpDZdYkS7Z0gEWlL4Pi27muayVp+7ph4Qgrik4U/z44bKO6d2wieP2acMGHp cWsA== Received: by 10.68.233.103 with SMTP id tv7mr40523044pbc.124.1343705353229; Mon, 30 Jul 2012 20:29:13 -0700 (PDT) MIME-Version: 1.0 Received: by 10.68.233.103 with SMTP id tv7mr40523031pbc.124.1343705353104; Mon, 30 Jul 2012 20:29:13 -0700 (PDT) Received: by 10.68.49.231 with HTTP; Mon, 30 Jul 2012 20:29:13 -0700 (PDT) Date: Tue, 31 Jul 2012 11:29:13 +0800 Message-ID: Subject: [PATCH] Set correct source location for deallocator calls From: Dehao Chen To: gcc-patches@gcc.gnu.org Cc: Richard Guenther , David Li X-System-Of-Record: true X-Gm-Message-State: ALoCoQnPojTKKWAf8NLlmPjgHFg4Or7K2BcVQ0beowIssnBa8u5VEnA0hwGM7VFoBfajCDUcV6KMCXVyRG1LML7LSrAjL06QXUuZpy7XGUtKbhGc9revsjb/k+8TLw22/lvJh0IAG9+e3+FjvLsYyXLSQhYhoTScWI2d9ExiCRweHz6KxW6CaQufdpvD7ttN4rJ9egW46QT0 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, This patch fixes the source location for automatically generated calls to deallocator. For example: 19 void foo(int i) 20 { 21 for (int j = 0; j < 10; j++) 22 { 23 t test; 24 test.foo(); 25 if (i + j) 26 { 27 test.bar(); 28 return; 29 } 30 } 31 return; 32 } The deallocator for "23 t test" is called in two places: Line 28 and line 30. However, gcc attributes both callsites to line 30. Bootstrapped and passed gcc regression tests. Is it ok for trunk? Thanks, Dehao gcc/ChangeLog 2012-07-31 Dehao Chen * tree-eh.c (goto_queue_node): New field. (record_in_goto_queue): New parameter. (record_in_goto_queue_label): New parameter. (lower_try_finally_copy): Update source location. gcc/testsuite/ChangeLog 2012-07-31 Dehao Chen * g++.dg/guality/deallocator.C: New test. default: @@ -1234,6 +1241,7 @@ for (index = 0; index < return_index + 1; index++) { tree lab; + gimple_stmt_iterator gsi; q = labels[index].q; if (! q) @@ -1252,6 +1260,11 @@ seq = lower_try_finally_dup_block (finally, state); lower_eh_constructs_1 (state, &seq); + for (gsi = gsi_start (seq); !gsi_end_p (gsi); gsi_next (&gsi)) + gimple_set_location (gsi_stmt (gsi), + q->code == GIMPLE_COND ? + EXPR_LOCATION (*q->stmt.tp) : + gimple_location (q->stmt.g)); gimple_seq_add_seq (&new_stmt, seq); gimple_seq_add_stmt (&new_stmt, q->cont_stmt); Index: gcc/testsuite/g++.dg/guality/deallocator.C =================================================================== --- gcc/testsuite/g++.dg/guality/deallocator.C (revision 0) +++ gcc/testsuite/g++.dg/guality/deallocator.C (revision 0) @@ -0,0 +1,33 @@ +// Test that debug info generated for auto-inserted deallocator is +// correctly attributed. +// This patch scans for the lineno directly from assembly, which may +// differ between different architectures. Because it mainly tests +// FE generated debug info, without losing generality, only x86 +// assembly is scanned in this test. +// { dg-do compile { target { i?86-*-* x86_64-*-* } } } +// { dg-options "-O2 -fno-exceptions -g" } + +struct t { + t (); + ~t (); + void foo(); + void bar(); +}; + +int bar(); + +void foo(int i) +{ + for (int j = 0; j < 10; j++) + { + t test; + test.foo(); + if (i + j) + { + test.bar(); + return; + } + } + return; +} +// { dg-final { scan-assembler "1 28 0" } } Index: gcc/tree-eh.c =================================================================== --- gcc/tree-eh.c (revision 189835) +++ gcc/tree-eh.c (working copy) @@ -321,6 +321,7 @@ struct goto_queue_node { treemple stmt; + enum gimple_code code; gimple_seq repl_stmt; gimple cont_stmt; int index; @@ -560,7 +561,8 @@ record_in_goto_queue (struct leh_tf_state *tf, treemple new_stmt, int index, - bool is_label) + bool is_label, + enum gimple_code code) { size_t active, size; struct goto_queue_node *q; @@ -583,6 +585,7 @@ memset (q, 0, sizeof (*q)); q->stmt = new_stmt; q->index = index; + q->code = code; q->is_label = is_label; } @@ -590,7 +593,8 @@ TF is not null. */ static void -record_in_goto_queue_label (struct leh_tf_state *tf, treemple stmt, tree label) +record_in_goto_queue_label (struct leh_tf_state *tf, treemple stmt, tree label, + enum gimple_code code) { int index; treemple temp, new_stmt; @@ -629,7 +633,7 @@ since with a GIMPLE_COND we have an easy access to the then/else labels. */ new_stmt = stmt; - record_in_goto_queue (tf, new_stmt, index, true); + record_in_goto_queue (tf, new_stmt, index, true, code); } /* For any GIMPLE_GOTO or GIMPLE_RETURN, decide whether it leaves a try_finally @@ -649,19 +653,22 @@ { case GIMPLE_COND: new_stmt.tp = gimple_op_ptr (stmt, 2); - record_in_goto_queue_label (tf, new_stmt, gimple_cond_true_label (stmt)); + record_in_goto_queue_label (tf, new_stmt, gimple_cond_true_label (stmt), + gimple_code (stmt)); new_stmt.tp = gimple_op_ptr (stmt, 3); - record_in_goto_queue_label (tf, new_stmt, gimple_cond_false_label (stmt)); + record_in_goto_queue_label (tf, new_stmt, gimple_cond_false_label (stmt), + gimple_code (stmt)); break; case GIMPLE_GOTO: new_stmt.g = stmt; - record_in_goto_queue_label (tf, new_stmt, gimple_goto_dest (stmt)); + record_in_goto_queue_label (tf, new_stmt, gimple_goto_dest (stmt), + gimple_code (stmt)); break; case GIMPLE_RETURN: tf->may_return = true; new_stmt.g = stmt; - record_in_goto_queue (tf, new_stmt, -1, false); + record_in_goto_queue (tf, new_stmt, -1, false, gimple_code (stmt)); break;