https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/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. ``` >From 853b6d8a92ec466e474e70f9c3e73c58bfd70c4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Thu, 5 Oct 2023 16:14:10 +0200 Subject: [PATCH] [clang][Diagnostics] Add bitfield source range to zero width diags --- clang/lib/Sema/SemaDecl.cpp | 3 ++- clang/test/Misc/misc-source-ranges.cpp | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 clang/test/Misc/misc-source-ranges.cpp diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 28d9a0ac654b81f..8fff33c49f2e5c7 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -18161,7 +18161,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} + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits