diff options
author | Tan S. B. <cpplearner@outlook.com> | 2018-12-18 07:38:06 +0000 |
---|---|---|
committer | Tan S. B. <cpplearner@outlook.com> | 2018-12-18 07:38:06 +0000 |
commit | 9f935e874979931dea895ee14b9dd742790f9928 (patch) | |
tree | 5a9a23d47dd4a7b2e092d35213dd19cbe766abb5 | |
parent | ecdab5bdd8036827dfdae1d3fc06a512bff55e10 (diff) | |
download | bcm5719-llvm-9f935e874979931dea895ee14b9dd742790f9928.tar.gz bcm5719-llvm-9f935e874979931dea895ee14b9dd742790f9928.zip |
[ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type
Fixes PR39858
Differential Revision: https://reviews.llvm.org/D55413
llvm-svn: 349444
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 26 | ||||
-rw-r--r-- | clang/test/SemaCXX/constant-expression-cxx1y.cpp | 8 |
2 files changed, 27 insertions, 7 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 837dc9c2a8e..2022b07bffe 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -3439,19 +3439,31 @@ struct CompoundAssignSubobjectHandler { if (!checkConst(SubobjType)) return false; - if (!SubobjType->isIntegerType() || !RHS.isInt()) { + if (!SubobjType->isIntegerType()) { // We don't support compound assignment on integer-cast-to-pointer // values. Info.FFDiag(E); return false; } - APSInt LHS = HandleIntToIntCast(Info, E, PromotedLHSType, - SubobjType, Value); - if (!handleIntIntBinOp(Info, E, LHS, Opcode, RHS.getInt(), LHS)) - return false; - Value = HandleIntToIntCast(Info, E, SubobjType, PromotedLHSType, LHS); - return true; + if (RHS.isInt()) { + APSInt LHS = + HandleIntToIntCast(Info, E, PromotedLHSType, SubobjType, Value); + if (!handleIntIntBinOp(Info, E, LHS, Opcode, RHS.getInt(), LHS)) + return false; + Value = HandleIntToIntCast(Info, E, SubobjType, PromotedLHSType, LHS); + return true; + } else 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); + } + + Info.FFDiag(E); + return false; } bool found(APFloat &Value, QualType SubobjType) { return checkConst(SubobjType) && diff --git a/clang/test/SemaCXX/constant-expression-cxx1y.cpp b/clang/test/SemaCXX/constant-expression-cxx1y.cpp index a71dbc0eb50..3c57ac573f2 100644 --- a/clang/test/SemaCXX/constant-expression-cxx1y.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx1y.cpp @@ -356,6 +356,14 @@ namespace compound_assign { if (a != 13) return false; a &= 14; if (a != 12) return false; + a += -1.2; + if (a != 10) return false; + a -= 3.1; + if (a != 6) return false; + a *= 2.2; + if (a != 13) return false; + if (&(a /= 1.5) != &a) return false; + if (a != 8) return false; return true; } static_assert(test_int(), ""); |