1; RUN: llc < %s -filetype=obj | llvm-readobj - --codeview | FileCheck %s 2; RUN: llc < %s | llvm-mc -filetype=obj --triple=x86_64-windows | llvm-readobj - --codeview | FileCheck %s 3; 4; Verify CodeView emission does not emit forward references for unnamed 5; structs/unions. If a forward reference is emitted for an unnamed composite 6; type then Visual Studio will not be able to display the value. 7; 8; Previous values displayed by Visual Studio: 9; local.unnamed_struct {...} 10; local.unnamed_union {...} 11; 12; New values displayed by Visual Studio: 13; local.unnamed_struct {m3=66 'B' } 14; local.unnamed_union {m1=65 m2=65 'A' } 15; 16; The reproducer: 17; $ cat unnamed.c 18; struct named_struct { 19; int id; 20; union { 21; int m1; 22; char m2; 23; } unnamed_union; 24; struct { 25; char m3; 26; } unnamed_struct; 27; }; 28; 29; int main() 30; { 31; struct named_struct local; 32; 33; local.id = 1; 34; local.unnamed_union.m1 = 65; 35; local.unnamed_struct.m3 = 'B'; 36; 37; return 0; 38; } 39; 40; To regenerate the IR below: 41; $ clang unnamed.c -S -emit-llvm -g -gcodeview 42; 43; CHECK: FieldList ([[UnnamedUnionFieldList:.*]]) { 44; CHECK-NEXT: TypeLeafKind: LF_FIELDLIST (0x1203) 45; CHECK-NEXT: DataMember { 46; CHECK-NEXT: TypeLeafKind: LF_MEMBER (0x150D) 47; CHECK-NEXT: AccessSpecifier: Public (0x3) 48; CHECK-NEXT: Type: int (0x74) 49; CHECK-NEXT: FieldOffset: 0x0 50; CHECK-NEXT: Name: m1 51; CHECK-NEXT: } 52; CHECK-NEXT: DataMember { 53; CHECK-NEXT: TypeLeafKind: LF_MEMBER (0x150D) 54; CHECK-NEXT: AccessSpecifier: Public (0x3) 55; CHECK-NEXT: Type: char (0x70) 56; CHECK-NEXT: FieldOffset: 0x0 57; CHECK-NEXT: Name: m2 58; CHECK-NEXT: } 59; CHECK-NEXT: } 60; CHECK: Union ([[UnnamedUnion:.*]]) { 61; CHECK-NEXT: TypeLeafKind: LF_UNION (0x1506) 62; CHECK-NEXT: MemberCount: 2 63; CHECK-NEXT: Properties [ (0x408) 64; CHECK-NEXT: Nested (0x8) 65; CHECK-NEXT: Sealed (0x400) 66; CHECK-NEXT: ] 67; CHECK-NEXT: FieldList: <field list> ([[UnnamedUnionFieldList]]) 68; CHECK-NEXT: SizeOf: 4 69; CHECK-NEXT: Name: named_struct::<unnamed-tag> 70; CHECK-NEXT: } 71; CHECK: FieldList ([[UnnamedStructFieldList:.*]]) { 72; CHECK-NEXT: TypeLeafKind: LF_FIELDLIST (0x1203) 73; CHECK-NEXT: DataMember { 74; CHECK-NEXT: TypeLeafKind: LF_MEMBER (0x150D) 75; CHECK-NEXT: AccessSpecifier: Public (0x3) 76; CHECK-NEXT: Type: char (0x70) 77; CHECK-NEXT: FieldOffset: 0x0 78; CHECK-NEXT: Name: m3 79; CHECK-NEXT: } 80; CHECK-NEXT: } 81; CHECK: Struct ([[UnnamedStruct:.*]]) { 82; CHECK-NEXT: TypeLeafKind: LF_STRUCTURE (0x1505) 83; CHECK-NEXT: MemberCount: 1 84; CHECK-NEXT: Properties [ (0x8) 85; CHECK-NEXT: Nested (0x8) 86; CHECK-NEXT: ] 87; CHECK-NEXT: FieldList: <field list> ([[UnnamedStructFieldList]]) 88; CHECK-NEXT: DerivedFrom: 0x0 89; CHECK-NEXT: VShape: 0x0 90; CHECK-NEXT: SizeOf: 1 91; CHECK-NEXT: Name: named_struct::<unnamed-tag> 92; CHECK-NEXT: } 93; CHECK: FieldList ([[NamedStructFieldList:.*]]) { 94; CHECK-NEXT: TypeLeafKind: LF_FIELDLIST (0x1203) 95; CHECK-NEXT: DataMember { 96; CHECK-NEXT: TypeLeafKind: LF_MEMBER (0x150D) 97; CHECK-NEXT: AccessSpecifier: Public (0x3) 98; CHECK-NEXT: Type: int (0x74) 99; CHECK-NEXT: FieldOffset: 0x0 100; CHECK-NEXT: Name: id 101; CHECK-NEXT: } 102; CHECK-NEXT: DataMember { 103; CHECK-NEXT: TypeLeafKind: LF_MEMBER (0x150D) 104; CHECK-NEXT: AccessSpecifier: Public (0x3) 105; CHECK-NEXT: Type: named_struct::<unnamed-tag> ([[UnnamedUnion]]) 106; CHECK-NEXT: FieldOffset: 0x4 107; CHECK-NEXT: Name: unnamed_union 108; CHECK-NEXT: } 109; CHECK-NEXT: DataMember { 110; CHECK-NEXT: TypeLeafKind: LF_MEMBER (0x150D) 111; CHECK-NEXT: AccessSpecifier: Public (0x3) 112; CHECK-NEXT: Type: named_struct::<unnamed-tag> ([[UnnamedStruct]]) 113; CHECK-NEXT: FieldOffset: 0x8 114; CHECK-NEXT: Name: unnamed_struct 115; CHECK-NEXT: } 116; CHECK-NEXT: } 117; CHECK: Struct ({{.*}}) { 118; CHECK-NEXT: TypeLeafKind: LF_STRUCTURE (0x1505) 119; CHECK-NEXT: MemberCount: 3 120; CHECK-NEXT: Properties [ (0x0) 121; CHECK-NEXT: ] 122; CHECK-NEXT: FieldList: <field list> ([[NamedStructFieldList]]) 123; CHECK-NEXT: DerivedFrom: 0x0 124; CHECK-NEXT: VShape: 0x0 125; CHECK-NEXT: SizeOf: 12 126; CHECK-NEXT: Name: named_struct 127; CHECK-NEXT: } 128 129; ModuleID = 'unnamed.c' 130source_filename = "unnamed.c" 131target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" 132target triple = "x86_64-pc-windows-msvc19.0.24210" 133 134%struct.named_struct = type { i32, %union.anon, %struct.anon } 135%union.anon = type { i32 } 136%struct.anon = type { i8 } 137 138; Function Attrs: noinline nounwind uwtable 139define i32 @main() #0 !dbg !7 { 140entry: 141 %retval = alloca i32, align 4 142 %local = alloca %struct.named_struct, align 4 143 store i32 0, i32* %retval, align 4 144 call void @llvm.dbg.declare(metadata %struct.named_struct* %local, metadata !11, metadata !25), !dbg !26 145 %id = getelementptr inbounds %struct.named_struct, %struct.named_struct* %local, i32 0, i32 0, !dbg !27 146 store i32 1, i32* %id, align 4, !dbg !28 147 %unnamed_union = getelementptr inbounds %struct.named_struct, %struct.named_struct* %local, i32 0, i32 1, !dbg !29 148 %m1 = bitcast %union.anon* %unnamed_union to i32*, !dbg !30 149 store i32 65, i32* %m1, align 4, !dbg !31 150 %unnamed_struct = getelementptr inbounds %struct.named_struct, %struct.named_struct* %local, i32 0, i32 2, !dbg !32 151 %m3 = getelementptr inbounds %struct.anon, %struct.anon* %unnamed_struct, i32 0, i32 0, !dbg !33 152 store i8 66, i8* %m3, align 4, !dbg !34 153 ret i32 0, !dbg !35 154} 155 156; Function Attrs: nounwind readnone 157declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 158 159attributes #0 = { noinline nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } 160attributes #1 = { nounwind readnone } 161 162!llvm.dbg.cu = !{!0} 163!llvm.module.flags = !{!3, !4, !5} 164!llvm.ident = !{!6} 165 166!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 5.0.0 (trunk)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) 167!1 = !DIFile(filename: "unnamed.c", directory: "C:\5Cpath\5Cto\5Cdirectory", checksumkind: CSK_MD5, checksum: "a1874da39665a126d6949d929fbd4818") 168!2 = !{} 169!3 = !{i32 2, !"CodeView", i32 1} 170!4 = !{i32 2, !"Debug Info Version", i32 3} 171!5 = !{i32 1, !"PIC Level", i32 2} 172!6 = !{!"clang version 5.0.0 (trunk)"} 173!7 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 12, type: !8, isLocal: false, isDefinition: true, scopeLine: 13, isOptimized: false, unit: !0, retainedNodes: !2) 174!8 = !DISubroutineType(types: !9) 175!9 = !{!10} 176!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 177!11 = !DILocalVariable(name: "local", scope: !7, file: !1, line: 14, type: !12) 178!12 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "named_struct", file: !1, line: 1, size: 96, elements: !13) 179!13 = !{!14, !15, !21} 180!14 = !DIDerivedType(tag: DW_TAG_member, name: "id", scope: !12, file: !1, line: 2, baseType: !10, size: 32) 181!15 = !DIDerivedType(tag: DW_TAG_member, name: "unnamed_union", scope: !12, file: !1, line: 6, baseType: !16, size: 32, offset: 32) 182!16 = distinct !DICompositeType(tag: DW_TAG_union_type, scope: !12, file: !1, line: 3, size: 32, elements: !17) 183!17 = !{!18, !19} 184!18 = !DIDerivedType(tag: DW_TAG_member, name: "m1", scope: !16, file: !1, line: 4, baseType: !10, size: 32) 185!19 = !DIDerivedType(tag: DW_TAG_member, name: "m2", scope: !16, file: !1, line: 5, baseType: !20, size: 8) 186!20 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) 187!21 = !DIDerivedType(tag: DW_TAG_member, name: "unnamed_struct", scope: !12, file: !1, line: 9, baseType: !22, size: 8, offset: 64) 188!22 = distinct !DICompositeType(tag: DW_TAG_structure_type, scope: !12, file: !1, line: 7, size: 8, elements: !23) 189!23 = !{!24} 190!24 = !DIDerivedType(tag: DW_TAG_member, name: "m3", scope: !22, file: !1, line: 8, baseType: !20, size: 8) 191!25 = !DIExpression() 192!26 = !DILocation(line: 14, column: 23, scope: !7) 193!27 = !DILocation(line: 16, column: 9, scope: !7) 194!28 = !DILocation(line: 16, column: 12, scope: !7) 195!29 = !DILocation(line: 17, column: 9, scope: !7) 196!30 = !DILocation(line: 17, column: 23, scope: !7) 197!31 = !DILocation(line: 17, column: 26, scope: !7) 198!32 = !DILocation(line: 18, column: 9, scope: !7) 199!33 = !DILocation(line: 18, column: 24, scope: !7) 200!34 = !DILocation(line: 18, column: 27, scope: !7) 201!35 = !DILocation(line: 20, column: 3, scope: !7) 202