1 | // RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple x86_64-linux-gnu %s -o - | FileCheck %s |
2 | |
3 | // Make sure that we emit a global variable for each of the members of the |
4 | // anonymous union. |
5 | |
6 | static union { |
7 | int c; |
8 | int d; |
9 | union { |
10 | int a; |
11 | }; |
12 | struct { |
13 | int b; |
14 | }; |
15 | }; |
16 | |
17 | int test_it() { |
18 | c = 1; |
19 | d = 2; |
20 | a = 4; |
21 | return (c == 1); |
22 | } |
23 | |
24 | void foo() { |
25 | union { |
26 | int i; |
27 | char c; |
28 | }; |
29 | i = 8; |
30 | } |
31 | |
32 | // A funky reinterpret cast idiom that we used to crash on. |
33 | template <class T> |
34 | unsigned char *buildBytes(const T v) { |
35 | static union { |
36 | unsigned char result[sizeof(T)]; |
37 | T value; |
38 | }; |
39 | value = v; |
40 | return result; |
41 | } |
42 | |
43 | void instantiate(int x) { |
44 | buildBytes(x); |
45 | } |
46 | |
47 | // CHECK: !DIGlobalVariable(name: "c",{{.*}} file: [[FILE:.*]], line: 6,{{.*}} isLocal: true, isDefinition: true |
48 | // CHECK: !DIGlobalVariable(name: "d",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true |
49 | // CHECK: [[FILE]] = !DIFile(filename: "{{.*}}debug-info-anon-union-vars.cpp", |
50 | // CHECK: !DIGlobalVariable(name: "a",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true |
51 | // CHECK: !DIGlobalVariable(name: "b",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true |
52 | // CHECK: !DIGlobalVariable(name: "result", {{.*}} isLocal: false, isDefinition: true |
53 | // CHECK: !DIGlobalVariable(name: "value", {{.*}} isLocal: false, isDefinition: true |
54 | // CHECK: !DILocalVariable(name: "i", {{.*}}, flags: DIFlagArtificial |
55 | // CHECK: !DILocalVariable(name: "c", {{.*}}, flags: DIFlagArtificial |
56 | // CHECK: !DILocalVariable( |
57 | // CHECK-NOT: name: |
58 | // CHECK: type: ![[UNION:[0-9]+]] |
59 | // CHECK: ![[UNION]] = distinct !DICompositeType(tag: DW_TAG_union_type, |
60 | // CHECK-NOT: name: |
61 | // CHECK: elements |
62 | // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "i", scope: ![[UNION]], |
63 | // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "c", scope: ![[UNION]], |
64 | |