Skip to content

Commit 075d427

Browse files
authored
Revert "[clang][UBSan] Add implicit conversion check for bitfields (#75481)"
This reverts commit 450f195.
1 parent 5b95931 commit 075d427

File tree

11 files changed

+73
-493
lines changed

11 files changed

+73
-493
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,6 @@ Non-comprehensive list of changes in this release
195195

196196
New Compiler Flags
197197
------------------
198-
- ``-fsanitize=implicit-bitfield-conversion`` checks implicit truncation and
199-
sign change.
200-
- ``-fsanitize=implicit-integer-conversion`` a group that replaces the previous
201-
group ``-fsanitize=implicit-conversion``.
202198

203199
- ``-Wmissing-designated-field-initializers``, grouped under ``-Wmissing-field-initializers``.
204200
This diagnostic can be disabled to make ``-Wmissing-field-initializers`` behave
@@ -212,9 +208,6 @@ Modified Compiler Flags
212208
- Added a new diagnostic flag ``-Wreturn-mismatch`` which is grouped under
213209
``-Wreturn-type``, and moved some of the diagnostics previously controlled by
214210
``-Wreturn-type`` under this new flag. Fixes #GH72116.
215-
- ``-fsanitize=implicit-conversion`` is now a group for both
216-
``-fsanitize=implicit-integer-conversion`` and
217-
``-fsanitize=implicit-bitfield-conversion``.
218211

219212
- Added ``-Wcast-function-type-mismatch`` under the ``-Wcast-function-type``
220213
warning group. Moved the diagnostic previously controlled by

clang/docs/UndefinedBehaviorSanitizer.rst

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,6 @@ Available checks are:
148148
Issues caught by this sanitizer are not undefined behavior,
149149
but are often unintentional.
150150
- ``-fsanitize=integer-divide-by-zero``: Integer division by zero.
151-
- ``-fsanitize=implicit-bitfield-conversion``: Implicit conversion from
152-
integer of larger bit width to smaller bitfield, if that results in data
153-
loss. This includes unsigned/signed truncations and sign changes, similarly
154-
to how the ``-fsanitize=implicit-integer-conversion`` group works, but
155-
explicitly for bitfields.
156151
- ``-fsanitize=nonnull-attribute``: Passing null pointer as a function
157152
parameter which is declared to never be null.
158153
- ``-fsanitize=null``: Use of a null pointer or creation of a null
@@ -198,16 +193,16 @@ Available checks are:
198193
signed division overflow (``INT_MIN/-1``). Note that checks are still
199194
added even when ``-fwrapv`` is enabled. This sanitizer does not check for
200195
lossy implicit conversions performed before the computation (see
201-
``-fsanitize=implicit-integer-conversion``). Both of these two issues are handled
202-
by ``-fsanitize=implicit-integer-conversion`` group of checks.
196+
``-fsanitize=implicit-conversion``). Both of these two issues are handled
197+
by ``-fsanitize=implicit-conversion`` group of checks.
203198
- ``-fsanitize=unreachable``: If control flow reaches an unreachable
204199
program point.
205200
- ``-fsanitize=unsigned-integer-overflow``: Unsigned integer overflow, where
206201
the result of an unsigned integer computation cannot be represented in its
207202
type. Unlike signed integer overflow, this is not undefined behavior, but
208203
it is often unintentional. This sanitizer does not check for lossy implicit
209204
conversions performed before such a computation
210-
(see ``-fsanitize=implicit-integer-conversion``).
205+
(see ``-fsanitize=implicit-conversion``).
211206
- ``-fsanitize=vla-bound``: A variable-length array whose bound
212207
does not evaluate to a positive value.
213208
- ``-fsanitize=vptr``: Use of an object whose vptr indicates that it is of
@@ -229,15 +224,11 @@ You can also use the following check groups:
229224
- ``-fsanitize=implicit-integer-arithmetic-value-change``: Catches implicit
230225
conversions that change the arithmetic value of the integer. Enables
231226
``implicit-signed-integer-truncation`` and ``implicit-integer-sign-change``.
232-
- ``-fsanitize=implicit-integer-conversion``: Checks for suspicious
233-
behavior of implicit integer conversions. Enables
227+
- ``-fsanitize=implicit-conversion``: Checks for suspicious
228+
behavior of implicit conversions. Enables
234229
``implicit-unsigned-integer-truncation``,
235230
``implicit-signed-integer-truncation``, and
236231
``implicit-integer-sign-change``.
237-
- ``-fsanitize=implicit-conversion``: Checks for suspicious
238-
behavior of implicit conversions. Enables
239-
``implicit-integer-conversion``, and
240-
``implicit-bitfield-conversion``.
241232
- ``-fsanitize=integer``: Checks for undefined or suspicious integer
242233
behavior (e.g. unsigned integer overflow).
243234
Enables ``signed-integer-overflow``, ``unsigned-integer-overflow``,

