Add DWARF5 variants of assembly scan tests that use DW_FORM_implicit_const
authorMark Wielaard <mark@klomp.org>
Sun, 23 Aug 2020 14:21:08 +0000 (16:21 +0200)
committerMark Wielaard <mark@klomp.org>
Thu, 17 Sep 2020 18:13:13 +0000 (20:13 +0200)
Some DWARF tests scan the assembly output looking for constant values.
When using DWARF5 those constants might use DW_FORM_implicit_const,
which are output (in the comments) after the attribute instead of
before. To make sure these tests work introduce a -gdwarf-5 variant
of these tests and explicitly use -gdwarf-2 for the original.

gcc/testsuite/ChangeLog:

* gcc.dg/debug/dwarf2/inline2.c: Add -gdwarf-2.
* g++.dg/debug/dwarf2/inline-var-1.C: Likewise.
* gcc.dg/debug/dwarf2/pr41445-5.c: Likewise.
* gcc.dg/debug/dwarf2/pr41445-6.c: Likewise.
* gcc.dg/debug/dwarf2/inline6.c: New variant with -gdwarf-5.
* g++.dg/debug/dwarf2/inline-var-3.C: Likewise.
* gcc.dg/debug/dwarf2/pr41445-7.c: Likewise.
* gcc.dg/debug/dwarf2/pr41445-8.c: Likewise.

gcc/testsuite/g++.dg/debug/dwarf2/inline-var-1.C
gcc/testsuite/g++.dg/debug/dwarf2/inline-var-3.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/debug/dwarf2/inline2.c
gcc/testsuite/gcc.dg/debug/dwarf2/inline6.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/debug/dwarf2/pr41445-5.c
gcc/testsuite/gcc.dg/debug/dwarf2/pr41445-6.c
gcc/testsuite/gcc.dg/debug/dwarf2/pr41445-7.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/debug/dwarf2/pr41445-8.c [new file with mode: 0644]

index 3b1c913edfca779e244c7fc121e4e6ffb9140b2b..9a88e28cbe0ff460f87680b94e7ee0b9a070a7a5 100644 (file)
@@ -1,5 +1,5 @@
 // { dg-do compile { target c++17 } }
-// { dg-options "-O -g -dA -gno-strict-dwarf -fno-eliminate-unused-debug-symbols" }
+// { dg-options "-O -gdwarf-2 -dA -gno-strict-dwarf -fno-eliminate-unused-debug-symbols" }
 // { dg-require-weak "" }
 // { dg-final { scan-assembler-times "0x3\[^\n\r]* DW_AT_inline" 6 { xfail *-*-aix* } } }
 // { dg-final { scan-assembler-times "0x1\[^\n\r]* DW_AT_inline" 2 { xfail *-*-aix* } } }
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/inline-var-3.C b/gcc/testsuite/g++.dg/debug/dwarf2/inline-var-3.C
new file mode 100644 (file)
index 0000000..52ed5b6
--- /dev/null
@@ -0,0 +1,29 @@
+// DWARF5 variant of inline-var-1.C
+// { dg-do compile { target c++17 } }
+// { dg-options "-O -gdwarf-5 -dA -gno-strict-dwarf -fno-eliminate-unused-debug-symbols" }
+// { dg-require-weak "" }
+// { dg-final { scan-assembler-times " DW_AT_inline \\(0x3\\)" 2 { xfail *-*-aix* } } }
+// { dg-final { scan-assembler-times "0x3\[^\n\r]* DW_AT_inline" 4 { xfail *-*-aix* } } }
+// { dg-final { scan-assembler-times "0x1\[^\n\r]* DW_AT_inline" 2 { xfail *-*-aix* } } }
+// { dg-final { scan-assembler-times " DW_AT_declaration" 6 { xfail *-*-aix* } } }
+// { dg-final { scan-assembler-times " DW_AT_specification" 6 { xfail *-*-aix* } } }
+// { dg-final { scan-assembler-times " DW_AT_\[^\n\r]*linkage_name" 7 { xfail *-*-aix* } } }
+
+inline int a;
+struct S
+{
+  static inline double b = 4.0;
+  static constexpr int c = 2;
+  static constexpr inline char d = 3;
+} s;
+template <int N>
+inline int e = N;
+int &f = e<2>;
+template <int N>
+struct T
+{
+  static inline double g = 4.0;
+  static constexpr int h = 2;
+  static inline constexpr char i = 3;
+};
+T<5> t;
index 7e019a6c06a0e5c73fe40288fa6e5dbf62257e4d..9c36450ae2de7326bb1cc4091bce2d6bd5c2bbda 100644 (file)
@@ -14,7 +14,9 @@
   properly nested DW_TAG_inlined_subroutine DIEs for third, second and first.
 */
 
