[clang] [RFC][Clang] Add the __addrspaceof operator (PR #210242)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 6 10:47:29 PDT 2026
================
@@ -4055,6 +4055,115 @@ template<typename T> constexpr T *addressof(T &value) {
}
```
+### `__addrspaceof`
+
+`__addrspaceof` returns a Clang address-space identifier for a type, object, or
+lvalue expression.
+
+This is useful for performance-sensitive code that needs a compile-time value
+to choose an address-space-specific operation, overload, or template
+specialization. For example, GPU code may select different loads for global,
+shared/local, or constant memory.
+
+**Syntax**:
+
+```c++
+int __addrspaceof(type-or-expression)
+```
+
+The parentheses are required. The operand is not evaluated. The result is an
----------------
AaronBallman wrote:
What happens if the operand is a VLA that would normally require evaluation? e.g.,
```
int vla = 1;
int val = __addrspaceof(int[vla++]);
```
https://github.com/llvm/llvm-project/pull/210242
More information about the cfe-commits
mailing list