[clang] [CIR][AMDGPU] Fix address space of __builtin_frame_address result (PR #233724)
Arseniy Obolenskiy via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 5 22:37:03 PST 2026
================
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple amdgpu-amd-amdhsa -Wno-frame-address -fclangir -emit-cir %s -o %t.cir
+// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
+// RUN: %clang_cc1 -triple amdgpu-amd-amdhsa -Wno-frame-address -fclangir -emit-llvm %s -o %t-cir.ll
+// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
+// RUN: %clang_cc1 -triple amdgpu-amd-amdhsa -Wno-frame-address -emit-llvm %s -o %t.ll
+// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
+
+// The frame address is a private (AS 5) pointer that must be cast to the
+// generic void * result type.
+
+void *test_frame_address() {
+ return __builtin_frame_address(1);
+}
+
+// CIR-LABEL: cir.func{{.*}} @_Z18test_frame_addressv()
+// CIR: %[[ARG:.*]] = cir.const #cir.int<1> : !u32i
+// CIR-NEXT: %[[ADDR:.*]] = cir.frame_address(%[[ARG]]) : !cir.ptr<!u8i, target_address_space(5)>
+// CIR-NEXT: %[[VOID:.*]] = cir.cast bitcast %[[ADDR]] : !cir.ptr<!u8i, target_address_space(5)> -> !cir.ptr<!void, target_address_space(5)>
+// CIR-NEXT: %[[CAST:.*]] = cir.cast address_space %[[VOID]] : !cir.ptr<!void, target_address_space(5)> -> !cir.ptr<!void>
----------------
aobolensk wrote:
This cast is still needed: the frame address is a 32-bit private pointer, but `void *` is a 64-bit generic pointer, without the cast the typed cir.store fails IR verification, and a bitcast is rejected by the llvm dialect
Classic codegen is able to skip conversion only because llvm opaque pointers don't really check it
https://github.com/llvm/llvm-project/pull/233724
More information about the cfe-commits
mailing list