-/* { dg-options "-O -g3 -gdwarf -dA -fgnu89-inline" } */
+/* Explicitly use dwarf-2 because dwarf-5 might use DW_FORM_implicit_const
+   which is hard to scan for. */
+/* { dg-options "-O -g3 -gdwarf-2 -dA -fgnu89-inline" } */
 /* { dg-do compile } */
 
 /* There are 6 inlined subroutines:
diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/inline6.c b/gcc/testsuite/gcc.dg/debug/dwarf2/inline6.c
new file mode 100644 (file)
index 0000000..03013f1
--- /dev/null
@@ -0,0 +1,69 @@
+/* DWARF5 variant of inline2.
+   Origin: PR debug/37801
+
+  Abstract instances (DW_TAG_subroutines having the DW_AT_inline attribute)
+  of second and first were having a DW_TAG_lexical_block DIE wrongly
+  representing the inlined calls to third (in second) and to
+  second (in first). At the same time, main didn't have children
+  DW_TAG_inlined_subroutine DIEs representing the inlined calls to
+  first, second and third.
+
+  The ideal goal here is to test that we have no superfluous
+  DW_TAG_lexical_block DIE anymore, that abstract instances DIEs have
+  no descendant DIE with a DW_AT_abstract_origin attribute, and that main has
+  properly nested DW_TAG_inlined_subroutine DIEs for third, second and first.
+*/
+
+/* Explicitly use dwarf-5 which uses DW_FORM_implicit_const.  */
+/* { dg-options "-O -g3 -gdwarf-5 -dA -fgnu89-inline" } */
+/* { dg-do compile } */
+
+/* There are 6 inlined subroutines:
+   - One for each subroutine inlined into main, that's 3.
+   - One for earch subroutine inline into the out of line instances
+     of third, second and first.  */
+/* { dg-final { scan-assembler-times "\\(DIE \\(\[^\n\]*\\) DW_TAG_inlined_subroutine" 6 } } */
+
+/* We should have no DW_TAG_lexical_block DIEs, all inline instances
+   should have the first subblock elided to match the abstract instance
+   layout.  */
+/* { dg-final { scan-assembler-times "\\(DIE \\(\[^\n\]*\\) DW_TAG_lexical_block" 0 } } */
+
+
+/* There are 3 DW_AT_inline attributes: one per abstract inline instance.
+   The value of the attribute must be 0x3, meaning the function was
+   actually inlined.  */
+/* { dg-final { scan-assembler-times  " DW_AT_inline \\(0x3\\)" 3 } } */
+
+volatile int *a;
+
+inline void
+third (int arg3)
+{
+  int var3 = arg3;
+  a[0] = var3;
+}
+
+inline void
+second (int arg2)
+{
+  int var2 = arg2;
+  third (var2+1);
+}
+
+inline void
+first (int arg1)
+{
+  int var1 = arg1;
+  second (var1+1);
+}
+
+int
+main ()
+{
+  int some_int = 1;
+  first (some_int);
+  return 0;
+}
+
+
index d646f5983b30ffd07126eff9b63de34e06aaf93e..80300ec22e87c32b6a4168b5e87724a0da9af5db 100644 (file)
@@ -2,7 +2,7 @@
 /* Test that token after multi-line function-like macro use
    gets correct locus even when preprocessing separately.  */
 /* { dg-do compile } */
-/* { dg-options "-save-temps -gdwarf -O0 -dA -fno-merge-debug-strings" } */
+/* { dg-options "-save-temps -gdwarf-2 -O0 -dA -fno-merge-debug-strings" } */
 
 #define A(x) vari x
 #define vari(x)
index 340cb3835307d2f94572a7b0dcd78cc86ec8e9f2..fbf033758b6b2916d972e7a406f56cf96193c821 100644 (file)
@@ -1,6 +1,6 @@
 /* PR preprocessor/41445 */
 /* { dg-do compile } */
-/* { dg-options "-gdwarf -O0 -dA -fno-merge-debug-strings" } */
+/* { dg-options "-gdwarf-2 -O0 -dA -fno-merge-debug-strings" } */
 
 #include "pr41445-5.c"
 
diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/pr41445-7.c b/gcc/testsuite/gcc.dg/debug/dwarf2/pr41445-7.c
new file mode 100644 (file)
index 0000000..0e0de82
--- /dev/null
@@ -0,0 +1,16 @@
+/* PR preprocessor/41445 DWARF5 variant */
+/* Test that token after multi-line function-like macro use
+   gets correct locus even when preprocessing separately.  */
+/* { dg-do compile } */
+/* { dg-options "-save-temps -gdwarf-5 -O0 -dA -fno-merge-debug-strings" } */
+
+#define A(x) vari x
+#define vari(x)
+#define B , varj
+int A(B) ;
+
+/*  We want to check that both vari and varj have the same line
+    number.  */
+
+/* { dg-final { scan-assembler "DW_TAG_variable\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\"vari\[^\\r\\n\]*DW_AT_name(\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*DW_AT_)*\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\[^\\r\\n\]*DW_AT_decl_line \\((0xa|10)\\)" } } */
+/* { dg-final { scan-assembler "DW_TAG_variable\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\"varj\[^\\r\\n\]*DW_AT_name(\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*DW_AT_)*\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\[^\\r\\n\]*DW_AT_decl_line \\((0xa|10)\\)" } } */
diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/pr41445-8.c b/gcc/testsuite/gcc.dg/debug/dwarf2/pr41445-8.c
new file mode 100644 (file)
index 0000000..3a6eeb5
--- /dev/null
@@ -0,0 +1,11 @@
+/* PR preprocessor/41445 DWARF5 variant*/
+/* { dg-do compile } */
+/* { dg-options "-gdwarf-5 -O0 -dA -fno-merge-debug-strings" } */
+
+#include "pr41445-5.c"
+
+/*  We want to check that both vari and varj have the same line
+    number.  */
+
+/* { dg-final { scan-assembler "DW_TAG_variable\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\"vari\[^\\r\\n\]*DW_AT_name(\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*DW_AT_)*\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\[^\\r\\n\]*DW_AT_decl_line \\((0xa|10)\\)" } } */
+/* { dg-final { scan-assembler "DW_TAG_variable\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\"varj\[^\\r\\n\]*DW_AT_name(\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*DW_AT_)*\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\[^\\r\\n\]*DW_AT_decl_line \\((0xa|10)\\)" } } */