]> granicus.if.org Git - clang/commitdiff
Fix PR8796.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 29 Dec 2010 23:02:58 +0000 (23:02 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 29 Dec 2010 23:02:58 +0000 (23:02 +0000)
The problem was that we were asserting the we never added an empty class
to the same offset twice. This is not true for unions, where two members, empty
or not, can have the some offset.

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

lib/AST/RecordLayoutBuilder.cpp
test/CodeGenCXX/empty-classes.cpp

index 34d4a7e5865b6f3fb9df9b63275a588c56a23d9c..143fc61da2bd4252930c631668b24d09c345b463 100644 (file)
@@ -216,10 +216,12 @@ void EmptySubobjectMap::AddSubobjectAtOffset(const CXXRecordDecl *RD,
   if (!RD->isEmpty())
     return;
 
+  // If we have empty structures inside an union, we can assign both
+  // the same offset. Just avoid pushing them twice in the list.
   ClassVectorTy& Classes = EmptyClassOffsets[Offset];
-  assert(std::find(Classes.begin(), Classes.end(), RD) == Classes.end() &&
-         "Duplicate empty class detected!");
-
+  if (std::find(Classes.begin(), Classes.end(), RD) != Classes.end())
+    return;
+  
   Classes.push_back(RD);
   
   // Update the empty class offset.
index 59124e3d55b25c0172fde996902a5401417e2ee4..1ce1dad40ffa55b508a2232e2e42aff3e057e5ac 100644 (file)
@@ -53,6 +53,19 @@ int f() {
   return 0;
 }
 
+namespace PR8796 {
+  struct FreeCell {
+  };
+  union ThingOrCell {
+    FreeCell t;
+    FreeCell cell;
+  };
+  struct Things {
+    ThingOrCell things;
+  };
+  Things x;
+}
+
 #ifdef HARNESS
 extern "C" void printf(const char *, ...);