18224c504SYuanfang Chen; RUN: opt < %s -S -mcpu=z13 -msan-kernel=1 -float-abi=soft -passes=msan 2>&1 | FileCheck %s 23bc439bdSIlya Leoshkevich 33bc439bdSIlya Leoshkevichtarget datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64" 43bc439bdSIlya Leoshkevichtarget triple = "s390x-unknown-linux-gnu" 53bc439bdSIlya Leoshkevich 6a3e56a87SIlya Leoshkevich%struct.__va_list = type { i64, i64, ptr, ptr } 7a3e56a87SIlya Leoshkevichdeclare void @llvm.lifetime.start.p0(i64, ptr) 8a3e56a87SIlya Leoshkevichdeclare void @llvm.va_start(ptr) 9a3e56a87SIlya Leoshkevichdeclare void @llvm.va_end(ptr) 10a3e56a87SIlya Leoshkevichdeclare void @llvm.lifetime.end.p0(i64, ptr) 113bc439bdSIlya Leoshkevich 12a3e56a87SIlya Leoshkevichdefine i64 @foo(i64 %guard, ...) #1 { 13a3e56a87SIlya Leoshkevich %vl = alloca %struct.__va_list 14a3e56a87SIlya Leoshkevich call void @llvm.lifetime.start.p0(i64 32, ptr %vl) 15a3e56a87SIlya Leoshkevich call void @llvm.va_start(ptr %vl) 16a3e56a87SIlya Leoshkevich call void @llvm.va_end(ptr %vl) 17a3e56a87SIlya Leoshkevich call void @llvm.lifetime.end.p0(i64 32, ptr %vl) 18a3e56a87SIlya Leoshkevich ret i64 0 19a3e56a87SIlya Leoshkevich} 20a3e56a87SIlya Leoshkevich 21a3e56a87SIlya Leoshkevich; CHECK-LABEL: define {{[^@]+}}@foo( 22a3e56a87SIlya Leoshkevich 23a3e56a87SIlya Leoshkevich; Callers store variadic arguments' shadow and origins into va_arg_shadow and 24a3e56a87SIlya Leoshkevich; va_arg_origin. Their layout is: the register save area (160 bytes) followed 25a3e56a87SIlya Leoshkevich; by the overflow arg area. It does not depend on "packed-stack". 26a3e56a87SIlya Leoshkevich; Check that callees correctly backup shadow into a local variable. 27a3e56a87SIlya Leoshkevich 28a3e56a87SIlya Leoshkevich; CHECK: [[TMP:%.*]] = alloca { ptr, ptr } 29a3e56a87SIlya Leoshkevich; CHECK: [[OverflowSize:%.*]] = load i64, ptr %va_arg_overflow_size 30a3e56a87SIlya Leoshkevich; CHECK: [[MetaSize:%.*]] = add i64 160, [[OverflowSize]] 31a3e56a87SIlya Leoshkevich; CHECK: [[ShadowBackup:%.*]] = alloca {{.*}} [[MetaSize]] 32a3e56a87SIlya Leoshkevich; CHECK: [[MetaCopySize:%.*]] = call i64 @llvm.umin.i64(i64 [[MetaSize]], i64 800) 33a3e56a87SIlya Leoshkevich; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[ShadowBackup]], ptr align 8 %va_arg_shadow, i64 [[MetaCopySize]], i1 false) 34a3e56a87SIlya Leoshkevich; CHECK: [[OverflowBackup:%.*]] = alloca {{.*}} [[MetaSize]] 35a3e56a87SIlya Leoshkevich; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[OverflowBackup]], ptr align 8 %va_arg_origin, i64 [[MetaCopySize]], i1 false) 36a3e56a87SIlya Leoshkevich 37a3e56a87SIlya Leoshkevich; Check that va_start() correctly copies the shadow backup into the shadow of 38a3e56a87SIlya Leoshkevich; the va_list. Register save area and overflow arg area are copied separately. 39a3e56a87SIlya Leoshkevich; Only 56 bytes of the register save area is copied, because of 40a3e56a87SIlya Leoshkevich; "use-soft-float". 41a3e56a87SIlya Leoshkevich 42*ab7dba23SAlex Voicu; CHECK: call void @llvm.va_start.p0(ptr %vl) 43a3e56a87SIlya Leoshkevich; CHECK: [[VlAddr:%.*]] = ptrtoint ptr %vl to i64 44a3e56a87SIlya Leoshkevich; CHECK: [[RegSaveAreaAddrAddr:%.*]] = add i64 [[VlAddr]], 24 45a3e56a87SIlya Leoshkevich; CHECK: [[RegSaveAreaAddr:%.*]] = inttoptr i64 [[RegSaveAreaAddrAddr]] to ptr 46a3e56a87SIlya Leoshkevich; CHECK: [[RegSaveArea:%.*]] = load ptr, ptr [[RegSaveAreaAddr]] 47a3e56a87SIlya Leoshkevich; CHECK: call void @__msan_metadata_ptr_for_store_1(ptr [[TMP]], ptr [[RegSaveArea]]) 48a3e56a87SIlya Leoshkevich; CHECK: [[RegSaveAreaMeta:%.*]] = load { ptr, ptr }, ptr [[TMP]] 49a3e56a87SIlya Leoshkevich; CHECK: [[RegSaveAreaShadow:%.*]] = extractvalue { ptr, ptr } [[RegSaveAreaMeta]], 0 50a3e56a87SIlya Leoshkevich; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[RegSaveAreaShadow]], ptr align 8 [[ShadowBackup]], i64 56, i1 false) 51a3e56a87SIlya Leoshkevich; CHECK: [[VlAddr:%.*]] = ptrtoint ptr %vl to i64 52a3e56a87SIlya Leoshkevich; CHECK: [[OverflowAddrAddr:%.*]] = add i64 [[VlAddr]], 16 53a3e56a87SIlya Leoshkevich; CHECK: [[OverflowAddr:%.*]] = inttoptr i64 [[OverflowAddrAddr]] to ptr 54a3e56a87SIlya Leoshkevich; CHECK: [[Overflow:%.*]] = load ptr, ptr [[OverflowAddr]] 55a3e56a87SIlya Leoshkevich; CHECK: call void @__msan_metadata_ptr_for_store_1(ptr [[TMP]], ptr [[Overflow]]) 56a3e56a87SIlya Leoshkevich; CHECK: [[OverflowMeta:%.*]] = load { ptr, ptr }, ptr [[TMP]] 57a3e56a87SIlya Leoshkevich; CHECK: [[OverflowShadow:%.*]] = extractvalue { ptr, ptr } [[OverflowMeta]], 0 58a3e56a87SIlya Leoshkevich; CHECK: [[OverflowShadowBackup:%.*]] = getelementptr i8, ptr [[ShadowBackup]], i32 160 59a3e56a87SIlya Leoshkevich; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[OverflowShadow]], ptr align 8 [[OverflowShadowBackup]], i64 [[OverflowSize]], i1 false) 603bc439bdSIlya Leoshkevich 613bc439bdSIlya Leoshkevichdeclare i32 @random_i32() 623bc439bdSIlya Leoshkevichdeclare i64 @random_i64() 633bc439bdSIlya Leoshkevichdeclare float @random_float() 643bc439bdSIlya Leoshkevichdeclare double @random_double() 653bc439bdSIlya Leoshkevich 663bc439bdSIlya Leoshkevichdefine i64 @bar() #1 { 673bc439bdSIlya Leoshkevich %arg2 = call i32 () @random_i32() 683bc439bdSIlya Leoshkevich %arg3 = call float () @random_float() 693bc439bdSIlya Leoshkevich %arg4 = call i32 () @random_i32() 703bc439bdSIlya Leoshkevich %arg5 = call double () @random_double() 713bc439bdSIlya Leoshkevich %arg6 = call i64 () @random_i64() 723bc439bdSIlya Leoshkevich %arg9 = call i32 () @random_i32() 733bc439bdSIlya Leoshkevich %arg11 = call float () @random_float() 743bc439bdSIlya Leoshkevich %arg12 = call i32 () @random_i32() 753bc439bdSIlya Leoshkevich %arg13 = call double () @random_double() 763bc439bdSIlya Leoshkevich %arg14 = call i64 () @random_i64() 773bc439bdSIlya Leoshkevich %1 = call i64 (i64, ...) @foo(i64 1, i32 zeroext %arg2, float %arg3, 783bc439bdSIlya Leoshkevich i32 signext %arg4, double %arg5, i64 %arg6, 793bc439bdSIlya Leoshkevich i64 7, double 8.0, i32 zeroext %arg9, 803bc439bdSIlya Leoshkevich double 10.0, float %arg11, i32 signext %arg12, 813bc439bdSIlya Leoshkevich double %arg13, i64 %arg14) 823bc439bdSIlya Leoshkevich ret i64 %1 833bc439bdSIlya Leoshkevich} 843bc439bdSIlya Leoshkevich 85322e150eSIlya Leoshkevichattributes #1 = { sanitize_memory "target-features"="+soft-float" "use-soft-float"="true" } 863bc439bdSIlya Leoshkevich 873bc439bdSIlya Leoshkevich; In kernel the floating point values are passed in GPRs: 883bc439bdSIlya Leoshkevich; - r2@16 == i64 1 - skipped, because it's fixed 893bc439bdSIlya Leoshkevich; - r3@24 == i32 zext %arg2 - shadow is zero-extended 903bc439bdSIlya Leoshkevich; - r4@(32 + 4) == float %arg3 - right-justified, shadow is 32-bit 913bc439bdSIlya Leoshkevich; - r5@40 == i32 sext %arg4 - shadow is sign-extended 923bc439bdSIlya Leoshkevich; - r6@48 == double %arg5 - straightforward 933bc439bdSIlya Leoshkevich; - overflow@160 == i64 %arg6 - straightforward 943bc439bdSIlya Leoshkevich; - overflow@168 == 7 - filler 953bc439bdSIlya Leoshkevich; - overflow@176 == 8.0 - filler 963bc439bdSIlya Leoshkevich; - overflow@184 == i32 zext %arg9 - shadow is zero-extended 973bc439bdSIlya Leoshkevich; - overflow@192 == 10.0 - filler 983bc439bdSIlya Leoshkevich; - overflow@(200 + 4) == float %arg11 - right-justified, shadow is 32-bit 993bc439bdSIlya Leoshkevich; - overflow@208 == i32 sext %arg12 - shadow is sign-extended 1003bc439bdSIlya Leoshkevich; - overflow@216 == double %arg13 - straightforward 1013bc439bdSIlya Leoshkevich; - overflow@224 == i64 %arg14 - straightforward 1023bc439bdSIlya Leoshkevich; Overflow arg area size is 72. 1033bc439bdSIlya Leoshkevich 1043bc439bdSIlya Leoshkevich; CHECK-LABEL: @bar 1053bc439bdSIlya Leoshkevich 10641d5033eSNikita Popov; CHECK: [[B:%.*]] = ptrtoint ptr %va_arg_shadow to i64 1073bc439bdSIlya Leoshkevich; CHECK: [[S:%.*]] = add i64 [[B]], 24 1083bc439bdSIlya Leoshkevich; CHECK: [[V:%.*]] = zext {{.*}} 10941d5033eSNikita Popov; CHECK: [[M:%_msarg_va_s.*]] = inttoptr i64 [[S]] to ptr 1103bc439bdSIlya Leoshkevich; CHECK: store {{.*}} [[V]], {{.*}} [[M]] 1113bc439bdSIlya Leoshkevich 11241d5033eSNikita Popov; CHECK: [[B:%.*]] = ptrtoint ptr %va_arg_shadow to i64 1133bc439bdSIlya Leoshkevich; CHECK: [[S:%.*]] = add i64 [[B]], 36 11441d5033eSNikita Popov; CHECK: [[M:%_msarg_va_s.*]] = inttoptr i64 [[S]] to ptr 1153bc439bdSIlya Leoshkevich; CHECK: store {{.*}} [[M]] 1163bc439bdSIlya Leoshkevich 11741d5033eSNikita Popov; CHECK: [[B:%.*]] = ptrtoint ptr %va_arg_shadow to i64 1183bc439bdSIlya Leoshkevich; CHECK: [[S:%.*]] = add i64 [[B]], 40 1193bc439bdSIlya Leoshkevich; CHECK: [[V:%.*]] = sext {{.*}} 12041d5033eSNikita Popov; CHECK: [[M:%_msarg_va_s.*]] = inttoptr i64 [[S]] to ptr 1213bc439bdSIlya Leoshkevich; CHECK: store {{.*}} [[V]], {{.*}} [[M]] 1223bc439bdSIlya Leoshkevich 12341d5033eSNikita Popov; CHECK: [[B:%.*]] = ptrtoint ptr %va_arg_shadow to i64 1243bc439bdSIlya Leoshkevich; CHECK: [[S:%.*]] = add i64 [[B]], 48 12541d5033eSNikita Popov; CHECK: [[M:%_msarg_va_s.*]] = inttoptr i64 [[S]] to ptr 1263bc439bdSIlya Leoshkevich; CHECK: store {{.*}} [[M]] 1273bc439bdSIlya Leoshkevich 12841d5033eSNikita Popov; CHECK: [[B:%.*]] = ptrtoint ptr %va_arg_shadow to i64 1293bc439bdSIlya Leoshkevich; CHECK: [[S:%.*]] = add i64 [[B]], 160 13041d5033eSNikita Popov; CHECK: [[M:%_msarg_va_s.*]] = inttoptr i64 [[S]] to ptr 1313bc439bdSIlya Leoshkevich; CHECK: store {{.*}} [[M]] 1323bc439bdSIlya Leoshkevich 13341d5033eSNikita Popov; CHECK: [[B:%.*]] = ptrtoint ptr %va_arg_shadow to i64 1343bc439bdSIlya Leoshkevich; CHECK: [[S:%.*]] = add i64 [[B]], 168 13541d5033eSNikita Popov; CHECK: [[M:%_msarg_va_s.*]] = inttoptr i64 [[S]] to ptr 1363bc439bdSIlya Leoshkevich; CHECK: store {{.*}} [[M]] 1373bc439bdSIlya Leoshkevich 13841d5033eSNikita Popov; CHECK: [[B:%.*]] = ptrtoint ptr %va_arg_shadow to i64 1393bc439bdSIlya Leoshkevich; CHECK: [[S:%.*]] = add i64 [[B]], 176 14041d5033eSNikita Popov; CHECK: [[M:%_msarg_va_s.*]] = inttoptr i64 [[S]] to ptr 1413bc439bdSIlya Leoshkevich; CHECK: store {{.*}} [[M]] 1423bc439bdSIlya Leoshkevich 14341d5033eSNikita Popov; CHECK: [[B:%.*]] = ptrtoint ptr %va_arg_shadow to i64 1443bc439bdSIlya Leoshkevich; CHECK: [[S:%.*]] = add i64 [[B]], 184 1453bc439bdSIlya Leoshkevich; CHECK: [[V:%.*]] = zext {{.*}} 14641d5033eSNikita Popov; CHECK: [[M:%_msarg_va_s.*]] = inttoptr i64 [[S]] to ptr 1473bc439bdSIlya Leoshkevich; CHECK: store {{.*}} [[V]], {{.*}} [[M]] 1483bc439bdSIlya Leoshkevich 14941d5033eSNikita Popov; CHECK: [[B:%.*]] = ptrtoint ptr %va_arg_shadow to i64 1503bc439bdSIlya Leoshkevich; CHECK: [[S:%.*]] = add i64 [[B]], 192 15141d5033eSNikita Popov; CHECK: [[M:%_msarg_va_s.*]] = inttoptr i64 [[S]] to ptr 1523bc439bdSIlya Leoshkevich; CHECK: store {{.*}} [[M]] 1533bc439bdSIlya Leoshkevich 15441d5033eSNikita Popov; CHECK: [[B:%.*]] = ptrtoint ptr %va_arg_shadow to i64 1553bc439bdSIlya Leoshkevich; CHECK: [[S:%.*]] = add i64 [[B]], 204 15641d5033eSNikita Popov; CHECK: [[M:%_msarg_va_s.*]] = inttoptr i64 [[S]] to ptr 1573bc439bdSIlya Leoshkevich; CHECK: store {{.*}} [[M]] 1583bc439bdSIlya Leoshkevich 15941d5033eSNikita Popov; CHECK: [[B:%.*]] = ptrtoint ptr %va_arg_shadow to i64 1603bc439bdSIlya Leoshkevich; CHECK: [[S:%.*]] = add i64 [[B]], 208 1613bc439bdSIlya Leoshkevich; CHECK: [[V:%.*]] = sext {{.*}} 16241d5033eSNikita Popov; CHECK: [[M:%_msarg_va_s.*]] = inttoptr i64 [[S]] to ptr 1633bc439bdSIlya Leoshkevich; CHECK: store {{.*}} [[V]], {{.*}} [[M]] 1643bc439bdSIlya Leoshkevich 16541d5033eSNikita Popov; CHECK: [[B:%.*]] = ptrtoint ptr %va_arg_shadow to i64 1663bc439bdSIlya Leoshkevich; CHECK: [[S:%.*]] = add i64 [[B]], 216 16741d5033eSNikita Popov; CHECK: [[M:%_msarg_va_s.*]] = inttoptr i64 [[S]] to ptr 1683bc439bdSIlya Leoshkevich; CHECK: store {{.*}} [[M]] 1693bc439bdSIlya Leoshkevich 17041d5033eSNikita Popov; CHECK: [[B:%.*]] = ptrtoint ptr %va_arg_shadow to i64 1713bc439bdSIlya Leoshkevich; CHECK: [[S:%.*]] = add i64 [[B]], 224 17241d5033eSNikita Popov; CHECK: [[M:%_msarg_va_s.*]] = inttoptr i64 [[S]] to ptr 1733bc439bdSIlya Leoshkevich; CHECK: store {{.*}} [[M]] 1743bc439bdSIlya Leoshkevich 1750b0bb196SJon Roelofs; CHECK: store {{.*}} 72, {{.*}} %va_arg_overflow_size 176