clang/include/clang/Basic/Sanitizers.def

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,24 +163,24 @@ SANITIZER_GROUP("implicit-integer-arithmetic-value-change",
163163
ImplicitIntegerArithmeticValueChange,
164164
ImplicitIntegerSignChange | ImplicitSignedIntegerTruncation)
165165

166-
SANITIZER_GROUP("implicit-integer-conversion", ImplicitIntegerConversion,
167-
ImplicitIntegerArithmeticValueChange |
168-
ImplicitUnsignedIntegerTruncation)
166+
SANITIZER("objc-cast", ObjCCast)
169167

170-
// Implicit bitfield sanitizers
171-
SANITIZER("implicit-bitfield-conversion", ImplicitBitfieldConversion)
168+
// FIXME:
169+
//SANITIZER_GROUP("implicit-integer-conversion", ImplicitIntegerConversion,
170+
// ImplicitIntegerArithmeticValueChange |
171+
// ImplicitUnsignedIntegerTruncation)
172+
//SANITIZER_GROUP("implicit-conversion", ImplicitConversion,
173+
// ImplicitIntegerConversion)
172174

173175
SANITIZER_GROUP("implicit-conversion", ImplicitConversion,
174-
ImplicitIntegerConversion |
175-
ImplicitBitfieldConversion)
176+
ImplicitIntegerArithmeticValueChange |
177+
ImplicitUnsignedIntegerTruncation)
176178

177179
SANITIZER_GROUP("integer", Integer,
178-
ImplicitIntegerConversion | IntegerDivideByZero | Shift |
180+
ImplicitConversion | IntegerDivideByZero | Shift |
179181
SignedIntegerOverflow | UnsignedIntegerOverflow |
180182
UnsignedShiftBase)
181183

182-
SANITIZER("objc-cast", ObjCCast)
183-
184184
SANITIZER("local-bounds", LocalBounds)
185185
SANITIZER_GROUP("bounds", Bounds, ArrayBounds | LocalBounds)
186186

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5580,44 +5580,11 @@ LValue CodeGenFunction::EmitBinaryOperatorLValue(const BinaryOperator *E) {
55805580
break;
55815581
}
55825582

5583-
// TODO: Can we de-duplicate this code with the corresponding code in
5584-
// CGExprScalar, similar to the way EmitCompoundAssignmentLValue works?
5585-
RValue RV;
5586-
llvm::Value *Previous = nullptr;
5587-
QualType SrcType = E->getRHS()->getType();
5588-
// Check if LHS is a bitfield, if RHS contains an implicit cast expression
5589-
// we want to extract that value and potentially (if the bitfield sanitizer
5590-
// is enabled) use it to check for an implicit conversion.
5591-
if (E->getLHS()->refersToBitField()) {
5592-
llvm::Value *RHS =
5593-
EmitWithOriginalRHSBitfieldAssignment(E, Previous, &SrcType);
5594-
RV = RValue::get(RHS);
5595-
} else
5596-
RV = EmitAnyExpr(E->getRHS());
5597-
5583+
RValue RV = EmitAnyExpr(E->getRHS());
55985584
LValue LV = EmitCheckedLValue(E->getLHS(), TCK_Store);
5599-
56005585
if (RV.isScalar())
56015586
EmitNullabilityCheck(LV, RV.getScalarVal(), E->getExprLoc());
5602-
5603-
if (LV.isBitField()) {
5604-
llvm::Value *Result;
5605-
// If bitfield sanitizers are enabled we want to use the result
5606-
// to check whether a truncation or sign change has occurred.
5607-
if (SanOpts.has(SanitizerKind::ImplicitBitfieldConversion))
5608-
EmitStoreThroughBitfieldLValue(RV, LV, &Result);
5609-
else
5610-
EmitStoreThroughBitfieldLValue(RV, LV);
5611-
5612-
// If the expression contained an implicit conversion, make sure
5613-
// to use the value before the scalar conversion.
5614-
llvm::Value *Src = Previous ? Previous : RV.getScalarVal();
5615-
QualType DstType = E->getLHS()->getType();
5616-
EmitBitfieldConversionCheck(Src, SrcType, Result, DstType,
5617-
LV.getBitFieldInfo(), E->getExprLoc());
5618-
} else
5619-
EmitStoreThroughLValue(RV, LV);
5620-
5587+
EmitStoreThroughLValue(RV, LV);
56215588
if (getLangOpts().OpenMP)
56225589
CGM.getOpenMPRuntime().checkAndEmitLastprivateConditional(*this,
56235590
E->getLHS());

0 commit comments

Comments
 (0)