debug-info-template.cpp revision 9dfd24324c079b564dda936c6ae46898b82121e2
1// RUN: %clang -S -emit-llvm -target x86_64-unknown_unknown -g %s -o - -std=c++11 | FileCheck %s
2
3// CHECK: [[INT:![0-9]*]] = {{.*}} ; [ DW_TAG_base_type ] [int]
4// CHECK: metadata [[TCI:![0-9]*]], i32 0, i32 1, %class.TC* @tci, null} ; [ DW_TAG_variable ] [tci]
5// CHECK: [[TC:![0-9]*]] = {{.*}}, metadata [[TCARGS:![0-9]*]]} ; [ DW_TAG_class_type ] [TC<unsigned int, 2, &glb, &foo::e, &foo::f>]
6// CHECK: [[TCARGS]] = metadata !{metadata [[TCARG1:![0-9]*]], metadata [[TCARG2:![0-9]*]], metadata [[TCARG3:![0-9]*]], metadata [[TCARG4:![0-9]*]], metadata [[TCARG5:![0-9]*]]}
7//
8// We seem to be missing file/line/col info on template value parameters -
9// metadata supports it but it's not populated. GCC doesn't emit it either,
10// perhaps we should just drop it from the metadata.
11//
12// CHECK: [[TCARG1]] = {{.*}}metadata !"T", metadata [[UINT:![0-9]*]], {{.*}} ; [ DW_TAG_template_type_parameter ]
13// CHECK: [[UINT:![0-9]*]] = {{.*}} ; [ DW_TAG_base_type ] [unsigned int]
14// CHECK: [[TCARG2]] = {{.*}}metadata !"", metadata [[UINT:![0-9]*]], i32 2, {{.*}} ; [ DW_TAG_template_value_parameter ]
15// CHECK: [[TCARG3]] = {{.*}}metadata !"x", metadata [[INTPTR:![0-9]*]], i32* @glb, {{.*}} ; [ DW_TAG_template_value_parameter ]
16// CHECK: [[INTPTR]] = {{.*}}, metadata [[INT]]} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [from int]
17// CHECK: [[TCARG4]] = {{.*}}metadata !"a", metadata [[MEMINTPTR:![0-9]*]], i64 8, {{.*}} ; [ DW_TAG_template_value_parameter ]
18// CHECK: [[MEMINTPTR]] = {{.*}}, metadata [[FOO:![0-9]*]]} ; [ DW_TAG_ptr_to_member_type ] {{.*}}[from int]
19//
20// We could just emit a declaration of 'foo' here, rather than the entire
21// definition (same goes for any time we emit a member (function or data)
22// pointer type)
23// CHECK: [[FOO]] = {{.*}} ; [ DW_TAG_structure_type ] [foo]
24// CHECK: metadata !"f", metadata !"_ZN3foo1fEv", i32 {{[0-9]*}}, metadata [[FTYPE:![0-9]*]],
25// CHECK: [[FTYPE:![0-9]*]] = {{.*}}, metadata [[FARGS:![0-9]*]], i32 0, i32 0} ; [ DW_TAG_subroutine_type ]
26// CHECK: [[FARGS]] = metadata !{null, metadata [[FARG1:![0-9]*]]}
27// CHECK: [[FARG1]] = {{.*}} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [artificial] [from foo]
28//
29// Currently Clang emits the pointer-to-member-function value, but LLVM doesn't
30// use it (GCC doesn't emit a value for pointers to member functions either - so
31// it's not clear what, if any, format would be acceptable to GDB)
32//
33// CHECK: [[TCARG5]] = {{.*}}metadata !"b", metadata [[MEMFUNPTR:![0-9]*]], { i64, i64 } { i64 ptrtoint (void (%struct.foo*)* @_ZN3foo1fEv to i64), i64 0 }, {{.*}} ; [ DW_TAG_template_value_parameter ]
34// CHECK: [[MEMFUNPTR]] = {{.*}}, metadata [[FTYPE]], metadata [[FOO]]} ; [ DW_TAG_ptr_to_member_type ]
35
36
37// CHECK: metadata [[TCNT:![0-9]*]], i32 0, i32 1, %class.TC.0* @tcn, null} ; [ DW_TAG_variable ] [tcn]
38// CHECK: [[TCNT:![0-9]*]] = {{.*}}, metadata [[TCNARGS:![0-9]*]]} ; [ DW_TAG_class_type ] [TC<int, -3, nullptr, nullptr, nullptr>]
39// CHECK: [[TCNARGS]] = metadata !{metadata [[TCNARG1:![0-9]*]], metadata [[TCNARG2:![0-9]*]], metadata [[TCNARG3:![0-9]*]], metadata [[TCNARG4:![0-9]*]], metadata [[TCNARG5:![0-9]*]]}
40// CHECK: [[TCNARG1]] = {{.*}}metadata !"T", metadata [[INT]], {{.*}} ; [ DW_TAG_template_type_parameter ]
41// CHECK: [[TCNARG2]] = {{.*}}metadata !"", metadata [[INT]], i32 -3, {{.*}} ; [ DW_TAG_template_value_parameter ]
42// CHECK: [[TCNARG3]] = {{.*}}metadata !"x", metadata [[INTPTR]], i8 0, {{.*}} ; [ DW_TAG_template_value_parameter ]
43
44// The interesting null pointer: -1 for member data pointers (since they are
45// just an offset in an object, they can be zero and non-null for the first
46// member)
47
48// CHECK: [[TCNARG4]] = {{.*}}metadata !"a", metadata [[MEMINTPTR]], i64 -1, {{.*}} ; [ DW_TAG_template_value_parameter ]
49//
50// In some future iteration we could possibly emit the value of a null member
51// function pointer as '{ i64, i64 } zeroinitializer' as it may be handled
52// naturally from the LLVM CodeGen side once we decide how to handle non-null
53// member function pointers. For now, it's simpler just to emit the 'i8 0'.
54//
55// CHECK: [[TCNARG5]] = {{.*}}metadata !"b", metadata [[MEMFUNPTR:![0-9]*]], i8 0, {{.*}} ; [ DW_TAG_template_value_parameter ]
56struct foo {
57  char pad[8]; // make the member pointer to 'e' a bit more interesting (nonzero)
58  int e;
59  void f();
60};
61
62template<typename T, T, int *x, int foo::*a, void (foo::*b)()>
63class TC {
64};
65
66int glb;
67
68TC<unsigned, 2, &glb, &foo::e, &foo::f> tci;
69TC<int, -3, nullptr, nullptr, nullptr> tcn;
70