]> granicus.if.org Git - clang/commitdiff
More then one anonymous aggregates on one line creates chaos when MDNode uniquness...
authorDevang Patel <dpatel@apple.com>
Tue, 9 Mar 2010 21:32:27 +0000 (21:32 +0000)
committerDevang Patel <dpatel@apple.com>
Tue, 9 Mar 2010 21:32:27 +0000 (21:32 +0000)
This fixes PR 6554.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98083 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDebugInfo.cpp
lib/CodeGen/CGDebugInfo.h
test/CodeGenCXX/2010-03-09-AnonAggregate.cpp [new file with mode: 0644]

index 892669299c65e4195dc82643c816555aaecda296..02e5d07d6aff9608a6bcc8af8a47ec7c908f4705 100644 (file)
@@ -37,7 +37,7 @@ using namespace clang::CodeGen;
 
 CGDebugInfo::CGDebugInfo(CodeGenModule &CGM)
   : CGM(CGM), DebugFactory(CGM.getModule()),
-    BlockLiteralGenericSet(false) {
+    FwdDeclCount(0), BlockLiteralGenericSet(false) {
   CreateCompileUnit();
 }
 
@@ -774,12 +774,12 @@ llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty,
 
   // A RD->getName() is not unique. However, the debug info descriptors 
   // are uniqued so use type name to ensure uniquness.
-  std::string STy = QualType(Ty, 0).getAsString();
+  char *FwdDeclName = (char *)alloca(65);
+  sprintf(FwdDeclName, "fwd.type.%d", FwdDeclCount++);
   llvm::DIDescriptor FDContext = 
     getContextDescriptor(dyn_cast<Decl>(RD->getDeclContext()), Unit);
   llvm::DICompositeType FwdDecl =
-    DebugFactory.CreateCompositeType(Tag, FDContext,
-                                     STy.c_str(),
+    DebugFactory.CreateCompositeType(Tag, FDContext, FwdDeclName,
                                      DefUnit, Line, 0, 0, 0, 0,
                                      llvm::DIType(), llvm::DIArray());
 
index f71f3626be0be725c545ecd00efa96cf1bb9eec5..47a462048342ba191c36257be39d8790153acecb 100644 (file)
@@ -45,11 +45,11 @@ class CGDebugInfo {
   CodeGenModule &CGM;
   llvm::DIFactory DebugFactory;
   llvm::DICompileUnit TheCU;
-
   SourceLocation CurLoc, PrevLoc;
-  
   llvm::DIType VTablePtrType;
-
+  /// FwdDeclCount - This counter is used to ensure unique names for forward
+  /// record decls.
+  unsigned FwdDeclCount;
   
   /// TypeCache - Cache of previously constructed Types.
   // FIXME: Eliminate this map.  Be careful of iterator invalidation.
diff --git a/test/CodeGenCXX/2010-03-09-AnonAggregate.cpp b/test/CodeGenCXX/2010-03-09-AnonAggregate.cpp
new file mode 100644 (file)
index 0000000..99883d8
--- /dev/null
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -g -S -o %t %s
+// PR: 6554
+// More then one anonymous aggregates on one line creates chaos when MDNode uniquness is 
+// combined with RAUW operation.
+// This test case causes crashes if malloc is configured to trip buffer overruns.
+class MO {
+
+  union {       struct {       union {    int BA;       } Val;       int Offset;     } OffsetedInfo;   } Contents; 
+
+};
+
+class MO m;