From ba6fdc57b4be3d65903531a7ad734ccf417cb0a6 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Wed, 24 Oct 2018 00:06:02 +0000 Subject: [PATCH] Debug Info (-gmodules): emit full types for non-anchored template specializations Before this patch, clang would emit a (module-)forward declaration for template instantiations that are not anchored by an explicit template instantiation, but still are guaranteed to be available in an imported module. Unfortunately detecting the owning module doesn't reliably work when local submodule visibility is enabled and the template is inside a cross-module namespace. This make clang debuggable again with -gmodules and LSV enabled. rdar://problem/41552377 llvm-svn: 345109 --- clang/lib/CodeGen/CGDebugInfo.cpp | 9 +++++ clang/test/Modules/ExtDebugInfo.cpp | 4 +- clang/test/Modules/Inputs/lsv-debuginfo/A/ADT.h | 45 ++++++++++++++++++++++ clang/test/Modules/Inputs/lsv-debuginfo/B/B.h | 14 +++++++ clang/test/Modules/Inputs/lsv-debuginfo/C/C.h | 13 +++++++ .../Modules/Inputs/lsv-debuginfo/module.modulemap | 9 +++++ clang/test/Modules/lsv-debuginfo.cpp | 39 +++++++++++++++++++ 7 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 clang/test/Modules/Inputs/lsv-debuginfo/A/ADT.h create mode 100644 clang/test/Modules/Inputs/lsv-debuginfo/B/B.h create mode 100644 clang/test/Modules/Inputs/lsv-debuginfo/C/C.h create mode 100644 clang/test/Modules/Inputs/lsv-debuginfo/module.modulemap create mode 100755 clang/test/Modules/lsv-debuginfo.cpp diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index bcd5338..0d42bef 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -1955,8 +1955,17 @@ static bool isDefinedInClangModule(const RecordDecl *RD) { if (auto *CXXDecl = dyn_cast(RD)) { if (!CXXDecl->isCompleteDefinition()) return false; + // Check wether RD is a template. auto TemplateKind = CXXDecl->getTemplateSpecializationKind(); if (TemplateKind != TSK_Undeclared) { + // Unfortunately getOwningModule() isn't accurate enough to find the + // owning module of a ClassTemplateSpecializationDecl that is inside a + // namespace spanning multiple modules. + bool Explicit = false; + if (auto *TD = dyn_cast(CXXDecl)) + Explicit = TD->isExplicitInstantiationOrSpecialization(); + if (!Explicit && CXXDecl->getEnclosingNamespaceContext()) + return false; // This is a template, check the origin of the first member. if (CXXDecl->field_begin() == CXXDecl->field_end()) return TemplateKind == TSK_ExplicitInstantiationDeclaration; diff --git a/clang/test/Modules/ExtDebugInfo.cpp b/clang/test/Modules/ExtDebugInfo.cpp index c57f1f0..592612b 100644 --- a/clang/test/Modules/ExtDebugInfo.cpp +++ b/clang/test/Modules/ExtDebugInfo.cpp @@ -83,11 +83,11 @@ void foo() { // CHECK: ![[NS]] = !DINamespace(name: "DebugCXX", scope: ![[MOD:[0-9]+]]) // CHECK: ![[MOD]] = !DIModule(scope: null, name: {{.*}}DebugCXX -// This type is anchored in the module by an explicit template instantiation. +// This type is not anchored in the module by an explicit template instantiation. // CHECK: !DICompositeType(tag: DW_TAG_class_type, // CHECK-SAME: name: "Template >", // CHECK-SAME: scope: ![[NS]], -// CHECK-SAME: flags: DIFlagFwdDecl, +// CHECK-SAME: elements: // CHECK-SAME: identifier: "_ZTSN8DebugCXX8TemplateIlNS_6traitsIlEEEE") // This type is anchored in the module by an explicit template instantiation. diff --git a/clang/test/Modules/Inputs/lsv-debuginfo/A/ADT.h b/clang/test/Modules/Inputs/lsv-debuginfo/A/ADT.h new file mode 100644 index 0000000..f48d4f7 --- /dev/null +++ b/clang/test/Modules/Inputs/lsv-debuginfo/A/ADT.h @@ -0,0 +1,45 @@ +#ifndef ADT +#define ADT + +#ifdef WITH_NAMESPACE +namespace llvm { +#endif +template +struct AlignedCharArray { + alignas(Alignment) char buffer[Size]; +}; + +template +class AlignerImpl { + T1 t1; +}; + +template +union SizerImpl { + char arr1[sizeof(T1)]; +}; + +template +struct AlignedCharArrayUnion + : AlignedCharArray), sizeof(SizerImpl)> {}; + +template +struct SmallVectorStorage { + AlignedCharArrayUnion InlineElts[N]; +}; +template +class SmallVector : SmallVectorStorage {}; + +template +struct OptionalStorage { + AlignedCharArrayUnion storage; +}; +template +class Optional { + OptionalStorage Storage; +}; + +#ifdef WITH_NAMESPACE +} // namespace llvm +#endif +#endif diff --git a/clang/test/Modules/Inputs/lsv-debuginfo/B/B.h b/clang/test/Modules/Inputs/lsv-debuginfo/B/B.h new file mode 100644 index 0000000..c00bc3c --- /dev/null +++ b/clang/test/Modules/Inputs/lsv-debuginfo/B/B.h @@ -0,0 +1,14 @@ +#ifndef B_H +#define B_H +#include +#include + +namespace llvm { +struct S { + unsigned a, b, c, d; +}; +class C { + Optional S; +}; +} +#endif diff --git a/clang/test/Modules/Inputs/lsv-debuginfo/C/C.h b/clang/test/Modules/Inputs/lsv-debuginfo/C/C.h new file mode 100644 index 0000000..52c6e4d --- /dev/null +++ b/clang/test/Modules/Inputs/lsv-debuginfo/C/C.h @@ -0,0 +1,13 @@ +#ifndef C_H +#define C_H +#include + +namespace llvm { +class D { + struct Q { + unsigned a, b, c, d; + }; + SmallVector q; +}; +} // namespace llvm +#endif diff --git a/clang/test/Modules/Inputs/lsv-debuginfo/module.modulemap b/clang/test/Modules/Inputs/lsv-debuginfo/module.modulemap new file mode 100644 index 0000000..5bb0449 --- /dev/null +++ b/clang/test/Modules/Inputs/lsv-debuginfo/module.modulemap @@ -0,0 +1,9 @@ +module A { + umbrella "A" module * { export * } +} +module B { + umbrella "B" module * { export * } +} +module C { + umbrella "C" module * { export * } +} diff --git a/clang/test/Modules/lsv-debuginfo.cpp b/clang/test/Modules/lsv-debuginfo.cpp new file mode 100755 index 0000000..4a2644f --- /dev/null +++ b/clang/test/Modules/lsv-debuginfo.cpp @@ -0,0 +1,39 @@ +// Test C++ -gmodules debug info in the PCMs with local submodule visibility. +// REQUIRES: asserts +// RUN: rm -rf %t +// RUN: %clang_cc1 -triple %itanium_abi_triple \ +// RUN: -fmodules-local-submodule-visibility %s \ +// RUN: -dwarf-ext-refs -fmodule-format=obj -debug-info-kind=standalone \ +// RUN: -dwarf-version=4 -fmodules -fimplicit-module-maps \ +// RUN: -fmodules-cache-path="%t" -o %t.ll -I%S/Inputs/lsv-debuginfo \ +// RUN: -mllvm -debug-only=pchcontainer &>%t-mod.ll +// RUN: cat %t-mod.ll | FileCheck %s + +// RUN: rm -rf %t +// RUN: %clang_cc1 -triple %itanium_abi_triple \ +// RUN: -fmodules-local-submodule-visibility %s \ +// RUN: -dwarf-ext-refs -fmodule-format=obj -debug-info-kind=standalone \ +// RUN: -dwarf-version=4 -fmodules -fimplicit-module-maps \ +// RUN: -fmodules-cache-path="%t" -o %t.ll -I%S/Inputs/lsv-debuginfo \ +// RUN: -mllvm -debug-only=pchcontainer &>%t-mod.ll \ +// RUN: -DWITH_NAMESPACE +// RUN: cat %t-mod.ll | FileCheck %s + +// ADT +// CHECK: @__clang_ast = + +// B +// CHECK: @__clang_ast = + +// This type isn't anchored anywhere, expect a full definition. +// CHECK: !DICompositeType({{.*}}, name: "AlignedCharArray<4, 16>", +// CHECK-SAME: elements: + +// C +// CHECK: @__clang_ast = + +// Here, too. +// CHECK: !DICompositeType({{.*}}, name: "AlignedCharArray<4, 16>", +// CHECK-SAME: elements: + +#include -- 2.7.4