[llvm-commits] CVS: llvm-gcc/gcc/llvm-types.c llvm-expand.c
Chris Lattner
lattner at cs.uiuc.edu
Tue May 10 15:33:29 PDT 2005
Changes in directory llvm-gcc/gcc:
llvm-types.c updated: 1.20 -> 1.21
llvm-expand.c updated: 1.97 -> 1.98
---
Log message:
Be less paranoid about structures with holes in them for unions. This fixes
PR562: http://llvm.cs.uiuc.edu/PR562 and CFrontend/2005-05-10-GlobalUnionInit.c
---
Diffs of the changes: (+23 -2)
llvm-expand.c | 3 ++-
llvm-types.c | 22 +++++++++++++++++++++-
2 files changed, 23 insertions(+), 2 deletions(-)
Index: llvm-gcc/gcc/llvm-types.c
diff -u llvm-gcc/gcc/llvm-types.c:1.20 llvm-gcc/gcc/llvm-types.c:1.21
--- llvm-gcc/gcc/llvm-types.c:1.20 Sat Dec 4 15:44:55 2004
+++ llvm-gcc/gcc/llvm-types.c Tue May 10 17:33:16 2005
@@ -943,6 +943,26 @@
return TREE_ADDRESSABLE(Type);
}
+/* isStructWithHoles - This function returns true if the specified type is a
+ * struct and if it has inter-element gaps.
+ */
+static isStructWithHoles(llvm_type *Ty) {
+ unsigned i, e;
+ if (Ty->ID != StructTyID) return 0;
+
+ /* Check to see that element i+1 starts at offsetof(i)+sizeof(STy[i]). */
+ for (i = 0, e = Ty->NumElements; i != e-1; ++i)
+ if (Ty->x.Struct.MemberOffsets[i] + llvm_type_get_size(Ty->Elements[i]) !=
+ Ty->x.Struct.MemberOffsets[i+1])
+ return 1;
+
+ /* Check for tail padding. */
+ if (Ty->x.Struct.MemberOffsets[e-1] + llvm_type_get_size(Ty->Elements[e-1]) !=
+ llvm_type_get_size(Ty))
+ return 1;
+ return 0;
+}
+
/* llvm_type_get_tree_type - Return the LLVM type that corresponds to the
* specified tree type. If this is the first time we have seen a structure
* type, we assign indexes to all of the FIELD_DECLs in it.
@@ -1195,7 +1215,7 @@
* FIXME: Couldn't there be arrays that have structure types in them?
* What about alignment? This preserves size but not necessarily alignment!
*/
- if (ElementType->ID == StructTyID) {
+ if (isStructWithHoles(ElementType)) {
assert((MaxSize & 7) == 0 &&
"Only unions that are multiple of byte size expected!");
if (MaxSize & 0xF)
Index: llvm-gcc/gcc/llvm-expand.c
diff -u llvm-gcc/gcc/llvm-expand.c:1.97 llvm-gcc/gcc/llvm-expand.c:1.98
--- llvm-gcc/gcc/llvm-expand.c:1.97 Fri May 6 21:16:47 2005
+++ llvm-gcc/gcc/llvm-expand.c Tue May 10 17:33:16 2005
@@ -3932,7 +3932,8 @@
* So, for now, we will simply assert and stay as compile-fail until
* we can get the whole thing working.
*/
- assert ((FieldSizeTree != NULL_TREE) && "Struct/Union member of unknown length!");
+ assert ((FieldSizeTree != NULL_TREE) &&
+ "Struct/Union member of unknown length!");
FieldSize = TREE_INT_CST_LOW (FieldSizeTree);
assert(FieldIndex && "Structure isn't laid out by LLVM yet!");
More information about the llvm-commits
mailing list