[llvm-commits] [llvm-gcc-4.2] r127309 - /llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
Stuart Hastings
stuart at apple.com
Tue Mar 8 19:59:41 PST 2011
Author: stuart
Date: Tue Mar 8 21:59:41 2011
New Revision: 127309
URL: http://llvm.org/viewvc/llvm-project?rev=127309&view=rev
Log:
2nd fix for initialized unions. <rdar://problem/9055247>
Modified:
llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=127309&r1=127308&r2=127309&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Tue Mar 8 21:59:41 2011
@@ -8582,13 +8582,27 @@
// Convert the constant itself.
Constant *Val = Convert(VEC_index(constructor_elt, elt, 0)->value);
- // Unions are initialized using the first member field. Find it.
+ // Unions are initialized using the first non-anonymous member field. Find it.
tree Field = TYPE_FIELDS(TREE_TYPE(exp));
+ tree namedField = Field;
+ tree first_field_decl = 0;
assert(Field && "cannot initialize union with no fields");
- while (TREE_CODE(Field) != FIELD_DECL) {
- Field = TREE_CHAIN(Field);
- assert(Field && "cannot initialize union with no fields");
+ while (namedField && (TREE_CODE(namedField) != FIELD_DECL ||
+ DECL_NAME(namedField) == NULL_TREE)) {
+ // Remember the first field_decl we encounter.
+ if (!first_field_decl && TREE_CODE(namedField) == FIELD_DECL)
+ first_field_decl = namedField;
+ namedField = TREE_CHAIN(namedField);
}
+ // If we located a legitimate, named field, prefer it;
+ // failing that, use the first_field_decl we found...
+ if (namedField)
+ Field = namedField;
+ else if (first_field_decl)
+ Field = first_field_decl;
+ // ...else, failing all of the above, use whatever we found at the top.
+
+ assert(Field && "cannot initialize union with no fields");
// If this is a non-bitfield value, just slap it onto the end of the struct
// with the appropriate padding etc. If it is a bitfield, we have more
More information about the llvm-commits
mailing list