r220089 - fix -fsanitize-address-field-padding for the cases with virtual base classes
Kostya Serebryany
kcc at google.com
Fri Oct 17 14:02:14 PDT 2014
Author: kcc
Date: Fri Oct 17 16:02:13 2014
New Revision: 220089
URL: http://llvm.org/viewvc/llvm-project?rev=220089&view=rev
Log:
fix -fsanitize-address-field-padding for the cases with virtual base classes
Summary: Correctly compute the non-virtual size of a class.
Test Plan: Build SPEC 2016 with -fsanitize-address-field-padding
Reviewers: rsmith
Reviewed By: rsmith
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D5848
Modified:
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/test/CodeGen/sanitize-address-field-padding.cpp
Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=220089&r1=220088&r2=220089&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Fri Oct 17 16:02:13 2014
@@ -750,9 +750,7 @@ void CodeGenFunction::EmitAsanPrologueOr
llvm::Value *ThisPtr = LoadCXXThis();
ThisPtr = Builder.CreatePtrToInt(ThisPtr, IntPtrTy);
- QualType RecordTy = Context.getTypeDeclType(ClassDecl);
- uint64_t TypeSize = Context.getTypeSizeInChars(RecordTy).getQuantity();
-
+ uint64_t TypeSize = Info.getNonVirtualSize().getQuantity();
// For each field check if it has sufficient padding,
// if so (un)poison it with a call.
for (size_t i = 0; i < SSV.size(); i++) {
Modified: cfe/trunk/test/CodeGen/sanitize-address-field-padding.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/sanitize-address-field-padding.cpp?rev=220089&r1=220088&r2=220089&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/sanitize-address-field-padding.cpp (original)
+++ cfe/trunk/test/CodeGen/sanitize-address-field-padding.cpp Fri Oct 17 16:02:13 2014
@@ -39,6 +39,23 @@ Positive1 positive1;
// Positive1 with extra paddings
// CHECK: type { i32, [12 x i8], i8, [15 x i8], i32, [12 x i8], [6 x i16], [12 x i8], i64, [8 x i8] }
+struct VirtualBase {
+ int foo;
+};
+
+class ClassWithVirtualBase : public virtual VirtualBase {
+ public:
+ ClassWithVirtualBase() {}
+ ~ClassWithVirtualBase() {}
+ int make_it_non_standard_layout;
+ private:
+ char x[7];
+ char y[9];
+};
+
+ClassWithVirtualBase class_with_virtual_base;
+
+
class Negative1 {
public:
Negative1() {}
@@ -137,3 +154,12 @@ ExternCStruct extern_C_struct;
// CHECK: call void @__asan_unpoison_intra_object_redzone({{.*}}8)
// CHECK-NOT: __asan_unpoison_intra_object_redzone
// CHECK: ret void
+//
+//
+// CHECK-LABEL: define linkonce_odr void @_ZN20ClassWithVirtualBaseC1Ev
+// CHECK: call void @__asan_poison_intra_object_redzone({{.*}} 12)
+// CHECK: call void @__asan_poison_intra_object_redzone({{.*}} 9)
+// CHECK: call void @__asan_poison_intra_object_redzone({{.*}} 15)
+// CHECK-NOT: __asan_poison_intra_object_redzone
+// CHECK: ret void
+//
More information about the cfe-commits
mailing list