[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:27 PDT 2026


================
@@ -4586,6 +4586,32 @@ bool Sema::CheckUnaryExprOrTypeTraitOperand(Expr *E,
   return false;
 }
 
+static bool CheckAddrSpaceOfExpr(Sema &S, Expr *E) {
+  if (E->isTypeDependent())
+    return false;
+
+  const ValueDecl *D = nullptr;
+  if (const auto *DRE = dyn_cast<DeclRefExpr>(E))
+    D = dyn_cast<ValueDecl>(DRE->getDecl());
+  else if (const auto *ME = dyn_cast<MemberExpr>(E))
+    D = ME->getMemberDecl();
+
+  if (D) {
+    if (isa<VarDecl, FieldDecl>(D))
----------------
AaronBallman wrote:

This seems perhaps overly restrictive (as mentioned above, binding decls can have address spaces); you could also run into things like:
```
__addrspaceof((int [[clang::address_space(12)]]){100})
```
which should presumably have an address space associated with it?

https://github.com/llvm/llvm-project/pull/210242


More information about the cfe-commits mailing list