[llvm-commits] [dragonegg] r159158 - in /dragonegg/trunk: src/TypeConversion.cpp test/validator/ada/empty_type.adb

Duncan Sands baldrick at free.fr
Mon Jun 25 12:53:12 PDT 2012


Author: baldrick
Date: Mon Jun 25 14:53:12 2012
New Revision: 159158

URL: http://llvm.org/viewvc/llvm-project?rev=159158&view=rev
Log:
Fix a regression caused by commit 155194 ("Stop using DECL_QUALIFIER...").
GCC's folding sometimes doesn't remove fields that aren't actually present
in a qualified union type, but manages to simplify away their contribution
to the type's size.  Adding the field to the LLVM type results in a type
that is too big according to GCC's computed type size.

Added:
    dragonegg/trunk/test/validator/ada/empty_type.adb
Modified:
    dragonegg/trunk/src/TypeConversion.cpp

Modified: dragonegg/trunk/src/TypeConversion.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/TypeConversion.cpp?rev=159158&r1=159157&r2=159158&view=diff
==============================================================================
--- dragonegg/trunk/src/TypeConversion.cpp (original)
+++ dragonegg/trunk/src/TypeConversion.cpp Mon Jun 25 14:53:12 2012
@@ -1136,6 +1136,16 @@
     }
     uint64_t LastBit = FirstBit + BitWidth;
 
+    if (LastBit > TypeSize) {
+      // Qualified union types may list fields that cannot be present, but that
+      // the optimizers weren't smart enough to remove.  It can sometimes happen
+      // that the optimizers nonetheless managed to simplify the type size to a
+      // constant, which can be smaller than the size of the non-present fields
+      // if were larger than the rest.
+      assert(isa<QUAL_UNION_TYPE>(type) && "Field runs off end of type!");
+      LastBit = TypeSize;
+    }
+
     // Set the type of the range of bits occupied by the field to the LLVM type
     // for the field.
     Layout.AddInterval(TypedRange::get(FirstBit, LastBit, FieldTy));

Added: dragonegg/trunk/test/validator/ada/empty_type.adb
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/ada/empty_type.adb?rev=159158&view=auto
==============================================================================
--- dragonegg/trunk/test/validator/ada/empty_type.adb (added)
+++ dragonegg/trunk/test/validator/ada/empty_type.adb Mon Jun 25 14:53:12 2012
@@ -0,0 +1,14 @@
+-- RUN: %dragonegg -S -O1 %s
+procedure Empty_Type is
+   type Rec (Disc : Integer := 1) is
+   record
+      case Disc is
+         when 1..0 => -- Empty range
+            Component : Integer;
+         when others => NULL;
+      end case;
+   end record;
+   R : Rec;
+begin
+   null;
+end;





More information about the llvm-commits mailing list