Patchwork Set correct source location for deallocator calls

login
register
mail settings
Submitter Dehao Chen
Date Sept. 8, 2012, 9:42 p.m.
Message ID <CAO2gOZVhW2+VfKU8+n2qrcKr9fgM1G4bRyUTUB_0DATH9eEW6w@mail.gmail.com>
Download mbox | patch
Permalink /patch/182599/
State New
Headers show

Comments

Dehao Chen - Sept. 8, 2012, 9:42 p.m.
Hi,

I've added a libjava unittest which verifies that this patch will not
break Java debug info. I've also incorporated Richard's review in the
previous mail. Attached is the new patch, which passed bootstrap and
all gcc/libjava testsuites on x86.

Is it ok for trunk?

Thanks,
Dehao

gcc/ChangeLog:
2012-09-08  Dehao Chen  <dehao@google.com>

	 * tree-eh.c (goto_queue_node): New field.
	(record_in_goto_queue): New parameter.
	(record_in_goto_queue_label): New parameter.
	(lower_try_finally_dup_block): New parameter.
	(maybe_record_in_goto_queue): Update source location.
	(lower_try_finally_copy): Likewise.
	(honor_protect_cleanup_actions): Likewise.
	* gimplify.c (gimplify_expr): Reset the location to unknown.

gcc/testsuite/ChangeLog:
2012-09-08  Dehao Chen  <dehao@google.com>

	* g++.dg/debug/dwarf2/deallocator.C: New test.

libjava/ChangeLog:
2012-09-08  Dehao Chen  <dehao@google.com>

	* testsuite/libjava.lang/sourcelocation.java: New cases.
	* testsuite/libjava.lang/sourcelocation.out: New cases.
Dehao Chen - Sept. 14, 2012, 3:14 p.m.
ping...

Thanks,
Dehao

On Sun, Sep 9, 2012 at 5:42 AM, Dehao Chen <dehao@google.com> wrote:
> Hi,
>
> I've added a libjava unittest which verifies that this patch will not
> break Java debug info. I've also incorporated Richard's review in the
> previous mail. Attached is the new patch, which passed bootstrap and
> all gcc/libjava testsuites on x86.
>
> Is it ok for trunk?
>
> Thanks,
> Dehao
>
> gcc/ChangeLog:
> 2012-09-08  Dehao Chen  <dehao@google.com>
>
>          * tree-eh.c (goto_queue_node): New field.
>         (record_in_goto_queue): New parameter.
>         (record_in_goto_queue_label): New parameter.
>         (lower_try_finally_dup_block): New parameter.
>         (maybe_record_in_goto_queue): Update source location.
>         (lower_try_finally_copy): Likewise.
>         (honor_protect_cleanup_actions): Likewise.
>         * gimplify.c (gimplify_expr): Reset the location to unknown.
>
> gcc/testsuite/ChangeLog:
> 2012-09-08  Dehao Chen  <dehao@google.com>
>
>         * g++.dg/debug/dwarf2/deallocator.C: New test.
>
> libjava/ChangeLog:
> 2012-09-08  Dehao Chen  <dehao@google.com>
>
>         * testsuite/libjava.lang/sourcelocation.java: New cases.
>         * testsuite/libjava.lang/sourcelocation.out: New cases.
Andrew Haley - Sept. 14, 2012, 3:19 p.m.
On 09/08/2012 10:42 PM, Dehao Chen wrote:
> I've added a libjava unittest which verifies that this patch will not
> break Java debug info. I've also incorporated Richard's review in the
> previous mail. Attached is the new patch, which passed bootstrap and
> all gcc/libjava testsuites on x86.
> 
> Is it ok for trunk?

Yes, thanks.

