[cfe-commits] r122633 - in /cfe/trunk: lib/AST/RecordLayoutBuilder.cpp test/CodeGenCXX/empty-classes.cpp

Rafael Espindola rafael.espindola at gmail.com
Wed Dec 29 15:02:58 PST 2010


Author: rafael
Date: Wed Dec 29 17:02:58 2010
New Revision: 122633

URL: http://llvm.org/viewvc/llvm-project?rev=122633&view=rev
Log:
Fix PR8796.

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.

Modified:
    cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
    cfe/trunk/test/CodeGenCXX/empty-classes.cpp

Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=122633&r1=122632&r2=122633&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Wed Dec 29 17:02:58 2010
@@ -216,10 +216,12 @@
   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.

Modified: cfe/trunk/test/CodeGenCXX/empty-classes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/empty-classes.cpp?rev=122633&r1=122632&r2=122633&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/empty-classes.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/empty-classes.cpp Wed Dec 29 17:02:58 2010
@@ -53,6 +53,19 @@
   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 *, ...);
 





More information about the cfe-commits mailing list