; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 ; Test cast instruction instrumentation support in the Instrumentor pass. ; This test verifies that cast instructions (PtrToInt, IntToPtr, Trunc, ; ZExt, SExt, FPToUI, FPToSI, UIToFP, SIToFP, FPTrunc, FPExt, AddrSpaceCast, ; and BitCast) are properly instrumented with both pre and post callbacks, ; including support for result replacement and opcode identification. ; ; RUN: opt < %s -passes=instrumentor -instrumentor-read-config-files=%S/cast_config.json -S | FileCheck %s define noundef i64 @test_ptrtoint_basic(ptr noundef %ptr) { ; CHECK-LABEL: define noundef i64 @test_ptrtoint_basic( ; CHECK-SAME: ptr noundef [[PTR:%.*]]) { ; CHECK-NEXT: [[ENTRY:.*:]] ; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr [[PTR]] to i64 ; CHECK-NEXT: call void @__instrumentor_pre_cast(i64 [[TMP0]], i32 15, i32 8, i32 12, i32 8, i32 48) #[[ATTR0:[0-9]+]] ; CHECK-NEXT: [[ADDR:%.*]] = ptrtoint ptr [[PTR]] to i64 ; CHECK-NEXT: [[TMP1:%.*]] = call i64 @__instrumentor_post_cast(i64 [[TMP0]], i32 15, i32 8, i64 [[ADDR]], i32 12, i32 8, i32 48) #[[ATTR0]] ; CHECK-NEXT: ret i64 [[TMP1]] ; entry: %addr = ptrtoint ptr %ptr to i64 ret i64 %addr } define noundef ptr @test_inttoptr_basic(i64 noundef %addr) { ; CHECK-LABEL: define noundef ptr @test_inttoptr_basic( ; CHECK-SAME: i64 noundef [[ADDR:%.*]]) { ; CHECK-NEXT: [[ENTRY:.*:]] ; CHECK-NEXT: call void @__instrumentor_pre_cast(i64 [[ADDR]], i32 12, i32 8, i32 15, i32 8, i32 50) #[[ATTR0]] ; CHECK-NEXT: [[PTR:%.*]] = inttoptr i64 [[ADDR]] to ptr ; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr [[PTR]] to i64 ; CHECK-NEXT: [[TMP1:%.*]] = call i64 @__instrumentor_post_cast(i64 [[ADDR]], i32 12, i32 8, i64 [[TMP0]], i32 15, i32 8, i32 50) #[[ATTR0]] ; CHECK-NEXT: [[TMP2:%.*]] = inttoptr i64 [[TMP1]] to ptr ; CHECK-NEXT: ret ptr [[TMP2]] ; entry: %ptr = inttoptr i64 %addr to ptr ret ptr %ptr } define noundef i32 @test_trunc(i64 noundef %val) { ; CHECK-LABEL: define noundef i32 @test_trunc( ; CHECK-SAME: i64 noundef [[VAL:%.*]]) { ; CHECK-NEXT: [[ENTRY:.*:]] ; CHECK-NEXT: call void @__instrumentor_pre_cast(i64 [[VAL]], i32 12, i32 8, i32 12, i32 4, i32 39) #[[ATTR0]] ; CHECK-NEXT: [[RESULT:%.*]] = trunc i64 [[VAL]] to i32 ; CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[RESULT]] to i64 ; CHECK-NEXT: [[TMP1:%.*]] = call i64 @__instrumentor_post_cast(i64 [[VAL]], i32 12, i32 8, i64 [[TMP0]], i32 12, i32 4, i32 39) #[[ATTR0]] ; CHECK-NEXT: [[TMP2:%.*]] = trunc i64 [[TMP1]] to i32 ; CHECK-NEXT: ret i32 [[TMP2]] ; entry: %result = trunc i64 %val to i32 ret i32 %result } define noundef i64 @test_zext(i32 noundef %val) { ; CHECK-LABEL: define noundef i64 @test_zext( ; CHECK-SAME: i32 noundef [[VAL:%.*]]) { ; CHECK-NEXT: [[ENTRY:.*:]] ; CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[VAL]] to i64 ; CHECK-NEXT: call void @__instrumentor_pre_cast(i64 [[TMP0]], i32 12, i32 4, i32 12, i32 8, i32 40) #[[ATTR0]] ; CHECK-NEXT: [[RESULT:%.*]] = zext i32 [[VAL]] to i64 ; CHECK-NEXT: [[TMP1:%.*]] = call i64 @__instrumentor_post_cast(i64 [[TMP0]], i32 12, i32 4, i64 [[RESULT]], i32 12, i32 8, i32 40) #[[ATTR0]] ; CHECK-NEXT: ret i64 [[TMP1]] ; entry: %result = zext i32 %val to i64 ret i64 %result } define noundef i64 @test_sext(i32 noundef %val) { ; CHECK-LABEL: define noundef i64 @test_sext( ; CHECK-SAME: i32 noundef [[VAL:%.*]]) { ; CHECK-NEXT: [[ENTRY:.*:]] ; CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[VAL]] to i64 ; CHECK-NEXT: call void @__instrumentor_pre_cast(i64 [[TMP0]], i32 12, i32 4, i32 12, i32 8, i32 41) #[[ATTR0]] ; CHECK-NEXT: [[RESULT:%.*]] = sext i32 [[VAL]] to i64 ; CHECK-NEXT: [[TMP1:%.*]] = call i64 @__instrumentor_post_cast(i64 [[TMP0]], i32 12, i32 4, i64 [[RESULT]], i32 12, i32 8, i32 41) #[[ATTR0]] ; CHECK-NEXT: ret i64 [[TMP1]] ; entry: %result = sext i32 %val to i64 ret i64 %result } define noundef i32 @test_fptoui(float noundef %val) { ; CHECK-LABEL: define noundef i32 @test_fptoui( ; CHECK-SAME: float noundef [[VAL:%.*]]) { ; CHECK-NEXT: [[ENTRY:.*:]] ; CHECK-NEXT: [[TMP0:%.*]] = bitcast float [[VAL]] to i32 ; CHECK-NEXT: [[TMP1:%.*]] = zext i32 [[TMP0]] to i64 ; CHECK-NEXT: call void @__instrumentor_pre_cast(i64 [[TMP1]], i32 2, i32 4, i32 12, i32 4, i32 42) #[[ATTR0]] ; CHECK-NEXT: [[RESULT:%.*]] = fptoui float [[VAL]] to i32 ; CHECK-NEXT: [[TMP2:%.*]] = zext i32 [[RESULT]] to i64 ; CHECK-NEXT: [[TMP3:%.*]] = call i64 @__instrumentor_post_cast(i64 [[TMP1]], i32 2, i32 4, i64 [[TMP2]], i32 12, i32 4, i32 42) #[[ATTR0]] ; CHECK-NEXT: [[TMP4:%.*]] = trunc i64 [[TMP3]] to i32 ; CHECK-NEXT: ret i32 [[TMP4]] ; entry: %result = fptoui float %val to i32 ret i32 %result } define noundef i32 @test_fptosi(float noundef %val) { ; CHECK-LABEL: define noundef i32 @test_fptosi( ; CHECK-SAME: float noundef [[VAL:%.*]]) { ; CHECK-NEXT: [[ENTRY:.*:]] ; CHECK-NEXT: [[TMP0:%.*]] = bitcast float [[VAL]] to i32 ; CHECK-NEXT: [[TMP1:%.*]] = zext i32 [[TMP0]] to i64 ; CHECK-NEXT: call void @__instrumentor_pre_cast(i64 [[TMP1]], i32 2, i32 4, i32 12, i32 4, i32 43) #[[ATTR0]] ; CHECK-NEXT: [[RESULT:%.*]] = fptosi float [[VAL]] to i32 ; CHECK-NEXT: [[TMP2:%.*]] = zext i32 [[RESULT]] to i64 ; CHECK-NEXT: [[TMP3:%.*]] = call i64 @__instrumentor_post_cast(i64 [[TMP1]], i32 2, i32 4, i64 [[TMP2]], i32 12, i32 4, i32 43) #[[ATTR0]] ; CHECK-NEXT: [[TMP4:%.*]] = trunc i64 [[TMP3]] to i32 ; CHECK-NEXT: ret i32 [[TMP4]] ; entry: %result = fptosi float %val to i32 ret i32 %result } define noundef float @test_uitofp(i32 noundef %val) { ; CHECK-LABEL: define noundef float @test_uitofp( ; CHECK-SAME: i32 noundef [[VAL:%.*]]) { ; CHECK-NEXT: [[ENTRY:.*:]] ; CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[VAL]] to i64 ; CHECK-NEXT: call void @__instrumentor_pre_cast(i64 [[TMP0]], i32 12, i32 4, i32 2, i32 4, i32 44) #[[ATTR0]] ; CHECK-NEXT: [[RESULT:%.*]] = uitofp i32 [[VAL]] to float ; CHECK-NEXT: [[TMP1:%.*]] = bitcast float [[RESULT]] to i32 ; CHECK-NEXT: [[TMP2:%.*]] = zext i32 [[TMP1]] to i64 ; CHECK-NEXT: [[TMP3:%.*]] = call i64 @__instrumentor_post_cast(i64 [[TMP0]], i32 12, i32 4, i64 [[TMP2]], i32 2, i32 4, i32 44) #[[ATTR0]] ; CHECK-NEXT: [[TMP4:%.*]] = trunc i64 [[TMP3]] to i32 ; CHECK-NEXT: [[TMP5:%.*]] = bitcast i32 [[TMP4]] to float ; CHECK-NEXT: ret float [[TMP5]] ; entry: %result = uitofp i32 %val to float ret float %result } define noundef float @test_sitofp(i32 noundef %val) { ; CHECK-LABEL: define noundef float @test_sitofp( ; CHECK-SAME: i32 noundef [[VAL:%.*]]) { ; CHECK-NEXT: [[ENTRY:.*:]] ; CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[VAL]] to i64 ; CHECK-NEXT: call void @__instrumentor_pre_cast(i64 [[TMP0]], i32 12, i32 4, i32 2, i32 4, i32 45) #[[ATTR0]] ; CHECK-NEXT: [[RESULT:%.*]] = sitofp i32 [[VAL]] to float ; CHECK-NEXT: [[TMP1:%.*]] = bitcast float [[RESULT]] to i32 ; CHECK-NEXT: [[TMP2:%.*]] = zext i32 [[TMP1]] to i64 ; CHECK-NEXT: [[TMP3:%.*]] = call i64 @__instrumentor_post_cast(i64 [[TMP0]], i32 12, i32 4, i64 [[TMP2]], i32 2, i32 4, i32 45) #[[ATTR0]] ; CHECK-NEXT: [[TMP4:%.*]] = trunc i64 [[TMP3]] to i32 ; CHECK-NEXT: [[TMP5:%.*]] = bitcast i32 [[TMP4]] to float ; CHECK-NEXT: ret float [[TMP5]] ; entry: %result = sitofp i32 %val to float ret float %result } define noundef float @test_fptrunc(double noundef %val) { ; CHECK-LABEL: define noundef float @test_fptrunc( ; CHECK-SAME: double noundef [[VAL:%.*]]) { ; CHECK-NEXT: [[ENTRY:.*:]] ; CHECK-NEXT: [[TMP0:%.*]] = bitcast double [[VAL]] to i64 ; CHECK-NEXT: call void @__instrumentor_pre_cast(i64 [[TMP0]], i32 3, i32 8, i32 2, i32 4, i32 46) #[[ATTR0]] ; CHECK-NEXT: [[RESULT:%.*]] = fptrunc double [[VAL]] to float ; CHECK-NEXT: [[TMP1:%.*]] = bitcast float [[RESULT]] to i32 ; CHECK-NEXT: [[TMP2:%.*]] = zext i32 [[TMP1]] to i64 ; CHECK-NEXT: [[TMP3:%.*]] = call i64 @__instrumentor_post_cast(i64 [[TMP0]], i32 3, i32 8, i64 [[TMP2]], i32 2, i32 4, i32 46) #[[ATTR0]] ; CHECK-NEXT: [[TMP4:%.*]] = trunc i64 [[TMP3]] to i32 ; CHECK-NEXT: [[TMP5:%.*]] = bitcast i32 [[TMP4]] to float ; CHECK-NEXT: ret float [[TMP5]] ; entry: %result = fptrunc double %val to float ret float %result } define noundef double @test_fpext(float noundef %val) { ; CHECK-LABEL: define noundef double @test_fpext( ; CHECK-SAME: float noundef [[VAL:%.*]]) { ; CHECK-NEXT: [[ENTRY:.*:]] ; CHECK-NEXT: [[TMP0:%.*]] = bitcast float [[VAL]] to i32 ; CHECK-NEXT: [[TMP1:%.*]] = zext i32 [[TMP0]] to i64 ; CHECK-NEXT: call void @__instrumentor_pre_cast(i64 [[TMP1]], i32 2, i32 4, i32 3, i32 8, i32 47) #[[ATTR0]] ; CHECK-NEXT: [[RESULT:%.*]] = fpext float [[VAL]] to double ; CHECK-NEXT: [[TMP2:%.*]] = bitcast double [[RESULT]] to i64 ; CHECK-NEXT: [[TMP3:%.*]] = call i64 @__instrumentor_post_cast(i64 [[TMP1]], i32 2, i32 4, i64 [[TMP2]], i32 3, i32 8, i32 47) #[[ATTR0]] ; CHECK-NEXT: [[TMP4:%.*]] = bitcast i64 [[TMP3]] to double ; CHECK-NEXT: ret double [[TMP4]] ; entry: %result = fpext float %val to double ret double %result } define noundef ptr addrspace(1) @test_addrspacecast(ptr noundef %ptr) { ; CHECK-LABEL: define noundef ptr addrspace(1) @test_addrspacecast( ; CHECK-SAME: ptr noundef [[PTR:%.*]]) { ; CHECK-NEXT: [[ENTRY:.*:]] ; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr [[PTR]] to i64 ; CHECK-NEXT: call void @__instrumentor_pre_cast(i64 [[TMP0]], i32 15, i32 8, i32 15, i32 8, i32 52) #[[ATTR0]] ; CHECK-NEXT: [[RESULT:%.*]] = addrspacecast ptr [[PTR]] to ptr addrspace(1) ; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr addrspace(1) [[RESULT]] to i64 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @__instrumentor_post_cast(i64 [[TMP0]], i32 15, i32 8, i64 [[TMP1]], i32 15, i32 8, i32 52) #[[ATTR0]] ; CHECK-NEXT: [[TMP3:%.*]] = inttoptr i64 [[TMP2]] to ptr addrspace(1) ; CHECK-NEXT: ret ptr addrspace(1) [[TMP3]] ; entry: %result = addrspacecast ptr %ptr to ptr addrspace(1) ret ptr addrspace(1) %result } define noundef i64 @test_bitcast(double noundef %val) { ; CHECK-LABEL: define noundef i64 @test_bitcast( ; CHECK-SAME: double noundef [[VAL:%.*]]) { ; CHECK-NEXT: [[ENTRY:.*:]] ; CHECK-NEXT: [[TMP0:%.*]] = bitcast double [[VAL]] to i64 ; CHECK-NEXT: call void @__instrumentor_pre_cast(i64 [[TMP0]], i32 3, i32 8, i32 12, i32 8, i32 51) #[[ATTR0]] ; CHECK-NEXT: [[RESULT:%.*]] = bitcast double [[VAL]] to i64 ; CHECK-NEXT: [[TMP1:%.*]] = call i64 @__instrumentor_post_cast(i64 [[TMP0]], i32 3, i32 8, i64 [[RESULT]], i32 12, i32 8, i32 51) #[[ATTR0]] ; CHECK-NEXT: ret i64 [[TMP1]] ; entry: %result = bitcast double %val to i64 ret i64 %result } define void @test_multiple_conversions(ptr noundef %p1, i64 noundef %i1, float noundef %f1) { ; CHECK-LABEL: define void @test_multiple_conversions( ; CHECK-SAME: ptr noundef [[P1:%.*]], i64 noundef [[I1:%.*]], float noundef [[F1:%.*]]) { ; CHECK-NEXT: [[ENTRY:.*:]] ; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr [[P1]] to i64 ; CHECK-NEXT: call void @__instrumentor_pre_cast(i64 [[TMP0]], i32 15, i32 8, i32 12, i32 8, i32 48) #[[ATTR0]] ; CHECK-NEXT: [[A1:%.*]] = ptrtoint ptr [[P1]] to i64 ; CHECK-NEXT: [[TMP1:%.*]] = call i64 @__instrumentor_post_cast(i64 [[TMP0]], i32 15, i32 8, i64 [[A1]], i32 12, i32 8, i32 48) #[[ATTR0]] ; CHECK-NEXT: call void @__instrumentor_pre_cast(i64 [[I1]], i32 12, i32 8, i32 15, i32 8, i32 50) #[[ATTR0]] ; CHECK-NEXT: [[P2:%.*]] = inttoptr i64 [[I1]] to ptr ; CHECK-NEXT: [[TMP2:%.*]] = ptrtoint ptr [[P2]] to i64 ; CHECK-NEXT: [[TMP3:%.*]] = call i64 @__instrumentor_post_cast(i64 [[I1]], i32 12, i32 8, i64 [[TMP2]], i32 15, i32 8, i32 50) #[[ATTR0]] ; CHECK-NEXT: [[TMP4:%.*]] = inttoptr i64 [[TMP3]] to ptr ; CHECK-NEXT: [[TMP5:%.*]] = bitcast float [[F1]] to i32 ; CHECK-NEXT: [[TMP6:%.*]] = zext i32 [[TMP5]] to i64 ; CHECK-NEXT: call void @__instrumentor_pre_cast(i64 [[TMP6]], i32 2, i32 4, i32 12, i32 4, i32 42) #[[ATTR0]] ; CHECK-NEXT: [[I2:%.*]] = fptoui float [[F1]] to i32 ; CHECK-NEXT: [[TMP7:%.*]] = zext i32 [[I2]] to i64 ; CHECK-NEXT: [[TMP8:%.*]] = call i64 @__instrumentor_post_cast(i64 [[TMP6]], i32 2, i32 4, i64 [[TMP7]], i32 12, i32 4, i32 42) #[[ATTR0]] ; CHECK-NEXT: [[TMP9:%.*]] = trunc i64 [[TMP8]] to i32 ; CHECK-NEXT: call void @use_values(i64 [[TMP1]], ptr [[TMP4]], i32 [[TMP9]]) ; CHECK-NEXT: ret void ; entry: %a1 = ptrtoint ptr %p1 to i64 %p2 = inttoptr i64 %i1 to ptr %i2 = fptoui float %f1 to i32 call void @use_values(i64 %a1, ptr %p2, i32 %i2) ret void } define i128 @test_ext(i32 %p1) { ; CHECK-LABEL: define i128 @test_ext( ; CHECK-SAME: i32 [[P1:%.*]]) { ; CHECK-NEXT: [[TMP1:%.*]] = alloca i128, align 8 ; CHECK-NEXT: [[TMP2:%.*]] = alloca i64, align 8 ; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[P1]] to i64 ; CHECK-NEXT: call void @__instrumentor_pre_cast(i64 [[TMP3]], i32 12, i32 4, i32 12, i32 16, i32 40) #[[ATTR0]] ; CHECK-NEXT: [[I1:%.*]] = zext i32 [[P1]] to i128 ; CHECK-NEXT: store i64 [[TMP3]], ptr [[TMP2]], align 4 ; CHECK-NEXT: store i128 [[I1]], ptr [[TMP1]], align 4 ; CHECK-NEXT: call void @__instrumentor_post_cast_ind(ptr [[TMP2]], i32 8, i32 12, i32 4, ptr [[TMP1]], i32 16, i32 12, i32 16, i32 40) #[[ATTR0]] ; CHECK-NEXT: [[TMP4:%.*]] = load i128, ptr [[TMP1]], align 4 ; CHECK-NEXT: ret i128 [[TMP4]] ; %i1 = zext i32 %p1 to i128 ret i128 %i1 } declare void @use_values(i64, ptr, i32)