[llvm-commits] [llvm-gcc-4.2] r66402 - /llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
Chris Lattner
sabre at nondot.org
Sun Mar 8 22:45:28 PDT 2009
Author: lattner
Date: Mon Mar 9 00:45:27 2009
New Revision: 66402
URL: http://llvm.org/viewvc/llvm-project?rev=66402&view=rev
Log:
Fix PR3744 - Crash on index into zero element struct.
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=66402&r1=66401&r2=66402&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Mon Mar 9 00:45:27 2009
@@ -5992,9 +5992,15 @@
// If this is a normal field at a fixed offset from the start, handle it.
if (TREE_CODE(field_offset) == INTEGER_CST) {
unsigned int MemberIndex = GetFieldIndex(FieldDecl);
- assert(MemberIndex < StructTy->getNumContainedTypes() &&
- "Field Idx out of range!");
- FieldPtr = Builder.CreateStructGEP(StructAddrLV.Ptr, MemberIndex);
+
+ // If the LLVM struct has zero field, don't try to index into it, just use
+ // the current pointer.
+ FieldPtr = StructAddrLV.Ptr;
+ if (StructTy->getNumContainedTypes() != 0) {
+ assert(MemberIndex < StructTy->getNumContainedTypes() &&
+ "Field Idx out of range!");
+ FieldPtr = Builder.CreateStructGEP(FieldPtr, MemberIndex);
+ }
// Now that we did an offset from the start of the struct, subtract off
// the offset from BitStart.
More information about the llvm-commits
mailing list