[clang] [CIR] Preserve address spaces in emitPointerWithAlignment casts (PR #228652)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-arm64-windows-msvc` running on `arm-bbot-clang-arm64-windows-msvc` while building `clang` at step 6 "test-build-unified-tree-check-all". Full details are available at: https://lab.llvm.org/buildbot/#/builders/161/builds/13410 Here is the relevant piece of the build log for the reference ``` Step 6 (test-build-unified-tree-check-all) failure: test (failure) TEST 'libomp :: tasking/issue-94260-2.c' FAILED Exit Code: 3221225477 Command Output (stdout): -- # RUN: at line 1 C:/buildbot/workspace/clang-arm64-windows-msvc/build/./bin/clang.exe -fopenmp -I C:/buildbot/workspace/clang-arm64-windows-msvc/build/runtimes/runtimes-bins/openmp/runtime/src -I C:/buildbot/workspace/clang-arm64-windows-msvc/llvm-project/openmp/runtime/test -L C:/buildbot/workspace/clang-arm64-windows-msvc/build/runtimes/runtimes-bins/openmp/runtime/src -fno-omit-frame-pointer C:\buildbot\workspace\clang-arm64-windows-msvc\llvm-project\openmp\runtime\test\tasking\issue-94260-2.c -o C:\buildbot\workspace\clang-arm64-windows-msvc\build\runtimes\runtimes-bins\openmp\runtime\test\tasking\Output\issue-94260-2.c.tmp && C:\buildbot\workspace\clang-arm64-windows-msvc\build\runtimes\runtimes-bins\openmp\runtime\test\tasking\Output\issue-94260-2.c.tmp # executed command: C:/buildbot/workspace/clang-arm64-windows-msvc/build/./bin/clang.exe -fopenmp -I C:/buildbot/workspace/clang-arm64-windows-msvc/build/runtimes/runtimes-bins/openmp/runtime/src -I C:/buildbot/workspace/clang-arm64-windows-msvc/llvm-project/openmp/runtime/test -L C:/buildbot/workspace/clang-arm64-windows-msvc/build/runtimes/runtimes-bins/openmp/runtime/src -fno-omit-frame-pointer 'C:\buildbot\workspace\clang-arm64-windows-msvc\llvm-project\openmp\runtime\test\tasking\issue-94260-2.c' -o 'C:\buildbot\workspace\clang-arm64-windows-msvc\build\runtimes\runtimes-bins\openmp\runtime\test\tasking\Output\issue-94260-2.c.tmp' # executed command: 'C:\buildbot\workspace\clang-arm64-windows-msvc\build\runtimes\runtimes-bins\openmp\runtime\test\tasking\Output\issue-94260-2.c.tmp' # note: command had no output on stdout or stderr # error: command failed with exit status: 0xc005 -- ``` https://github.com/llvm/llvm-project/pull/228652 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Preserve address spaces in emitPointerWithAlignment casts (PR #228652)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-arm64-windows-msvc` running on `arm-bbot-clang-arm64-windows-msvc` while building `clang` at step 6 "test-build-unified-tree-check-all". Full details are available at: https://lab.llvm.org/buildbot/#/builders/161/builds/13410 Here is the relevant piece of the build log for the reference ``` Step 6 (test-build-unified-tree-check-all) failure: test (failure) TEST 'libomp :: tasking/issue-94260-2.c' FAILED Exit Code: 3221225477 Command Output (stdout): -- # RUN: at line 1 C:/buildbot/workspace/clang-arm64-windows-msvc/build/./bin/clang.exe -fopenmp -I C:/buildbot/workspace/clang-arm64-windows-msvc/build/runtimes/runtimes-bins/openmp/runtime/src -I C:/buildbot/workspace/clang-arm64-windows-msvc/llvm-project/openmp/runtime/test -L C:/buildbot/workspace/clang-arm64-windows-msvc/build/runtimes/runtimes-bins/openmp/runtime/src -fno-omit-frame-pointer C:\buildbot\workspace\clang-arm64-windows-msvc\llvm-project\openmp\runtime\test\tasking\issue-94260-2.c -o C:\buildbot\workspace\clang-arm64-windows-msvc\build\runtimes\runtimes-bins\openmp\runtime\test\tasking\Output\issue-94260-2.c.tmp && C:\buildbot\workspace\clang-arm64-windows-msvc\build\runtimes\runtimes-bins\openmp\runtime\test\tasking\Output\issue-94260-2.c.tmp # executed command: C:/buildbot/workspace/clang-arm64-windows-msvc/build/./bin/clang.exe -fopenmp -I C:/buildbot/workspace/clang-arm64-windows-msvc/build/runtimes/runtimes-bins/openmp/runtime/src -I C:/buildbot/workspace/clang-arm64-windows-msvc/llvm-project/openmp/runtime/test -L C:/buildbot/workspace/clang-arm64-windows-msvc/build/runtimes/runtimes-bins/openmp/runtime/src -fno-omit-frame-pointer 'C:\buildbot\workspace\clang-arm64-windows-msvc\llvm-project\openmp\runtime\test\tasking\issue-94260-2.c' -o 'C:\buildbot\workspace\clang-arm64-windows-msvc\build\runtimes\runtimes-bins\openmp\runtime\test\tasking\Output\issue-94260-2.c.tmp' # executed command: 'C:\buildbot\workspace\clang-arm64-windows-msvc\build\runtimes\runtimes-bins\openmp\runtime\test\tasking\Output\issue-94260-2.c.tmp' # note: command had no output on stdout or stderr # error: command failed with exit status: 0xc005 -- ``` https://github.com/llvm/llvm-project/pull/228652 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Preserve address spaces in emitPointerWithAlignment casts (PR #228652)
https://github.com/RiverDave approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/228652 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Preserve address spaces in emitPointerWithAlignment casts (PR #228652)
llvmorg-github-actions[bot] wrote:
@llvm/pr-subscribers-clangir
Author: Konstantinos Parasyris (koparasy)
Changes
emitPointerWithAlignment handled CK_AddressSpaceConversion like CK_BitCast and
never emitted the address-space cast, so the result kept the source address
space. When the address escaped (returned reference, stored pointer), the store
path bitcast the destination slot to the wrong address space. This miscompiled
sycl::multi_ptr::operator[] on SPIR-V: a local-memory offset was used as a
generic address. Emit the cast after the element bitcast, as classic CodeGen
does.
createElementBitCast also built the new pointer type in the default address
space, so changing the element type of a non-default-AS pointer produced an
AS-changing bitcast that the verifier rejects (for example ((int *)p)[i] or
__builtin_stdc_memreverse8 on an AS3 pointer). Keep the source address space,
which matches classic's withElementType.
---
Full diff: https://github.com/llvm/llvm-project/pull/228652.diff
4 Files Affected:
- (modified) clang/lib/CIR/CodeGen/CIRGenBuilder.h (+2-1)
- (modified) clang/lib/CIR/CodeGen/CIRGenExpr.cpp (+3-1)
- (added) clang/test/CIR/CodeGen/subscript-addrspace-cast.cpp (+69)
- (modified) clang/test/CIR/CodeGenBuiltins/builtin-stdc-bit-c2y.c (+18)
``diff
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h
b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
index d224feb83b03d..2e9bae5e7d2c8 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
@@ -539,7 +539,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
if (destType == addr.getElementType())
return addr;
-auto ptrTy = getPointerTo(destType);
+auto srcPtrTy = mlir::cast(addr.getPointer().getType());
+auto ptrTy = getPointerTo(destType, srcPtrTy.getAddrSpace());
return Address(createBitcast(loc, addr.getPointer(), ptrTy), destType,
addr.getAlignment());
}
diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
index 62740dc246827..f5eafaf393c02 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
@@ -173,7 +173,9 @@ Address CIRGenFunction::emitPointerWithAlignment(const Expr
*expr,
convertTypeForMem(expr->getType()->getPointeeType());
addr =
getBuilder().createElementBitCast(getLoc(expr->getSourceRange()),
addr, eltTy);
-assert(!cir::MissingFeatures::addressSpace());
+if (ce->getCastKind() == CK_AddressSpaceConversion)
+ addr = addr.withPointer(performAddrSpaceCast(
+ addr.getPointer(), convertType(expr->getType(;
return addr;
}
diff --git a/clang/test/CIR/CodeGen/subscript-addrspace-cast.cpp
b/clang/test/CIR/CodeGen/subscript-addrspace-cast.cpp
new file mode 100644
index 0..c75d615138961
--- /dev/null
+++ b/clang/test/CIR/CodeGen/subscript-addrspace-cast.cpp
@@ -0,0 +1,69 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o
%t.cir
+// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o
%t-cir.ll
+// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll
+// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG
+
+#define AS3 __attribute__((address_space(3)))
+
+float &at(AS3 float *p, long i) {
+ return ((float *)p)[i];
+}
+
+// CIR-LABEL: cir.func{{.*}} @_Z2atPU3AS3fl(
+// CIR: %[[RETVAL:.*]] = cir.alloca "__retval" {{.*}} :
!cir.ptr>
+// CIR: %[[P:.*]] = cir.load{{.*}} : !cir.ptr>, !cir.ptr
+// CIR: %[[G:.*]] = cir.cast address_space %[[P]] : !cir.ptr -> !cir.ptr
+// CIR: %[[ELT:.*]] = cir.ptr_stride %[[G]], %{{.*}} :
(!cir.ptr, !s64i) -> !cir.ptr
+// CIR-NOT: cir.cast bitcast
+// CIR: cir.store %[[ELT]], %[[RETVAL]] : !cir.ptr,
!cir.ptr>
+
+// LLVM-LABEL: define {{.*}}@_Z2atPU3AS3fl(
+// LLVM: %[[G:.*]] = addrspacecast ptr addrspace(3) %{{.*}} to ptr
+// LLVM: getelementptr float, ptr %[[G]]
+
+// OGCG-LABEL: define {{.*}}@_Z2atPU3AS3fl(
+// OGCG: %[[G:.*]] = addrspacecast ptr addrspace(3) %{{.*}} to ptr
+// OGCG: getelementptr inbounds float, ptr %[[G]]
+
+int &at_int(AS3 float *p, long i) {
+ return ((int *)p)[i];
+}
+
+// CIR-LABEL: cir.func{{.*}} @_Z6at_intPU3AS3fl(
+// CIR: %[[P:.*]] = cir.load{{.*}} : !cir.ptr>, !cir.ptr
+// CIR: %[[BC:.*]] = cir.cast bitcast %[[P]] : !cir.ptr -> !cir.ptr
+// CIR: %[[G:.*]] = cir.cast address_space %[[BC]] : !cir.ptr -> !cir.ptr
+// CIR: cir.ptr_stride %[[G]], %{{.*}} : (!cir.ptr, !s64i) ->
!cir.ptr
+
+// LLVM-LABEL: define {{.*}}@_Z6at_intPU3AS3fl(
+// LLVM: %[[G:.*]] = addrspacecast ptr addrspace(3) %{{.*}} to ptr
+// LLVM: getelementptr i32, ptr %[[G]]
+
+// OGCG-LABEL: define {{.*}}@_Z6at_intPU3AS3fl(
+// OGCG:
[clang] [CIR] Preserve address spaces in emitPointerWithAlignment casts (PR #228652)
llvmorg-github-actions[bot] wrote:
@llvm/pr-subscribers-clang
Author: Konstantinos Parasyris (koparasy)
Changes
emitPointerWithAlignment handled CK_AddressSpaceConversion like CK_BitCast and
never emitted the address-space cast, so the result kept the source address
space. When the address escaped (returned reference, stored pointer), the store
path bitcast the destination slot to the wrong address space. This miscompiled
sycl::multi_ptr::operator[] on SPIR-V: a local-memory offset was used as a
generic address. Emit the cast after the element bitcast, as classic CodeGen
does.
createElementBitCast also built the new pointer type in the default address
space, so changing the element type of a non-default-AS pointer produced an
AS-changing bitcast that the verifier rejects (for example ((int *)p)[i] or
__builtin_stdc_memreverse8 on an AS3 pointer). Keep the source address space,
which matches classic's withElementType.
---
Full diff: https://github.com/llvm/llvm-project/pull/228652.diff
4 Files Affected:
- (modified) clang/lib/CIR/CodeGen/CIRGenBuilder.h (+2-1)
- (modified) clang/lib/CIR/CodeGen/CIRGenExpr.cpp (+3-1)
- (added) clang/test/CIR/CodeGen/subscript-addrspace-cast.cpp (+69)
- (modified) clang/test/CIR/CodeGenBuiltins/builtin-stdc-bit-c2y.c (+18)
``diff
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h
b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
index d224feb83b03d..2e9bae5e7d2c8 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
@@ -539,7 +539,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
if (destType == addr.getElementType())
return addr;
-auto ptrTy = getPointerTo(destType);
+auto srcPtrTy = mlir::cast(addr.getPointer().getType());
+auto ptrTy = getPointerTo(destType, srcPtrTy.getAddrSpace());
return Address(createBitcast(loc, addr.getPointer(), ptrTy), destType,
addr.getAlignment());
}
diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
index 62740dc246827..f5eafaf393c02 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
@@ -173,7 +173,9 @@ Address CIRGenFunction::emitPointerWithAlignment(const Expr
*expr,
convertTypeForMem(expr->getType()->getPointeeType());
addr =
getBuilder().createElementBitCast(getLoc(expr->getSourceRange()),
addr, eltTy);
-assert(!cir::MissingFeatures::addressSpace());
+if (ce->getCastKind() == CK_AddressSpaceConversion)
+ addr = addr.withPointer(performAddrSpaceCast(
+ addr.getPointer(), convertType(expr->getType(;
return addr;
}
diff --git a/clang/test/CIR/CodeGen/subscript-addrspace-cast.cpp
b/clang/test/CIR/CodeGen/subscript-addrspace-cast.cpp
new file mode 100644
index 0..c75d615138961
--- /dev/null
+++ b/clang/test/CIR/CodeGen/subscript-addrspace-cast.cpp
@@ -0,0 +1,69 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o
%t.cir
+// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o
%t-cir.ll
+// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll
+// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG
+
+#define AS3 __attribute__((address_space(3)))
+
+float &at(AS3 float *p, long i) {
+ return ((float *)p)[i];
+}
+
+// CIR-LABEL: cir.func{{.*}} @_Z2atPU3AS3fl(
+// CIR: %[[RETVAL:.*]] = cir.alloca "__retval" {{.*}} :
!cir.ptr>
+// CIR: %[[P:.*]] = cir.load{{.*}} : !cir.ptr>, !cir.ptr
+// CIR: %[[G:.*]] = cir.cast address_space %[[P]] : !cir.ptr -> !cir.ptr
+// CIR: %[[ELT:.*]] = cir.ptr_stride %[[G]], %{{.*}} :
(!cir.ptr, !s64i) -> !cir.ptr
+// CIR-NOT: cir.cast bitcast
+// CIR: cir.store %[[ELT]], %[[RETVAL]] : !cir.ptr,
!cir.ptr>
+
+// LLVM-LABEL: define {{.*}}@_Z2atPU3AS3fl(
+// LLVM: %[[G:.*]] = addrspacecast ptr addrspace(3) %{{.*}} to ptr
+// LLVM: getelementptr float, ptr %[[G]]
+
+// OGCG-LABEL: define {{.*}}@_Z2atPU3AS3fl(
+// OGCG: %[[G:.*]] = addrspacecast ptr addrspace(3) %{{.*}} to ptr
+// OGCG: getelementptr inbounds float, ptr %[[G]]
+
+int &at_int(AS3 float *p, long i) {
+ return ((int *)p)[i];
+}
+
+// CIR-LABEL: cir.func{{.*}} @_Z6at_intPU3AS3fl(
+// CIR: %[[P:.*]] = cir.load{{.*}} : !cir.ptr>, !cir.ptr
+// CIR: %[[BC:.*]] = cir.cast bitcast %[[P]] : !cir.ptr -> !cir.ptr
+// CIR: %[[G:.*]] = cir.cast address_space %[[BC]] : !cir.ptr -> !cir.ptr
+// CIR: cir.ptr_stride %[[G]], %{{.*}} : (!cir.ptr, !s64i) ->
!cir.ptr
+
+// LLVM-LABEL: define {{.*}}@_Z6at_intPU3AS3fl(
+// LLVM: %[[G:.*]] = addrspacecast ptr addrspace(3) %{{.*}} to ptr
+// LLVM: getelementptr i32, ptr %[[G]]
+
+// OGCG-LABEL: define {{.*}}@_Z6at_intPU3AS3fl(
+// OGCG: %[[G:.*]]
[clang] [CIR] Preserve address spaces in emitPointerWithAlignment casts (PR #228652)
https://github.com/koparasy created
https://github.com/llvm/llvm-project/pull/228652
emitPointerWithAlignment handled CK_AddressSpaceConversion like CK_BitCast and
never emitted the address-space cast, so the result kept the source address
space. When the address escaped (returned reference, stored pointer), the store
path bitcast the destination slot to the wrong address space. This miscompiled
sycl::multi_ptr::operator[] on SPIR-V: a local-memory offset was used as a
generic address. Emit the cast after the element bitcast, as classic CodeGen
does.
createElementBitCast also built the new pointer type in the default address
space, so changing the element type of a non-default-AS pointer produced an
AS-changing bitcast that the verifier rejects (for example ((int *)p)[i] or
__builtin_stdc_memreverse8 on an AS3 pointer). Keep the source address space,
which matches classic's withElementType.
>From ae0573f2f79079b30a408c60825347d2080aab46 Mon Sep 17 00:00:00 2001
From: Konstantinos Parasyris
Date: Fri, 2 Oct 2026 20:54:12 -0700
Subject: [PATCH] [CIR] Preserve address spaces in emitPointerWithAlignment
casts
emitPointerWithAlignment handled CK_AddressSpaceConversion like
CK_BitCast and never emitted the address-space cast, so the result kept
the source address space. When the address escaped (returned reference,
stored pointer), the store path bitcast the destination slot to the
wrong address space. This miscompiled sycl::multi_ptr::operator[] on
SPIR-V: a local-memory offset was used as a generic address. Emit the
cast after the element bitcast, as classic CodeGen does.
createElementBitCast also built the new pointer type in the default
address space, so changing the element type of a non-default-AS pointer
produced an AS-changing bitcast that the verifier rejects (for example
((int *)p)[i] or __builtin_stdc_memreverse8 on an AS3 pointer). Keep
the source address space, which matches classic's withElementType.
Co-Authored-By: Claude Opus 5.5 (1M context)
---
clang/lib/CIR/CodeGen/CIRGenBuilder.h | 3 +-
clang/lib/CIR/CodeGen/CIRGenExpr.cpp | 4 +-
.../CIR/CodeGen/subscript-addrspace-cast.cpp | 69 +++
.../CodeGenBuiltins/builtin-stdc-bit-c2y.c| 18 +
4 files changed, 92 insertions(+), 2 deletions(-)
create mode 100644 clang/test/CIR/CodeGen/subscript-addrspace-cast.cpp
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h
b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
index d224feb83b03df..2e9bae5e7d2c80 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
@@ -539,7 +539,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
if (destType == addr.getElementType())
return addr;
-auto ptrTy = getPointerTo(destType);
+auto srcPtrTy = mlir::cast(addr.getPointer().getType());
+auto ptrTy = getPointerTo(destType, srcPtrTy.getAddrSpace());
return Address(createBitcast(loc, addr.getPointer(), ptrTy), destType,
addr.getAlignment());
}
diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
index 62740dc246827c..f5eafaf393c029 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
@@ -173,7 +173,9 @@ Address CIRGenFunction::emitPointerWithAlignment(const Expr
*expr,
convertTypeForMem(expr->getType()->getPointeeType());
addr =
getBuilder().createElementBitCast(getLoc(expr->getSourceRange()),
addr, eltTy);
-assert(!cir::MissingFeatures::addressSpace());
+if (ce->getCastKind() == CK_AddressSpaceConversion)
+ addr = addr.withPointer(performAddrSpaceCast(
+ addr.getPointer(), convertType(expr->getType(;
return addr;
}
diff --git a/clang/test/CIR/CodeGen/subscript-addrspace-cast.cpp
b/clang/test/CIR/CodeGen/subscript-addrspace-cast.cpp
new file mode 100644
index 00..c75d615138961f
--- /dev/null
+++ b/clang/test/CIR/CodeGen/subscript-addrspace-cast.cpp
@@ -0,0 +1,69 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o
%t.cir
+// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o
%t-cir.ll
+// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll
+// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG
+
+#define AS3 __attribute__((address_space(3)))
+
+float &at(AS3 float *p, long i) {
+ return ((float *)p)[i];
+}
+
+// CIR-LABEL: cir.func{{.*}} @_Z2atPU3AS3fl(
+// CIR: %[[RETVAL:.*]] = cir.alloca "__retval" {{.*}} :
!cir.ptr>
+// CIR: %[[P:.*]] = cir.load{{.*}} : !cir.ptr>, !cir.ptr
+// CIR: %[[G:.*]] = cir.cast address_space %[[P]] : !cir.ptr -> !cir.ptr
+// CIR: %[[ELT:.*]] = cir.ptr_stride %[[G]], %{{.*}} :
(!cir.ptr, !s64i) -> !cir.ptr
