[clang] [AST] Support structural equivalence checking of attributes on Decls (PR #168769)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 6 09:23:35 PST 2026


AaronBallman wrote:

> I concluded that the local queue introduced in the previous commits isn’t necessary in C mode. Since attribute equivalence is currently checked only for C23, I removed the code entirely.
> 
> If we later enable attribute equivalence checking in C++ mode, we may need to revisit this and adopt a similar approach. For example, without a separate queue, clang will diagnose the attribute but fail to report the mismatch in the type of member `a` when attempting to merge the following struct:
> 
> ```
> struct GuardedBy {
>   int b __attribute__((guarded_by(lock)));
>   // The pair of S is added to NonEquivalentDecls, but the pair of Lock isn't. 
>   struct __attribute__ ((lockable)) Lock {
>     struct S {
> #ifdef D1
>       unsigned a;
> #else
>       int a;
> #endif
>     } s;
>   } lock;
> };
> ```
> 
> $ clang -cc1 -std=c++20 -emit-pch -o f1.ast -x c++ test.h $ clang -cc1 -std=c++20 -emit-pch -o f2.ast -DD1 -x c++ test.h $ clang -cc1 -std=c++20 -ast-merge f1.ast -ast-merge f2.ast -x c++ test.cpp

CC @ChuanqiXu9 @Bigcheese as C++ modules maintainers. I am under the impression we need this for both C++ modules support and C23's redefinition checking. If we don't need the more complicated approach right now, I think the current approach is reasonable for C (but CC @erichkeane for awareness of the tablegen changes), I just want to make sure we're not making further work harder for ourselves.

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


More information about the cfe-commits mailing list