Andrew.
H.J. Lu - Sept. 15, 2012, 4:25 a.m.
On Sat, Sep 8, 2012 at 2:42 PM, Dehao Chen <dehao@google.com> wrote:
> Hi,
>
> I've added a libjava unittest which verifies that this patch will not
> break Java debug info. I've also incorporated Richard's review in the
> previous mail. Attached is the new patch, which passed bootstrap and
> all gcc/libjava testsuites on x86.
>
> Is it ok for trunk?
>
> Thanks,
> Dehao
>
> gcc/ChangeLog:
> 2012-09-08  Dehao Chen  <dehao@google.com>
>
>          * tree-eh.c (goto_queue_node): New field.
>         (record_in_goto_queue): New parameter.
>         (record_in_goto_queue_label): New parameter.
>         (lower_try_finally_dup_block): New parameter.
>         (maybe_record_in_goto_queue): Update source location.
>         (lower_try_finally_copy): Likewise.
>         (honor_protect_cleanup_actions): Likewise.
>         * gimplify.c (gimplify_expr): Reset the location to unknown.
>
> gcc/testsuite/ChangeLog:
> 2012-09-08  Dehao Chen  <dehao@google.com>
>
>         * g++.dg/debug/dwarf2/deallocator.C: New test.
>
> libjava/ChangeLog:
> 2012-09-08  Dehao Chen  <dehao@google.com>
>
>         * testsuite/libjava.lang/sourcelocation.java: New cases.
>         * testsuite/libjava.lang/sourcelocation.out: New cases.

On Linux/x86, I got

FAIL: sourcelocation -O3 -findirect-dispatch output - source compiled test
FAIL: sourcelocation -O3 output - source compiled test
FAIL: sourcelocation -findirect-dispatch output - source compiled test
FAIL: sourcelocation output - source compiled test

spawn [open ...]^M
-1
-1
-1
PASS: sourcelocation -findirect-dispatch execution - source compiled test
FAIL: sourcelocation -findirect-dispatch output - source compiled test
H.J. Lu - Sept. 15, 2012, 4:27 a.m.
On Fri, Sep 14, 2012 at 9:25 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Sat, Sep 8, 2012 at 2:42 PM, Dehao Chen <dehao@google.com> wrote:
>> Hi,
>>
>> I've added a libjava unittest which verifies that this patch will not
>> break Java debug info. I've also incorporated Richard's review in the
>> previous mail. Attached is the new patch, which passed bootstrap and
>> all gcc/libjava testsuites on x86.
>>
>> Is it ok for trunk?
>>
>> Thanks,
>> Dehao
>>
>> gcc/ChangeLog:
>> 2012-09-08  Dehao Chen  <dehao@google.com>
>>
>>          * tree-eh.c (goto_queue_node): New field.
>>         (record_in_goto_queue): New parameter.
>>         (record_in_goto_queue_label): New parameter.
>>         (lower_try_finally_dup_block): New parameter.
>>         (maybe_record_in_goto_queue): Update source location.
>>         (lower_try_finally_copy): Likewise.
>>         (honor_protect_cleanup_actions): Likewise.
>>         * gimplify.c (gimplify_expr): Reset the location to unknown.
>>
>> gcc/testsuite/ChangeLog:
>> 2012-09-08  Dehao Chen  <dehao@google.com>
>>
>>         * g++.dg/debug/dwarf2/deallocator.C: New test.
>>
>> libjava/ChangeLog:
>> 2012-09-08  Dehao Chen  <dehao@google.com>
>>
>>         * testsuite/libjava.lang/sourcelocation.java: New cases.
>>         * testsuite/libjava.lang/sourcelocation.out: New cases.
>
> On Linux/x86, I got
>
> FAIL: sourcelocation -O3 -findirect-dispatch output - source compiled test
> FAIL: sourcelocation -O3 output - source compiled test
> FAIL: sourcelocation -findirect-dispatch output - source compiled test
> FAIL: sourcelocation output - source compiled test
>
> spawn [open ...]^M
> -1
> -1
> -1
> PASS: sourcelocation -findirect-dispatch execution - source compiled test
> FAIL: sourcelocation -findirect-dispatch output - source compiled test
>
>

