Skip to content

Revert "[Sema] Add check for bitfield assignments to integral types" #68963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2023

Conversation

vabridgers
Copy link
Contributor

This reverts commit 47e3626.

This change broke some arm8/arm7 build bots because int and void * have the same size.

This reverts commit 47e3626.

This change broke some arm8/arm7 build bots because int and void * have
the same size.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Oct 13, 2023
@llvmbot
Copy link
Member

llvmbot commented Oct 13, 2023

@llvm/pr-subscribers-clang

Author: None (vabridgers)

Changes

This reverts commit 47e3626.

This change broke some arm8/arm7 build bots because int and void * have the same size.


Full diff: https://github.com/llvm/llvm-project/pull/68963.diff

5 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (-3)
  • (modified) clang/include/clang/Basic/DiagnosticGroups.td (-2)
  • (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (-3)
  • (modified) clang/lib/Sema/SemaChecking.cpp (+1-12)
  • (removed) clang/test/SemaCXX/bitfield-width.c (-34)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 31969201a1cac8c..2d918967e7f0b02 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -185,9 +185,6 @@ New Compiler Flags
   the preprocessed text to the output. This can greatly reduce the size of the
   preprocessed output, which can be helpful when trying to reduce a test case.
 
-* ``-Wbitfield-conversion`` was added to detect assignments of integral
-  types to a bitfield that may change the value.
-
 Deprecated Compiler Flags
 -------------------------
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 674eb9f4ef2e73f..0b09c002191848a 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -53,7 +53,6 @@ def SingleBitBitFieldConstantConversion :
 def BitFieldConstantConversion : DiagGroup<"bitfield-constant-conversion",
                                            [SingleBitBitFieldConstantConversion]>;
 def BitFieldEnumConversion : DiagGroup<"bitfield-enum-conversion">;
-def BitFieldConversion : DiagGroup<"bitfield-conversion">;
 def BitFieldWidth : DiagGroup<"bitfield-width">;
 def CompoundTokenSplitByMacro : DiagGroup<"compound-token-split-by-macro">;
 def CompoundTokenSplitBySpace : DiagGroup<"compound-token-split-by-space">;
@@ -934,7 +933,6 @@ def Conversion : DiagGroup<"conversion",
                             ConstantConversion,
                             EnumConversion,
                             BitFieldEnumConversion,
-                            BitFieldConversion,
                             FloatConversion,
                             Shorten64To32,
                             IntConversion,
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index ab7fe881976aad2..c1a6e3831127e56 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6171,9 +6171,6 @@ def warn_signed_bitfield_enum_conversion : Warning<
   "signed bit-field %0 needs an extra bit to represent the largest positive "
   "enumerators of %1">,
   InGroup<BitFieldEnumConversion>, DefaultIgnore;
-def warn_bitfield_too_small_for_integral_type : Warning<
-  "conversion from %2 (%3 bits) to bit-field %0 (%1 bits) may change value">,
-  InGroup<BitFieldConversion>, DefaultIgnore;
 def note_change_bitfield_sign : Note<
   "consider making the bitfield type %select{unsigned|signed}0">;
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index cd61459cfbb13d6..35b36db2049db09 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -14298,18 +14298,6 @@ static bool AnalyzeBitFieldAssignment(Sema &S, FieldDecl *Bitfield, Expr *Init,
         S.Diag(WidthExpr->getExprLoc(), diag::note_widen_bitfield)
             << BitsNeeded << ED << WidthExpr->getSourceRange();
       }
-    } else if (OriginalInit->getType()->isIntegralType(S.Context)) {
-      IntRange LikelySourceRange =
-          GetExprRange(S.Context, Init, S.isConstantEvaluatedContext(),
-                       /*Approximate=*/true);
-
-      if (LikelySourceRange.Width > FieldWidth) {
-        Expr *WidthExpr = Bitfield->getBitWidth();
-        S.Diag(InitLoc, diag::warn_bitfield_too_small_for_integral_type)
-            << Bitfield << FieldWidth << OriginalInit->getType()
-            << LikelySourceRange.Width;
-        S.Diag(WidthExpr->getExprLoc(), diag::note_declared_at);
-      }
     }
 
     return false;
@@ -15207,6 +15195,7 @@ static void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
 
   if (LikelySourceRange.Width > TargetRange.Width) {
     // If the source is a constant, use a default-on diagnostic.
+    // TODO: this should happen for bitfield stores, too.
     Expr::EvalResult Result;
     if (E->EvaluateAsInt(Result, S.Context, Expr::SE_AllowSideEffects,
                          S.isConstantEvaluatedContext())) {
diff --git a/clang/test/SemaCXX/bitfield-width.c b/clang/test/SemaCXX/bitfield-width.c
deleted file mode 100644
index 8219054b959e544..000000000000000
--- a/clang/test/SemaCXX/bitfield-width.c
+++ /dev/null
@@ -1,34 +0,0 @@
-// RUN: %clang_cc1 -Wconversion -fsyntax-only -verify %s
-// RUN: %clang_cc1 -Wbitfield-conversion -fsyntax-only -verify %s
-
-typedef struct _xx {
-     int bf:9; // expected-note 4{{declared here}}
- } xx, *pxx; 
-
- xx vxx;
-
- void foo1(int x) {     
-     vxx.bf = x; // expected-warning{{conversion from 'int' (32 bits) to bit-field 'bf' (9 bits) may change value}}
- } 
- void foo2(short x) {     
-     vxx.bf = x; // expected-warning{{conversion from 'short' (16 bits) to bit-field 'bf' (9 bits) may change value}}
- } 
- void foo3(char x) {     
-     vxx.bf = x; // no warning expected
- } 
- void foo5(void * x) {     
-     vxx.bf = (int)x; // expected-warning{{cast to smaller integer type 'int' from 'void *'}}
-     // expected-warning@-1{{conversion from 'int' (32 bits) to bit-field 'bf' (9 bits) may change value}}
- } 
- void foo6(short x) {     
-     vxx.bf = 0xff & x; // no warning expected 
- } 
- void foo7(short x) {     
-     vxx.bf = 0x1ff & x; // no warning expected 
- } 
- void foo8(short x) {     
-     vxx.bf = 0x3ff & x; // expected-warning{{conversion from 'int' (10 bits) to bit-field 'bf' (9 bits) may change value}}
- } 
- int fee(void) {
-     return 0;
- }

@cor3ntin
Copy link
Contributor

Original PR - #68276
FYI you do not need to make a PR to revert a change that breaks the build - especially your own

@vabridgers vabridgers merged commit 2e955c0 into llvm:main Oct 13, 2023
@vabridgers vabridgers deleted the bitfield-warn branch October 13, 2023 10:03
@vabridgers
Copy link
Contributor Author

Original PR - #68276 FYI you do not need to make a PR to revert a change that breaks the build - especially your own

revert is merged, thanks for the advice. Best

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants