This commit adds a new testsuite for the CTF debug format.
2021-01-22 Indu Bhagat <[email protected]>
gcc/testsuite/
* gcc.dg/debug/ctf/ctf-1.c: New test.
* gcc.dg/debug/ctf/ctf-2.c: Likewise.
* gcc.dg/debug/ctf/ctf-anonymous-struct-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-anonymous-union-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-array-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-array-2.c: Likewise.
* gcc.dg/debug/ctf/ctf-array-3.c: Likewise.
* gcc.dg/debug/ctf/ctf-array-4.c: Likewise.
* gcc.dg/debug/ctf/ctf-attr-mode-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-attr-used-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-bitfields-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-bitfields-2.c: Likewise.
* gcc.dg/debug/ctf/ctf-bitfields-3.c: Likewise.
* gcc.dg/debug/ctf/ctf-bitfields-4.c: Likewise.
* gcc.dg/debug/ctf/ctf-complex-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-cvr-quals-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-cvr-quals-2.c: Likewise.
* gcc.dg/debug/ctf/ctf-cvr-quals-3.c: Likewise.
* gcc.dg/debug/ctf/ctf-cvr-quals-4.c: Likewise.
* gcc.dg/debug/ctf/ctf-enum-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-enum-2.c: Likewise.
* gcc.dg/debug/ctf/ctf-file-scope-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-float-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-forward-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-forward-2.c: Likewise.
* gcc.dg/debug/ctf/ctf-func-index-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-function-pointers-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-function-pointers-2.c: Likewise.
* gcc.dg/debug/ctf/ctf-function-pointers-3.c: Likewise.
* gcc.dg/debug/ctf/ctf-functions-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-int-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-objt-index-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-pointers-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-pointers-2.c: Likewise.
* gcc.dg/debug/ctf/ctf-preamble-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-skip-types-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-skip-types-2.c: Likewise.
* gcc.dg/debug/ctf/ctf-skip-types-3.c: Likewise.
* gcc.dg/debug/ctf/ctf-skip-types-4.c: Likewise.
* gcc.dg/debug/ctf/ctf-skip-types-5.c: Likewise.
* gcc.dg/debug/ctf/ctf-skip-types-6.c: Likewise.
* gcc.dg/debug/ctf/ctf-str-table-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-struct-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-struct-2.c: Likewise.
* gcc.dg/debug/ctf/ctf-struct-array-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-struct-pointer-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-struct-pointer-2.c: Likewise.
* gcc.dg/debug/ctf/ctf-typedef-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-typedef-2.c: Likewise.
* gcc.dg/debug/ctf/ctf-typedef-3.c: Likewise.
* gcc.dg/debug/ctf/ctf-typedef-struct-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-typedef-struct-2.c: Likewise.
* gcc.dg/debug/ctf/ctf-typedef-struct-3.c: Likewise.
* gcc.dg/debug/ctf/ctf-union-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-variables-1.c: Likewise.
* gcc.dg/debug/ctf/ctf-variables-2.c: Likewise.
* gcc.dg/debug/ctf/ctf.exp: Likewise.
* gcc.dg/debug/dwarf2-ctf-1.c: Likewise.
---
gcc/testsuite/gcc.dg/debug/ctf/ctf-1.c | 6 ++
gcc/testsuite/gcc.dg/debug/ctf/ctf-2.c | 10 +++
.../gcc.dg/debug/ctf/ctf-anonymous-struct-1.c | 23 +++++++
.../gcc.dg/debug/ctf/ctf-anonymous-union-1.c | 26 +++++++
gcc/testsuite/gcc.dg/debug/ctf/ctf-array-1.c | 31 +++++++++
gcc/testsuite/gcc.dg/debug/ctf/ctf-array-2.c | 38 +++++++++++
gcc/testsuite/gcc.dg/debug/ctf/ctf-array-3.c | 17 +++++
gcc/testsuite/gcc.dg/debug/ctf/ctf-array-4.c | 13 ++++
.../gcc.dg/debug/ctf/ctf-attr-mode-1.c | 22 ++++++
.../gcc.dg/debug/ctf/ctf-attr-used-1.c | 22 ++++++
.../gcc.dg/debug/ctf/ctf-bitfields-1.c | 30 ++++++++
.../gcc.dg/debug/ctf/ctf-bitfields-2.c | 39 +++++++++++
.../gcc.dg/debug/ctf/ctf-bitfields-3.c | 16 +++++
.../gcc.dg/debug/ctf/ctf-bitfields-4.c | 19 ++++++
.../gcc.dg/debug/ctf/ctf-complex-1.c | 22 ++++++
.../gcc.dg/debug/ctf/ctf-cvr-quals-1.c | 65 ++++++++++++++++++
.../gcc.dg/debug/ctf/ctf-cvr-quals-2.c | 30 ++++++++
.../gcc.dg/debug/ctf/ctf-cvr-quals-3.c | 25 +++++++
.../gcc.dg/debug/ctf/ctf-cvr-quals-4.c | 23 +++++++
gcc/testsuite/gcc.dg/debug/ctf/ctf-enum-1.c | 21 ++++++
gcc/testsuite/gcc.dg/debug/ctf/ctf-enum-2.c | 27 ++++++++
.../gcc.dg/debug/ctf/ctf-file-scope-1.c | 25 +++++++
gcc/testsuite/gcc.dg/debug/ctf/ctf-float-1.c | 16 +++++
.../gcc.dg/debug/ctf/ctf-forward-1.c | 40 +++++++++++
.../gcc.dg/debug/ctf/ctf-forward-2.c | 16 +++++
.../gcc.dg/debug/ctf/ctf-func-index-1.c | 25 +++++++
.../debug/ctf/ctf-function-pointers-1.c | 24 +++++++
.../debug/ctf/ctf-function-pointers-2.c | 22 ++++++
.../debug/ctf/ctf-function-pointers-3.c | 21 ++++++
.../gcc.dg/debug/ctf/ctf-functions-1.c | 34 ++++++++++
gcc/testsuite/gcc.dg/debug/ctf/ctf-int-1.c | 17 +++++
.../gcc.dg/debug/ctf/ctf-objt-index-1.c | 30 ++++++++
.../gcc.dg/debug/ctf/ctf-pointers-1.c | 26 +++++++
.../gcc.dg/debug/ctf/ctf-pointers-2.c | 25 +++++++
.../gcc.dg/debug/ctf/ctf-preamble-1.c | 11 +++
.../gcc.dg/debug/ctf/ctf-skip-types-1.c | 33 +++++++++
.../gcc.dg/debug/ctf/ctf-skip-types-2.c | 17 +++++
.../gcc.dg/debug/ctf/ctf-skip-types-3.c | 20 ++++++
.../gcc.dg/debug/ctf/ctf-skip-types-4.c | 19 ++++++
.../gcc.dg/debug/ctf/ctf-skip-types-5.c | 19 ++++++
.../gcc.dg/debug/ctf/ctf-skip-types-6.c | 18 +++++
.../gcc.dg/debug/ctf/ctf-str-table-1.c | 26 +++++++
gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-1.c | 25 +++++++
gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-2.c | 32 +++++++++
.../gcc.dg/debug/ctf/ctf-struct-array-1.c | 65 ++++++++++++++++++
.../gcc.dg/debug/ctf/ctf-struct-pointer-1.c | 21 ++++++
.../gcc.dg/debug/ctf/ctf-struct-pointer-2.c | 22 ++++++
.../gcc.dg/debug/ctf/ctf-typedef-1.c | 68 +++++++++++++++++++
.../gcc.dg/debug/ctf/ctf-typedef-2.c | 20 ++++++
.../gcc.dg/debug/ctf/ctf-typedef-3.c | 24 +++++++
.../gcc.dg/debug/ctf/ctf-typedef-struct-1.c | 14 ++++
.../gcc.dg/debug/ctf/ctf-typedef-struct-2.c | 17 +++++
.../gcc.dg/debug/ctf/ctf-typedef-struct-3.c | 32 +++++++++
gcc/testsuite/gcc.dg/debug/ctf/ctf-union-1.c | 14 ++++
.../gcc.dg/debug/ctf/ctf-variables-1.c | 25 +++++++
.../gcc.dg/debug/ctf/ctf-variables-2.c | 16 +++++
gcc/testsuite/gcc.dg/debug/ctf/ctf.exp | 41 +++++++++++
gcc/testsuite/gcc.dg/debug/dwarf2-ctf-1.c | 7 ++
58 files changed, 1452 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-2.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-anonymous-struct-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-anonymous-union-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-array-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-array-2.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-array-3.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-array-4.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-attr-mode-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-attr-used-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-2.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-3.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-4.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-complex-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-2.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-3.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-4.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-enum-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-enum-2.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-file-scope-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-float-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-forward-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-forward-2.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-func-index-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-function-pointers-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-function-pointers-2.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-function-pointers-3.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-functions-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-int-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-objt-index-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-pointers-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-pointers-2.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-preamble-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-2.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-3.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-4.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-5.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-6.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-str-table-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-2.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-array-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-pointer-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-pointer-2.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-2.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-3.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-struct-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-struct-2.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-struct-3.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-union-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-variables-1.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-variables-2.c
create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf.exp
create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2-ctf-1.c
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-1.c
new file mode 100644
index 00000000000..1be0dfb0e65
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-1.c
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-gt" } */
+
+void func(void)
+{
+}
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-2.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-2.c
new file mode 100644
index 00000000000..891f20ed85d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-2.c
@@ -0,0 +1,10 @@
+/* A LEVEL of 0 with -gt turns off CTF debug info generation. */
+
+/* { dg-do compile } */
+/* { dg-options "-gt0 -dA" } */
+
+/* { dg-final { scan-assembler-times "0xdff2.*CTF preamble magic number" 0} }
*/
+/* { dg-final { scan-assembler-times "0x4.*CTF preamble version" 0 } } */
+/* { dg-final { scan-assembler-times "0.*CTF preamble flags" 0 } } */
+
+const char * _CONTEXT_NAME = "foobar";
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-anonymous-struct-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-anonymous-struct-1.c
new file mode 100644
index 00000000000..0973b2b8882
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-anonymous-struct-1.c
@@ -0,0 +1,23 @@
+/* Test compilation and CTF generation of anonymous structs. An anonymous
+ struct type is encoded as no-name CTF struct type.
+
+ For this testcase, a single CTF anonymous struct is expected.
+ struct {} : ctt_name = 0 (point to offset 0 in the CTF string table to
+ denote empty string)
+
+ Two CTF struct records should be generated in total.
+ struct a : ctt_info = 0x1a000002 (2 fields)
+ struct {} : ctt_info = 0x1a000001 (1 field) */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "\[\t \]0\[\t \]+\[^\n\]*ctt_name" 1 } }
*/
+/* { dg-final { scan-assembler-times "0x1a000002\[\t \]+\[^\n\]*ctt_info" 1 }
} */
+/* { dg-final { scan-assembler-times "0x1a000001\[\t \]+\[^\n\]*ctt_info" 1 }
} */
+
+struct a
+{
+ struct { int b1; } a1;
+ int a2;
+} my_a;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-anonymous-union-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-anonymous-union-1.c
new file mode 100644
index 00000000000..71b491ab109
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-anonymous-union-1.c
@@ -0,0 +1,26 @@
+/* Test compilation and CTF generation of anonymous union. An anonymous union
+ is encoded as no-name CTF union type.
+
+ For this testcase, a single CTF anonymous union is expected.
+ struct {} : ctt_name = 0 (point to offset 0 in the CTF string table to
+ denote empty string)
+
+ Two CTF struct records should be generated in total.
+ struct anon_union : ctt_info = 0x1a000001 (1 field)
+ union {} : ctt_info = 0x1e000002 (2 fields) */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "\[\t \]0\[\t \]+\[^\n\]*ctt_name" 1 } }
*/
+/* { dg-final { scan-assembler-times "0x1a000001\[\t \]+\[^\n\]*ctt_info" 1 }
} */
+/* { dg-final { scan-assembler-times "0x1e000002\[\t \]+\[^\n\]*ctt_info" 1 }
} */
+
+struct anon_union
+{
+ union
+ {
+ char name;
+ int value;
+ };
+} my_anon_u;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-1.c
new file mode 100644
index 00000000000..cd342b1b23d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-1.c
@@ -0,0 +1,31 @@
+/* CTF generation for array type.
+
+ Unsized arrays are encoded with a 0 for the number of elements.
+
+ In this testcase, 5 distinct CTF records for arrays are expected
+ b1 : cta_nelems = 2
+ c1 : cta_nelems = 3
+ a1 : cta_nelems = 2, 5
+ buf : cta_nelems = 0. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "0x12000000\[\t \]+\[^\n\]*ctt_info" 5 }
} */
+
+/* { dg-final { scan-assembler-times "\[\t \]0x2\[\t \]+\[^\n\]*cta_nelems" 2
} } */
+/* { dg-final { scan-assembler-times "\[\t \]0x3\[\t \]+\[^\n\]*cta_nelems" 1
} } */
+/* { dg-final { scan-assembler-times "\[\t \]0x5\[\t \]+\[^\n\]*cta_nelems" 1
} } */
+/* { dg-final { scan-assembler-times "\[\t \]0\[\t \]+\[^\n\]*cta_nelems" 1 }
} */
+
+int b1[2] = {0,1};
+int c1[5] = {0,1,2,3,4};
+int a1[2][3] = { {3,4,5}, {2,3,4} };
+
+/* Variable length struct using arrays. */
+struct my_array
+{
+ int flags;
+ int length;
+ int buf[];
+} my_array_obj;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-2.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-2.c
new file mode 100644
index 00000000000..abadc646378
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-2.c
@@ -0,0 +1,38 @@
+/* CTF generation for unsized arrays.
+
+ Unsized arrays are encoded with a 0 for the number of elements. The type
+ of array index is the INT type.
+
+ TBD_CTF_FORMAT_OPEN_ISSUES (1) -
+ This testcase makes a note of the case of a probable misrepresentation.
+ See Note 1 and Note 2 below.
+
+ In the CTF section, these types are encoded as :
+
+ Variables:
+ _CTF_NEWSTR -> 7: const char [0] (size 0x0)
+ _CTF_SECTION -> 6: const char [5] (size 0x5)
+ b1 -> 2: int [0] (size 0x0)
+ b2 -> 3: int [0] (size 0x0)
+
+ Note 1 : There is misrepresentation in that b1 and b2 are specified
+ differently by the user.
+ Note 2 : It is arguable though whether the representation for
+ _CTF_NEWSTR is incorrect. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "0x12000000\[\t \]+\[^\n\]*ctt_info" 5 }
} */
+
+/* { dg-final { scan-assembler-times "\[\t \]0\[\t \]+\[^\n\]*cta_nelems" 3 }
} */
+/* { dg-final { scan-assembler-times "\[\t \]0x5\[\t \]+\[^\n\]*cta_nelems" 1
} } */
+
+static int b1[] = {};
+
+int b2[0];
+
+const char _CTF_SECTION[] = ".ctf";
+
+extern const char _CTF_NEWSTR[];
+const char _CTF_NEWSTR[] = "ctfinfo";
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-3.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-3.c
new file mode 100644
index 00000000000..77a33ada7c9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-3.c
@@ -0,0 +1,17 @@
+/* CTF generation for variable length arrays.
+
+ In this testcase, a specific flavor of vla appears in the function
+ signature.
+
+ TBD_CTF_FORMAT_OPEN_ISSUES (1) -
+ This testcase makes a note of another case of a probable misrepresentation.
+ See ctf-array-2.c for some context on how vla's are a case of a probable
+ misrepresentation in CTF. Nevertheless, compilation should not fail. */
+
+/* { dg-do compile } */
+/* { dg-options "-gt" } */
+
+int foo (int a, int b[a][a])
+{
+ return b[a-1][a-3];
+}
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-4.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-4.c
new file mode 100644
index 00000000000..042023d75c8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-array-4.c
@@ -0,0 +1,13 @@
+/* CTF generation for array type.
+
+ Test CTF generation for single element arrays. In this testcase, one CTF
+ record for array is expected with cta_nelems = 1. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "0x12000000\[\t \]+\[^\n\]*ctt_info" 1 }
} */
+
+/* { dg-final { scan-assembler-times "\[\t \]0x1\[\t \]+\[^\n\]*cta_nelems" 1
} } */
+
+int b[1];
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-attr-mode-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-attr-mode-1.c
new file mode 100644
index 00000000000..4bb67ef67bf
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-attr-mode-1.c
@@ -0,0 +1,22 @@
+/* Test CTF generation works well with ((mode)) attribute.
+
+ In this testcase, CTF should report type of bqi to be an enum and
+ not an int. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "ascii \"B1.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"B2.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"B3.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "cte_value" 3} } */
+
+/* There are no better/direct methods to assert that the CTF for typedef of
+ enum has been added. */
+/* { dg-final { scan-assembler-times "\[\t \]0x22000003\[\t
\]+\[^\n\]*ctt_info" 1 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0x2a000000\[\t
\]+\[^\n\]*ctt_info" 1 } } */
+
+/* { dg-final { scan-assembler-times "\[\t \]0x3\[\t \]+\[^\n\]*ctv_typeidx"
1} } */
+
+typedef enum { B1 = 1, B2 = 2, B3 = 3 } B;
+B __attribute__ ((mode (QI))) bqi;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-attr-used-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-attr-used-1.c
new file mode 100644
index 00000000000..0415f3ec300
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-attr-used-1.c
@@ -0,0 +1,22 @@
+/* Test CTF generation works well with ((used)) function attribute.
+
+ This attribute, attached to a function, means that code must be emitted for
+ the function even if it appears that the function is not referenced. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O2 -gt -dA" } */
+
+/* These should be true for higher optimization levels. */
+/* { dg-final { scan-assembler-times "ascii \"keep_this.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"lose_this.0\"\[\t
\]+\[^\n\]*ctf_string" 0 } } */
+
+static int lose_this(int a)
+{
+ return a + 2;
+}
+
+__attribute__((used))
+static int keep_this(double a)
+{
+ return a * 2;
+}
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-1.c
new file mode 100644
index 00000000000..5f26629dcdf
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-1.c
@@ -0,0 +1,30 @@
+/* CTF generation for bitfields.
+
+ In this testcase, two slices are expected - one for enum and the other for
+ int. CTF slices are unnamed records. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "\[\t \]0x2\[\t \]+\[^\n\]*cts_bits" 1 }
} */
+/* { dg-final { scan-assembler-times "\[\t \]0x3\[\t \]+\[^\n\]*cts_bits" 1 }
} */
+/* { dg-final { scan-assembler-times "\[\t \]0\[\t \]+\[^\n\]*ctt_name" 2 } }
*/
+
+enum color
+{
+ RED,
+ GREEN,
+ BLUE,
+ YELLOW,
+ ORANGE,
+ BLACK
+};
+
+struct quickcolor
+{
+ enum color col:3;
+ int brushid:2;
+ int strokes;
+};
+
+struct quickcolor qc;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-2.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-2.c
new file mode 100644
index 00000000000..ed85cf3d7f3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-2.c
@@ -0,0 +1,39 @@
+/* The bitfield type (int) may be shared, but slices are not de-duplicated.
+
+ In this testcase, it is expected to see a total of 6 CTF slices and 2 CTF
+ integer types for the bitfields - unsigned long long and signed long long.
+
+ cts_offset is the offset of the bitfield into a machine word.
+ TBD - hardcoding cts_offset checks into the testcase will cause it to break
+ across targets with different BIT_PER_WORD. Is there a way to add
+ cts_offset related checks in the testcase? */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "\[\t \]0x6\[\t \]+\[^\n\]*cts_type" 3 }
} */
+/* { dg-final { scan-assembler-times "\[\t \]0x2\[\t \]+\[^\n\]*cts_type" 3 }
} */
+
+/* { dg-final { scan-assembler-times "\[\t \]0xf\[\t \]+\[^\n\]*cts_bits" 2 }
} */
+/* { dg-final { scan-assembler-times "\[\t \]0x21\[\t \]+\[^\n\]*cts_bits" 2 }
} */
+/* { dg-final { scan-assembler-times "\[\t \]0x10\[\t \]+\[^\n\]*cts_bits" 2 }
} */
+
+/* { dg-final { scan-assembler-times "ascii \"long long unsigned int.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"long long int.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+
+struct fields
+{
+ unsigned long long u1 : 15;
+ unsigned long long u2 : 33;
+ unsigned long long u3 : 16;
+ signed long long s1 : 15;
+ signed long long s2 : 33;
+ signed long long s3 : 16;
+} flags;
+
+int i = 33;
+
+int main ()
+{
+ return flags.u1 + i;
+}
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-3.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-3.c
new file mode 100644
index 00000000000..dcb6a2a3e17
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-3.c
@@ -0,0 +1,16 @@
+/* The bool bitfield type. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "\[\t \]0x2\[\t \]+\[^\n\]*cts_type" 2 }
} */
+/* { dg-final { scan-assembler-times "\[\t \]0x1\[\t \]+\[^\n\]*cts_bits" 2 }
} */
+
+/* { dg-final { scan-assembler-times "ascii \"_Bool.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+
+#include <stdbool.h>
+
+struct open_file {
+ bool mmapped:1;
+ bool released:1;
+} of;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-4.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-4.c
new file mode 100644
index 00000000000..e4be6113d1c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-4.c
@@ -0,0 +1,19 @@
+/* The zero sized bitfield.
+
+ In this testcase, two slices are expected. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "\[\t \]0x2\[\t \]+\[^\n\]*cts_type" 2 }
} */
+
+/* { dg-final { scan-assembler-times "\[\t \]0x5\[\t \]+\[^\n\]*cts_bits" 1 }
} */
+/* { dg-final { scan-assembler-times "\[\t \]0xa\[\t \]+\[^\n\]*cts_bits" 1 }
} */
+
+/* { dg-final { scan-assembler-times "ctm_name" 2 } } */
+struct foo
+{
+ int a:5;
+ unsigned:0;
+ int b:10;
+} foome;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-complex-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-complex-1.c
new file mode 100644
index 00000000000..3d02b8765d1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-complex-1.c
@@ -0,0 +1,22 @@
+/* Tests for CTF complex base types.
+
+ CTF does not have representation for COMPLEX integer types.
+
+ This testcase has a mix of C constructs containing COMPLEX_TYPE. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "\[\t \]0xa000000\[\t
\]+\[^\n\]*ctt_info" 3 } } */
+
+/* { dg-final { scan-assembler-times "ascii \"complex double.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"complex long double.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"complex float.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+
+#include <complex.h>
+
+double complex z1 = I * I;
+
+const long double complex z2 = I * I;
+
+float complex z4 = 1+2.11*I;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-1.c
new file mode 100644
index 00000000000..f52dc24d95b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-1.c
@@ -0,0 +1,65 @@
+/* Test compilation of stubs with various qualifiers - const, restrict and
+ volatile.
+
+ Testcase includes a std header to allow testing of shared types across
+ files. Only one CTF record for int is expected.
+
+ CTF records for CVR qualifiers are no-name records. In this testcase, there
+ are 5 qualifiers across constructs. 2 more no-name CTF records correspond
to
+ CTF pointer records.
+
+ TYPEID: name string (size) -> ref TYPEID : ref name string (size) -> ...
+
+ Types:
+ 1: long int (size 0x8)
+ 2: long unsigned int (size 0x8)
+ 3: size_t (size 0x8) -> 2: long unsigned int (size 0x8)
+ 4: int (size 0x4)
+ 5: const int (size 0x4) -> 4: int (size 0x4)
+ 6: volatile const int (size 0x4) -> 5: const int (size 0x4) -> 4: int
(size 0x4)
+ 7: long long int (size 0x8)
+ 8: long double (size 0x10)
+ 9: int * (size 0x8) -> 4: int (size 0x4)
+ a: int *restrict (size 0x8) -> 9: int * (size 0x8) -> 4: int (size 0x4)
+ b: const int * (size 0x8) -> 5: const int (size 0x4) -> 4: int (size 0x4)
+ c: const int *restrict (size 0x8) -> b: const int * (size 0x8) -> 5:
const int (size 0x4) -> 4: int (size 0x4)
+ d: INTP (size 0x8) -> 9: int * (size 0x8) -> 4: int (size 0x4)
+ e: const INTP (size 0x8) -> d: INTP (size 0x8) -> 9: int * (size 0x8) ->
4: int (size 0x4)
+ f: void (size 0x0)
+ 10: void (*) (size_t, int *restrict, const int *restrict) (size 0x0)
+ */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "ascii \"int.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0\[\t \]+\[^\n\]*ctt_name" 7 } }
*/
+
+/* type id 9, b have POINTER type. */
+/* { dg-final { scan-assembler-times "\[\t \]0xe000000\[\t
\]+\[^\n\]*ctt_info" 2 } } */
+
+/* type id 5, e have CONST qualifier. */
+/* { dg-final { scan-assembler-times "\[\t \]0x32000000\[\t
\]+\[^\n\]*ctt_info" 2 } } */
+
+/* type id a, c have RESTRICT qualifier. */
+/* { dg-final { scan-assembler-times "\[\t \]0x36000000\[\t
\]+\[^\n\]*ctt_info" 2 } } */
+
+/* type id 6 has VOLATILE qualifier. */
+/* { dg-final { scan-assembler-times "\[\t \]0x2e000000\[\t
\]+\[^\n\]*ctt_info" 1 } } */
+
+#include "stddef.h"
+
+const volatile int a = 5;
+int *restrict b;
+
+const int * i;
+int const * j;
+
+typedef int * INTP;
+const INTP int_p;
+
+void foo (size_t n, int *restrict p, const int *restrict q)
+{
+ while (n-- > 0)
+ *p++ = *q++;
+}
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-2.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-2.c
new file mode 100644
index 00000000000..8ce6676319c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-2.c
@@ -0,0 +1,30 @@
+/* Test compilation of stubs with various expressions involving const
+ qualifier.
+
+ In this testcase, a single CTF record for const int is expected. A total of
+ two const qualifier CTF records are expected (const int and const struct
+ s1). */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "ascii \"int.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0x32000000\[\t
\]+\[^\n\]*ctt_info" 2 } } */
+
+struct mystruct
+{
+ struct
+ {
+ int a;
+ const int b;
+ } s1;
+ char * name;
+} my_a;
+
+struct s1
+{
+ int i;
+ const int ci;
+} s;
+
+const struct s1 cs;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-3.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-3.c
new file mode 100644
index 00000000000..6d42e00a272
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-3.c
@@ -0,0 +1,25 @@
+/* Test compilation of stubs with various expressions involving const and
+ volatile qualifiers.
+
+ In this testcase, it is expected to have const and volatile CTF
+ records. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "ascii \"unsigned char.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0x2e000000\[\t
\]+\[^\n\]*ctt_info" 5 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0x32000000\[\t
\]+\[^\n\]*ctt_info" 3 } } */
+/* Two arrays. */
+/* { dg-final { scan-assembler-times "\[\t \]0x12000000\[\t
\]+\[^\n\]*ctt_info" 2 } } */
+
+
+const volatile unsigned char vicar = 11;
+
+const volatile unsigned char * vicarage = &vicar;
+
+volatile float vilify[2];
+
+const volatile char victor = 'Y';
+
+const volatile char vindictive[2];
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-4.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-4.c
new file mode 100644
index 00000000000..5a1f789a2f7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-4.c
@@ -0,0 +1,23 @@
+/* Test compilation of stubs with various qualifiers - const, restrict and
+ volatile.
+
+ CTF records for CVR qualifiers are no-name records. In this testcase, there
+ is 1 const qualifier. 1 more no-name CTF record corresponds to the CTF
+ pointer record. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "\[\t \]0\[\t \]+\[^\n\]*ctt_name" 2 } }
*/
+/* { dg-final { scan-assembler-times "\[\t \]0xe000000\[\t
\]+\[^\n\]*ctt_info" 1 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0x32000000\[\t
\]+\[^\n\]*ctt_info" 1 } } */
+
+typedef const struct howto_struct howto_type;
+
+typedef struct entry
+{
+ int addend;
+ howto_type *howto;
+} how_ent;
+
+how_ent hent;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-enum-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-enum-1.c
new file mode 100644
index 00000000000..d91a4194221
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-enum-1.c
@@ -0,0 +1,21 @@
+/* CTF generation for enums. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "ascii \"RED.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"GREEN.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"BLUE.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"YELLOW.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "cte_value" 4} } */
+
+
+enum foo_color
+{
+ RED,
+ GREEN,
+ BLUE,
+ YELLOW
+};
+
+enum foo_color my_color;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-enum-2.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-enum-2.c
new file mode 100644
index 00000000000..bf2a08cda61
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-enum-2.c
@@ -0,0 +1,27 @@
+/* CTF generation for enums.
+
+ CTF represents enum values with an int32_t. For enum values not
+ representable with int32_t data type, the compiler skips adding CTF for
+ them. This will be fixed soon in the CTF format.
+ TBD_CTF_REPRESENTATION_LIMIT.
+
+ In this testcase, CTF for enumerator GFS_MONOTONIC will not be generated.
*/
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "ascii \"GFS_MONOTONIC.0\"\[\t
\]+\[^\n\]*ctf_string" 0 } } */
+/* { dg-final { scan-assembler-times "ascii \"GFS_RUNTIME.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"GFS_STATIC.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "cte_value" 2} } */
+
+
+enum gomp_schedule_type
+{
+ GFS_RUNTIME,
+ GFS_STATIC,
+ GFS_MONOTONIC = 0x80000000U
+};
+
+enum gomp_schedule_type gsch_type;
+
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-file-scope-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-file-scope-1.c
new file mode 100644
index 00000000000..5c7ad49392e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-file-scope-1.c
@@ -0,0 +1,25 @@
+/* CTF is not generated for entities not at file-scope. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "ascii \"SFOO.0\"\[\t
\]+\[^\n\]*ctf_string" 0 } } */
+/* { dg-final { scan-assembler-times "ascii \"gfoo.0\"\[\t
\]+\[^\n\]*ctf_string" 0 } } */
+/* { dg-final { scan-assembler-times "ascii \"foo.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+
+int foo (int n)
+{
+ typedef struct { int a[n]; } SFOO;
+
+ SFOO a;
+ __attribute__ ((noinline)) SFOO gfoo (void) { return a; }
+
+ a.a[0] = 1;
+ a.a[9] = 2;
+
+ SFOO b;
+ b = gfoo ();
+
+ return b.a[0] == 1 && b.a[9] == 2;
+}
+
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-float-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-float-1.c
new file mode 100644
index 00000000000..ae2dfc2e401
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-float-1.c
@@ -0,0 +1,16 @@
+/* Tests for CTF float base types.
+ - Verify that there is a single record for the base types. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+/* { dg-final { scan-assembler-times "ascii \"float.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"double.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"long double.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+
+float a;
+float b = 33;
+
+double c = 44;
+double d = 45;
+
+long double e;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-forward-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-forward-1.c
new file mode 100644
index 00000000000..9d9b96d6358
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-forward-1.c
@@ -0,0 +1,40 @@
+/* CTF forward type is generated for forward declarations of types in C.
+
+ Check that the ctf-kind of CTF_K_FOWARD type is CTF_K_STRUCT or CTF_K_UNION.
+ For forward types, the compiler encodes the CTF kind in the ctt_type field.
+ CTF_K_FORWARD is used as the CTF type as usual in the ctt_info. */
+
+/* Note - A value of 6 in "ctt_size or ctt_type" appears twice in this
+ testcase. This might be misconstrued as 2 CTK_K_FORWARD records of struct
+ type. The second assembler tag is due to a ref type in a CVR CTF record.
+ TBD - perhaps a more robust string pattern is needed. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "\[\t \]0x26000000\[\t
\]+\[^\n\]*ctt_info" 2 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0x6\[\t \]+\[^\n\]*ctt_size or
ctt_type" 2 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0x7\[\t \]+\[^\n\]*ctt_size or
ctt_type" 2 } } */
+
+typedef struct __locale_struct
+{
+ struct __locale_data *__locales[13]; /* forward struct type. */
+
+ const int *__ctype_toupper;
+ const char *__names[13];
+} *__locale_t;
+
+typedef __locale_t locale_t;
+
+locale_t loc;
+
+typedef struct __inter_struct
+{
+ union __inter_data * __inters[13]; /* forward union type. */
+
+ const int * __ctype_kind;
+} * __inter_t;
+
+typedef __inter_t inter_t;
+
+inter_t inter;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-forward-2.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-forward-2.c
new file mode 100644
index 00000000000..33080f259a2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-forward-2.c
@@ -0,0 +1,16 @@
+/* CTF forward type is generated for forward declarations of enum types in C.
+
+ Check that the ctf-kind of CTF_K_FOWARD type is CTF_K_ENUM.
+ For forward types, the compiler encodes the CTF kind in the ctt_type field.
+ CTF_K_FORWARD is used as the CTF type as usual in the ctt_info. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "\[\t \]0x26000000\[\t
\]+\[^\n\]*ctt_info" 1 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0x8\[\t \]+\[^\n\]*ctt_size or
ctt_type" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"vibgyor.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+
+enum vibgyor;
+
+char * (*get_color_name) (enum vibgyor);
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-func-index-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-func-index-1.c
new file mode 100644
index 00000000000..4215615bfc9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-func-index-1.c
@@ -0,0 +1,25 @@
+/* CTF function index sub-section.
+
+ A function index sub-section in the CTF section contains the offset to the
+ string name of the global function symbols. The number of entries in the
+ func info section and the func index section are always the same.
+
+ In this testcase, 2 records in the function index section are expected. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "funcinfo_name" 2 } } */
+/* { dg-final { scan-assembler-times "funcinfo_func_type" 2 } } */
+/* { dg-final { scan-assembler-times "ascii \"bar.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"foo.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+
+int foo (void)
+{
+ return 0;
+}
+
+int bar (int a)
+{
+ return 33 + a;
+}
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-function-pointers-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-function-pointers-1.c
new file mode 100644
index 00000000000..30026ea4349
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-function-pointers-1.c
@@ -0,0 +1,24 @@
+/* CTF generation of function pointers. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+/* { dg-final { scan-assembler-times "\[\t \]0x16000001\[\t
\]+\[^\n\]*ctt_info" 1 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0x16000002\[\t
\]+\[^\n\]*ctt_info" 1 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0x16000003\[\t
\]+\[^\n\]*ctt_info" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"__foo_fn.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"destroy.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"func.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+
+int (*func) (int *, char);
+
+typedef int (*__foo_fn) (void *__cookie, char *__buf, int __nbytes);
+
+typedef struct object
+{
+ int myint;
+ char mychar;
+ void (*destroy)(struct object *);
+} object_t;
+
+object_t myobj;
+__foo_fn fooit;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-function-pointers-2.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-function-pointers-2.c
new file mode 100644
index 00000000000..26b0ec678db
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-function-pointers-2.c
@@ -0,0 +1,22 @@
+/* CTF generation of function pointers.
+
+ In this testcase, there is a single function type expected for two
+ different function pointer types. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+/* { dg-final { scan-assembler-times "\[\t \]0x16000001\[\t
\]+\[^\n\]*ctt_info" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"rcu_callback_t.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"func.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+
+struct callback_head {
+ struct callback_head *next;
+ void (*func) (struct callback_head *head);
+} __attribute__ (( aligned (sizeof (void *))));
+#define rcu_head callback_head
+
+struct callback_head chead;
+
+typedef void (*rcu_callback_t) (struct rcu_head *head);
+
+rcu_callback_t rcb;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-function-pointers-3.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-function-pointers-3.c
new file mode 100644
index 00000000000..c97bb168e86
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-function-pointers-3.c
@@ -0,0 +1,21 @@
+/* CTF generation of function pointers.
+
+ In this testcase, there is a single function type expected. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+/* { dg-final { scan-assembler-times "\[\t \]0x16000001\[\t
\]+\[^\n\]*ctt_info" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"foo_init_callback.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"fn.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+
+struct foo;
+
+typedef void (* foo_init_callback) (struct foo *f1);
+
+struct foo
+{
+ /* Function to call to initialize. */
+ foo_init_callback fn;
+};
+
+struct foo f;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-functions-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-functions-1.c
new file mode 100644
index 00000000000..20bade108f6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-functions-1.c
@@ -0,0 +1,34 @@
+/* CTF generation for functions with varargs or otherwise.
+
+ In this testcase, it is expected to see one CTF_K_FUNCTION record with two
+ function arguments. The second function argument with a value of 0
+ corresponds to the ellipsis.
+
+ Example CTF section excerpt on x86_64 :
+
+ .long 0x5 # ctt_name (name = format)
+ .long 0x16000002 # ctt_info (CTF_K_FUNCTION with 2 arguments)
+ .long 0x2 # ctt_size or ctt_type (return typeID)
+ .long 0x2 # dtu_argv (TypeID of the First argument)
+ .long 0 # dtu_argv (TypeID of the second argument)
+ .ascii "\0" # ctf_string
+ .ascii "int\0" # ctf_string
+ .ascii "format\0" # ctf_string
+
+ */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "\[\t \]0x16000002\[\t
\]+\[^\n\]*ctt_info" 1 } } */
+/* { dg-final { scan-assembler-times "dtu_argv" 2 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0\[\t \]+\[^\n\]*dtu_argv" 1 } }
*/
+
+int foo (void);
+
+int bar (int);
+
+int * format (int * fmt, ...)
+{
+ return fmt;
+}
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-int-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-int-1.c
new file mode 100644
index 00000000000..88f2a3aa066
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-int-1.c
@@ -0,0 +1,17 @@
+/* Tests for CTF integer base types.
+ - Verify that there is a single record for the base types. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+/* { dg-final { scan-assembler-times "ascii \"int.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"short int.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"long int.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+
+int a;
+int b = 33;
+
+short int c = 44;
+short int d = 45;
+
+long int e = 90;
+long int f;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-objt-index-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-objt-index-1.c
new file mode 100644
index 00000000000..9196ce88ae0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-objt-index-1.c
@@ -0,0 +1,30 @@
+/* CTF objext index sub-section.
+
+ An object index sub-section in the CTF section contains the offset to the
+ string name of the global object symbols. The number of entries in the
+ obj info section and objt index section are always the same.
+
+ In this testcase, 4 records in the object index section are expected. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "objtinfo_name" 4 } } */
+/* { dg-final { scan-assembler-times "objtinfo_var_type" 4 } } */
+/* { dg-final { scan-assembler-times "ascii \"a.0\"\[\t \]+\[^\n\]*ctf_string"
1 } } */
+/* { dg-final { scan-assembler-times "ascii \"b.0\"\[\t \]+\[^\n\]*ctf_string"
1 } } */
+/* { dg-final { scan-assembler-times "ascii \"a1.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"d_instance.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+
+static int b = 33;
+
+int a = 44;
+int a1[2] = {22, 33};
+
+struct d
+{
+ int d1;
+ int d2;
+};
+
+struct d d_instance;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-pointers-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-pointers-1.c
new file mode 100644
index 00000000000..32da7bdd9bd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-pointers-1.c
@@ -0,0 +1,26 @@
+/* CTF generation for pointer types.
+
+ In this testcase, two CTF pointer type records are expected
+ - int *
+ - struct foo_struct *
+ */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "ascii \"foo_struct.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"int.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0xe000000\[\t
\]+\[^\n\]*ctt_info" 2 } } */
+
+int b = 44;
+int * a = &b;
+
+struct foo_struct
+{
+ int bar_mem_1;
+ int bar_mem_2;
+ float d;
+ struct foo_struct *next;
+};
+
+struct foo_struct * node;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-pointers-2.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-pointers-2.c
new file mode 100644
index 00000000000..f7eb13c342c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-pointers-2.c
@@ -0,0 +1,25 @@
+/* CTF generation for pointer types.
+
+ In this testcase, de-duplication of pointer types is exercised. The
+ compostition of structs in this testcase is such that when adding CTF for
+ pointer type (link), the pointed-to-type type already adds the pointer to
+ struct link.
+
+ In this testcase, one CTF pointer type record is expected. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "\[\t \]0xe000000\[\t
\]+\[^\n\]*ctt_info" 1 } } */
+
+struct link;
+
+typedef struct items {
+ struct link * link;
+ int str;
+} itemslist;
+
+itemslist il;
+
+struct link { struct link * next; };
+
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-preamble-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-preamble-1.c
new file mode 100644
index 00000000000..476ca80dd65
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-preamble-1.c
@@ -0,0 +1,11 @@
+/* Verify the CTF preamble in the CTF section. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+/* { dg-final { scan-assembler "0xdff2.*CTF preamble magic number" } } */
+/* { dg-final { scan-assembler "0x4.*CTF preamble version" } } */
+/* { dg-final { scan-assembler "0.*CTF preamble flags" } } */
+
+void func (void)
+{
+}
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-1.c
new file mode 100644
index 00000000000..bd2935dbee6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-1.c
@@ -0,0 +1,33 @@
+/* CTF does not have representation for some types at this time. These types
+ are skipped in the CTF generation phase in the compiler.
+
+ This testcase does NOT cover all skipped types exhaustively. */
+
+/* { dg-do compile } */
+/* { dg-options "-gt" } */
+
+#include <complex.h>
+
+typedef float La_x86_64_xmm __attribute__ ((__vector_size__ (16)));
+La_x86_64_xmm a1;
+
+/* GCC also supports complex integer data types. */
+complex char a;
+complex signed char b;
+complex unsigned char c;
+complex short int d;
+complex short unsigned int e;
+complex int f;
+complex unsigned int g;
+complex long int h;
+complex long unsigned int i;
+complex long long int j;
+
+enum gomp_schedule_type
+{
+ GFS_RUNTIME,
+ GFS_STATIC,
+ GFS_MONOTONIC = 0x80000000U
+};
+
+enum gomp_schedule_type gsch_type;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-2.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-2.c
new file mode 100644
index 00000000000..6e0d39e8373
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-2.c
@@ -0,0 +1,17 @@
+/* CTF does not have representation for some types at this time. These types
+ are skipped in the CTF generation phase in the compiler.
+
+ Skip IEEE interchange and extended formats for CTF generation.
+
+ In this testcase, CTF records for types are not added as CTF has no
+ representation for IEEE interchange and extended formats.
+
+ CTF records for variables do exist, however. The referenced type is
+ CTF_TYPE_NULLID. */
+
+/* { dg-do compile } */
+/* { dg-options "-gt" } */
+
+/* { dg-require-effective-target float16 } */
+
+_Float16 f16;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-3.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-3.c
new file mode 100644
index 00000000000..e08d142b63e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-3.c
@@ -0,0 +1,20 @@
+/* CTF does not have representation for some types at this time. These types
+ are skipped in the CTF generation phase in the compiler.
+
+ Skip IEEE interchange and extended formats for CTF generation.
+
+ In this testcase, CTF records for types are not added as CTF has no
+ representation for IEEE interchange and extended formats.
+
+ CTF records for variables and pointer do exist, however. The referenced
+ type is CTF_TYPE_NULLID. */
+
+/* { dg-do compile } */
+/* { dg-options "-gt" } */
+
+/* { dg-require-effective-target float32 } */
+/* { dg-require-effective-target float32x } */
+
+_Float32 f32;
+_Float32x f32x;
+_Float32 * f32p;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-4.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-4.c
new file mode 100644
index 00000000000..d29bd8bdf54
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-4.c
@@ -0,0 +1,19 @@
+/* CTF does not have representation for some types at this time. These types
+ are skipped in the CTF generation phase in the compiler.
+
+ Skip IEEE interchange and extended formats for CTF generation.
+
+ In this testcase, CTF records for types are not added as CTF has no
+ representation for IEEE interchange and extended formats.
+
+ CTF records for variables and pointer do exist, however. The referenced
+ type is CTF_TYPE_NULLID. */
+
+/* { dg-do compile } */
+/* { dg-options "-gt" } */
+
+/* { dg-require-effective-target float64 } */
+/* { dg-require-effective-target float64x } */
+
+_Float64 f64;
+_Float64x f64x;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-5.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-5.c
new file mode 100644
index 00000000000..37a2a899c55
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-5.c
@@ -0,0 +1,19 @@
+/* CTF does not have representation for some types at this time. These types
+ are skipped in the CTF generation phase in the compiler.
+
+ Skip IEEE interchange and extended formats for CTF generation.
+
+ In this testcase, CTF records for types are not added as CTF has no
+ representation for IEEE interchange and extended formats.
+
+ CTF records for variables and pointer do exist, however. The referenced
+ type is CTF_TYPE_NULLID. */
+
+/* { dg-do compile } */
+/* { dg-options "-gt" } */
+
+/* { dg-require-effective-target float128 } */
+/* { dg-require-effective-target float128x } */
+
+_Float128 f128;
+_Float128x f128x;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-6.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-6.c
new file mode 100644
index 00000000000..ffdfb017ce1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-6.c
@@ -0,0 +1,18 @@
+/* CTF does not have representation for some types at this time. These types
+ are skipped in the CTF generation phase in the compiler.
+
+ Skip Decimal Floating Point format types for CTF generation.
+
+ In this testcase, CTF records for types are not added as CTF has no
+ representation for Decimal floating point format.
+
+ CTF records for variables do exist, however. The referenced type is
+ CTF_TYPE_NULLID. */
+
+/* { dg-do compile } */
+/* { dg-options "-gt" } */
+/* { dg-require-effective-target dfp } */
+
+_Decimal32 d32;
+_Decimal64 d64;
+_Decimal128 d128;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-str-table-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-str-table-1.c
new file mode 100644
index 00000000000..2c5e3527109
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-str-table-1.c
@@ -0,0 +1,26 @@
+/* CTF String Table as generated by the compiler is expected to have only a
+ single empty string. Just an optimization by the compiler, it is not
+ mandated by the CTF format. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+/* { dg-final { scan-assembler-times "ascii \".0\"\[\t \]+\[^\n\]*ctf_string"
1 } } */
+
+union wait
+{
+ int w_status;
+ struct
+ {
+ int __w_termsig;
+ int __w_coredump;
+ } __wait_terminated;
+ struct
+ {
+ int __w_stopval;
+ int __w_stopsig;
+ } __wait_stopped;
+};
+
+typedef union { union wait * __uptr; int * iptr; } __WAIT_STATUS;
+
+__WAIT_STATUS waitstatus;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-1.c
new file mode 100644
index 00000000000..5d496d83efc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-1.c
@@ -0,0 +1,25 @@
+/* Test compilation of struct type.
+
+ In this testcase, two CTF_K_STRUCT records are expected
+ struct a : ctt_info = 0x1a000004 (4 field members)
+ struct b : ctt_into = 0x1a000002 (2 field members)
+*/
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "\[\t \]0x1a000004\[\t
\]+\[^\n\]*ctt_info" 1 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0x1a000002\[\t
\]+\[^\n\]*ctt_info" 1 } } */
+/* { dg-final { scan-assembler-times "ctm_name" 6 } } */
+
+struct a
+{
+ int d1;
+ int d2;
+ float c;
+ struct b
+ {
+ int time;
+ int wall;
+ } b1;
+} my_a;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-2.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-2.c
new file mode 100644
index 00000000000..84b41fd246b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-2.c
@@ -0,0 +1,32 @@
+/* Test for compilation of self-referntial structs.
+
+ Further, the compiler is expected to generate a single CTF struct type for
+ struct dmx_dtdef (due to Type de-duplication at CTF generation). */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+/* { dg-final { scan-assembler-times "ascii \"dmx_dtdef.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"dtd_name.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"dtd_type.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"dmx_dtdef_t.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+
+struct link
+{
+ struct link * next;
+} * s_link;
+
+typedef long dmx_id_t;
+
+typedef struct dmx_dtdef
+{
+ char * dtd_name;
+ dmx_id_t dtd_type;
+} dmx_dtdef_t;
+
+typedef struct dmx_bundle
+{
+ dmx_id_t dmb_type;
+ dmx_dtdef_t * dmb_dtd;
+} dmx_bundle_t;
+
+dmx_bundle_t dbt;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-array-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-array-1.c
new file mode 100644
index 00000000000..cb3f8864fb3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-array-1.c
@@ -0,0 +1,65 @@
+/* Test Compilation of mixed constructs containing structs and arrays.
+
+ Further, the compiler is expected to generate a single CTF struct type for
+ struct cmodel (due to Type de-duplication at the time of CTF generation).
+
+ const qualifier in fields of structs should be processed. It appears as a
+ no-name CTF record with appropriate ctt_info. In this testcase, there are
+ two const qualifiers - const char and const struct cmodel. However, due to
+ way the debug information is represented in DWARF die, 3 const qualifier
+ records appear in the CTF section.
+
+ <1><e1>: Abbrev Number: 14 (DW_TAG_typedef)
+ <e2> DW_AT_name : (indirect string, offset: 0x114): cmodel_t
+ <e9> DW_AT_type : <0x9a>
+ <1><ed>: Abbrev Number: 13 (DW_TAG_const_type)
+ <ee> DW_AT_type : <0xe1>
+ <1><f2>: Abbrev Number: 4 (DW_TAG_array_type)
+ <f3> DW_AT_type : <0xed>
+ <f7> DW_AT_sibling : <0x102>
+
+ <2><101>: Abbrev Number: 0
+ <1><102>: Abbrev Number: 13 (DW_TAG_const_type)
+ <103> DW_AT_type : <0xf2>
+ <1><107>: Abbrev Number: 15 (DW_TAG_variable)
+ <108> DW_AT_name : (indirect string, offset: 0x57): _models
+ <10f> DW_AT_type : <0x102>
+ <1><11d>: Abbrev Number: 0
+
+ This results in:
+
+ _models -> e: const const cmodel_t [3] (size 0x30) -> d: const cmodel_t
[3] (size 0x30)
+
+ Deemed as acceptable for now. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "ascii \"cmodel.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"cname.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"cpointer.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"cmodel_t.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+
+/* 3 const records are expected. */
+/* { dg-final { scan-assembler-times "\[\t \]0x32000000\[\t
\]+\[^\n\]*ctt_info" 3 } } */
+
+struct a
+{
+ int a1[2];
+ struct { int b[3]; } a2;
+};
+
+struct a my_a;
+
+typedef struct cmodel
+{
+ const char *cname;
+ int ccode;
+ int cpointer;
+} cmodel_t;
+
+static const cmodel_t _models[] = {
+ {"ILP32", 0, 4},
+ {"LP64", 0, 8},
+ {"", 0, 0}
+};
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-pointer-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-pointer-1.c
new file mode 100644
index 00000000000..af8c413e77d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-pointer-1.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* This tests the following scenario:
+
+ 1. struct foo;
+ 2. struct foo *a_foo;
+ 3. struct foo { int bar; };
+ 4. void baz (struct foo *f) { f->bar = 0; }
+
+ At 2. a forward for struct foo is generated and at 3. the struct
+ type is fully defined. When a pointer to foo is encountered at 4.,
+ an additional CTF type for the completed struct shall be emitted as
+ well. The linker will deduplicate both types. */
+
+struct foo;
+struct foo *a_foo;
+struct foo { int bar; };
+void baz (struct foo *f) { f->bar = 0; }
+
+/* { dg-final { scan-assembler-times "\[\t \]\"bar.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-pointer-2.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-pointer-2.c
new file mode 100644
index 00000000000..f7783f04476
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-pointer-2.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* This tests the following scenario:
+
+ 1. struct foo;
+ 2. struct foo *a_foo;
+ 3. struct foo { int bar; };
+ 4. void baz (struct foo **f) { f->bar = 0; }
+
+ At 2. a forward for struct foo is generated and at 3. the struct
+ type is fully defined. When a pointer to a pointer to foo is
+ encountered at 4., an additional CTF type for the completed struct
+ shall be emitted as well. The linker will deduplicate both
+ types. */
+
+struct foo;
+struct foo *a_foo;
+struct foo { int bar; };
+void baz (struct foo **f) { (*f)->bar = 0; }
+
+/* { dg-final { scan-assembler-times "\[\t \]\"bar.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-1.c
new file mode 100644
index 00000000000..82642b1bc8b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-1.c
@@ -0,0 +1,68 @@
+/* CTF_K_TYPEDEF record generation.
+
+ In this testcase, 7 typedef records are expected.
+
+ Further, the declared variables must be of type typedef
+
+ Variables:
+ a -> 2: my_int (size 0x4) -> 1: int (size 0x4)
+ b -> 3: bar_int (size 0x4) -> 1: int (size 0x4)
+ c -> 4: foo_int (size 0x4) -> 1: int (size 0x4)
+ d -> 7: my_array (size 0x8) -> 5: struct (size 0x8)
+ e -> 9: CINT (size 0x4) -> 8: const int (size 0x4) -> 1: int (size 0x4)
+ f -> c: CINTP (size 0x8) -> b: const int * (size 0x8) -> a: const int
(size 0x4) -> 1: int (size 0x4)
+ g -> f: my_node_t (size 0x8) -> d: struct my_node (size 0x8)
+
+ There is no direct way to check that the variables are of type typedef.
+ So in this testcase, we simply check that:
+ 1. The typedef records are generated (Check for 7 specific ctt_info, and
+ check for the ascii strings for the typedef names).
+ 2. The ctv_typeidx are distinct (each pointing to a specfic unique type).
+ Note that if variables were not of type typedef, ctv_typeidx will not be
+ unique (type of a, b, c will all point to int); hence, the check.
+ */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "0x2a000000\[\t \]+\[^\n\]*ctt_info" 7 }
} */
+/* { dg-final { scan-assembler-times "ascii \"my_int.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"bar_int.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"foo_int.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"my_array.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"CINT.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"CINTP.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"my_node_t.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+
+/* { dg-final { scan-assembler-times "\[\t \]0x2\[\t \]+\[^\n\]*ctv_typeidx" 1
} } */
+/* { dg-final { scan-assembler-times "\[\t \]0x4\[\t \]+\[^\n\]*ctv_typeidx" 1
} } */
+/* { dg-final { scan-assembler-times "\[\t \]0x5\[\t \]+\[^\n\]*ctv_typeidx" 1
} } */
+/* { dg-final { scan-assembler-times "\[\t \]0x9\[\t \]+\[^\n\]*ctv_typeidx" 1
} } */
+/* { dg-final { scan-assembler-times "\[\t \]0xa\[\t \]+\[^\n\]*ctv_typeidx" 1
} } */
+/* { dg-final { scan-assembler-times "\[\t \]0xc\[\t \]+\[^\n\]*ctv_typeidx" 1
} } */
+/* { dg-final { scan-assembler-times "\[\t \]0xf\[\t \]+\[^\n\]*ctv_typeidx" 1
} } */
+
+typedef int my_int;
+typedef int bar_int;
+typedef int foo_int;
+
+typedef struct { int a[2]; } my_array;
+
+typedef const int CINT;
+typedef const int * CINTP;
+
+typedef struct my_node
+{
+ int flags;
+ char value;
+} my_node_t;
+
+my_int a;
+bar_int b;
+foo_int c;
+
+my_array d;
+CINT e = 3;
+CINTP f = &e;
+
+my_node_t g;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-2.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-2.c
new file mode 100644
index 00000000000..275985c80da
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-2.c
@@ -0,0 +1,20 @@
+/* CTF_K_TYPEDEF record generation.
+
+ In this testcase, typedef of type void should be generated. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "0x2a000000\[\t \]+\[^\n\]*ctt_info" 1 }
} */
+/* { dg-final { scan-assembler-times "ascii \"foo_void_type.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"void.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+
+typedef void foo_void_type;
+
+struct bar
+{
+ int a;
+ foo_void_type *b;
+};
+
+struct bar c;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-3.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-3.c
new file mode 100644
index 00000000000..0b7e3aa0857
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-3.c
@@ -0,0 +1,24 @@
+/* Type de-duplication of CTF_K_TYPEDEF records.
+
+ In this testcase, a single CTF record for typedef is expected. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "0x2a000000\[\t \]+\[^\n\]*ctt_info" 1 }
} */
+/* { dg-final { scan-assembler-times "ascii \"foo_type.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"foo.0\"\[\t
\]+\[^\n\]*ctf_string" 1 } } */
+
+typedef struct foo foo_type;
+
+struct bar
+{
+ struct foo * f1;
+ foo_type * f2;
+};
+
+struct testme {
+ struct bar * b1;
+};
+
+struct testme * t1;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-struct-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-struct-1.c
new file mode 100644
index 00000000000..a10ce0eca7b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-struct-1.c
@@ -0,0 +1,14 @@
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+typedef struct my_int
+{
+ int upper;
+ int lower;
+ struct bitmask
+ {
+ int flags;
+ } my_mask;
+} my_int_t;
+
+my_int_t mit;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-struct-2.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-struct-2.c
new file mode 100644
index 00000000000..092c70a0a80
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-struct-2.c
@@ -0,0 +1,17 @@
+/* Test compilation of typedef composition in structs. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+typedef struct
+{
+ int day, month, year;
+} Date;
+
+typedef struct
+{
+ Date filedDate, fixedDate;
+ int severity;
+} BugRef;
+
+BugRef CR2112;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-struct-3.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-struct-3.c
new file mode 100644
index 00000000000..1f88db503e9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-struct-3.c
@@ -0,0 +1,32 @@
+/* Test CTF generation for a typedef instantiation with CVR quals.
+
+ Caveat: There is no direct way to test that the type of foo is
+ "const my_int_t" via scanning the assembly. This test instead
+ checks for the presence of some of the CTF constructs involved
+ individually. Specifically, it checks for CTF const record and
+ CTF typedef record.
+
+ Variables:
+ foo -> 4: const my_int_t (size 0x8) -> 3: my_int_t (size 0x8) -> 1:
struct my_int (size 0x8)
+
+ Types:
+ 1: struct my_int (size 0x8)
+ 2: int (size 0x4)
+ 3: my_int_t (size 0x8) -> 1: struct my_int (size 0x8)
+ 4: const my_int_t (size 0x8) -> 3: my_int_t (size 0x8) -> 1: struct
my_int (size 0x8)
+*/
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "\[\t \]0x4\[\t \]+\[^\n\]*ctv_typeidx" 1
} } */
+/* { dg-final { scan-assembler-times "\[\t \]0x2a000000\[\t
\]+\[^\n\]*ctt_info" 1 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0x32000000\[\t
\]+\[^\n\]*ctt_info" 1 } } */
+
+typedef struct my_int
+{
+ int upper;
+ int lower;
+} my_int_t;
+
+const my_int_t foo = {10, 20};
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-union-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-union-1.c
new file mode 100644
index 00000000000..59b4cb7035c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-union-1.c
@@ -0,0 +1,14 @@
+/* CTF generation for union type. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+/* { dg-final { scan-assembler-times "\[\t \]0x1e000004\[\t
\]+\[^\n\]*ctt_info" 1 } } */
+/* { dg-final { scan-assembler-times "ctm_name" 4 } } */
+
+union c
+{
+ int c1;
+ int c2;
+ int c3;
+ int c4;
+} my_u_c;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-variables-1.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-variables-1.c
new file mode 100644
index 00000000000..a2e25577eee
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-variables-1.c
@@ -0,0 +1,25 @@
+/* CTF generation for global variables.
+
+ In this testcase, 7 records in the variable info section are expected. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "ctv_name" 7 } } */
+
+float var1;
+double var2;
+long double var3;
+
+char ascii = 'a';
+
+int a = 33;
+int a1[2] = {22, 33};
+
+struct d
+{
+ int d1;
+ int d2;
+};
+
+struct d d_instance;
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-variables-2.c
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-variables-2.c
new file mode 100644
index 00000000000..cd9ab510b16
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-variables-2.c
@@ -0,0 +1,16 @@
+/* CTF generation for static variables inside a function.
+
+ In this testcase, CTF record for bstatic is NOT expected. CTF generation
+ is only carried out for variables at file-scope or global-scope. */
+
+/* { dg-do compile ) */
+/* { dg-options "-O0 -gt -dA" } */
+
+/* { dg-final { scan-assembler-times "ctv_name" 0 } } */
+/* { dg-final { scan-assembler-times "ascii \"bstatic.0\"\[\t
\]+\[^\n\]*ctf_string" 0 } } */
+
+int foo (int a)
+{
+ static int bstatic = 3;
+ return a + bstatic;
+}
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf.exp
b/gcc/testsuite/gcc.dg/debug/ctf/ctf.exp
new file mode 100644
index 00000000000..46055f8a2bf
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf.exp
@@ -0,0 +1,41 @@
+# Copyright (C) 2002-2019 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+# GCC testsuite that uses the `dg.exp' driver.
+
+# Load support procs.
+load_lib gcc-dg.exp
+
+# Disable on ptx (in sync with DWARF testsuite)
+if { [istarget nvptx-*-*] } {
+ return
+}
+
+# If a testcase doesn't have special options, use these.
+global DEFAULT_CFLAGS
+if ![info exists DEFAULT_CFLAGS] then {
+ set DEFAULT_CFLAGS " -ansi -pedantic-errors"
+}
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\] ]] \
+ "" $DEFAULT_CFLAGS
+
+# All done.
+dg-finish
diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2-ctf-1.c
b/gcc/testsuite/gcc.dg/debug/dwarf2-ctf-1.c
new file mode 100644
index 00000000000..4ffa8eed418
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/dwarf2-ctf-1.c
@@ -0,0 +1,7 @@
+/* Verify that CTF debug info can co-exist with other debug formats. */
+/* { dg-do compile } */
+/* { dg-options "-gt -dA" } */
+/* { dg-final { scan-assembler "0xdff2.*CTF preamble magic number" } } */
+
+void func (void)
+{ }
--
2.25.0.2.g232378479e