Skip to content

Commit f952255

Browse files
committed
Revert "[Clang][Sema] Enabled implicit conversion warning for CompoundAssignment operator."
This reverts commit 4c37671, aka llvmorg-16-init-17246-g4c37671a7c94 This caused many warnings in the current llvm codebase.
1 parent e3eca33 commit f952255

File tree

3 files changed

+5
-54
lines changed

3 files changed

+5
-54
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,6 @@ Bug Fixes
351351

352352
Improvements to Clang's diagnostics
353353
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
354-
- Clang now supports implicit conversion warnings (``-Wsign-conversion``,
355-
``Wshorten-64-to-32``, etc) for compound assignment operators (like +=, -=, <<=, >>= etc)
356-
with integral operands.
357354
- Clang will now check compile-time determinable string literals as format strings.
358355
Fixes `Issue 55805: <https://github.com/llvm/llvm-project/issues/55805>`_.
359356
- ``-Wformat`` now recognizes ``%b`` for the ``printf``/``scanf`` family of

clang/lib/Sema/SemaChecking.cpp

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13508,13 +13508,8 @@ static void DiagnoseFloatingImpCast(Sema &S, Expr *E, QualType T,
1350813508
}
1350913509
}
1351013510

13511-
static void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
13512-
SourceLocation CC,
13513-
bool *ICContext = nullptr,
13514-
bool IsListInit = false);
13515-
1351613511
/// Analyze the given compound assignment for the possible losing of
13517-
/// floating-point precision and for implicit conversions for integral operands.
13512+
/// floating-point precision.
1351813513
static void AnalyzeCompoundAssignment(Sema &S, BinaryOperator *E) {
1351913514
assert(isa<CompoundAssignOperator>(E) &&
1352013515
"Must be compound assignment operation");
@@ -13531,17 +13526,8 @@ static void AnalyzeCompoundAssignment(Sema &S, BinaryOperator *E) {
1353113526
->getComputationResultType()
1353213527
->getAs<BuiltinType>();
1353313528

13534-
// Check for implicit conversions for compound assignment statements with
13535-
// intergral operands.
13536-
// FIXME: should this handle floating-point as well?
13537-
if (E->getLHS()->getType()->isIntegerType() &&
13538-
E->getRHS()->getType()->isIntegerType() && !E->isShiftAssignOp())
13539-
CheckImplicitConversion(S, E->getRHS(), E->getType(),
13540-
E->getRHS()->getExprLoc());
13541-
1354213529
// The below checks assume source is floating point.
13543-
if (!ResultBT || !RBT || !RBT->isFloatingPoint())
13544-
return;
13530+
if (!ResultBT || !RBT || !RBT->isFloatingPoint()) return;
1354513531

1354613532
// If source is floating point but target is an integer.
1354713533
if (ResultBT->isInteger())
@@ -13830,8 +13816,9 @@ static void DiagnoseIntInBoolContext(Sema &S, Expr *E) {
1383013816
}
1383113817

1383213818
static void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
13833-
SourceLocation CC, bool *ICContext,
13834-
bool IsListInit) {
13819+
SourceLocation CC,
13820+
bool *ICContext = nullptr,
13821+
bool IsListInit = false) {
1383513822
if (E->isTypeDependent() || E->isValueDependent()) return;
1383613823

1383713824
const Type *Source = S.Context.getCanonicalType(E->getType()).getTypePtr();

clang/test/Sema/conversion-64-32.c

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,3 @@ int4 test1(long2 a) {
1717
int test2(long v) {
1818
return v / 2; // expected-warning {{implicit conversion loses integer precision: 'long' to 'int'}}
1919
}
20-
21-
// rdar://10466193
22-
void test3(int i, long long ll) {
23-
i += ll; // expected-warning {{implicit conversion loses integer precision}}
24-
i -= ll; // expected-warning {{implicit conversion loses integer precision}}
25-
i *= ll; // expected-warning {{implicit conversion loses integer precision}}
26-
i /= ll; // expected-warning {{implicit conversion loses integer precision}}
27-
}
28-
29-
void test4(int i, long long ll) {
30-
i += i-ll; // expected-warning {{implicit conversion loses integer precision}}
31-
i += i+ll; // expected-warning {{implicit conversion loses integer precision}}
32-
i -= i-ll; // expected-warning {{implicit conversion loses integer precision}}
33-
i -= i+ll; // expected-warning {{implicit conversion loses integer precision}}
34-
}
35-
36-
void test5(int i, int j, long long ll) {
37-
i += (i-j)*ll; // expected-warning {{implicit conversion loses integer precision}}
38-
i += (i+j)*ll; // expected-warning {{implicit conversion loses integer precision}}
39-
i -= ll/(i-j); // expected-warning {{implicit conversion loses integer precision}}
40-
i -= ll/(i-j); // expected-warning {{implicit conversion loses integer precision}}
41-
}
42-
43-
void test6(char c) {
44-
c <<= 999999; // expected-warning {{shift count >= width of type}} \
45-
// cxx17-warning {{shift count >= width of type}} \
46-
// ref-warning {{shift count >= width of type}} \
47-
// ref-cxx17-warning {{shift count >= width of type}}
48-
c >>= 999999; // expected-warning {{shift count >= width of type}} \
49-
// cxx17-warning {{shift count >= width of type}} \
50-
// ref-warning {{shift count >= width of type}} \
51-
// ref-cxx17-warning {{shift count >= width of type}}
52-
}

0 commit comments

Comments
 (0)