[clang] e214bda - Revert "[Sema] Add check for bitfield assignments to integral types (#69049)"
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 23 09:30:42 PDT 2023
Author: Kadir Cetinkaya
Date: 2023-10-23T18:23:21+02:00
New Revision: e214bdac51c46b554e1fb99de6b6b6c735b75bf1
URL: https://github.com/llvm/llvm-project/commit/e214bdac51c46b554e1fb99de6b6b6c735b75bf1
DIFF: https://github.com/llvm/llvm-project/commit/e214bdac51c46b554e1fb99de6b6b6c735b75bf1.diff
LOG: Revert "[Sema] Add check for bitfield assignments to integral types (#69049)"
This reverts commit 708808e8532e7c3647356aec0664fcf94b1093d1 which is
causing crashes on valid code, see
https://github.com/llvm/llvm-project/pull/69049#issuecomment-1775538177.
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaChecking.cpp
Removed:
clang/test/SemaCXX/bitfield-width.c
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f71b458597e1833..403a74fc602fd81 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -211,9 +211,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 4cb792132d6e09d..e990bf6b7938ac6 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">;
@@ -936,7 +935,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 3bcbb003d6dee19..88315f25d1dcd79 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6191,9 +6191,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 f3c55d059e66380..7972919d1420116 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -14332,18 +14332,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;
@@ -15241,6 +15229,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 7b4e4444c245b0e..000000000000000
--- a/clang/test/SemaCXX/bitfield-width.c
+++ /dev/null
@@ -1,42 +0,0 @@
-// RUN: %clang_cc1 -Wconversion -fsyntax-only -verify %s
-// RUN: %clang_cc1 -Wbitfield-conversion -fsyntax-only -verify %s
-// RUN: %clang_cc1 -triple armebv7-unknown-linux -Wbitfield-conversion \
-// RUN: -fsyntax-only -verify %s
-// RUN: %clang_cc1 -triple arm64-unknown-linux -Wbitfield-conversion \
-// RUN: -fsyntax-only -verify %s
-// RUN: %clang_cc1 -triple arm-unknown-linux -Wbitfield-conversion \
-// RUN: -fsyntax-only -verify %s
-// RUN: %clang_cc1 -triple aarch64-unknown-linux -Wbitfield-conversion \
-// RUN: -fsyntax-only -verify %s
-// RUN: %clang_cc1 -triple mipsel-unknown-linux -Wbitfield-conversion \
-// RUN: -fsyntax-only -verify %s
-// RUN: %clang_cc1 -triple mips64el-unknown-linux -Wbitfield-conversion \
-// RUN: -fsyntax-only -verify %s
-
-typedef struct _xx {
- int bf:9; // expected-note 3{{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 foo4(short x) {
- vxx.bf = 0xff & x; // no warning expected
- }
- void foo5(short x) {
- vxx.bf = 0x1ff & x; // no warning expected
- }
- void foo6(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;
- }
More information about the cfe-commits
mailing list