225 lines · cpp
1// UNSUPPORTED: target={{.*}}-zos{{.*}}, target={{.*}}-aix{{.*}}2// RUN: rm -rf %t3// Test that only forward declarations are emitted for types defined in modules.4 5// Modules:6// RUN: %clang_cc1 -x objective-c++ -std=c++11 -debug-info-kind=standalone \7// RUN: -dwarf-ext-refs -fmodules \8// RUN: -fmodule-format=obj -fimplicit-module-maps -DMODULES \9// RUN: -triple %itanium_abi_triple \10// RUN: -fmodules-cache-path=%t %s -I %S/Inputs -I %t -emit-llvm -o %t-mod.ll11// RUN: cat %t-mod.ll | FileCheck %s12 13// PCH:14// RUN: %clang_cc1 -x c++ -std=c++11 -fmodule-format=obj -emit-pch -I%S/Inputs \15// RUN: -triple %itanium_abi_triple \16// RUN: -o %t.pch %S/Inputs/DebugCXX.h17// RUN: %clang_cc1 -std=c++11 -debug-info-kind=standalone \18// RUN: -dwarf-ext-refs -fmodule-format=obj \19// RUN: -triple %itanium_abi_triple \20// RUN: -include-pch %t.pch %s -emit-llvm -o %t-pch.ll21// RUN: cat %t-pch.ll | FileCheck %s22// RUN: cat %t-pch.ll | FileCheck %s --check-prefix=CHECK-PCH23 24#ifdef MODULES25@import DebugCXX;26#endif27 28// Set the line number so that the LIT check expected line number doesn't have to be updated after adding/removing a line in the RUN section.29#line 5030using DebugCXX::Struct;31 32Struct s;33DebugCXX::Enum e;34 35// Template instantiations.36DebugCXX::Template<long> implicitTemplate;37DebugCXX::Template<int> explicitTemplate;38DebugCXX::FloatInstantiation typedefTemplate;39DebugCXX::B anchoredTemplate;40 41int Struct::static_member = -1;42enum {43 e3 = -144} conflicting_uid = e3;45auto anon_enum = DebugCXX::e2;46char _anchor = anon_enum + conflicting_uid;47 48TypedefUnion tdu;49TypedefEnum tde;50TypedefStruct tds;51TypedefTemplate tdt;52Template1<int> explicitTemplate1;53 54template <class T> class FwdDeclTemplate { T t; };55TypedefFwdDeclTemplate tdfdt;56 57InAnonymousNamespace anon;58 59// Types that are forward-declared in the module and defined here.60struct PureFwdDecl { int i; };61PureFwdDecl definedLocally;62 63struct Specialized<int>::Member { int i; };64struct Specialized<int>::Member definedLocally2;65 66template <class T> struct FwdDeclTemplateMember<T>::Member { T t; };67TypedefFwdDeclTemplateMember tdfdtm;68 69SpecializedBase definedLocally3;70extern template class WithSpecializedBase<int>;71WithSpecializedBase<int> definedLocally4;72 73void foo() {74 anon.i = GlobalStruct.i = GlobalUnion.i = GlobalEnum;75 A a;76 Virtual virt;77}78 79// CHECK: ![[CPP:.*]] = !DIFile(filename: {{.*}}ExtDebugInfo.cpp"80 81// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum",82// CHECK-SAME: scope: ![[NS:[0-9]+]],83// CHECK-SAME: flags: DIFlagFwdDecl84// CHECK-SAME: identifier: "_ZTSN8DebugCXX4EnumE")85 86// CHECK: ![[NS]] = !DINamespace(name: "DebugCXX", scope: ![[MOD:[0-9]+]])87// CHECK: ![[MOD]] = !DIModule(scope: null, name: {{.*}}DebugCXX88 89// This type is not anchored in the module by an explicit template instantiation.90// CHECK: !DICompositeType(tag: DW_TAG_class_type,91// CHECK-SAME: name: "Template<long, DebugCXX::traits<long> >",92// CHECK-SAME: scope: ![[NS]],93// CHECK-SAME: elements:94// CHECK-SAME: identifier: "_ZTSN8DebugCXX8TemplateIlNS_6traitsIlEEEE")95 96// This type is anchored in the module by an explicit template instantiation.97// CHECK: !DICompositeType(tag: DW_TAG_class_type,98// CHECK-SAME: name: "Template<int, DebugCXX::traits<int> >",99// CHECK-SAME: scope: ![[NS]],100// CHECK-SAME: flags: DIFlagFwdDecl101// CHECK-SAME: identifier: "_ZTSN8DebugCXX8TemplateIiNS_6traitsIiEEEE")102 103// This type isn't, however, even with standalone non-module debug info this104// type is a forward declaration.105// CHECK-NOT: !DICompositeType(tag: DW_TAG_structure_type, name: "traits<int>",106 107// This one isn't.108// CHECK: !DICompositeType(tag: DW_TAG_class_type,109// CHECK-SAME: name: "Template<float, DebugCXX::traits<float> >",110// CHECK-SAME: scope: ![[NS]],111// CHECK-SAME: elements:112// CHECK-SAME: templateParams:113// CHECK-SAME: identifier: "_ZTSN8DebugCXX8TemplateIfNS_6traitsIfEEEE")114 115// This type is anchored in the module by an explicit template instantiation.116// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "traits<float>",117// CHECK-SAME: flags: DIFlagFwdDecl118// CHECK-SAME: identifier: "_ZTSN8DebugCXX6traitsIfEE")119 120 121// This type is anchored in the module via a function argument,122// but we don't know this (yet).123// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "A<void>",124// CHECK-SAME: scope: ![[NS]],125// CHECK-SAME: elements:126// CHECK-SAME: identifier: "_ZTSN8DebugCXX1AIJvEEE")127 128// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "static_member",129// CHECK-SAME: scope: ![[STRUCT:[0-9]*]]130 131// CHECK: ![[STRUCT]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Struct",132// CHECK-SAME: scope: ![[NS]],133// CHECK-SAME: flags: DIFlagFwdDecl134// CHECK-SAME: identifier: "_ZTSN8DebugCXX6StructE")135 136// CHECK: !DICompositeType(tag: DW_TAG_union_type,137// CHECK-SAME: flags: DIFlagFwdDecl138// CHECK-SAME: identifier: "_ZTS12TypedefUnion")139// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,140// CHECK-SAME: flags: DIFlagFwdDecl,141// CHECK-SAME: identifier: "_ZTS11TypedefEnum")142// CHECK: !DICompositeType(tag: DW_TAG_structure_type,143// CHECK-SAME: flags: DIFlagFwdDecl,144// CHECK-SAME: identifier: "_ZTS13TypedefStruct")145 146// This one isn't.147// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "Template1<void *>",148// CHECK-SAME: elements:149// CHECK-SAME: templateParams:150// CHECK-SAME: identifier: "_ZTS9Template1IPvE")151 152// This type is anchored in the module by an explicit template instantiation.153// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "Template1<int>",154// CHECK-SAME: flags: DIFlagFwdDecl,155// CHECK-SAME: identifier: "_ZTS9Template1IiE")156 157// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "FwdDeclTemplate<int>",158// CHECK-SAME: elements:159// CHECK-SAME: templateParams:160// CHECK-SAME: identifier: "_ZTS15FwdDeclTemplateIiE")161 162// This type is defined locally and forward-declared in the module.163// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "PureFwdDecl",164// CHECK-SAME: elements:165// CHECK-SAME: identifier: "_ZTS11PureFwdDecl")166 167// This type is defined locally and forward-declared in the module.168// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Member",169// CHECK-SAME: elements:170// CHECK-SAME: identifier: "_ZTSN11SpecializedIiE6MemberE")171 172// This type is defined locally and forward-declared in the module.173// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Member",174// CHECK-SAME: elements:175// CHECK-SAME: identifier: "_ZTSN21FwdDeclTemplateMemberIiE6MemberE")176 177// This type is defined locally and forward-declared in the module.178// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "SpecializedBase",179// CHECK-SAME: baseType: ![[SPECIALIZEDBASE:.*]])180// CHECK: ![[SPECIALIZEDBASE]] =181// CHECK-SAME: !DICompositeType(tag: DW_TAG_class_type,182// CHECK-SAME: name: "WithSpecializedBase<float>",183// CHECK-SAME: elements:184// CHECK-SAME: identifier: "_ZTS19WithSpecializedBaseIfE")185 186// This type is explicitly specialized locally.187// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "WithSpecializedBase<int>",188// CHECK-SAME: elements:189// CHECK-SAME: identifier: "_ZTS19WithSpecializedBaseIiE")190 191// CHECK: !DIGlobalVariable(name: "anon_enum", {{.*}}, type: ![[ANON_ENUM:[0-9]+]]192// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, scope: ![[NS]],193// CHECK-SAME: line: 19194 195// CHECK: !DIGlobalVariable(name: "GlobalUnion",196// CHECK-SAME: type: ![[GLOBAL_UNION:[0-9]+]]197// CHECK: ![[GLOBAL_UNION]] = distinct !DICompositeType(tag: DW_TAG_union_type,198// CHECK-SAME: elements: !{{[0-9]+}})199// CHECK: !DIGlobalVariable(name: "GlobalStruct",200// CHECK-SAME: type: ![[GLOBAL_STRUCT:[0-9]+]]201// CHECK: ![[GLOBAL_STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type,202// CHECK-SAME: elements: !{{[0-9]+}})203 204 205// CHECK: !DIGlobalVariable(name: "anon",206// CHECK-SAME: type: ![[GLOBAL_ANON:[0-9]+]]207// CHECK: ![[GLOBAL_ANON]] = !DICompositeType(tag: DW_TAG_structure_type,208// CHECK-SAME: name: "InAnonymousNamespace", {{.*}}DIFlagFwdDecl)209 210// There is a full definition of the type available in the module.211// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Virtual",212// CHECK-SAME: DIFlagFwdDecl213// CHECK-SAME: identifier: "_ZTS7Virtual")214 215// CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !{{[0-9]+}}, entity: ![[STRUCT]], file: ![[CPP]], line: 50)216 217// CHECK: !DICompileUnit(218// CHECK-SAME: splitDebugFilename:219// CHECK-SAME: dwoId:220// CHECK-PCH: !DICompileUnit({{.*}}splitDebugFilename:221// CHECK-PCH: dwoId: 18446744073709551614222 223// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "A",224// CHECK-SAME: DIFlagFwdDecl225