[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
Thu Dec 6 23:33:48 PST 2018


cpplearner created this revision.
cpplearner added a reviewer: rsmith.
Herald added a subscriber: cfe-commits.

Fixes PR39858


Repository:
  rC Clang

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
@@ -338,11 +338,11 @@
     int a = 3;
     a += 6;
     if (a != 9) return false;
-    a -= 2;
+    a -= 1.8;
     if (a != 7) return false;
     a *= 3;
     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.177130.patch
Type: text/x-patch
Size: 1689 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181207/588dabf9/attachment-0001.bin>


More information about the cfe-commits mailing list