Changed the patch so that it does not check the field size any more,
but only relies on hasFlexibleArrayMember().
Now the loop iterating over the fields actually knows which element is the last
one.
This way we will avoid instrumenting flexible arrays and structs that contain
those.
Combined with the David's patch http://reviews.llvm.org/D5478
this will automatically handle cases like
struct S {int Array[0]; }
and
struct S {int Array[1]; }
as well as the cases where S is the last field of another struct.
PTAL
http://reviews.llvm.org/D5924
Files:
lib/AST/RecordLayoutBuilder.cpp
test/CodeGen/sanitize-address-field-padding.cpp
Index: lib/AST/RecordLayoutBuilder.cpp
===================================================================
--- lib/AST/RecordLayoutBuilder.cpp
+++ lib/AST/RecordLayoutBuilder.cpp
@@ -1331,8 +1331,14 @@
// Layout each field, for now, just sequentially, respecting alignment. In
// the future, this will need to be tweakable by targets.
bool InsertExtraPadding = D->mayInsertExtraPadding(/*EmitRemark=*/true);
- for (const auto *Field : D->fields())
- LayoutField(Field, InsertExtraPadding);
+ bool HasFlexibleArrayMember = D->hasFlexibleArrayMember();
+ // for (const auto *Field : D->fields())
+ for (auto I = D->field_begin(), End = D->field_end(); I != End; ++I) {
+ auto Next(I);
+ ++Next;
+ LayoutField(*I,
+ InsertExtraPadding && (Next != End || !HasFlexibleArrayMember));
+ }
}
// Rounds the specified size to have it a multiple of the char size.
@@ -1750,7 +1756,7 @@
Context.toBits(UnpackedFieldOffset),
Context.toBits(UnpackedFieldAlign), FieldPacked, D);
- if (InsertExtraPadding && !FieldSize.isZero()) {
+ if (InsertExtraPadding) {
CharUnits ASanAlignment = CharUnits::fromQuantity(8);
CharUnits ExtraSizeForAsan = ASanAlignment;
if (FieldSize % ASanAlignment)
Index: test/CodeGen/sanitize-address-field-padding.cpp
===================================================================
--- test/CodeGen/sanitize-address-field-padding.cpp
+++ test/CodeGen/sanitize-address-field-padding.cpp
@@ -55,6 +55,36 @@
ClassWithVirtualBase class_with_virtual_base;
+class WithFlexibleArray1 {
+ public:
+ WithFlexibleArray1() {}
+ ~WithFlexibleArray1() {}
+ int make_it_non_standard_layout;
+ private:
+ char private1[33];
+ int flexible[]; // Don't insert padding after this field.
+};
+
+WithFlexibleArray1 with_flexible_array1;
+// CHECK: %class.WithFlexibleArray1 = type { i32, [12 x i8], [33 x i8], [15 x i8], [0 x i32] }
+
+class WithFlexibleArray2 {
+ public:
+ char x[21];
+ WithFlexibleArray1 flex1; // Don't insert padding after this field.
+};
+
+WithFlexibleArray2 with_flexible_array2;
+// CHECK: %class.WithFlexibleArray2 = type { [21 x i8], [11 x i8], %class.WithFlexibleArray1 }
+
+class WithFlexibleArray3 {
+ public:
+ char x[13];
+ WithFlexibleArray2 flex2; // Don't insert padding after this field.
+};
+
+WithFlexibleArray3 with_flexible_array3;
+
class Negative1 {
public:
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits