[PATCH] D157201: [Clang] Support qualified name as member designator in offsetof

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 8 13:46:33 PDT 2023


aaron.ballman added a comment.

Thank you for working on this!



================
Comment at: clang/docs/ReleaseNotes.rst:59
 --------------------
+- Improved `__builtin_offsetof` support, allowing qualified name in member designator.
 
----------------
You should also link to https://github.com/llvm/llvm-project/issues/64154 here to tie it back to a bug report.


================
Comment at: clang/include/clang/Sema/Sema.h:6038
     SourceLocation LocStart, LocEnd;
     bool isBrackets;  // true if [expr], false if .ident
+    bool isQualifier;
----------------
I think we should combine `isBrackets` and `isQualifier` since a component can't be both at the same time anyway. e.g.,
```
enum {
  Brackets,   // U.E is valid
  Identifier, // U.IdentInfo is valid
  Qualifier,  // Nothing in U is valid
} Kind;
```


================
Comment at: clang/test/Sema/offsetof.c:77-79
+struct X2 { int a; };
+int x2[__builtin_offsetof(struct X2, X2::a) == 0 ? 1 : -1];
+int x3[__builtin_offsetof(struct X2, X2::X2) == 0 ? 1 : -1]; // expected-error{{no member named 'X2'}}
----------------
Neither of these should be valid in C -- there is no way to name subobjects in C like there is in C++.


================
Comment at: clang/test/SemaCXX/offsetof.cpp:104
+struct X2 { int a; static int static_a; };
+int x2[__builtin_offsetof(struct X2, X2::static_a) == 0 ? 1 : -1]; // expected-error{{no member named 'static_a'}}
----------------
It'd be good to add the `int x2[__builtin_offsetof(struct X2, X2::a) == 0 ? 1 : -1];` test here from the C test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157201/new/

https://reviews.llvm.org/D157201



More information about the cfe-commits mailing list