[clang] aad7e0a - [clang][Diagnostics] Add bitfield source range to zero width diags (#68312)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 5 23:41:52 PDT 2023
Author: Timm Baeder
Date: 2023-10-06T08:41:49+02:00
New Revision: aad7e0a994f4e3d73137fc4a1001785110f9bbe6
URL: https://github.com/llvm/llvm-project/commit/aad7e0a994f4e3d73137fc4a1001785110f9bbe6
DIFF: https://github.com/llvm/llvm-project/commit/aad7e0a994f4e3d73137fc4a1001785110f9bbe6.diff
LOG: [clang][Diagnostics] Add bitfield source range to zero width diags (#68312)
Before:
```
array.cpp:157:8: error: named bit-field 'a' has zero width
157 | char a : 12 - 12;
| ^
1 error generated.
```
After:
```
array.cpp:157:8: error: named bit-field 'a' has zero width
157 | char a : 12 - 12;
| ^ ~~~~~~~
1 error generated.
```
Added:
clang/test/Misc/misc-source-ranges.cpp
Modified:
clang/lib/Sema/SemaDecl.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 6ac02df193976a9..324a3674732aa04 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -18170,7 +18170,8 @@ ExprResult Sema::VerifyBitField(SourceLocation FieldLoc,
// Zero-width bitfield is ok for anonymous field.
if (Value == 0 && FieldName)
- return Diag(FieldLoc, diag::err_bitfield_has_zero_width) << FieldName;
+ return Diag(FieldLoc, diag::err_bitfield_has_zero_width)
+ << FieldName << BitWidth->getSourceRange();
if (Value.isSigned() && Value.isNegative()) {
if (FieldName)
diff --git a/clang/test/Misc/misc-source-ranges.cpp b/clang/test/Misc/misc-source-ranges.cpp
new file mode 100644
index 000000000000000..7a9d9d057dac407
--- /dev/null
+++ b/clang/test/Misc/misc-source-ranges.cpp
@@ -0,0 +1,7 @@
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info %s 2>&1 | FileCheck %s
+
+struct S {
+ char a : 12 - 12;
+};
+// CHECK: misc-source-ranges.cpp:[[@LINE-2]]:8:{[[@LINE-2]]:12-[[@LINE-2]]:19}
+
More information about the cfe-commits
mailing list