[PATCH] D55413: [ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type

S. B. Tam via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 11 07:44:29 PST 2018


cpplearner updated this revision to Diff 177708.

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55413/new/

https://reviews.llvm.org/D55413

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/constant-expression-cxx1y.cpp


Index: clang/test/SemaCXX/constant-expression-cxx1y.cpp
===================================================================
--- clang/test/SemaCXX/constant-expression-cxx1y.cpp
+++ clang/test/SemaCXX/constant-expression-cxx1y.cpp
@@ -340,9 +340,9 @@
     if (a != 9) return false;
     a -= 2;
     if (a != 7) return false;
-    a *= 3;
+    a *= 3.1;
     if (a != 21) return false;
-    if (&(a /= 10) != &a) return false;
+    if (&(a /= 7.9) != &a) return false;
     if (a != 2) return false;
     a <<= 3;
     if (a != 16) return false;
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -3424,13 +3424,21 @@
     if (!checkConst(SubobjType))
       return false;
 
-    if (!SubobjType->isIntegerType() || !RHS.isInt()) {
+    if (!SubobjType->isIntegerType() || !RHS.isInt() && !RHS.isFloat()) {
       // We don't support compound assignment on integer-cast-to-pointer
       // values.
       Info.FFDiag(E);
       return false;
     }
 
+    if (RHS.isFloat()) {
+      APFloat FValue(0.0);
+      return HandleIntToFloatCast(Info, E, SubobjType, Value, PromotedLHSType,
+                                  FValue) &&
+             handleFloatFloatBinOp(Info, E, FValue, Opcode, RHS.getFloat()) &&
+             HandleFloatToIntCast(Info, E, PromotedLHSType, FValue, SubobjType,
+                                  Value);
+    }
     APSInt LHS = HandleIntToIntCast(Info, E, PromotedLHSType,
                                     SubobjType, Value);
     if (!handleIntIntBinOp(Info, E, LHS, Opcode, RHS.getInt(), LHS))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55413.177708.patch
Type: text/x-patch
Size: 1660 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181211/f6629018/attachment.bin>


More information about the cfe-commits mailing list