[clang] aefd6c6 - Combine two diagnostics into one and correct grammar

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 14 08:43:41 PDT 2021


Author: Aaron Ballman
Date: 2021-07-14T11:43:28-04:00
New Revision: aefd6c615c91a2af89fa3697cf1813aac0f622de

URL: https://github.com/llvm/llvm-project/commit/aefd6c615c91a2af89fa3697cf1813aac0f622de
DIFF: https://github.com/llvm/llvm-project/commit/aefd6c615c91a2af89fa3697cf1813aac0f622de.diff

LOG: Combine two diagnostics into one and correct grammar

The anonymous and non-anonymous bit-field diagnostics are easily
combined into one diagnostic. However, the diagnostic was missing a
"the" that is present in the almost-identically worded
warn_bitfield_width_exceeds_type_width diagnostic, hence the changes to
test cases.

Added: 
    

Modified: 
    clang/include/clang/Basic/DiagnosticSemaKinds.td
    clang/lib/Sema/SemaDecl.cpp
    clang/test/Sema/bitfield.c
    clang/test/SemaCXX/ms_wide_bitfield.cpp
    clang/test/SemaObjC/class-bitfield.m

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 422507cd2842b..f4c189a3d178f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5839,11 +5839,8 @@ def err_anon_bitfield_has_negative_width : Error<
   "anonymous bit-field has negative width (%0)">;
 def err_bitfield_has_zero_width : Error<"named bit-field %0 has zero width">;
 def err_bitfield_width_exceeds_type_width : Error<
-  "width of bit-field %0 (%1 bits) exceeds %select{width|size}2 "
-  "of its type (%3 bit%s3)">;
-def err_anon_bitfield_width_exceeds_type_width : Error<
-  "width of anonymous bit-field (%0 bits) exceeds %select{width|size}1 "
-  "of its type (%2 bit%s2)">;
+  "width of%select{ anonymous|}0 bit-field%select{| %1}0 (%2 bits) exceeds the "
+  "%select{width|size}3 of its type (%4 bit%s4)">;
 def err_incorrect_number_of_vector_initializers : Error<
   "number of elements must be either one or match the size of the vector">;
 

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 700a6db7fea89..c2dcdf0b8d1f6 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16685,14 +16685,9 @@ ExprResult Sema::VerifyBitField(SourceLocation FieldLoc,
     if (CStdConstraintViolation || MSBitfieldViolation) {
       unsigned DiagWidth =
           CStdConstraintViolation ? TypeWidth : TypeStorageSize;
-      if (FieldName)
-        return Diag(FieldLoc, diag::err_bitfield_width_exceeds_type_width)
-               << FieldName << toString(Value, 10)
-               << !CStdConstraintViolation << DiagWidth;
-
-      return Diag(FieldLoc, diag::err_anon_bitfield_width_exceeds_type_width)
-             << toString(Value, 10) << !CStdConstraintViolation
-             << DiagWidth;
+      return Diag(FieldLoc, diag::err_bitfield_width_exceeds_type_width)
+             << (bool)FieldName << FieldName << toString(Value, 10)
+             << !CStdConstraintViolation << DiagWidth;
     }
 
     // Warn on types where the user might conceivably expect to get all

diff  --git a/clang/test/Sema/bitfield.c b/clang/test/Sema/bitfield.c
index 03b2a22d3ed9b..13b6c3e152d72 100644
--- a/clang/test/Sema/bitfield.c
+++ b/clang/test/Sema/bitfield.c
@@ -6,7 +6,7 @@ struct a {
   int a : -1; // expected-error{{bit-field 'a' has negative width}}
 
   // rdar://6081627
-  int b : 33; // expected-error{{width of bit-field 'b' (33 bits) exceeds width of its type (32 bits)}}
+  int b : 33; // expected-error{{width of bit-field 'b' (33 bits) exceeds the width of its type (32 bits)}}
 
   int c : (1 + 0.25); // expected-error{{integer constant expression must have integer type}}
   int d : (int)(1 + 0.25); 
@@ -22,12 +22,12 @@ struct a {
   int g : (_Bool)1;
   
   // PR4017  
-  char : 10;      // expected-error {{width of anonymous bit-field (10 bits) exceeds width of its type (8 bits)}}
+  char : 10;      // expected-error {{width of anonymous bit-field (10 bits) exceeds the width of its type (8 bits)}}
   unsigned : -2;  // expected-error {{anonymous bit-field has negative width (-2)}}
   float : 12;     // expected-error {{anonymous bit-field has non-integral type 'float'}}
 
-  _Bool : 2;   // expected-error {{width of anonymous bit-field (2 bits) exceeds width of its type (1 bit)}}
-  _Bool h : 5; // expected-error {{width of bit-field 'h' (5 bits) exceeds width of its type (1 bit)}}
+  _Bool : 2;   // expected-error {{width of anonymous bit-field (2 bits) exceeds the width of its type (1 bit)}}
+  _Bool h : 5; // expected-error {{width of bit-field 'h' (5 bits) exceeds the width of its type (1 bit)}}
 };
 
 struct b {unsigned x : 2;} x;

diff  --git a/clang/test/SemaCXX/ms_wide_bitfield.cpp b/clang/test/SemaCXX/ms_wide_bitfield.cpp
index b634e78c70ce5..0dcc787928b0a 100644
--- a/clang/test/SemaCXX/ms_wide_bitfield.cpp
+++ b/clang/test/SemaCXX/ms_wide_bitfield.cpp
@@ -1,9 +1,9 @@
 // RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple i686-pc-win32 -fdump-record-layouts -fsyntax-only -mms-bitfields -verify %s 2>&1
 
 struct A {
-  char a : 9; // expected-error{{width of bit-field 'a' (9 bits) exceeds size of its type (8 bits)}}
-  int b : 33; // expected-error{{width of bit-field 'b' (33 bits) exceeds size of its type (32 bits)}}
-  bool c : 9; // expected-error{{width of bit-field 'c' (9 bits) exceeds size of its type (8 bits)}}
+  char a : 9; // expected-error{{width of bit-field 'a' (9 bits) exceeds the size of its type (8 bits)}}
+  int b : 33; // expected-error{{width of bit-field 'b' (33 bits) exceeds the size of its type (32 bits)}}
+  bool c : 9; // expected-error{{width of bit-field 'c' (9 bits) exceeds the size of its type (8 bits)}}
   bool d : 3;
 };
 

diff  --git a/clang/test/SemaObjC/class-bitfield.m b/clang/test/SemaObjC/class-bitfield.m
index 07d690a94a9d2..0e88c44ae0ffd 100644
--- a/clang/test/SemaObjC/class-bitfield.m
+++ b/clang/test/SemaObjC/class-bitfield.m
@@ -5,7 +5,7 @@ @interface X
   int a : -1; // expected-error{{bit-field 'a' has negative width}}
 
   // rdar://6081627
-  int b : 33; // expected-error{{width of bit-field 'b' (33 bits) exceeds width of its type (32 bits)}}
+  int b : 33; // expected-error{{width of bit-field 'b' (33 bits) exceeds the width of its type (32 bits)}}
 
   int c : (1 + 0.25); // expected-error{{integer constant expression must have integer type}}
   int d : (int)(1 + 0.25); 


        


More information about the cfe-commits mailing list