r345109 - Debug Info (-gmodules): emit full types for non-anchored template specializations

David Blaikie via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 29 11:26:19 PDT 2018


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 at 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<CXXRecordDecl>(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<ClassTemplateSpecializationDecl>(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<long, DebugCXX::traits<long>
> >",
>  // 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.
>
> 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 <unsigned Alignment, unsigned Size>
> +struct AlignedCharArray {
> +  alignas(Alignment) char buffer[Size];
> +};
> +
> +template <typename T1>
> +class AlignerImpl {
> +  T1 t1;
> +};
> +
> +template <typename T1>
> +union SizerImpl {
> +  char arr1[sizeof(T1)];
> +};
> +
> +template <typename T1>
> +struct AlignedCharArrayUnion
> +    : AlignedCharArray<alignof(AlignerImpl<T1>), sizeof(SizerImpl<T1>)>
> {};
> +
> +template <typename T, unsigned N>
> +struct SmallVectorStorage {
> +  AlignedCharArrayUnion<T> InlineElts[N];
> +};
> +template <typename T, unsigned N>
> +class SmallVector : SmallVectorStorage<T, N> {};
> +
> +template <typename T>
> +struct OptionalStorage {
> +  AlignedCharArrayUnion<T> storage;
> +};
> +template <typename T>
> +class Optional {
> +  OptionalStorage<T> 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
>
> ==============================================================================
> --- cfe/trunk/test/Modules/Inputs/lsv-debuginfo/B/B.h (added)
> +++ cfe/trunk/test/Modules/Inputs/lsv-debuginfo/B/B.h Tue Oct 23 17:06:02
> 2018
> @@ -0,0 +1,14 @@
> +#ifndef B_H
> +#define B_H
> +#include <A/ADT.h>
> +#include <C/C.h>
> +
> +namespace llvm {
> +struct S {
> +  unsigned a, b, c, d;
> +};
> +class C {
> +  Optional<S> S;
> +};
> +}
> +#endif
>
> Added: cfe/trunk/test/Modules/Inputs/lsv-debuginfo/C/C.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/lsv-debuginfo/C/C.h?rev=345109&view=auto
>
> ==============================================================================
> --- cfe/trunk/test/Modules/Inputs/lsv-debuginfo/C/C.h (added)
> +++ cfe/trunk/test/Modules/Inputs/lsv-debuginfo/C/C.h Tue Oct 23 17:06:02
> 2018
> @@ -0,0 +1,13 @@
> +#ifndef C_H
> +#define C_H
> +#include <A/ADT.h>
> +
> +namespace llvm {
> +class D {
> +  struct Q {
> +    unsigned a, b, c, d;
> +  };
> +  SmallVector<Q, 4> q;
> +};
> +} // namespace llvm
> +#endif
>
> Added: cfe/trunk/test/Modules/Inputs/lsv-debuginfo/module.modulemap
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/lsv-debuginfo/module.modulemap?rev=345109&view=auto
>
> ==============================================================================
> --- cfe/trunk/test/Modules/Inputs/lsv-debuginfo/module.modulemap (added)
> +++ cfe/trunk/test/Modules/Inputs/lsv-debuginfo/module.modulemap Tue Oct
> 23 17:06:02 2018
> @@ -0,0 +1,9 @@
> +module A {
> +  umbrella "A" module * { export * }
> +}
> +module B {
> +  umbrella "B" module * { export * }
> +}
> +module C {
> +  umbrella "C" module * { export * }
> +}
>
> Added: cfe/trunk/test/Modules/lsv-debuginfo.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/lsv-debuginfo.cpp?rev=345109&view=auto
>
> ==============================================================================
> --- cfe/trunk/test/Modules/lsv-debuginfo.cpp (added)
> +++ cfe/trunk/test/Modules/lsv-debuginfo.cpp Tue Oct 23 17:06:02 2018
> @@ -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 <B/B.h>
>
> Propchange: cfe/trunk/test/Modules/lsv-debuginfo.cpp
>
> ------------------------------------------------------------------------------
>     svn:executable = *
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181029/523ef673/attachment.html>


More information about the cfe-commits mailing list