https://github.com/aobolensk updated https://github.com/llvm/llvm-project/pull/233724
>From e1c5471003c7b1b5fde6b1468a75359ddb6692c9 Mon Sep 17 00:00:00 2001 From: Arseniy Obolenskiy <[email protected]> Date: Tue, 20 Oct 2026 09:19:27 +0200 Subject: [PATCH] [CIR][AMDGPU] Fix address space of __builtin_frame_address result Use an address space cast instead of a bitcast, which failed CIR verification --- clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp | 5 +++-- clang/test/CIR/CodeGenBuiltins/builtins.cpp | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp index a94139cff20ff..160578037066c 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp @@ -2538,8 +2538,9 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID, mlir::Value addr = cir::FrameAddrOp::create( builder, loc, allocaInt8PtrTy, builder.getConstAPInt(loc, builder.getUInt32Ty(), level)); - return RValue::get( - builder.createCast(loc, cir::CastKind::bitcast, addr, voidPtrTy)); + addr = builder.createBitcast( + addr, builder.getVoidPtrTy(getCIRAllocaAddressSpace())); + return RValue::get(performAddrSpaceCast(addr, convertType(e->getType()))); } case Builtin::BI__builtin_extract_return_addr: case Builtin::BI__builtin_frob_return_addr: diff --git a/clang/test/CIR/CodeGenBuiltins/builtins.cpp b/clang/test/CIR/CodeGenBuiltins/builtins.cpp index 920f0696dba2d..8e4be00faaba0 100644 --- a/clang/test/CIR/CodeGenBuiltins/builtins.cpp +++ b/clang/test/CIR/CodeGenBuiltins/builtins.cpp @@ -4,6 +4,10 @@ // RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll // RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM +// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -Wno-unused-value -fclangir -emit-cir %s -o %t-amdgpu.cir +// RUN: FileCheck --input-file=%t-amdgpu.cir %s -check-prefix=CIR-AMDGPU +// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -Wno-unused-value -fclangir -emit-llvm %s -o %t-amdgpu.ll +// RUN: FileCheck --input-file=%t-amdgpu.ll %s -check-prefix=LLVM-AMDGPU double fabs(double x) { return __builtin_fabs(x); @@ -35,4 +39,14 @@ extern "C" void *test_frame_address(void) { // LLVM-LABEL: @test_frame_address // LLVM: {{%.*}} = call ptr @llvm.frameaddress.p0(i32 1) + // CIR-AMDGPU-LABEL: test_frame_address + // CIR-AMDGPU: [[ARG:%.*]] = cir.const #cir.int<1> : !u32i + // CIR-AMDGPU: %[[ADDR:.*]] = cir.frame_address([[ARG]]) : !cir.ptr<!u8i, target_address_space(5)> + // CIR-AMDGPU: %[[CAST:.*]] = cir.cast bitcast %[[ADDR]] : !cir.ptr<!u8i, target_address_space(5)> -> !cir.ptr<!void, target_address_space(5)> + // CIR-AMDGPU: {{%.*}} = cir.cast address_space %[[CAST]] : !cir.ptr<!void, target_address_space(5)> -> !cir.ptr<!void> + + // LLVM-AMDGPU-LABEL: @test_frame_address + // LLVM-AMDGPU: %[[ADDR:.*]] = call ptr addrspace(5) @llvm.frameaddress.p5(i32 1) + // LLVM-AMDGPU: {{%.*}} = addrspacecast ptr addrspace(5) %[[ADDR]] to ptr + } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
