================
@@ -3983,6 +3983,82 @@ template<typename T> constexpr T *addressof(T &value) {
}
```
+### `__builtin_pointee_address_space`
+
+`__builtin_pointee_address_space` returns the target address space number
+of the pointee type of a pointer expression, or the element type of an
+array expression.
+
+**Syntax**:
+
+```c++
+int __builtin_pointee_address_space(pointer-or-array)
+```
+
+The argument must have pointer or array type. For an array expression, the
+result is computed from the array element type. The argument is not evaluated
+and is not converted to `void *` before its type is inspected.
+
+The result is an integer constant expression. It is based on the address space
+that Clang can determine from the expression in the frontend. It does not use
+optimizer or interprocedural analysis to infer a more precise address space.
+
+For a pointer expression, the builtin normally returns the address space of the
+pointee type of the expression as written. This makes the result stable for
+ordinary pointers and for explicitly address-spaced pointer types. In CUDA/HIP
+compilation, Clang can also determine the address space of known `__device__`,
+`__shared__`, and `__constant__` objects. In host compilation, this requires
+auxiliary target information for the device target. If auxiliary target
+information is not available, Clang returns the default address space and emits
+a warning. This is useful because CUDA/HIP pointer types are source-level
+generic, so this information is not otherwise visible from a plain `T *` type.
+An explicit `__device__` `const` global or static data member that is promoted
+to constant memory is reported as the constant address space.
+
+Explicit user-written casts are respected. If a cast changes the pointer type
+seen by the builtin, the builtin reports the pointee address space of the cast
+type rather than looking through the cast to recover the original object.
+
+When the builtin is evaluated in a constant expression, Clang may look through
a
+constexpr function parameter to the argument passed by the caller, as long as
----------------
efriedma-quic wrote:
Special-casing constant evaluation is going to end up being extremely
unintuitive due to the rules for when exactly we do constexpr evaluation.
There's evaluation in constant contexts, and there's eager folding, which we
may or may not do. And the way constexpr-unknown works depends on the C++
standard version.
Are you certain you need this, as opposed to just making your wrappers
templates?
https://github.com/llvm/llvm-project/pull/210242
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits