diff options
author | Adrian Prantl <aprantl@apple.com> | 2016-02-06 01:59:09 +0000 |
---|---|---|
committer | Adrian Prantl <aprantl@apple.com> | 2016-02-06 01:59:09 +0000 |
commit | a40030f308759728ed4ab55847abff63a8ac2c61 (patch) | |
tree | 36ed5a655aa7626b676d33d3f956aedf6ee1230e | |
parent | b925b9c85f36cddbcd69bdcc44f5725cafe0d7b6 (diff) | |
download | bcm5719-llvm-a40030f308759728ed4ab55847abff63a8ac2c61.tar.gz bcm5719-llvm-a40030f308759728ed4ab55847abff63a8ac2c61.zip |
Fix a crash when emitting dbeug info for forward-declared scoped enums.
It is possible for enums to be created as part of their own
declcontext. We need to cache a placeholder to avoid the type being
created twice before hitting the cache.
<rdar://problem/24493203>
llvm-svn: 259975
-rw-r--r-- | clang/lib/CodeGen/CGDebugInfo.cpp | 14 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/debug-info-scoped-class.cpp | 15 |
2 files changed, 28 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 7bd0e11439f..34dcea11266 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -2051,13 +2051,25 @@ llvm::DIType *CGDebugInfo::CreateEnumType(const EnumType *Ty) { // If this is just a forward declaration, construct an appropriately // marked node and just return it. if (isImportedFromModule || !ED->getDefinition()) { - llvm::DIScope *EDContext = getDeclContextDescriptor(ED); llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation()); + + // It is possible for enums to be created as part of their own + // declcontext. We need to cache a placeholder to avoid the type being + // created twice before hitting the cache. + llvm::DIScope *EDContext = DBuilder.createReplaceableCompositeType( + llvm::dwarf::DW_TAG_enumeration_type, "", TheCU, DefUnit, 0); + unsigned Line = getLineNumber(ED->getLocation()); StringRef EDName = ED->getName(); llvm::DIType *RetTy = DBuilder.createReplaceableCompositeType( llvm::dwarf::DW_TAG_enumeration_type, EDName, EDContext, DefUnit, Line, 0, Size, Align, llvm::DINode::FlagFwdDecl, FullName); + + // Cache the enum type so it is available when building the declcontext + // and replace the declcontect with the real thing. + TypeCache[Ty].reset(RetTy); + EDContext->replaceAllUsesWith(getDeclContextDescriptor(ED)); + ReplaceMap.emplace_back( std::piecewise_construct, std::make_tuple(Ty), std::make_tuple(static_cast<llvm::Metadata *>(RetTy))); diff --git a/clang/test/CodeGenCXX/debug-info-scoped-class.cpp b/clang/test/CodeGenCXX/debug-info-scoped-class.cpp new file mode 100644 index 00000000000..de4aee9a1b4 --- /dev/null +++ b/clang/test/CodeGenCXX/debug-info-scoped-class.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone -std=c++11 \ +// RUN: -triple thumbv7-apple-ios %s -o - | FileCheck %s + +// This forward-declared scoped enum will be created while building its own +// declcontext. Make sure it is only emitted once. + +struct A { + enum class Return; + Return f1(); +}; +A::Return* f2() {} + +// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "Return", +// CHECK-SAME: flags: DIFlagFwdDecl, +// CHECK-NOT: tag: DW_TAG_enumeration_type, name: "Return" |