[clang] f952255 - Revert "[Clang][Sema] Enabled implicit conversion warning for CompoundAssignment operator."

NAKAMURA Takumi via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 13 15:53:32 PST 2023


Author: NAKAMURA Takumi
Date: 2023-01-14T08:53:00+09:00
New Revision: f952255907a5a10925a565948f2ca8a61a826d92

URL: https://github.com/llvm/llvm-project/commit/f952255907a5a10925a565948f2ca8a61a826d92
DIFF: https://github.com/llvm/llvm-project/commit/f952255907a5a10925a565948f2ca8a61a826d92.diff

LOG: Revert "[Clang][Sema] Enabled implicit conversion warning for CompoundAssignment operator."

This reverts commit 4c37671a7c946ac246b52fa44a6a649b89d6310b,
aka llvmorg-16-init-17246-g4c37671a7c94

This caused many warnings in the current llvm codebase.

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Sema/SemaChecking.cpp
    clang/test/Sema/conversion-64-32.c

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 34b96789d38bb..a75bc1df2d7c9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -351,9 +351,6 @@ Bug Fixes
 
 Improvements to Clang's diagnostics
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-- Clang now supports implicit conversion warnings (``-Wsign-conversion``,
-  ``Wshorten-64-to-32``, etc) for compound assignment operators (like +=, -=, <<=, >>= etc) 
-  with integral operands.
 - Clang will now check compile-time determinable string literals as format strings.
   Fixes `Issue 55805: <https://github.com/llvm/llvm-project/issues/55805>`_.
 - ``-Wformat`` now recognizes ``%b`` for the ``printf``/``scanf`` family of

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index b3834c830d7b7..1d956fadcf670 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -13508,13 +13508,8 @@ static void DiagnoseFloatingImpCast(Sema &S, Expr *E, QualType T,
   }
 }
 
-static void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
-                                    SourceLocation CC,
-                                    bool *ICContext = nullptr,
-                                    bool IsListInit = false);
-
 /// Analyze the given compound assignment for the possible losing of
-/// floating-point precision and for implicit conversions for integral operands.
+/// floating-point precision.
 static void AnalyzeCompoundAssignment(Sema &S, BinaryOperator *E) {
   assert(isa<CompoundAssignOperator>(E) &&
          "Must be compound assignment operation");
@@ -13531,17 +13526,8 @@ static void AnalyzeCompoundAssignment(Sema &S, BinaryOperator *E) {
                         ->getComputationResultType()
                         ->getAs<BuiltinType>();
 
-  // Check for implicit conversions for compound assignment statements with
-  // intergral operands.
-  // FIXME: should this handle floating-point as well?
-  if (E->getLHS()->getType()->isIntegerType() &&
-      E->getRHS()->getType()->isIntegerType() && !E->isShiftAssignOp())
-    CheckImplicitConversion(S, E->getRHS(), E->getType(),
-                            E->getRHS()->getExprLoc());
-
   // The below checks assume source is floating point.
-  if (!ResultBT || !RBT || !RBT->isFloatingPoint())
-    return;
+  if (!ResultBT || !RBT || !RBT->isFloatingPoint()) return;
 
   // If source is floating point but target is an integer.
   if (ResultBT->isInteger())
@@ -13830,8 +13816,9 @@ static void DiagnoseIntInBoolContext(Sema &S, Expr *E) {
 }
 
 static void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
-                                    SourceLocation CC, bool *ICContext,
-                                    bool IsListInit) {
+                                    SourceLocation CC,
+                                    bool *ICContext = nullptr,
+                                    bool IsListInit = false) {
   if (E->isTypeDependent() || E->isValueDependent()) return;
 
   const Type *Source = S.Context.getCanonicalType(E->getType()).getTypePtr();

diff  --git a/clang/test/Sema/conversion-64-32.c b/clang/test/Sema/conversion-64-32.c
index 6b9d2e2ff35ae..3de20cb0fda3a 100644
--- a/clang/test/Sema/conversion-64-32.c
+++ b/clang/test/Sema/conversion-64-32.c
@@ -17,36 +17,3 @@ int4 test1(long2 a) {
 int test2(long v) {
   return v / 2; // expected-warning {{implicit conversion loses integer precision: 'long' to 'int'}}
 }
-
-// rdar://10466193
-void test3(int i, long long ll) {
-  i += ll; // expected-warning {{implicit conversion loses integer precision}}
-  i -= ll; // expected-warning {{implicit conversion loses integer precision}}
-  i *= ll; // expected-warning {{implicit conversion loses integer precision}}
-  i /= ll; // expected-warning {{implicit conversion loses integer precision}}
-}
-
-void test4(int i, long long ll) {
-  i += i-ll; // expected-warning {{implicit conversion loses integer precision}}
-  i += i+ll; // expected-warning {{implicit conversion loses integer precision}}
-  i -= i-ll; // expected-warning {{implicit conversion loses integer precision}}
-  i -= i+ll; // expected-warning {{implicit conversion loses integer precision}}
-}
-
-void test5(int i, int j, long long ll) {
-  i += (i-j)*ll; // expected-warning {{implicit conversion loses integer precision}}
-  i += (i+j)*ll; // expected-warning {{implicit conversion loses integer precision}}
-  i -= ll/(i-j); // expected-warning {{implicit conversion loses integer precision}}
-  i -= ll/(i-j); // expected-warning {{implicit conversion loses integer precision}}
-}
-
-void test6(char c) {
-  c <<= 999999; // expected-warning {{shift count >= width of type}} \
-                  // cxx17-warning {{shift count >= width of type}} \
-                  // ref-warning {{shift count >= width of type}} \
-                  // ref-cxx17-warning {{shift count >= width of type}}
-  c >>= 999999; // expected-warning {{shift count >= width of type}} \
-                  // cxx17-warning {{shift count >= width of type}} \
-                  // ref-warning {{shift count >= width of type}} \
-                  // ref-cxx17-warning {{shift count >= width of type}}
-}


        


More information about the cfe-commits mailing list