[clang] [Clang] Consider preferred_type in bitfield warnings (#116760) (PR #116785)
Martin Storsjö via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 24 05:34:40 PDT 2025
mstorsjo wrote:
This change makes Clang produce warnings when building Clang itself; warnings looking like this:
```
/home/martin/code/llvm-project/clang/include/clang/Basic/LangOptions.def:352:1: warning: bit-field 'FPEvalMethod' is not wide enough to store all enumerators of preferred type 'FPEvalMethodKind' [-Wpreferred-type-bitfield-enum-conversion]
352 | BENIGN_ENUM_LANGOPT(FPEvalMethod, FPEvalMethodKind, 2, FEM_UnsetOnCommandLine, "FP type used for floating point arithmetic")
| ^
/home/martin/code/llvm-project/clang/include/clang/Basic/LangOptions.def:67:6: note: expanded from macro 'BENIGN_ENUM_LANGOPT'
67 | COMPATIBLE_ENUM_LANGOPT(Name, Type, Bits, Default, Description)
| ^
/home/martin/code/llvm-project/clang/include/clang/Basic/LangOptions.def:62:6: note: expanded from macro 'COMPATIBLE_ENUM_LANGOPT'
62 | ENUM_LANGOPT(Name, Type, Bits, Default, Description)
| ^
/home/martin/code/llvm-project/clang/include/clang/Basic/LangOptions.h:646:37: note: expanded from macro 'ENUM_LANGOPT'
646 | void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
| ^
/home/martin/code/llvm-project/clang/include/clang/Basic/LangOptions.def:352:53: note: widen this field to 3 bits to store all values of 'FPEvalMethodKind'
352 | BENIGN_ENUM_LANGOPT(FPEvalMethod, FPEvalMethodKind, 2, FEM_UnsetOnCommandLine, "FP type used for floating point arithmetic")
| ^
/home/martin/code/llvm-project/clang/include/clang/Basic/LangOptions.def:352:1: note: preferred type for bit-field 'FPEvalMethodKind' specified here
352 | BENIGN_ENUM_LANGOPT(FPEvalMethod, FPEvalMethodKind, 2, FEM_UnsetOnCommandLine, "FP type used for floating point arithmetic")
| ^
/home/martin/code/llvm-project/clang/include/clang/Basic/LangOptions.def:67:6: note: expanded from macro 'BENIGN_ENUM_LANGOPT'
67 | COMPATIBLE_ENUM_LANGOPT(Name, Type, Bits, Default, Description)
| ^
/home/martin/code/llvm-project/clang/include/clang/Basic/LangOptions.def:62:6: note: expanded from macro 'COMPATIBLE_ENUM_LANGOPT'
62 | ENUM_LANGOPT(Name, Type, Bits, Default, Description)
| ^
/home/martin/code/llvm-project/clang/include/clang/Basic/LangOptions.h:493:3: note: expanded from macro 'ENUM_LANGOPT'
493 | LLVM_PREFERRED_TYPE(Type) \
| ^
/home/martin/code/llvm-project/llvm/include/llvm/Support/Compiler.h:687:47: note: expanded from macro 'LLVM_PREFERRED_TYPE'
687 | #define LLVM_PREFERRED_TYPE(T) __attribute__((preferred_type(T)))
| ^
```
I've seen such warnings when building Clang for x86_64 linux, aarch64 linux and aarch64 mingw at least.
https://github.com/llvm/llvm-project/pull/116785
More information about the cfe-commits
mailing list