[clang] [clang] Add clang::debug_info_type attribute for bitfields (PR #69104)
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 19 03:26:30 PDT 2023
================
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify %s
+
+struct A {
+ enum E : unsigned {};
+ [[clang::preferred_type(E)]] unsigned b : 2;
+ [[clang::preferred_type(E)]] int b2 : 2;
+ // expected-warning at -1 {{underlying type 'unsigned int' of enumeration 'E' doesn't match bit-field type 'int'}}
+ [[clang::preferred_type(E)]] const unsigned b3 : 2;
+ [[clang::preferred_type(bool)]] unsigned b4 : 1;
+ [[clang::preferred_type(bool)]] unsigned b5 : 2;
+ // expected-warning at -1 {{bit-field that holds a boolean value should have width of 1 instead of 2}}
+ [[clang::preferred_type()]] unsigned b6 : 2;
+ // expected-error at -1 {{'preferred_type' attribute takes one argument}}
+ [[clang::preferred_type]] unsigned b7 : 2;
+ // expected-error at -1 {{'preferred_type' attribute takes one argument}}
+ [[clang::preferred_type(E, int)]] unsigned b8 : 2;
----------------
Endilll wrote:
@AaronBallman On the topic of automatically-generated diagnostics:
```
/home/user/endill/llvm-project/clang/test/Sema/attr-preferred-type.cpp:16:28: error: expected ')'
16 | [[clang::preferred_type(E, int)]] unsigned b8 : 2;
| ^
| )
/home/user/endill/llvm-project/clang/test/Sema/attr-preferred-type.cpp:16:33: error: expected ','
16 | [[clang::preferred_type(E, int)]] unsigned b8 : 2;
| ^
| ,
/home/user/endill/llvm-project/clang/test/Sema/attr-preferred-type.cpp:16:30: warning: unknown attribute 'int' ignored [-Wunknown-attributes]
16 | [[clang::preferred_type(E, int)]] unsigned b8 : 2;
| ^~~
```
3 diagnostics are issued, 0 says that wrong number of attribute arguments is passed.
https://github.com/llvm/llvm-project/pull/69104
More information about the cfe-commits
mailing list