Author: adrian Date: Fri Feb 5 19:59:09 2016 New Revision: 259975 URL: http://llvm.org/viewvc/llvm-project?rev=259975&view=rev Log: 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> Added: cfe/trunk/test/CodeGenCXX/debug-info-scoped-class.cpp Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=259975&r1=259974&r2=259975&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original) +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Feb 5 19:59:09 2016 @@ -2051,13 +2051,25 @@ llvm::DIType *CGDebugInfo::CreateEnumTyp // 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))); Added: cfe/trunk/test/CodeGenCXX/debug-info-scoped-class.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-scoped-class.cpp?rev=259975&view=auto ============================================================================== --- cfe/trunk/test/CodeGenCXX/debug-info-scoped-class.cpp (added) +++ cfe/trunk/test/CodeGenCXX/debug-info-scoped-class.cpp Fri Feb 5 19:59:09 2016 @@ -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" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits