]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: fix debug info for array temporary [PR107154]
authorJason Merrill <jason@redhat.com>
Tue, 4 Oct 2022 21:06:04 +0000 (17:06 -0400)
committerJason Merrill <jason@redhat.com>
Tue, 18 Apr 2023 20:44:26 +0000 (16:44 -0400)
In the testcase the elaboration of the array init that happens at genericize
time was getting the location info for the end of the function; fixed by
doing the expansion at the location of the original expression.

PR c++/107154

gcc/cp/ChangeLog:

* cp-gimplify.cc (cp_genericize_init_expr): Use iloc_sentinel.
(cp_genericize_target_expr): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/debug/dwarf2/lineno-array1.C: New test.

gcc/cp/cp-gimplify.cc
gcc/testsuite/g++.dg/debug/dwarf2/lineno-array1.C [new file with mode: 0644]

index 1c996cec80ad10f5085002a9d4f4a16bf0bd8905..1982f5ba9ce77f90856cd1c728ed4bd93d7d6889 100644 (file)
@@ -915,6 +915,7 @@ cp_genericize_init (tree *replace, tree from, tree to)
 static void
 cp_genericize_init_expr (tree *stmt_p)
 {
+  iloc_sentinel ils = EXPR_LOCATION (*stmt_p);
   tree to = TREE_OPERAND (*stmt_p, 0);
   tree from = TREE_OPERAND (*stmt_p, 1);
   if (SIMPLE_TARGET_EXPR_P (from)
@@ -930,6 +931,7 @@ cp_genericize_init_expr (tree *stmt_p)
 static void
 cp_genericize_target_expr (tree *stmt_p)
 {
+  iloc_sentinel ils = EXPR_LOCATION (*stmt_p);
   tree slot = TARGET_EXPR_SLOT (*stmt_p);
   cp_genericize_init (&TARGET_EXPR_INITIAL (*stmt_p),
                      TARGET_EXPR_INITIAL (*stmt_p), slot);
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/lineno-array1.C b/gcc/testsuite/g++.dg/debug/dwarf2/lineno-array1.C
new file mode 100644 (file)
index 0000000..befac5f
--- /dev/null
@@ -0,0 +1,25 @@
+// PR c++/107154
+// { dg-do compile { target c++11 } }
+// { dg-additional-options "-gno-as-loc-support -dA" }
+// Test that we emit debug info exactly once for the last line.
+// { dg-final { scan-assembler-times {:25:1} 1 } }
+
+bool dummy;
+
+struct S {
+  const char *p;
+  S(const char *p): p(p) {}
+  ~S() { dummy = true; }
+};
+
+using Sar = S[];
+
+struct X {
+  X(Sar&&) { }
+};
+
+int main()
+{
+  X x(Sar{"", ""});
+  return 0;
+}