I am using binutils mainline 20120914 from CVS.
Andrew Pinski - Sept. 15, 2012, 4:27 a.m.
On Fri, Sep 14, 2012 at 9:25 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Sat, Sep 8, 2012 at 2:42 PM, Dehao Chen <dehao@google.com> wrote:
>> Hi,
>>
>> I've added a libjava unittest which verifies that this patch will not
>> break Java debug info. I've also incorporated Richard's review in the
>> previous mail. Attached is the new patch, which passed bootstrap and
>> all gcc/libjava testsuites on x86.
>>
>> Is it ok for trunk?
>>
>> Thanks,
>> Dehao
>>
>> gcc/ChangeLog:
>> 2012-09-08  Dehao Chen  <dehao@google.com>
>>
>>          * tree-eh.c (goto_queue_node): New field.
>>         (record_in_goto_queue): New parameter.
>>         (record_in_goto_queue_label): New parameter.
>>         (lower_try_finally_dup_block): New parameter.
>>         (maybe_record_in_goto_queue): Update source location.
>>         (lower_try_finally_copy): Likewise.
>>         (honor_protect_cleanup_actions): Likewise.
>>         * gimplify.c (gimplify_expr): Reset the location to unknown.
>>
>> gcc/testsuite/ChangeLog:
>> 2012-09-08  Dehao Chen  <dehao@google.com>
>>
>>         * g++.dg/debug/dwarf2/deallocator.C: New test.
>>
>> libjava/ChangeLog:
>> 2012-09-08  Dehao Chen  <dehao@google.com>
>>
>>         * testsuite/libjava.lang/sourcelocation.java: New cases.
>>         * testsuite/libjava.lang/sourcelocation.out: New cases.
>
> On Linux/x86, I got
>
> FAIL: sourcelocation -O3 -findirect-dispatch output - source compiled test
> FAIL: sourcelocation -O3 output - source compiled test
> FAIL: sourcelocation -findirect-dispatch output - source compiled test
> FAIL: sourcelocation output - source compiled test
>
> spawn [open ...]^M
> -1
> -1
> -1
> PASS: sourcelocation -findirect-dispatch execution - source compiled test
> FAIL: sourcelocation -findirect-dispatch output - source compiled test

I bet you have an older addr2line installed.

Thanks,
Andrew Pinski
H.J. Lu - Sept. 15, 2012, 12:55 p.m.
On Fri, Sep 14, 2012 at 9:27 PM, Andrew Pinski <pinskia@gmail.com> wrote:
> On Fri, Sep 14, 2012 at 9:25 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Sat, Sep 8, 2012 at 2:42 PM, Dehao Chen <dehao@google.com> wrote:
>>> Hi,
>>>
>>> I've added a libjava unittest which verifies that this patch will not
>>> break Java debug info. I've also incorporated Richard's review in the
>>> previous mail. Attached is the new patch, which passed bootstrap and
>>> all gcc/libjava testsuites on x86.
>>>
>>> Is it ok for trunk?
>>>
>>> Thanks,
>>> Dehao
>>>
>>> gcc/ChangeLog:
>>> 2012-09-08  Dehao Chen  <dehao@google.com>
>>>
>>>          * tree-eh.c (goto_queue_node): New field.
>>>         (record_in_goto_queue): New parameter.
>>>         (record_in_goto_queue_label): New parameter.
>>>         (lower_try_finally_dup_block): New parameter.
>>>         (maybe_record_in_goto_queue): Update source location.
>>>         (lower_try_finally_copy): Likewise.
>>>         (honor_protect_cleanup_actions): Likewise.
>>>         * gimplify.c (gimplify_expr): Reset the location to unknown.
>>>
>>> gcc/testsuite/ChangeLog:
>>> 2012-09-08  Dehao Chen  <dehao@google.com>
>>>
>>>         * g++.dg/debug/dwarf2/deallocator.C: New test.
>>>
>>> libjava/ChangeLog:
>>> 2012-09-08  Dehao Chen  <dehao@google.com>
>>>
>>>         * testsuite/libjava.lang/sourcelocation.java: New cases.
>>>         * testsuite/libjava.lang/sourcelocation.out: New cases.
>>
>> On Linux/x86, I got
>>
>> FAIL: sourcelocation -O3 -findirect-dispatch output - source compiled test
>> FAIL: sourcelocation -O3 output - source compiled test
>> FAIL: sourcelocation -findirect-dispatch output - source compiled test
>> FAIL: sourcelocation output - source compiled test
>>
>> spawn [open ...]^M
>> -1
>> -1
>> -1
>> PASS: sourcelocation -findirect-dispatch execution - source compiled test
>> FAIL: sourcelocation -findirect-dispatch output - source compiled test
>
> I bet you have an older addr2line installed.
>

