Skip to content

Commit e214bda

Browse files
committed
Revert "[Sema] Add check for bitfield assignments to integral types (#69049)"
This reverts commit 708808e which is causing crashes on valid code, see #69049 (comment).
1 parent 65c9c92 commit e214bda

File tree

5 files changed

+1
-62
lines changed

5 files changed

+1
-62
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,6 @@ New Compiler Flags
211211
the preprocessed text to the output. This can greatly reduce the size of the
212212
preprocessed output, which can be helpful when trying to reduce a test case.
213213

214-
* ``-Wbitfield-conversion`` was added to detect assignments of integral
215-
types to a bitfield that may change the value.
216-
217214
Deprecated Compiler Flags
218215
-------------------------
219216

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ def SingleBitBitFieldConstantConversion :
5353
def BitFieldConstantConversion : DiagGroup<"bitfield-constant-conversion",
5454
[SingleBitBitFieldConstantConversion]>;
5555
def BitFieldEnumConversion : DiagGroup<"bitfield-enum-conversion">;
56-
def BitFieldConversion : DiagGroup<"bitfield-conversion">;
5756
def BitFieldWidth : DiagGroup<"bitfield-width">;
5857
def CompoundTokenSplitByMacro : DiagGroup<"compound-token-split-by-macro">;
5958
def CompoundTokenSplitBySpace : DiagGroup<"compound-token-split-by-space">;
@@ -936,7 +935,6 @@ def Conversion : DiagGroup<"conversion",
936935
ConstantConversion,
937936
EnumConversion,
938937
BitFieldEnumConversion,
939-
BitFieldConversion,
940938
FloatConversion,
941939
Shorten64To32,
942940
IntConversion,

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6191,9 +6191,6 @@ def warn_signed_bitfield_enum_conversion : Warning<
61916191
"signed bit-field %0 needs an extra bit to represent the largest positive "
61926192
"enumerators of %1">,
61936193
InGroup<BitFieldEnumConversion>, DefaultIgnore;
6194-
def warn_bitfield_too_small_for_integral_type : Warning<
6195-
"conversion from %2 (%3 bits) to bit-field %0 (%1 bits) may change value">,
6196-
InGroup<BitFieldConversion>, DefaultIgnore;
61976194
def note_change_bitfield_sign : Note<
61986195
"consider making the bitfield type %select{unsigned|signed}0">;
61996196

clang/lib/Sema/SemaChecking.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14332,18 +14332,6 @@ static bool AnalyzeBitFieldAssignment(Sema &S, FieldDecl *Bitfield, Expr *Init,
1433214332
S.Diag(WidthExpr->getExprLoc(), diag::note_widen_bitfield)
1433314333
<< BitsNeeded << ED << WidthExpr->getSourceRange();
1433414334
}
14335-
} else if (OriginalInit->getType()->isIntegralType(S.Context)) {
14336-
IntRange LikelySourceRange =
14337-
GetExprRange(S.Context, Init, S.isConstantEvaluatedContext(),
14338-
/*Approximate=*/true);
14339-
14340-
if (LikelySourceRange.Width > FieldWidth) {
14341-
Expr *WidthExpr = Bitfield->getBitWidth();
14342-
S.Diag(InitLoc, diag::warn_bitfield_too_small_for_integral_type)
14343-
<< Bitfield << FieldWidth << OriginalInit->getType()
14344-
<< LikelySourceRange.Width;
14345-
S.Diag(WidthExpr->getExprLoc(), diag::note_declared_at);
14346-
}
1434714335
}
1434814336

1434914337
return false;
@@ -15241,6 +15229,7 @@ static void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
1524115229

1524215230
if (LikelySourceRange.Width > TargetRange.Width) {
1524315231
// If the source is a constant, use a default-on diagnostic.
15232+
// TODO: this should happen for bitfield stores, too.
1524415233
Expr::EvalResult Result;
1524515234
if (E->EvaluateAsInt(Result, S.Context, Expr::SE_AllowSideEffects,
1524615235
S.isConstantEvaluatedContext())) {

clang/test/SemaCXX/bitfield-width.c

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)