forked from OSchip/llvm-project
[esan|cfrag] Add the struct field size array in StructInfo
Summary: Adds the struct field size array in struct StructInfo. Updates test struct_field_count_basic.ll. Reviewers: aizatsky Subscribers: vitalybuka, zhaoqin, kcc, eugenis, bruening, llvm-commits Differential Revision: http://reviews.llvm.org/D21341 llvm-svn: 272989
This commit is contained in:
parent
e24bc365e8
commit
bb4496f8c8
|
@ -304,12 +304,13 @@ GlobalVariable *EfficiencySanitizer::createCacheFragInfoGV(
|
||||||
// u32 Size;
|
// u32 Size;
|
||||||
// u32 NumFields;
|
// u32 NumFields;
|
||||||
// u32 *FieldOffsets;
|
// u32 *FieldOffsets;
|
||||||
|
// u32 *FieldSize;
|
||||||
// u64 *FieldCounters;
|
// u64 *FieldCounters;
|
||||||
// const char **FieldTypeNames;
|
// const char **FieldTypeNames;
|
||||||
// };
|
// };
|
||||||
auto *StructInfoTy =
|
auto *StructInfoTy =
|
||||||
StructType::get(Int8PtrTy, Int32Ty, Int32Ty, Int32PtrTy, Int64PtrTy,
|
StructType::get(Int8PtrTy, Int32Ty, Int32Ty, Int32PtrTy, Int32PtrTy,
|
||||||
Int8PtrPtrTy, nullptr);
|
Int64PtrTy, Int8PtrPtrTy, nullptr);
|
||||||
auto *StructInfoPtrTy = StructInfoTy->getPointerTo();
|
auto *StructInfoPtrTy = StructInfoTy->getPointerTo();
|
||||||
// This structure should be kept consistent with the CacheFragInfo struct
|
// This structure should be kept consistent with the CacheFragInfo struct
|
||||||
// in the runtime library.
|
// in the runtime library.
|
||||||
|
@ -367,6 +368,12 @@ GlobalVariable *EfficiencySanitizer::createCacheFragInfoGV(
|
||||||
new GlobalVariable(M, OffsetArrayTy, true,
|
new GlobalVariable(M, OffsetArrayTy, true,
|
||||||
GlobalVariable::InternalLinkage, nullptr);
|
GlobalVariable::InternalLinkage, nullptr);
|
||||||
SmallVector<Constant *, 16> OffsetVec;
|
SmallVector<Constant *, 16> OffsetVec;
|
||||||
|
// FieldSize
|
||||||
|
auto *SizeArrayTy = ArrayType::get(Int32Ty, StructTy->getNumElements());
|
||||||
|
GlobalVariable *Size =
|
||||||
|
new GlobalVariable(M, SizeArrayTy, true,
|
||||||
|
GlobalVariable::InternalLinkage, nullptr);
|
||||||
|
SmallVector<Constant *, 16> SizeVec;
|
||||||
for (unsigned i = 0; i < StructTy->getNumElements(); ++i) {
|
for (unsigned i = 0; i < StructTy->getNumElements(); ++i) {
|
||||||
Type *Ty = StructTy->getElementType(i);
|
Type *Ty = StructTy->getElementType(i);
|
||||||
std::string Str;
|
std::string Str;
|
||||||
|
@ -377,9 +384,12 @@ GlobalVariable *EfficiencySanitizer::createCacheFragInfoGV(
|
||||||
createPrivateGlobalForString(M, StrOS.str(), true),
|
createPrivateGlobalForString(M, StrOS.str(), true),
|
||||||
Int8PtrTy));
|
Int8PtrTy));
|
||||||
OffsetVec.push_back(ConstantInt::get(Int32Ty, SL->getElementOffset(i)));
|
OffsetVec.push_back(ConstantInt::get(Int32Ty, SL->getElementOffset(i)));
|
||||||
|
SizeVec.push_back(ConstantInt::get(Int32Ty,
|
||||||
|
DL.getTypeAllocSize(Ty)));
|
||||||
}
|
}
|
||||||
TypeNames->setInitializer(ConstantArray::get(TypeNameArrayTy, TypeNameVec));
|
TypeNames->setInitializer(ConstantArray::get(TypeNameArrayTy, TypeNameVec));
|
||||||
Offsets->setInitializer(ConstantArray::get(OffsetArrayTy, OffsetVec));
|
Offsets->setInitializer(ConstantArray::get(OffsetArrayTy, OffsetVec));
|
||||||
|
Size->setInitializer(ConstantArray::get(SizeArrayTy, SizeVec));
|
||||||
|
|
||||||
Initializers.push_back(
|
Initializers.push_back(
|
||||||
ConstantStruct::get(
|
ConstantStruct::get(
|
||||||
|
@ -388,6 +398,7 @@ GlobalVariable *EfficiencySanitizer::createCacheFragInfoGV(
|
||||||
ConstantInt::get(Int32Ty, SL->getSizeInBytes()),
|
ConstantInt::get(Int32Ty, SL->getSizeInBytes()),
|
||||||
ConstantInt::get(Int32Ty, StructTy->getNumElements()),
|
ConstantInt::get(Int32Ty, StructTy->getNumElements()),
|
||||||
ConstantExpr::getPointerCast(Offsets, Int32PtrTy),
|
ConstantExpr::getPointerCast(Offsets, Int32PtrTy),
|
||||||
|
ConstantExpr::getPointerCast(Size, Int32PtrTy),
|
||||||
ConstantExpr::getPointerCast(Counters, Int64PtrTy),
|
ConstantExpr::getPointerCast(Counters, Int64PtrTy),
|
||||||
ConstantExpr::getPointerCast(TypeNames, Int8PtrPtrTy),
|
ConstantExpr::getPointerCast(TypeNames, Int8PtrPtrTy),
|
||||||
nullptr));
|
nullptr));
|
||||||
|
|
|
@ -11,36 +11,40 @@
|
||||||
; CHECK: @0 = private unnamed_addr constant [8 x i8] c"<stdin>\00", align 1
|
; CHECK: @0 = private unnamed_addr constant [8 x i8] c"<stdin>\00", align 1
|
||||||
; CHECK-NEXT: @1 = private unnamed_addr constant [17 x i8] c"struct.A#2#11#11\00", align 1
|
; CHECK-NEXT: @1 = private unnamed_addr constant [17 x i8] c"struct.A#2#11#11\00", align 1
|
||||||
; CHECK-NEXT: @"struct.A#2#11#11" = weak global [2 x i64] zeroinitializer
|
; CHECK-NEXT: @"struct.A#2#11#11" = weak global [2 x i64] zeroinitializer
|
||||||
; CHECK-NEXT: @2 = internal constant [2 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @5, i32 0, i32 0)]
|
; CHECK-NEXT: @2 = internal constant [2 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @5, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @6, i32 0, i32 0)]
|
||||||
; CHECK-NEXT: @3 = internal constant [2 x i32] [i32 0, i32 4]
|
; CHECK-NEXT: @3 = internal constant [2 x i32] [i32 0, i32 4]
|
||||||
; CHECK-NEXT: @4 = private unnamed_addr constant [4 x i8] c"i32\00", align 1
|
; CHECK-NEXT: @4 = internal constant [2 x i32] [i32 4, i32 4]
|
||||||
; CHECK-NEXT: @5 = private unnamed_addr constant [4 x i8] c"i32\00", align 1
|
; CHECK-NEXT: @5 = private unnamed_addr constant [4 x i8] c"i32\00", align 1
|
||||||
; CHECK-NEXT: @6 = private unnamed_addr constant [12 x i8] c"union.U#1#3\00", align 1
|
; CHECK-NEXT: @6 = private unnamed_addr constant [4 x i8] c"i32\00", align 1
|
||||||
|
; CHECK-NEXT: @7 = private unnamed_addr constant [12 x i8] c"union.U#1#3\00", align 1
|
||||||
; CHECK-NEXT: @"union.U#1#3" = weak global [1 x i64] zeroinitializer
|
; CHECK-NEXT: @"union.U#1#3" = weak global [1 x i64] zeroinitializer
|
||||||
; CHECK-NEXT: @7 = internal constant [1 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @9, i32 0, i32 0)]
|
; CHECK-NEXT: @8 = internal constant [1 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @11, i32 0, i32 0)]
|
||||||
; CHECK-NEXT: @8 = internal constant [1 x i32] zeroinitializer
|
; CHECK-NEXT: @9 = internal constant [1 x i32] zeroinitializer
|
||||||
; CHECK-NEXT: @9 = private unnamed_addr constant [7 x i8] c"double\00", align 1
|
; CHECK-NEXT: @10 = internal constant [1 x i32] [i32 8]
|
||||||
; CHECK-NEXT: @10 = private unnamed_addr constant [20 x i8] c"struct.C#3#14#13#13\00", align 1
|
; CHECK-NEXT: @11 = private unnamed_addr constant [7 x i8] c"double\00", align 1
|
||||||
|
; CHECK-NEXT: @12 = private unnamed_addr constant [20 x i8] c"struct.C#3#14#13#13\00", align 1
|
||||||
; CHECK-NEXT: @"struct.C#3#14#13#13" = weak global [3 x i64] zeroinitializer
|
; CHECK-NEXT: @"struct.C#3#14#13#13" = weak global [3 x i64] zeroinitializer
|
||||||
; CHECK-NEXT: @11 = internal constant [3 x i8*] [i8* getelementptr inbounds ([33 x i8], [33 x i8]* @13, i32 0, i32 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @14, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @15, i32 0, i32 0)]
|
; CHECK-NEXT: @13 = internal constant [3 x i8*] [i8* getelementptr inbounds ([33 x i8], [33 x i8]* @16, i32 0, i32 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @17, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @18, i32 0, i32 0)]
|
||||||
; CHECK-NEXT: @12 = internal constant [3 x i32] [i32 0, i32 8, i32 16]
|
; CHECK-NEXT: @14 = internal constant [3 x i32] [i32 0, i32 8, i32 16]
|
||||||
; CHECK-NEXT: @13 = private unnamed_addr constant [33 x i8] c"%struct.anon = type { i32, i32 }\00", align 1
|
; CHECK-NEXT: @15 = internal constant [3 x i32] [i32 8, i32 8, i32 10]
|
||||||
; CHECK-NEXT: @14 = private unnamed_addr constant [30 x i8] c"%union.anon = type { double }\00", align 1
|
; CHECK-NEXT: @16 = private unnamed_addr constant [33 x i8] c"%struct.anon = type { i32, i32 }\00", align 1
|
||||||
; CHECK-NEXT: @15 = private unnamed_addr constant [10 x i8] c"[10 x i8]\00", align 1
|
; CHECK-NEXT: @17 = private unnamed_addr constant [30 x i8] c"%union.anon = type { double }\00", align 1
|
||||||
; CHECK-NEXT: @16 = private unnamed_addr constant [20 x i8] c"struct.anon#2#11#11\00", align 1
|
; CHECK-NEXT: @18 = private unnamed_addr constant [10 x i8] c"[10 x i8]\00", align 1
|
||||||
|
; CHECK-NEXT: @19 = private unnamed_addr constant [20 x i8] c"struct.anon#2#11#11\00", align 1
|
||||||
; CHECK-NEXT: @"struct.anon#2#11#11" = weak global [2 x i64] zeroinitializer
|
; CHECK-NEXT: @"struct.anon#2#11#11" = weak global [2 x i64] zeroinitializer
|
||||||
; CHECK-NEXT: @17 = internal constant [2 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @19, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @20, i32 0, i32 0)]
|
; CHECK-NEXT: @20 = internal constant [2 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @23, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @24, i32 0, i32 0)]
|
||||||
; CHECK-NEXT: @18 = internal constant [2 x i32] [i32 0, i32 4]
|
; CHECK-NEXT: @21 = internal constant [2 x i32] [i32 0, i32 4]
|
||||||
; CHECK-NEXT: @19 = private unnamed_addr constant [4 x i8] c"i32\00", align 1
|
; CHECK-NEXT: @22 = internal constant [2 x i32] [i32 4, i32 4]
|
||||||
; CHECK-NEXT: @20 = private unnamed_addr constant [4 x i8] c"i32\00", align 1
|
; CHECK-NEXT: @23 = private unnamed_addr constant [4 x i8] c"i32\00", align 1
|
||||||
; CHECK-NEXT: @21 = private unnamed_addr constant [15 x i8] c"union.anon#1#3\00", align 1
|
; CHECK-NEXT: @24 = private unnamed_addr constant [4 x i8] c"i32\00", align 1
|
||||||
|
; CHECK-NEXT: @25 = private unnamed_addr constant [15 x i8] c"union.anon#1#3\00", align 1
|
||||||
; CHECK-NEXT: @"union.anon#1#3" = weak global [1 x i64] zeroinitializer
|
; CHECK-NEXT: @"union.anon#1#3" = weak global [1 x i64] zeroinitializer
|
||||||
; CHECK-NEXT: @22 = internal constant [1 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @24, i32 0, i32 0)]
|
; CHECK-NEXT: @26 = internal constant [1 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @29, i32 0, i32 0)]
|
||||||
; CHECK-NEXT: @23 = internal constant [1 x i32] zeroinitializer
|
; CHECK-NEXT: @27 = internal constant [1 x i32] zeroinitializer
|
||||||
; CHECK-NEXT: @24 = private unnamed_addr constant [7 x i8] c"double\00", align 1
|
; CHECK-NEXT: @28 = internal constant [1 x i32] [i32 8]
|
||||||
; CHECK-NEXT: @25 = internal global [5 x { i8*, i32, i32, i32*, i64*, i8** }] [{ i8*, i32, i32, i32*, i64*, i8** } { i8* getelementptr inbounds ([17 x i8], [17 x i8]* @1, i32 0, i32 0), i32 8, i32 2, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @3, i32 0, i32 0), i64* getelementptr inbounds ([2 x i64], [2 x i64]* @"struct.A#2#11#11", i32 0, i32 0), i8** getelementptr inbounds ([2 x i8*], [2 x i8*]* @2, i32 0, i32 0) }, { i8*, i32, i32, i32*, i64*, i8** } { i8* getelementptr inbounds ([12 x i8], [12 x i8]* @6, i32 0, i32 0), i32 8, i32 1, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @8, i32 0, i32 0), i64* getelementptr inbounds ([1 x i64], [1 x i64]* @"union.U#1#3", i32 0, i32 0), i8** getelementptr inbounds ([1 x i8*], [1 x i8*]* @7, i32 0, i32 0) }, { i8*, i32, i32, i32*, i64*, i8** } { i8* getelementptr inbounds ([20 x i8], [20 x i8]* @10, i32 0, i32 0), i32 32, i32 3, i32* getelementptr inbounds ([3 x i32], [3 x i32]* @12, i32 0, i32 0), i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"struct.C#3#14#13#13", i32 0, i32 0), i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @11, i32 0, i32 0) }, { i8*, i32, i32, i32*, i64*, i8** } { i8* getelementptr inbounds ([20 x i8], [20 x i8]* @16, i32 0, i32 0), i32 8, i32 2, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @18, i32 0, i32 0), i64* getelementptr inbounds ([2 x i64], [2 x i64]* @"struct.anon#2#11#11", i32 0, i32 0), i8** getelementptr inbounds ([2 x i8*], [2 x i8*]* @17, i32 0, i32 0) }, { i8*, i32, i32, i32*, i64*, i8** } { i8* getelementptr inbounds ([15 x i8], [15 x i8]* @21, i32 0, i32 0), i32 8, i32 1, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @23, i32 0, i32 0), i64* getelementptr inbounds ([1 x i64], [1 x i64]* @"union.anon#1#3", i32 0, i32 0), i8** getelementptr inbounds ([1 x i8*], [1 x i8*]* @22, i32 0, i32 0) }]
|
; CHECK-NEXT: @29 = private unnamed_addr constant [7 x i8] c"double\00", align 1
|
||||||
; CHECK-NEXT: @26 = internal constant { i8*, i32, { i8*, i32, i32, i32*, i64*, i8** }* } { i8* getelementptr inbounds ([8 x i8], [8 x i8]* @0, i32 0, i32 0), i32 5, { i8*, i32, i32, i32*, i64*, i8** }* getelementptr inbounds ([5 x { i8*, i32, i32, i32*, i64*, i8** }], [5 x { i8*, i32, i32, i32*, i64*, i8** }]* @25, i32 0, i32 0) }
|
; CHECK-NEXT: @30 = internal global [5 x { i8*, i32, i32, i32*, i32*, i64*, i8** }] [{ i8*, i32, i32, i32*, i32*, i64*, i8** } { i8* getelementptr inbounds ([17 x i8], [17 x i8]* @1, i32 0, i32 0), i32 8, i32 2, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @3, i32 0, i32 0), i32* getelementptr inbounds ([2 x i32], [2 x i32]* @4, i32 0, i32 0), i64* getelementptr inbounds ([2 x i64], [2 x i64]* @"struct.A#2#11#11", i32 0, i32 0), i8** getelementptr inbounds ([2 x i8*], [2 x i8*]* @2, i32 0, i32 0) }, { i8*, i32, i32, i32*, i32*, i64*, i8** } { i8* getelementptr inbounds ([12 x i8], [12 x i8]* @7, i32 0, i32 0), i32 8, i32 1, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @9, i32 0, i32 0), i32* getelementptr inbounds ([1 x i32], [1 x i32]* @10, i32 0, i32 0), i64* getelementptr inbounds ([1 x i64], [1 x i64]* @"union.U#1#3", i32 0, i32 0), i8** getelementptr inbounds ([1 x i8*], [1 x i8*]* @8, i32 0, i32 0) }, { i8*, i32, i32, i32*, i32*, i64*, i8** } { i8* getelementptr inbounds ([20 x i8], [20 x i8]* @12, i32 0, i32 0), i32 32, i32 3, i32* getelementptr inbounds ([3 x i32], [3 x i32]* @14, i32 0, i32 0), i32* getelementptr inbounds ([3 x i32], [3 x i32]* @15, i32 0, i32 0), i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"struct.C#3#14#13#13", i32 0, i32 0), i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @13, i32 0, i32 0) }, { i8*, i32, i32, i32*, i32*, i64*, i8** } { i8* getelementptr inbounds ([20 x i8], [20 x i8]* @19, i32 0, i32 0), i32 8, i32 2, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @21, i32 0, i32 0), i32* getelementptr inbounds ([2 x i32], [2 x i32]* @22, i32 0, i32 0), i64* getelementptr inbounds ([2 x i64], [2 x i64]* @"struct.anon#2#11#11", i32 0, i32 0), i8** getelementptr inbounds ([2 x i8*], [2 x i8*]* @20, i32 0, i32 0) }, { i8*, i32, i32, i32*, i32*, i64*, i8** } { i8* getelementptr inbounds ([15 x i8], [15 x i8]* @25, i32 0, i32 0), i32 8, i32 1, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @27, i32 0, i32 0), i32* getelementptr inbounds ([1 x i32], [1 x i32]* @28, i32 0, i32 0), i64* getelementptr inbounds ([1 x i64], [1 x i64]* @"union.anon#1#3", i32 0, i32 0), i8** getelementptr inbounds ([1 x i8*], [1 x i8*]* @26, i32 0, i32 0) }]
|
||||||
|
; CHECK-NEXT: @31 = internal constant { i8*, i32, { i8*, i32, i32, i32*, i32*, i64*, i8** }* } { i8* getelementptr inbounds ([8 x i8], [8 x i8]* @0, i32 0, i32 0), i32 5, { i8*, i32, i32, i32*, i32*, i64*, i8** }* getelementptr inbounds ([5 x { i8*, i32, i32, i32*, i32*, i64*, i8** }], [5 x { i8*, i32, i32, i32*, i32*, i64*, i8** }]* @30, i32 0, i32 0) }
|
||||||
|
|
||||||
define i32 @main() {
|
define i32 @main() {
|
||||||
entry:
|
entry:
|
||||||
|
@ -133,6 +137,6 @@ entry:
|
||||||
; Top-level:
|
; Top-level:
|
||||||
|
|
||||||
; CHECK: define internal void @esan.module_ctor()
|
; CHECK: define internal void @esan.module_ctor()
|
||||||
; CHECK: call void @__esan_init(i32 1, i8* bitcast ({ i8*, i32, { i8*, i32, i32, i32*, i64*, i8** }* }* @26 to i8*))
|
; CHECK: call void @__esan_init(i32 1, i8* bitcast ({ i8*, i32, { i8*, i32, i32, i32*, i32*, i64*, i8** }* }* @31 to i8*))
|
||||||
; CHECK: define internal void @esan.module_dtor()
|
; CHECK: define internal void @esan.module_dtor()
|
||||||
; CHECK: call void @__esan_exit(i8* bitcast ({ i8*, i32, { i8*, i32, i32, i32*, i64*, i8** }* }* @26 to i8*))
|
; CHECK: call void @__esan_exit(i8* bitcast ({ i8*, i32, { i8*, i32, i32, i32*, i32*, i64*, i8** }* }* @31 to i8*))
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
; double Y;
|
; double Y;
|
||||||
; struct RT Z;
|
; struct RT Z;
|
||||||
; };
|
; };
|
||||||
;
|
;
|
||||||
; int *foo(struct ST *s) {
|
; int *foo(struct ST *s) {
|
||||||
; return &s[1].Z.B[5][13];
|
; return &s[1].Z.B[5][13];
|
||||||
; }
|
; }
|
||||||
|
|
Loading…
Reference in New Issue