// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o - | FileCheck %s -check-prefix=CIR // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o - | FileCheck %s -check-prefix=LLVM // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s -check-prefix=LLVM struct S { void do_thing(); }; void test_const_cast(const S &s) { const_cast(s).do_thing(); } // CIR: cir.func {{.*}}@_Z15test_const_castRK1S(%[[ARG:.*]]: !cir.ptr{{.*}}) {{.*}}{ // CIR-NEXT: %[[ARG_ALLOCA:.*]] = cir.alloca !cir.ptr, !cir.ptr>, ["s", init, const] // CIR-NEXT: cir.store %[[ARG]], %[[ARG_ALLOCA]] : !cir.ptr, !cir.ptr> // CIR-NEXT: %[[ARG_LOAD:.*]] = cir.load %[[ARG_ALLOCA]] : !cir.ptr>, !cir.ptr // CIR-NEXT: cir.call @_ZN1S8do_thingEv(%[[ARG_LOAD]]) // LLVM: define {{.*}}void @_Z15test_const_castRK1S(ptr{{.*}}%[[ARG:.*]]) // LLVM: %[[ARG_ALLOCA:.*]] = alloca ptr // LLVM-NEXT: store ptr %[[ARG]], ptr %[[ARG_ALLOCA]] // LLVM-NEXT: %[[ARG_LOAD:.*]] = load ptr, ptr %[[ARG_ALLOCA]] // LLVM-NEXT: call void @_ZN1S8do_thingEv(ptr {{.*}}%[[ARG_LOAD]]) void call_with_ri_cast(S*&); void call_with_ri_cast(int*&); void test_reinterpet_cast(void *&data) { call_with_ri_cast(reinterpret_cast(data)); call_with_ri_cast(reinterpret_cast(data)); } // CIR: cir.func {{.*}}@_Z20test_reinterpet_castRPv(%[[ARG:.*]]: !cir.ptr>{{.*}}) {{.*}}{ // CIR-NEXT: %[[ARG_ALLOCA:.*]] = cir.alloca !cir.ptr>, !cir.ptr>>, ["data", init, const] // CIR-NEXT: cir.store %[[ARG]], %[[ARG_ALLOCA]] : !cir.ptr>, !cir.ptr>> // CIR-NEXT: %[[ARG_LOAD:.*]] = cir.load %[[ARG_ALLOCA]] : !cir.ptr>>, !cir.ptr> // CIR-NEXT: %[[RI_CAST:.*]] = cir.cast bitcast %[[ARG_LOAD]] : !cir.ptr> -> !cir.ptr> // CIR-NEXT: cir.call @_Z17call_with_ri_castRP1S(%[[RI_CAST]]) // CIR-NEXT: %[[ARG_LOAD:.*]] = cir.load %[[ARG_ALLOCA]] : !cir.ptr>>, !cir.ptr> // CIR-NEXT: %[[RI_CAST:.*]] = cir.cast bitcast %[[ARG_LOAD]] : !cir.ptr> -> !cir.ptr> // CIR-NEXT: cir.call @_Z17call_with_ri_castRPi(%[[RI_CAST]]) // LLVM: define dso_local void @_Z20test_reinterpet_castRPv(ptr {{.*}}%[[ARG:.*]]) // LLVM: %[[ARG_ALLOCA:.*]] = alloca ptr // LLVM-NEXT: store ptr %[[ARG]], ptr %[[ARG_ALLOCA]] // LLVM-NEXT: %[[ARG_LOAD:.*]] = load ptr, ptr %[[ARG_ALLOCA]] // LLVM-NEXT: call void @_Z17call_with_ri_castRP1S(ptr {{.*}}%[[ARG_LOAD]]) // LLVM-NEXT: %[[ARG_LOAD:.*]] = load ptr, ptr %[[ARG_ALLOCA]] // LLVM-NEXT: call void @_Z17call_with_ri_castRPi(ptr {{.*}}%[[ARG_LOAD]])