1 // RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown_unknown -debug-info-kind=limited -gsimple-template-names=mangled %s -o - -w -std=c++17 | FileCheck %s
2 // RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown_unknown -debug-info-kind=limited -gsimple-template-names=simple %s -o - -w -std=c++17 | FileCheck --check-prefix=SIMPLE --implicit-check-not=_STN %s
3 // RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown_unknown -debug-info-kind=limited %s -o - -w -std=c++17 | FileCheck --check-prefix=FULL --implicit-check-not=_STN %s
4 
5 template <typename... T>
6 void f1() {}
7 template <typename T, T V>
8 void f2() {}
9 template <typename... T>
10 struct t1 {};
11 extern int x;
12 int x;
13 struct t2 {
14   template <typename T = float>
15   operator t1<int>() { __builtin_unreachable(); }
16 };
17 template <template <typename...> class T>
18 void f3() {}
19 namespace {
20 enum LocalEnum { LocalEnum1 };
21 }
22 template<typename T, T ... ts>
23 struct t3 { };
24 struct t4 {
25   t3<LocalEnum, LocalEnum1> m1;
26 };
27 
28 t4 v1;
29 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "t3<(anonymous namespace)::LocalEnum, (anonymous namespace)::LocalEnum1>"
30 void f() {
31   // Basic examples of simplifiable/rebuildable names
32   f1<>();
33   // CHECK: !DISubprogram(name: "_STNf1|<>",
34   // SIMPLE: !DISubprogram(name: "f1",
35   // FULL: !DISubprogram(name: "f1<>",
36   f1<int>();
37   // CHECK: !DISubprogram(name: "_STNf1|<int>",
38   f1<void()>();
39   // CHECK: !DISubprogram(name: "_STNf1|<void ()>",
40   f2<int, 42>();
41   // CHECK: !DISubprogram(name: "_STNf2|<int, 42>",
42 
43   // Check that even though the nested name can't be rebuilt, it'll carry its
44   // full name and the outer name can be rebuilt from that.
45   f1<t1<void() noexcept>>();
46   // CHECK: !DISubprogram(name: "_STNf1|<t1<void () noexcept> >",
47 
48   // Vector array types are encoded in DWARF but the decoding in llvm-dwarfdump
49   // isn't implemented yet.
50   f1<__attribute__((__vector_size__((sizeof(int) * 2)))) int>();
51   // CHECK: !DISubprogram(name: "f1<__attribute__((__vector_size__(2 * sizeof(int)))) int>",
52 
53   // noexcept is part of function types in C++17 onwards, but not encoded in
54   // DWARF
55   f1<void() noexcept>();
56   // CHECK: !DISubprogram(name: "f1<void () noexcept>",
57 
58   // Unnamed entities (lambdas, structs/classes, enums) can't be fully rebuilt
59   // since we don't emit the column number. Also lambdas and unnamed classes are
60   // ambiguous with each other - there's no DWARF that designates a lambda as
61   // anything other than another unnamed class/struct.
62   auto Lambda = [] {};
63   f1<decltype(Lambda)>();
64   // CHECK: !DISubprogram(name: "f1<(lambda at {{.*}}debug-info-simple-template-names.cpp:[[# @LINE - 2]]:17)>",
65   f1<t1<t1<decltype(Lambda)>>>();
66   // CHECK: !DISubprogram(name: "f1<t1<t1<(lambda at {{.*}}> > >",
67   struct {
68   } unnamed_struct;
69   f1<decltype(unnamed_struct)>();
70   // CHECK: !DISubprogram(name: "f1<(unnamed struct at {{.*}}debug-info-simple-template-names.cpp:[[# @LINE - 3]]:3)>",
71   f1<void (decltype(unnamed_struct))>();
72   // CHECK: !DISubprogram(name: "f1<void ((unnamed struct at {{.*}}debug-info-simple-template-names.cpp:[[# @LINE - 5]]:3))>",
73   enum {} unnamed_enum;
74   f1<decltype(unnamed_enum)>();
75   // CHECK: !DISubprogram(name: "f1<(unnamed enum at {{.*}}debug-info-simple-template-names.cpp:[[# @LINE - 2]]:3)>",
76 
77   // Declarations can't readily be reversed as the value in the DWARF only
78   // contains the address of the value - we'd have to do symbol lookup to find
79   // the name of that value (& rely on it not having been stripped out, etc).
80   f2<int *, &x>();
81   // CHECK: !DISubprogram(name: "f2<int *, &x>",
82 
83   // We could probably handle \/ this case, but since it's a small subset of
84   // pointer typed non-type-template parameters which can't be handled it
85   // doesn't seem high priority.
86   f2<decltype(nullptr), nullptr>();
87   // CHECK: !DISubprogram(name: "f2<std::nullptr_t, nullptr>",
88 
89   // These larger constants are encoded as data blocks which makes them a bit
90   // harder to re-render. I think they might be missing sign information, or at
91   // maybe it's just a question of doing APInt things to render such large
92   // values. Punting on this for now.
93   f2<__int128, ((__int128)9223372036854775807) * 2>();
94   // CHECK: !DISubprogram(name: "f2<__int128, (__int128)18446744073709551614>",
95 
96   t2().operator t1<int>();
97   // FIXME: This should be something like "operator t1<int><float>"
98   // CHECK: !DISubprogram(name: "operator t1<float>",
99 
100   // Function pointer non-type-template parameters currently don't get any DWARF
101   // value (GCC doesn't provide one either) and even if there was a value, if
102   // it's like variable/pointer non-type template parameters, it couldn't be
103   // rebuilt anyway (see the note above for details on that) so we don't have to
104   // worry about seeing conversion operators as parameters to other templates.
105 
106   f3<t1>();
107   // CHECK: !DISubprogram(name: "_STNf3|<t1>",
108 }
109