[clang] [clang] Replace LLVM_ATTRIBUTE_UNUSED with [[maybe_unused]] (NFC) (PR #163914)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 17 08:38:14 PDT 2025


erichkeane wrote:

> This is causing a regression for me:
> 
> ```
> In file included from /local/home/ekeane/llvm-project/clang/lib/CIR/CodeGen/CIRGenDeclOpenACC.cpp:13:
> In file included from /local/home/ekeane/llvm-project/clang/lib/CIR/CodeGen/CIRGenFunction.h:17:
> In file included from /local/home/ekeane/llvm-project/clang/lib/CIR/CodeGen/CIRGenCall.h:17:
> /local/home/ekeane/llvm-project/clang/lib/CIR/CodeGen/CIRGenValue.h:311:3: error: an attribute list cannot appear here
>   311 |   [[maybe_unused]] unsigned destructedFlag : 1;
>       |   ^~~~~~~~~~~~~~~~
> /local/home/ekeane/llvm-project/clang/lib/CIR/CodeGen/CIRGenValue.h:330:3: error: an attribute list cannot appear here
>   330 |   [[maybe_unused]] unsigned aliasedFlag : 1;
>       |   ^~~~~~~~~~~~~~~~
> /local/home/ekeane/llvm-project/clang/lib/CIR/CodeGen/CIRGenValue.h:338:3: error: an attribute list cannot appear here
>   338 |   [[maybe_unused]] unsigned overlapFlag : 1;
> ```
> 
> ```
> ekeane at dev-epyc4:/local/home/ekeane/llvm-project/build$ /usr/bin/clang++ --version 
> Ubuntu clang version 18.1.3 (1ubuntu1)
> Target: x86_64-pc-linux-gnu
> Thread model: posix
> InstalledDir: /usr/bin
> ```

See: https://godbolt.org/z/W6nbMbzve

Seemingly we've fixed that in Clang 21 (I vaguely remember reviewing the patch).  Clang 18 however is on our support matrix.

The difference is that `LLVM_ATTRIBUTE_UNUSED` is defined to use the GNU spelling, so we allow those spellings in that location, however the GNU-then-CXX spellings we do not (again, as a since-fixed clang bug).

There are two potential fixes I've identified.  FIRST, we could just change preferred-type to use cxx spellings in Compiler.h:
```
-#define LLVM_PREFERRED_TYPE(T) __attribute__((preferred_type(T)))
+#define LLVM_PREFERRED_TYPE(T) [[clang::preferred_type(T)]]
```

Second would be to just re-order the two in the cases this causes problems.  We can put the CXX spellings FIRST (so put maybe-unused BEFORE the preferred type).





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


More information about the cfe-commits mailing list