[llvm-commits] [dragonegg] r169678 - in /dragonegg/trunk: src/ConstantConversion.cpp test/validator/c++/2012-12-08-Padding.cpp
Duncan Sands
baldrick at free.fr
Sat Dec 8 06:38:16 PST 2012
Author: baldrick
Date: Sat Dec 8 08:38:16 2012
New Revision: 169678
URL: http://llvm.org/viewvc/llvm-project?rev=169678&view=rev
Log:
Initialize explicit padding bytes to zero for C++ 11 (in fact for all versions
and all C-like languages), fixing the testcase in PR11742. However this does
not do anything for implicit padding bytes, eg those caused by alignment.
Added:
dragonegg/trunk/test/validator/c++/2012-12-08-Padding.cpp
Modified:
dragonegg/trunk/src/ConstantConversion.cpp
Modified: dragonegg/trunk/src/ConstantConversion.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/ConstantConversion.cpp?rev=169678&r1=169677&r2=169678&view=diff
==============================================================================
--- dragonegg/trunk/src/ConstantConversion.cpp (original)
+++ dragonegg/trunk/src/ConstantConversion.cpp Sat Dec 8 08:38:16 2012
@@ -857,7 +857,7 @@
assert(PadBits % BITS_PER_UNIT == 0 && "Non-unit type size?");
unsigned Units = PadBits / BITS_PER_UNIT;
Constant *PaddedElt[] = {
- Val, UndefValue::get(GetUnitType(Context, Units))
+ Val, getDefaultValue(GetUnitType(Context, Units))
};
Val = ConstantStruct::getAnon(PaddedElt);
@@ -935,7 +935,7 @@
unsigned PadBits = TypeSize - NumElts * EltSize;
assert(PadBits % BITS_PER_UNIT == 0 && "Non-unit type size?");
unsigned Units = PadBits / BITS_PER_UNIT;
- Elts.push_back(UndefValue::get(GetUnitType(Context, Units)));
+ Elts.push_back(getDefaultValue(GetUnitType(Context, Units)));
isHomogeneous = false;
}
@@ -1263,11 +1263,11 @@
NeedPadding = false;
}
if (NeedPadding) {
- // Fill the gap with undefined bytes.
+ // Fill the gap with padding.
assert((First - EndOfPrevious) % BITS_PER_UNIT == 0 &&
"Non-unit field boundaries!");
unsigned Units = (First - EndOfPrevious) / BITS_PER_UNIT;
- Elts.push_back(UndefValue::get(GetUnitType(Context, Units)));
+ Elts.push_back(getDefaultValue(GetUnitType(Context, Units)));
}
}
@@ -1282,7 +1282,7 @@
assert((TypeSize - EndOfPrevious) % BITS_PER_UNIT == 0 &&
"Non-unit type size?");
unsigned Units = (TypeSize - EndOfPrevious) / BITS_PER_UNIT;
- Elts.push_back(UndefValue::get(GetUnitType(Context, Units)));
+ Elts.push_back(getDefaultValue(GetUnitType(Context, Units)));
}
// Okay, we're done. Return the computed elements as a constant with the type
Added: dragonegg/trunk/test/validator/c++/2012-12-08-Padding.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/c%2B%2B/2012-12-08-Padding.cpp?rev=169678&view=auto
==============================================================================
--- dragonegg/trunk/test/validator/c++/2012-12-08-Padding.cpp (added)
+++ dragonegg/trunk/test/validator/c++/2012-12-08-Padding.cpp Sat Dec 8 08:38:16 2012
@@ -0,0 +1,9 @@
+// RUN: %dragonegg -S %s -o - -std=c++11 | FileCheck %s
+// PR11742
+// This construct is not supported by gcc-4.6 and earlier.
+// XFAIL: gcc-4.5, gcc-4.6
+
+struct S { char c = 1; __attribute__((aligned(8))) char d = 2; } s = S();
+char k = ((char*)&s)[1] + 1;
+
+// CHECK-NOT: undef
More information about the llvm-commits
mailing list