I am using  addr2line from binutils 20120914.
Dehao Chen - Sept. 15, 2012, 4:09 p.m.
I tried the up-to-date addr2line on any "gcc -g" generated code, it
does not work either. This is because in the new dwarf, the
DW_AT_high_pc now actually means the size. e.g.

 <1><9b>: Abbrev Number: 2 (DW_TAG_subprogram)
    <9c>   DW_AT_external    : 1	
    <9c>   DW_AT_name        : bar	
    <a0>   DW_AT_decl_file   : 1	
    <a1>   DW_AT_decl_line   : 8	
    <a2>   DW_AT_linkage_name: (indirect string, offset: 0x7b): _Z3barv	
    <a6>   DW_AT_type        : <0x8d>	
    <aa>   DW_AT_low_pc      : 0x400583	
    <b2>   DW_AT_high_pc     : 0x37 0x0	
    <ba>   DW_AT_frame_base  : 1 byte block: 9c 	(DW_OP_call_frame_cfa)
    <bc>   DW_AT_GNU_all_call_sites: 1	
    <bc>   DW_AT_sibling     : <0xff>	

However, addr2line still thinks DW_AT_high_pc means "high_pc". I think
we should wait for binutil to catch up with gcc.

Thanks,
Dehao

On Sat, Sep 15, 2012 at 8:55 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Fri, Sep 14, 2012 at 9:27 PM, Andrew Pinski <pinskia@gmail.com> wrote:
>> On Fri, Sep 14, 2012 at 9:25 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Sat, Sep 8, 2012 at 2:42 PM, Dehao Chen <dehao@google.com> wrote:
>>>> Hi,
>>>>
>>>> I've added a libjava unittest which verifies that this patch will not
>>>> break Java debug info. I've also incorporated Richard's review in the
>>>> previous mail. Attached is the new patch, which passed bootstrap and
>>>> all gcc/libjava testsuites on x86.
>>>>
>>>> Is it ok for trunk?
>>>>
>>>> Thanks,
>>>> Dehao
>>>>
>>>> gcc/ChangeLog:
>>>> 2012-09-08  Dehao Chen  <dehao@google.com>
>>>>
>>>>          * tree-eh.c (goto_queue_node): New field.
>>>>         (record_in_goto_queue): New parameter.
>>>>         (record_in_goto_queue_label): New parameter.
>>>>         (lower_try_finally_dup_block): New parameter.
>>>>         (maybe_record_in_goto_queue): Update source location.
>>>>         (lower_try_finally_copy): Likewise.
>>>>         (honor_protect_cleanup_actions): Likewise.
>>>>         * gimplify.c (gimplify_expr): Reset the location to unknown.
>>>>
>>>> gcc/testsuite/ChangeLog:
>>>> 2012-09-08  Dehao Chen  <dehao@google.com>
>>>>
>>>>         * g++.dg/debug/dwarf2/deallocator.C: New test.
>>>>
>>>> libjava/ChangeLog:
>>>> 2012-09-08  Dehao Chen  <dehao@google.com>
>>>>
>>>>         * testsuite/libjava.lang/sourcelocation.java: New cases.
>>>>         * testsuite/libjava.lang/sourcelocation.out: New cases.
>>>
>>> On Linux/x86, I got
>>>
>>> FAIL: sourcelocation -O3 -findirect-dispatch output - source compiled test
>>> FAIL: sourcelocation -O3 output - source compiled test
>>> FAIL: sourcelocation -findirect-dispatch output - source compiled test
>>> FAIL: sourcelocation output - source compiled test
>>>
>>> spawn [open ...]^M
>>> -1
>>> -1
>>> -1
>>> PASS: sourcelocation -findirect-dispatch execution - source compiled test
>>> FAIL: sourcelocation -findirect-dispatch output - source compiled test
>>
>> I bet you have an older addr2line installed.
>>
>
> I am using  addr2line from binutils 20120914.
>
>
> --
> H.J.
H.J. Lu - Sept. 15, 2012, 6:06 p.m.
On Sat, Sep 15, 2012 at 9:09 AM, Dehao Chen <dehao@google.com> wrote:
> I tried the up-to-date addr2line on any "gcc -g" generated code, it
> does not work either. This is because in the new dwarf, the
> DW_AT_high_pc now actually means the size. e.g.
>
>  <1><9b>: Abbrev Number: 2 (DW_TAG_subprogram)
>     <9c>   DW_AT_external    : 1
>     <9c>   DW_AT_name        : bar
>     <a0>   DW_AT_decl_file   : 1
>     <a1>   DW_AT_decl_line   : 8
>     <a2>   DW_AT_linkage_name: (indirect string, offset: 0x7b): _Z3barv
>     <a6>   DW_AT_type        : <0x8d>
>     <aa>   DW_AT_low_pc      : 0x400583
>     <b2>   DW_AT_high_pc     : 0x37 0x0
>     <ba>   DW_AT_frame_base  : 1 byte block: 9c         (DW_OP_call_frame_cfa)
>     <bc>   DW_AT_GNU_all_call_sites: 1
>     <bc>   DW_AT_sibling     : <0xff>
>
> However, addr2line still thinks DW_AT_high_pc means "high_pc". I think
> we should wait for binutil to catch up with gcc.
>

