Re: r345109 - Debug Info (-gmodules): emit full types for non-anchored template specializations
Fair enough - pity we couldn't readily have a single implementation or at least semantics for modular debug info between implicit and explicit modes (I mean, my fault in part for building a separate/new system when I did modular codegen anyway) but hopefully we'll move to explicit modules across the board in the future anyway & standardize there. Thanks for the context! On Mon, Oct 29, 2018 at 12:32 PM Adrian Prantl wrote: > > > > On Oct 29, 2018, at 11:26 AM, David Blaikie wrote: > > > > Is this a workaround for now with the intent to fix this to allow such > implicit specializations to have their debug info modularized? I believe > this does work correctly in modular debug info with expliict modules, would > probably be sort of nice to have these things be consistent/similar? > > It started as a workaround, but I reached the conclusion that it's not > worthwhile pursuing a more space-efficient solution. Note that all this > patch does is emit plain old non-modular debug info for non-explicit > template specializations, so it is definitely safe & conservative. This > increases the size of the clang module cache in a build of clang by 4MiB > out of 1GiB total. > > As you can read in my thread with Richard, it isn't possible in Clang to > determine the clang module that contains the complete definition of a > template specialization inside of a namespace for indirectly imported > modules (such as in my testcase). That means that a consumer would have to > look in every Clang module for complete types; not just in the transitive > closure of imports of the .pcm that has the forward declaration. This > lookup is expensive and difficult to implement in LLDB, so I decided not to > pursue this further. > > -- adrian > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r345109 - Debug Info (-gmodules): emit full types for non-anchored template specializations
> On Oct 29, 2018, at 11:26 AM, David Blaikie wrote: > > Is this a workaround for now with the intent to fix this to allow such > implicit specializations to have their debug info modularized? I believe this > does work correctly in modular debug info with expliict modules, would > probably be sort of nice to have these things be consistent/similar? It started as a workaround, but I reached the conclusion that it's not worthwhile pursuing a more space-efficient solution. Note that all this patch does is emit plain old non-modular debug info for non-explicit template specializations, so it is definitely safe & conservative. This increases the size of the clang module cache in a build of clang by 4MiB out of 1GiB total. As you can read in my thread with Richard, it isn't possible in Clang to determine the clang module that contains the complete definition of a template specialization inside of a namespace for indirectly imported modules (such as in my testcase). That means that a consumer would have to look in every Clang module for complete types; not just in the transitive closure of imports of the .pcm that has the forward declaration. This lookup is expensive and difficult to implement in LLDB, so I decided not to pursue this further. -- adrian ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r345109 - Debug Info (-gmodules): emit full types for non-anchored template specializations
Is this a workaround for now with the intent to fix this to allow such implicit specializations to have their debug info modularized? I believe this does work correctly in modular debug info with expliict modules, would probably be sort of nice to have these things be consistent/similar? On Tue, Oct 23, 2018 at 5:08 PM Adrian Prantl via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Author: adrian > Date: Tue Oct 23 17:06:02 2018 > New Revision: 345109 > > URL: http://llvm.org/viewvc/llvm-project?rev=345109&view=rev > Log: > 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 > > Added: > cfe/trunk/test/Modules/Inputs/lsv-debuginfo/ > cfe/trunk/test/Modules/Inputs/lsv-debuginfo/A/ > cfe/trunk/test/Modules/Inputs/lsv-debuginfo/A/ADT.h > cfe/trunk/test/Modules/Inputs/lsv-debuginfo/B/ > cfe/trunk/test/Modules/Inputs/lsv-debuginfo/B/B.h > cfe/trunk/test/Modules/Inputs/lsv-debuginfo/C/ > cfe/trunk/test/Modules/Inputs/lsv-debuginfo/C/C.h > cfe/trunk/test/Modules/Inputs/lsv-debuginfo/module.modulemap > cfe/trunk/test/Modules/lsv-debuginfo.cpp (with props) > Modified: > cfe/trunk/lib/CodeGen/CGDebugInfo.cpp > cfe/trunk/test/Modules/ExtDebugInfo.cpp > > Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=345109&r1=345108&r2=345109&view=diff > > == > --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original) > +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Oct 23 17:06:02 2018 > @@ -1955,8 +1955,17 @@ static bool isDefinedInClangModule(const >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; > > Modified: cfe/trunk/test/Modules/ExtDebugInfo.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/ExtDebugInfo.cpp?rev=345109&r1=345108&r2=345109&view=diff > > == > --- cfe/trunk/test/Modules/ExtDebugInfo.cpp (original) > +++ cfe/trunk/test/Modules/ExtDebugInfo.cpp Tue Oct 23 17:06:02 2018 > @@ -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_6traitsIl") > > // This type is anchored in the module by an explicit template > instantiation. > > Added: cfe/trunk/test/Modules/Inputs/lsv-debuginfo/A/ADT.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/lsv-debuginfo/A/ADT.h?rev=345109&view=auto > > == > --- cfe/trunk/test/Modules/Inputs/lsv-debuginfo/A/ADT.h (added) > +++ cfe/trunk/test/Modules/Inputs/lsv-debuginfo/A/ADT.h Tue Oct 23 > 17:06:02 2018 > @@ -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)]; > +}
r345109 - Debug Info (-gmodules): emit full types for non-anchored template specializations
Author: adrian Date: Tue Oct 23 17:06:02 2018 New Revision: 345109 URL: http://llvm.org/viewvc/llvm-project?rev=345109&view=rev Log: 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 Added: cfe/trunk/test/Modules/Inputs/lsv-debuginfo/ cfe/trunk/test/Modules/Inputs/lsv-debuginfo/A/ cfe/trunk/test/Modules/Inputs/lsv-debuginfo/A/ADT.h cfe/trunk/test/Modules/Inputs/lsv-debuginfo/B/ cfe/trunk/test/Modules/Inputs/lsv-debuginfo/B/B.h cfe/trunk/test/Modules/Inputs/lsv-debuginfo/C/ cfe/trunk/test/Modules/Inputs/lsv-debuginfo/C/C.h cfe/trunk/test/Modules/Inputs/lsv-debuginfo/module.modulemap cfe/trunk/test/Modules/lsv-debuginfo.cpp (with props) Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp cfe/trunk/test/Modules/ExtDebugInfo.cpp Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=345109&r1=345108&r2=345109&view=diff == --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original) +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Oct 23 17:06:02 2018 @@ -1955,8 +1955,17 @@ static bool isDefinedInClangModule(const 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; Modified: cfe/trunk/test/Modules/ExtDebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/ExtDebugInfo.cpp?rev=345109&r1=345108&r2=345109&view=diff == --- cfe/trunk/test/Modules/ExtDebugInfo.cpp (original) +++ cfe/trunk/test/Modules/ExtDebugInfo.cpp Tue Oct 23 17:06:02 2018 @@ -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_6traitsIl") // This type is anchored in the module by an explicit template instantiation. Added: cfe/trunk/test/Modules/Inputs/lsv-debuginfo/A/ADT.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/lsv-debuginfo/A/ADT.h?rev=345109&view=auto == --- cfe/trunk/test/Modules/Inputs/lsv-debuginfo/A/ADT.h (added) +++ cfe/trunk/test/Modules/Inputs/lsv-debuginfo/A/ADT.h Tue Oct 23 17:06:02 2018 @@ -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 Added: cfe/trunk/test/Modules/Inputs/lsv-debuginfo/B/B.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/lsv-debuginfo/B/B.h?rev=345109&view=auto