[llvm-commits] [llvm-gcc-4.2] r58458 - /llvm-gcc-4.2/trunk/gcc/llvm-types.cpp
Duncan Sands
baldrick at free.fr
Thu Oct 30 14:12:40 PDT 2008
Author: baldrick
Date: Thu Oct 30 16:12:33 2008
New Revision: 58458
URL: http://llvm.org/viewvc/llvm-project?rev=58458&view=rev
Log:
Fix PR2987, a long standing if fairly harmless
bug which could result in zero sized fields
being indexed to wrong LLVM fields. In the
testcase it was indexed to a field 2 bytes
into the struct when it should have been 4
bytes in. This bug was exposed by extra
sanity checking I added in commit 58387.
Modified:
llvm-gcc-4.2/trunk/gcc/llvm-types.cpp
Modified: llvm-gcc-4.2/trunk/gcc/llvm-types.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-types.cpp?rev=58458&r1=58457&r2=58458&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-types.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-types.cpp Thu Oct 30 16:12:33 2008
@@ -1553,22 +1553,22 @@
// Handle zero sized fields now.
// Skip over LLVM fields that start and end before the GCC field starts.
- // Such fields are always nonzero sized, and we don't want to skip past
+ // Such fields are always nonzero sized, and we don't want to skip past
// zero sized ones as well, which happens if you use only the Offset
// comparison.
while (CurFieldNo < ElementOffsetInBytes.size() &&
- getFieldEndOffsetInBytes(CurFieldNo)*8 <= FieldOffsetInBits &&
- ElementSizeInBytes[CurFieldNo] != 0)
+ getFieldEndOffsetInBytes(CurFieldNo)*8 <
+ FieldOffsetInBits + (ElementSizeInBytes[CurFieldNo] != 0))
++CurFieldNo;
- // If the next field is zero sized, advance past this one. This is a nicety
- // that causes us to assign C fields different LLVM fields in cases like
+ // If the next field is zero sized, advance past this one. This is a nicety
+ // that causes us to assign C fields different LLVM fields in cases like
// struct X {}; struct Y { struct X a, b, c };
if (CurFieldNo+1 < ElementOffsetInBytes.size() &&
ElementSizeInBytes[CurFieldNo+1] == 0) {
return CurFieldNo++;
}
-
+
// Otherwise, if this is a zero sized field, return it.
if (CurFieldNo < ElementOffsetInBytes.size() &&
ElementSizeInBytes[CurFieldNo] == 0) {
More information about the llvm-commits
mailing list