1 ; Test basic EfficiencySanitizer struct field count instrumentation. 2 ; 3 ; RUN: opt < %s -esan -esan-cache-frag -S | FileCheck %s 4 5 %struct.A = type { i32, i32 } 6 %union.U = type { double } 7 %struct.C = type { %struct.anon, %union.anon, [10 x i8] } 8 %struct.anon = type { i32, i32 } 9 %union.anon = type { double } 10 11 ; CHECK: @0 = private unnamed_addr constant [8 x i8] c"<stdin>\00", align 1 12 ; CHECK-NEXT: @1 = private unnamed_addr constant [17 x i8] c"struct.A#2#11#11\00", align 1 13 ; CHECK-NEXT: @"struct.A#2#11#11" = weak global [3 x i64] zeroinitializer 14 ; 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)] 15 ; CHECK-NEXT: @3 = internal constant [2 x i32] [i32 0, i32 4] 16 ; CHECK-NEXT: @4 = internal constant [2 x i32] [i32 4, i32 4] 17 ; CHECK-NEXT: @5 = private unnamed_addr constant [4 x i8] c"i32\00", align 1 18 ; CHECK-NEXT: @6 = private unnamed_addr constant [4 x i8] c"i32\00", align 1 19 ; CHECK-NEXT: @7 = private unnamed_addr constant [12 x i8] c"union.U#1#3\00", align 1 20 ; CHECK-NEXT: @"union.U#1#3" = weak global [2 x i64] zeroinitializer 21 ; CHECK-NEXT: @8 = internal constant [1 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @11, i32 0, i32 0)] 22 ; CHECK-NEXT: @9 = internal constant [1 x i32] zeroinitializer 23 ; CHECK-NEXT: @10 = internal constant [1 x i32] [i32 8] 24 ; CHECK-NEXT: @11 = private unnamed_addr constant [7 x i8] c"double\00", align 1 25 ; CHECK-NEXT: @12 = private unnamed_addr constant [20 x i8] c"struct.C#3#14#13#13\00", align 1 26 ; CHECK-NEXT: @"struct.C#3#14#13#13" = weak global [4 x i64] zeroinitializer 27 ; 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)] 28 ; CHECK-NEXT: @14 = internal constant [3 x i32] [i32 0, i32 8, i32 16] 29 ; CHECK-NEXT: @15 = internal constant [3 x i32] [i32 8, i32 8, i32 10] 30 ; CHECK-NEXT: @16 = private unnamed_addr constant [33 x i8] c"%struct.anon = type { i32, i32 }\00", align 1 31 ; CHECK-NEXT: @17 = private unnamed_addr constant [30 x i8] c"%union.anon = type { double }\00", align 1 32 ; CHECK-NEXT: @18 = private unnamed_addr constant [10 x i8] c"[10 x i8]\00", align 1 33 ; CHECK-NEXT: @19 = private unnamed_addr constant [20 x i8] c"struct.anon#2#11#11\00", align 1 34 ; CHECK-NEXT: @"struct.anon#2#11#11" = weak global [3 x i64] zeroinitializer 35 ; 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)] 36 ; CHECK-NEXT: @21 = internal constant [2 x i32] [i32 0, i32 4] 37 ; CHECK-NEXT: @22 = internal constant [2 x i32] [i32 4, i32 4] 38 ; CHECK-NEXT: @23 = private unnamed_addr constant [4 x i8] c"i32\00", align 1 39 ; CHECK-NEXT: @24 = private unnamed_addr constant [4 x i8] c"i32\00", align 1 40 ; CHECK-NEXT: @25 = private unnamed_addr constant [15 x i8] c"union.anon#1#3\00", align 1 41 ; CHECK-NEXT: @"union.anon#1#3" = weak global [2 x i64] zeroinitializer 42 ; CHECK-NEXT: @26 = internal constant [1 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @29, i32 0, i32 0)] 43 ; CHECK-NEXT: @27 = internal constant [1 x i32] zeroinitializer 44 ; CHECK-NEXT: @28 = internal constant [1 x i32] [i32 8] 45 ; CHECK-NEXT: @29 = private unnamed_addr constant [7 x i8] c"double\00", align 1 46 ; CHECK-NEXT: @30 = internal global [5 x { i8*, i32, i32, i32*, i32*, i8**, i64*, i64* }] [{ i8*, i32, i32, i32*, i32*, i8**, i64*, i64* } { 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), i8** getelementptr inbounds ([2 x i8*], [2 x i8*]* @2, i32 0, i32 0), i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"struct.A#2#11#11", i32 0, i32 0), i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"struct.A#2#11#11", i32 0, i32 2) }, { i8*, i32, i32, i32*, i32*, i8**, i64*, i64* } { 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), i8** getelementptr inbounds ([1 x i8*], [1 x i8*]* @8, i32 0, i32 0), i64* getelementptr inbounds ([2 x i64], [2 x i64]* @"union.U#1#3", i32 0, i32 0), i64* getelementptr inbounds ([2 x i64], [2 x i64]* @"union.U#1#3", i32 0, i32 1) }, { i8*, i32, i32, i32*, i32*, i8**, i64*, i64* } { 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), i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @13, i32 0, i32 0), i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.C#3#14#13#13", i32 0, i32 0), i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.C#3#14#13#13", i32 0, i32 3) }, { i8*, i32, i32, i32*, i32*, i8**, i64*, i64* } { 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), i8** getelementptr inbounds ([2 x i8*], [2 x i8*]* @20, i32 0, i32 0), i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"struct.anon#2#11#11", i32 0, i32 0), i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"struct.anon#2#11#11", i32 0, i32 2) }, { i8*, i32, i32, i32*, i32*, i8**, i64*, i64* } { 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), i8** getelementptr inbounds ([1 x i8*], [1 x i8*]* @26, i32 0, i32 0), i64* getelementptr inbounds ([2 x i64], [2 x i64]* @"union.anon#1#3", i32 0, i32 0), i64* getelementptr inbounds ([2 x i64], [2 x i64]* @"union.anon#1#3", i32 0, i32 1) }] 47 ; CHECK-NEXT: @31 = internal constant { i8*, i32, { i8*, i32, i32, i32*, i32*, i8**, i64*, i64* }* } { i8* getelementptr inbounds ([8 x i8], [8 x i8]* @0, i32 0, i32 0), i32 5, { i8*, i32, i32, i32*, i32*, i8**, i64*, i64* }* getelementptr inbounds ([5 x { i8*, i32, i32, i32*, i32*, i8**, i64*, i64* }], [5 x { i8*, i32, i32, i32*, i32*, i8**, i64*, i64* }]* @30, i32 0, i32 0) } 48 49 define i32 @main() { 50 entry: 51 %a = alloca %struct.A, align 4 52 %u = alloca %union.U, align 8 53 %c = alloca [2 x %struct.C], align 16 54 %k = alloca %struct.A*, align 8 55 %x = getelementptr inbounds %struct.A, %struct.A* %a, i32 0, i32 0 56 %y = getelementptr inbounds %struct.A, %struct.A* %a, i32 0, i32 1 57 %f = bitcast %union.U* %u to float* 58 %d = bitcast %union.U* %u to double* 59 %arrayidx = getelementptr inbounds [2 x %struct.C], [2 x %struct.C]* %c, i64 0, i64 0 60 %cs = getelementptr inbounds %struct.C, %struct.C* %arrayidx, i32 0, i32 0 61 %x1 = getelementptr inbounds %struct.anon, %struct.anon* %cs, i32 0, i32 0 62 %arrayidx2 = getelementptr inbounds [2 x %struct.C], [2 x %struct.C]* %c, i64 0, i64 1 63 %cs3 = getelementptr inbounds %struct.C, %struct.C* %arrayidx2, i32 0, i32 0 64 %y4 = getelementptr inbounds %struct.anon, %struct.anon* %cs3, i32 0, i32 1 65 %arrayidx5 = getelementptr inbounds [2 x %struct.C], [2 x %struct.C]* %c, i64 0, i64 0 66 %cu = getelementptr inbounds %struct.C, %struct.C* %arrayidx5, i32 0, i32 1 67 %f6 = bitcast %union.anon* %cu to float* 68 %arrayidx7 = getelementptr inbounds [2 x %struct.C], [2 x %struct.C]* %c, i64 0, i64 1 69 %cu8 = getelementptr inbounds %struct.C, %struct.C* %arrayidx7, i32 0, i32 1 70 %d9 = bitcast %union.anon* %cu8 to double* 71 %arrayidx10 = getelementptr inbounds [2 x %struct.C], [2 x %struct.C]* %c, i64 0, i64 0 72 %c11 = getelementptr inbounds %struct.C, %struct.C* %arrayidx10, i32 0, i32 2 73 %arrayidx12 = getelementptr inbounds [10 x i8], [10 x i8]* %c11, i64 0, i64 2 74 %k1 = load %struct.A*, %struct.A** %k, align 8 75 %arrayidx13 = getelementptr inbounds %struct.A, %struct.A* %k1, i64 0 76 ret i32 0 77 } 78 79 ; CHECK: @llvm.global_ctors = {{.*}}@esan.module_ctor 80 ; CHECK: @llvm.global_dtors = {{.*}}@esan.module_dtor 81 82 ; CHECK: %a = alloca %struct.A, align 4 83 ; CHECK-NEXT: %u = alloca %union.U, align 8 84 ; CHECK-NEXT: %c = alloca [2 x %struct.C], align 16 85 ; CHECK-NEXT: %k = alloca %struct.A*, align 8 86 ; CHECK-NEXT: %0 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"struct.A#2#11#11", i32 0, i32 0) 87 ; CHECK-NEXT: %1 = add i64 %0, 1 88 ; CHECK-NEXT: store i64 %1, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"struct.A#2#11#11", i32 0, i32 0) 89 ; CHECK-NEXT: %x = getelementptr inbounds %struct.A, %struct.A* %a, i32 0, i32 0 90 ; CHECK-NEXT: %2 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"struct.A#2#11#11", i32 0, i32 1) 91 ; CHECK-NEXT: %3 = add i64 %2, 1 92 ; CHECK-NEXT: store i64 %3, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"struct.A#2#11#11", i32 0, i32 1) 93 ; CHECK-NEXT: %y = getelementptr inbounds %struct.A, %struct.A* %a, i32 0, i32 1 94 ; CHECK-NEXT: %f = bitcast %union.U* %u to float* 95 ; CHECK-NEXT: %d = bitcast %union.U* %u to double* 96 ; CHECK-NEXT: %4 = load i64, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.C#3#14#13#13", i32 0, i32 3) 97 ; CHECK-NEXT: %5 = add i64 %4, 1 98 ; CHECK-NEXT: store i64 %5, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.C#3#14#13#13", i32 0, i32 3) 99 ; CHECK-NEXT: %arrayidx = getelementptr inbounds [2 x %struct.C], [2 x %struct.C]* %c, i64 0, i64 0 100 ; CHECK-NEXT: %6 = load i64, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.C#3#14#13#13", i32 0, i32 0) 101 ; CHECK-NEXT: %7 = add i64 %6, 1 102 ; CHECK-NEXT: store i64 %7, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.C#3#14#13#13", i32 0, i32 0) 103 ; CHECK-NEXT: %cs = getelementptr inbounds %struct.C, %struct.C* %arrayidx, i32 0, i32 0 104 ; CHECK-NEXT: %8 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"struct.anon#2#11#11", i32 0, i32 0) 105 ; CHECK-NEXT: %9 = add i64 %8, 1 106 ; CHECK-NEXT: store i64 %9, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"struct.anon#2#11#11", i32 0, i32 0) 107 ; CHECK-NEXT: %x1 = getelementptr inbounds %struct.anon, %struct.anon* %cs, i32 0, i32 0 108 ; CHECK-NEXT: %10 = load i64, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.C#3#14#13#13", i32 0, i32 3) 109 ; CHECK-NEXT: %11 = add i64 %10, 1 110 ; CHECK-NEXT: store i64 %11, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.C#3#14#13#13", i32 0, i32 3) 111 ; CHECK-NEXT: %arrayidx2 = getelementptr inbounds [2 x %struct.C], [2 x %struct.C]* %c, i64 0, i64 1 112 ; CHECK-NEXT: %12 = load i64, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.C#3#14#13#13", i32 0, i32 0) 113 ; CHECK-NEXT: %13 = add i64 %12, 1 114 ; CHECK-NEXT: store i64 %13, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.C#3#14#13#13", i32 0, i32 0) 115 ; CHECK-NEXT: %cs3 = getelementptr inbounds %struct.C, %struct.C* %arrayidx2, i32 0, i32 0 116 ; CHECK-NEXT: %14 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"struct.anon#2#11#11", i32 0, i32 1) 117 ; CHECK-NEXT: %15 = add i64 %14, 1 118 ; CHECK-NEXT: store i64 %15, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"struct.anon#2#11#11", i32 0, i32 1) 119 ; CHECK-NEXT: %y4 = getelementptr inbounds %struct.anon, %struct.anon* %cs3, i32 0, i32 1 120 ; CHECK-NEXT: %16 = load i64, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.C#3#14#13#13", i32 0, i32 3) 121 ; CHECK-NEXT: %17 = add i64 %16, 1 122 ; CHECK-NEXT: store i64 %17, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.C#3#14#13#13", i32 0, i32 3) 123 ; CHECK-NEXT: %arrayidx5 = getelementptr inbounds [2 x %struct.C], [2 x %struct.C]* %c, i64 0, i64 0 124 ; CHECK-NEXT: %18 = load i64, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.C#3#14#13#13", i32 0, i32 1) 125 ; CHECK-NEXT: %19 = add i64 %18, 1 126 ; CHECK-NEXT: store i64 %19, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.C#3#14#13#13", i32 0, i32 1) 127 ; CHECK-NEXT: %cu = getelementptr inbounds %struct.C, %struct.C* %arrayidx5, i32 0, i32 1 128 ; CHECK-NEXT: %f6 = bitcast %union.anon* %cu to float* 129 ; CHECK-NEXT: %20 = load i64, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.C#3#14#13#13", i32 0, i32 3) 130 ; CHECK-NEXT: %21 = add i64 %20, 1 131 ; CHECK-NEXT: store i64 %21, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.C#3#14#13#13", i32 0, i32 3) 132 ; CHECK-NEXT: %arrayidx7 = getelementptr inbounds [2 x %struct.C], [2 x %struct.C]* %c, i64 0, i64 1 133 ; CHECK-NEXT: %22 = load i64, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.C#3#14#13#13", i32 0, i32 1) 134 ; CHECK-NEXT: %23 = add i64 %22, 1 135 ; CHECK-NEXT: store i64 %23, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.C#3#14#13#13", i32 0, i32 1) 136 ; CHECK-NEXT: %cu8 = getelementptr inbounds %struct.C, %struct.C* %arrayidx7, i32 0, i32 1 137 ; CHECK-NEXT: %d9 = bitcast %union.anon* %cu8 to double* 138 ; CHECK-NEXT: %24 = load i64, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.C#3#14#13#13", i32 0, i32 3) 139 ; CHECK-NEXT: %25 = add i64 %24, 1 140 ; CHECK-NEXT: store i64 %25, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.C#3#14#13#13", i32 0, i32 3) 141 ; CHECK-NEXT: %arrayidx10 = getelementptr inbounds [2 x %struct.C], [2 x %struct.C]* %c, i64 0, i64 0 142 ; CHECK-NEXT: %26 = load i64, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.C#3#14#13#13", i32 0, i32 2) 143 ; CHECK-NEXT: %27 = add i64 %26, 1 144 ; CHECK-NEXT: store i64 %27, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.C#3#14#13#13", i32 0, i32 2) 145 ; CHECK-NEXT: %c11 = getelementptr inbounds %struct.C, %struct.C* %arrayidx10, i32 0, i32 2 146 ; CHECK-NEXT: %arrayidx12 = getelementptr inbounds [10 x i8], [10 x i8]* %c11, i64 0, i64 2 147 ; CHECK-NEXT: %k1 = load %struct.A*, %struct.A** %k, align 8 148 ; CHECK-NEXT: %arrayidx13 = getelementptr inbounds %struct.A, %struct.A* %k1, i64 0 149 ; CHECK-NEXT: ret i32 0 150 151 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 152 ; Top-level: 153 154 ; CHECK: define internal void @esan.module_ctor() 155 ; CHECK: call void @__esan_init(i32 1, i8* bitcast ({ i8*, i32, { i8*, i32, i32, i32*, i32*, i8**, i64*, i64* }* }* @31 to i8*)) 156 ; CHECK: define internal void @esan.module_dtor() 157 ; CHECK: call void @__esan_exit(i8* bitcast ({ i8*, i32, { i8*, i32, i32, i32*, i32*, i8**, i64*, i64* }* }* @31 to i8*)) 158