blob: 61b3c7c0526c8ef2da867889c734c543aeb17554 [file] [log] [blame]
Douglas Katzman3459ce22015-10-08 04:24:12 +00001// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple x86_64-linux-gnu %s -o - | FileCheck %s
Eric Christophercab9fae2014-04-10 05:20:00 +00002
3// Make sure that we emit a global variable for each of the members of the
4// anonymous union.
5
6static union {
7 int c;
8 int d;
9 union {
10 int a;
11 };
12 struct {
13 int b;
14 };
15};
16
17int test_it() {
18 c = 1;
19 d = 2;
20 a = 4;
21 return (c == 1);
22}
23
Adrian Prantl00820ab2015-04-29 16:52:31 +000024void foo() {
25 union {
26 int i;
27 char c;
28 };
29 i = 8;
30}
31
Reid Kleckner43ecd7c2015-11-20 17:41:12 +000032// A funky reinterpret cast idiom that we used to crash on.
33template <class T>
34unsigned 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
43void instantiate(int x) {
44 buildBytes(x);
45}
46
Amjad Abouddc4531e2016-04-30 01:44:38 +000047// CHECK: !DIGlobalVariable(name: "c",{{.*}} file: [[FILE:.*]], line: 6,{{.*}} isLocal: true, isDefinition: true
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000048// CHECK: !DIGlobalVariable(name: "d",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true
Peter Collingbourneeeb56ab2016-09-13 01:13:19 +000049// CHECK: [[FILE]] = !DIFile(filename: "{{.*}}debug-info-anon-union-vars.cpp",
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000050// 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
Reid Kleckner43ecd7c2015-11-20 17:41:12 +000052// CHECK: !DIGlobalVariable(name: "result", {{.*}} isLocal: false, isDefinition: true
53// CHECK: !DIGlobalVariable(name: "value", {{.*}} isLocal: false, isDefinition: true
Duncan P. N. Exon Smith38a7f112015-07-31 18:59:37 +000054// CHECK: !DILocalVariable(name: "i", {{.*}}, flags: DIFlagArtificial
55// CHECK: !DILocalVariable(name: "c", {{.*}}, flags: DIFlagArtificial
Adrian Prantl00820ab2015-04-29 16:52:31 +000056// CHECK: !DILocalVariable(
57// CHECK-NOT: name:
Amjad Abouddc4531e2016-04-30 01:44:38 +000058// 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]],