So, the meaning of  DW_AT_high_pc in DWARF4 is different
from DWARF3?
Dehao Chen - Sept. 15, 2012, 10:03 p.m.
Yeah, in dwarf2out.c:

 4590 add_AT_low_high_pc (dw_die_ref die, const char *lbl_low, const
char *lbl_high,
......
 4604   if (dwarf_version < 4)
 4605     attr.dw_attr_val.val_class = dw_val_class_lbl_id;
 4606   else
 4607     attr.dw_attr_val.val_class = dw_val_class_high_pc;
.
dw_val_class_lbl_id is handled:
 7984         case dw_val_class_lbl_id:
 7985           dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
 7986           break;

dw_val_class_high_pc is handled:
 8027         case dw_val_class_high_pc:
 8028           dw2_asm_output_delta (DWARF2_ADDR_SIZE, AT_lbl (a),
 8029                                 get_AT_low_pc (die), "DW_AT_high_pc");
 8030           break;

The dwarf4 specification says:

If the value of the DW_AT_high_pc is of class address, it is the
relocated address of the first location past the last instruction
associated with the entity; if it is of class constant, the value is
an unsigned integer offset which when added to the low PC gives the
address of the first location past the last instruction associated
with the entity.

However, I'm not sure how to tell how the DW_AT_high_pc's class is
represented...

Maybe it's the bug in the gcc dwarf implementation?

Dehao

On Sun, Sep 16, 2012 at 2:06 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Sat, Sep 15, 2012 at 9:09 AM, Dehao Chen <dehao@google.com> wrote:
>> I tried the up-to-date addr2line on any "gcc -g" generated code, it
>> does not work either. This is because in the new dwarf, the
>> DW_AT_high_pc now actually means the size. e.g.
>>
>>  <1><9b>: Abbrev Number: 2 (DW_TAG_subprogram)
>>     <9c>   DW_AT_external    : 1
>>     <9c>   DW_AT_name        : bar
>>     <a0>   DW_AT_decl_file   : 1
>>     <a1>   DW_AT_decl_line   : 8
>>     <a2>   DW_AT_linkage_name: (indirect string, offset: 0x7b): _Z3barv
>>     <a6>   DW_AT_type        : <0x8d>
>>     <aa>   DW_AT_low_pc      : 0x400583
>>     <b2>   DW_AT_high_pc     : 0x37 0x0
>>     <ba>   DW_AT_frame_base  : 1 byte block: 9c         (DW_OP_call_frame_cfa)
>>     <bc>   DW_AT_GNU_all_call_sites: 1
>>     <bc>   DW_AT_sibling     : <0xff>
>>
>> However, addr2line still thinks DW_AT_high_pc means "high_pc". I think
>> we should wait for binutil to catch up with gcc.
>>
>
> So, the meaning of  DW_AT_high_pc in DWARF4 is different
> from DWARF3?
>
> --
> H.J.
Mark Wielaard - Sept. 15, 2012, 10:31 p.m.
On Sun, Sep 16, 2012 at 06:03:24AM +0800, Dehao Chen wrote:
> The dwarf4 specification says:
> 
> If the value of the DW_AT_high_pc is of class address, it is the
> relocated address of the first location past the last instruction
> associated with the entity; if it is of class constant, the value is
> an unsigned integer offset which when added to the low PC gives the
> address of the first location past the last instruction associated
> with the entity.
> 
> However, I'm not sure how to tell how the DW_AT_high_pc's class is
> represented...

You look at the form in which the attribute is encoded. If it is
DW_FORM_addr then it is of class address, otherwise (DW_FORM_data1,
DW_FORM_data2, DW_FORM_data4, DW_FORM_data8, DW_FORM_sdata or
DW_FORM_udata) it is of class constant.

Cheers,

Mark
Mark Wielaard - Sept. 15, 2012, 10:38 p.m.
On Sun, Sep 16, 2012 at 12:09:04AM +0800, Dehao Chen wrote:
> I tried the up-to-date addr2line on any "gcc -g" generated code, it
> does not work either. This is because in the new dwarf, the
> DW_AT_high_pc now actually means the size. e.g.
> 
>  <1><9b>: Abbrev Number: 2 (DW_TAG_subprogram)
>     <9c>   DW_AT_external    : 1	
>     <9c>   DW_AT_name        : bar	
>     <a0>   DW_AT_decl_file   : 1	
>     <a1>   DW_AT_decl_line   : 8	
>     <a2>   DW_AT_linkage_name: (indirect string, offset: 0x7b): _Z3barv	
>     <a6>   DW_AT_type        : <0x8d>	
>     <aa>   DW_AT_low_pc      : 0x400583	
>     <b2>   DW_AT_high_pc     : 0x37 0x0	
>     <ba>   DW_AT_frame_base  : 1 byte block: 9c 	(DW_OP_call_frame_cfa)
>     <bc>   DW_AT_GNU_all_call_sites: 1	
>     <bc>   DW_AT_sibling     : <0xff>	
> 
> However, addr2line still thinks DW_AT_high_pc means "high_pc". I think
> we should wait for binutil to catch up with gcc.

I thought it had some months ago:
http://sourceware.org/ml/binutils/2012-04/msg00447.html

If that patch is present in your binutils and addr2line still doesn't
work as intented there might be a bug or some other place to update.

Thanks,

Mark

Patch

Index: libjava/testsuite/libjava.lang/sourcelocation.java
===================================================================
--- libjava/testsuite/libjava.lang/sourcelocation.java	(revision 0)
+++ libjava/testsuite/libjava.lang/sourcelocation.java	(revision 0)
@@ -0,0 +1,18 @@ 
+/* This test should test the source location attribution.
+   We print the line number of different parts of the program to make sure
+   that the source code attribution is correct.
+   To make this test pass, one need to have up-to-date addr2line installed
+   to parse the dwarf4 data format.
+*/
+public class sourcelocation {
+  public static void main(String args[]) {
+    try {
+      System.out.println(new Exception().getStackTrace()[0].getLineNumber());
+      throw new Exception();
+    } catch (Exception e) {
+      System.out.println(new Exception().getStackTrace()[0].getLineNumber());
+    } finally {
+      System.out.println(new Exception().getStackTrace()[0].getLineNumber());
+    }
+  }
+}
Index: libjava/testsuite/libjava.lang/sourcelocation.out
===================================================================
--- libjava/testsuite/libjava.lang/sourcelocation.out	(revision 0)
+++ libjava/testsuite/libjava.lang/sourcelocation.out	(revision 0)
@@ -0,0 +1,3 @@ 
+10
+13
+15
Index: libjava/testsuite/libjava.lang/sourcelocation.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: libjava/testsuite/libjava.lang/sourcelocation.jar
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Index: gcc/testsuite/g++.dg/debug/dwarf2/deallocator.C
===================================================================
--- gcc/testsuite/g++.dg/debug/dwarf2/deallocator.C	(revision 0)
+++ gcc/testsuite/g++.dg/debug/dwarf2/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 -dA" }
+
+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 "deallocator.C:28" } }
Index: gcc/tree-eh.c
===================================================================
--- gcc/tree-eh.c	(revision 191083)
+++ gcc/tree-eh.c	(working copy)
@@ -321,6 +321,7 @@  static bitmap eh_region_may_contain_throw_map;
 struct goto_queue_node
 {
   treemple stmt;
+  location_t location;
   gimple_seq repl_stmt;
   gimple cont_stmt;
   int index;
@@ -560,7 +561,8 @@  static void
 record_in_goto_queue (struct leh_tf_state *tf,
                       treemple new_stmt,
                       int index,
-                      bool is_label)
+                      bool is_label,
+		      location_t location)
 {
   size_t active, size;
   struct goto_queue_node *q;
@@ -583,6 +585,7 @@  record_in_goto_queue (struct leh_tf_state *tf,
   memset (q, 0, sizeof (*q));
   q->stmt = new_stmt;
   q->index = index;
+  q->location = location;
   q->is_label = is_label;
 }
 
@@ -590,7 +593,8 @@  record_in_goto_queue (struct leh_tf_state *tf,
    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,
+			    location_t location)
 {
   int index;
   treemple temp, new_stmt;
@@ -629,7 +633,7 @@  static void
      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, location);
 }
 
 /* For any GIMPLE_GOTO or GIMPLE_RETURN, decide whether it leaves a try_finally
@@ -649,19 +653,22 @@  maybe_record_in_goto_queue (struct leh_state *stat
     {
     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),
+				  EXPR_LOCATION (*new_stmt.tp));
       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),
+				  EXPR_LOCATION (*new_stmt.tp));
       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_location (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_location (stmt));
       break;
 
     default:
@@ -866,13 +873,19 @@  frob_into_branch_around (gimple tp, eh_region regi
    Make sure to record all new labels found.  */
 
 static gimple_seq
