Evgeniy Stepanov | 42f3b12 | 2015-12-01 00:40:05 +0000 | [diff] [blame] | 1 | ; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s |
| 2 | ; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s |
| 3 | |
| 4 | target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" |
| 5 | target triple = "x86_64-unknown-linux-gnu" |
| 6 | |
| 7 | %struct.S = type { [100 x i32] } |
| 8 | |
| 9 | ; Safe access to a byval argument. |
| 10 | define i32 @ByValSafe(%struct.S* byval nocapture readonly align 8 %zzz) norecurse nounwind readonly safestack uwtable { |
| 11 | entry: |
| 12 | ; CHECK-LABEL: @ByValSafe |
| 13 | ; CHECK-NOT: __safestack_unsafe_stack_ptr |
| 14 | ; CHECK: ret i32 |
| 15 | %arrayidx = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 3 |
| 16 | %0 = load i32, i32* %arrayidx, align 4 |
| 17 | ret i32 %0 |
| 18 | } |
| 19 | |
| 20 | ; Unsafe access to a byval argument. |
| 21 | ; Argument is copied to the unsafe stack. |
| 22 | define i32 @ByValUnsafe(%struct.S* byval nocapture readonly align 8 %zzz, i64 %idx) norecurse nounwind readonly safestack uwtable { |
| 23 | entry: |
| 24 | ; CHECK-LABEL: @ByValUnsafe |
| 25 | ; CHECK: %[[A:.*]] = load {{.*}} @__safestack_unsafe_stack_ptr |
| 26 | ; CHECK: store {{.*}} @__safestack_unsafe_stack_ptr |
| 27 | ; CHECK: %[[B:.*]] = getelementptr i8, i8* %[[A]], i32 -400 |
| 28 | ; CHECK: %[[C:.*]] = bitcast %struct.S* %zzz to i8* |
Daniel Neilson | 1e68724 | 2018-01-19 17:13:12 +0000 | [diff] [blame] | 29 | ; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %[[B]], i8* align 8 %[[C]], i64 400, i1 false) |
Evgeniy Stepanov | 42f3b12 | 2015-12-01 00:40:05 +0000 | [diff] [blame] | 30 | ; CHECK: ret i32 |
| 31 | %arrayidx = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 %idx |
| 32 | %0 = load i32, i32* %arrayidx, align 4 |
| 33 | ret i32 %0 |
| 34 | } |
| 35 | |
Daniel Neilson | 095d729 | 2018-02-12 22:39:47 +0000 | [diff] [blame] | 36 | ; Unsafe access to a byval argument. |
| 37 | ; Argument is copied to the unsafe stack. |
| 38 | ; Check that dest align of memcpy is set according to datalayout prefered alignment |
| 39 | define i32 @ByValUnsafe2(%struct.S* byval nocapture readonly %zzz, i64 %idx) norecurse nounwind readonly safestack uwtable { |
| 40 | entry: |
| 41 | ; CHECK-LABEL: @ByValUnsafe |
| 42 | ; CHECK: %[[A:.*]] = load {{.*}} @__safestack_unsafe_stack_ptr |
| 43 | ; CHECK: store {{.*}} @__safestack_unsafe_stack_ptr |
| 44 | ; CHECK: %[[B:.*]] = getelementptr i8, i8* %[[A]], i32 -400 |
| 45 | ; CHECK: %[[C:.*]] = bitcast %struct.S* %zzz to i8* |
| 46 | ; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %[[B]], i8* %[[C]], i64 400, i1 false) |
| 47 | ; CHECK: ret i32 |
| 48 | %arrayidx = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 %idx |
| 49 | %0 = load i32, i32* %arrayidx, align 4 |
| 50 | ret i32 %0 |
| 51 | } |
| 52 | |
Evgeniy Stepanov | 42f3b12 | 2015-12-01 00:40:05 +0000 | [diff] [blame] | 53 | ; Highly aligned byval argument. |
| 54 | define i32 @ByValUnsafeAligned(%struct.S* byval nocapture readonly align 64 %zzz, i64 %idx) norecurse nounwind readonly safestack uwtable { |
| 55 | entry: |
| 56 | ; CHECK-LABEL: @ByValUnsafeAligned |
| 57 | ; CHECK: %[[A:.*]] = load {{.*}} @__safestack_unsafe_stack_ptr |
| 58 | ; CHECK: %[[B:.*]] = ptrtoint i8* %[[A]] to i64 |
| 59 | ; CHECK: and i64 %[[B]], -64 |
| 60 | ; CHECK: ret i32 |
| 61 | %arrayidx = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 0 |
| 62 | %0 = load i32, i32* %arrayidx, align 64 |
| 63 | %arrayidx2 = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 %idx |
| 64 | %1 = load i32, i32* %arrayidx2, align 4 |
| 65 | %add = add nsw i32 %1, %0 |
| 66 | ret i32 %add |
| 67 | } |
| 68 | |