1 ; Test the complex GetElementPtr instruction handling in the EfficiencySanitizer 2 ; cache fragmentation tool. 3 ; 4 ; RUN: opt < %s -esan -esan-cache-frag -S | FileCheck %s 5 6 ; Code from http://llvm.org/docs/LangRef.html#getelementptr-instruction 7 ; struct RT { 8 ; char A; 9 ; int B[10][20]; 10 ; char C; 11 ; }; 12 ; struct ST { 13 ; int X; 14 ; double Y; 15 ; struct RT Z; 16 ; }; 17 ; 18 ; int *foo(struct ST *s) { 19 ; return &s[1].Z.B[5][13]; 20 ; } 21 22 %struct.RT = type { i8, [10 x [20 x i32]], i8 } 23 %struct.ST = type { i32, double, %struct.RT } 24 25 define i32* @foo(%struct.ST* %s) nounwind uwtable readnone optsize ssp { 26 entry: 27 %arrayidx = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 1, i32 2, i32 1, i64 5, i64 13 28 ret i32* %arrayidx 29 } 30 31 ; CHECK: %0 = load i64, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.ST#3#13#3#11", i32 0, i32 3) 32 ; CHECK-NEXT: %1 = add i64 %0, 1 33 ; CHECK-NEXT: store i64 %1, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.ST#3#13#3#11", i32 0, i32 3) 34 ; CHECK-NEXT: %2 = load i64, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.ST#3#13#3#11", i32 0, i32 2) 35 ; CHECK-NEXT: %3 = add i64 %2, 1 36 ; CHECK-NEXT: store i64 %3, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.ST#3#13#3#11", i32 0, i32 2) 37 ; CHECK-NEXT: %4 = load i64, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.RT#3#11#14#11", i32 0, i32 1) 38 ; CHECK-NEXT: %5 = add i64 %4, 1 39 ; CHECK-NEXT: store i64 %5, i64* getelementptr inbounds ([4 x i64], [4 x i64]* @"struct.RT#3#11#14#11", i32 0, i32 1) 40 ; CHECK-NEXT: %arrayidx = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 1, i32 2, i32 1, i64 5, i64 13 41 ; CHECK-NEXT: ret i32* %arrayidx 42