-lower_try_finally_dup_block (gimple_seq seq, struct leh_state *outer_state)
+lower_try_finally_dup_block (gimple_seq seq, struct leh_state *outer_state,
+			     location_t loc)
 {
   gimple region = NULL;
   gimple_seq new_seq;
+  gimple_stmt_iterator gsi;
 
   new_seq = copy_gimple_seq_and_replace_locals (seq);
 
+  for (gsi = gsi_start (new_seq); !gsi_end_p (gsi); gsi_next (&gsi))
+    if (gimple_location (gsi_stmt (gsi)) == UNKNOWN_LOCATION)
+      gimple_set_location (gsi_stmt (gsi), loc);
+
   if (outer_state->tf)
     region = outer_state->tf->try_finally_expr;
   collect_finally_tree_1 (new_seq, region);
@@ -967,7 +980,8 @@  honor_protect_cleanup_actions (struct leh_state *o
       gimple_try_set_cleanup (tf->top_p, gimple_eh_else_n_body (eh_else));
     }
   else if (this_state)
-    finally = lower_try_finally_dup_block (finally, outer_state);
+    finally = lower_try_finally_dup_block (finally, outer_state,
+					   UNKNOWN_LOCATION);
   finally_may_fallthru = gimple_seq_may_fallthru (finally);
 
   /* If this cleanup consists of a TRY_CATCH_EXPR with TRY_CATCH_IS_CLEANUP
@@ -1184,7 +1198,7 @@  lower_try_finally_copy (struct leh_state *state, s
 
   if (tf->may_fallthru)
     {
-      seq = lower_try_finally_dup_block (finally, state);
+      seq = lower_try_finally_dup_block (finally, state, tf_loc);
       lower_eh_constructs_1 (state, &seq);
       gimple_seq_add_seq (&new_stmt, seq);
 
@@ -1200,7 +1214,7 @@  lower_try_finally_copy (struct leh_state *state, s
       if (eh_else)
 	seq = gimple_eh_else_e_body (eh_else);
       else
-	seq = lower_try_finally_dup_block (finally, state);
+	seq = lower_try_finally_dup_block (finally, state, tf_loc);
       lower_eh_constructs_1 (state, &seq);
 
       emit_post_landing_pad (&eh_seq, tf->region);
@@ -1250,7 +1264,7 @@  lower_try_finally_copy (struct leh_state *state, s
 	  x = gimple_build_label (lab);
           gimple_seq_add_stmt (&new_stmt, x);
 
-	  seq = lower_try_finally_dup_block (finally, state);
+	  seq = lower_try_finally_dup_block (finally, state, q->location);
 	  lower_eh_constructs_1 (state, &seq);
           gimple_seq_add_seq (&new_stmt, seq);
 
Index: gcc/gimplify.c
===================================================================
--- gcc/gimplify.c	(revision 191083)
+++ gcc/gimplify.c	(working copy)
@@ -7429,6 +7429,15 @@  gimplify_expr (tree *expr_p, gimple_seq *pre_p, gi
 	    gimple_seq eval, cleanup;
 	    gimple try_;
 
+	    /* Calls to destructors are generated automatically in FINALLY/CATCH
+	       block. They should have location as UNKNOWN_LOCATION. However,
+	       gimplify_call_expr will reset these call stmts to input_location
+	       if it finds stmt's location is unknown. To prevent resetting for
+	       destructors, we set the input_location to unknown.
+	       Note that this only affects the destructor calls in FINALLY/CATCH
+	       block, and will automatically reset to its original value by the
+	       end of gimplify_expr.  */
+	    input_location = UNKNOWN_LOCATION;
 	    eval = cleanup = NULL;
 	    gimplify_and_add (TREE_OPERAND (*expr_p, 0), &eval);
 	    gimplify_and_add (TREE_OPERAND (*expr_p, 1), &cleanup);