[PATCH] D55413: [ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type
This revision was automatically updated to reflect the committed changes. Closed by commit rC349444: [ExprConstant] Handle compound assignment when LHS has integral type and RHS… (authored by cpplearner, committed by ). Changed prior to commit: https://reviews.llvm.org/D55413?vs=178242=178597#toc Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D55413/new/ https://reviews.llvm.org/D55413 Files: lib/AST/ExprConstant.cpp test/SemaCXX/constant-expression-cxx1y.cpp Index: test/SemaCXX/constant-expression-cxx1y.cpp === --- test/SemaCXX/constant-expression-cxx1y.cpp +++ test/SemaCXX/constant-expression-cxx1y.cpp @@ -356,6 +356,14 @@ 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) != ) return false; +if (a != 8) return false; return true; } static_assert(test_int(), ""); Index: lib/AST/ExprConstant.cpp === --- lib/AST/ExprConstant.cpp +++ lib/AST/ExprConstant.cpp @@ -3439,19 +3439,31 @@ 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 , QualType SubobjType) { return checkConst(SubobjType) && Index: test/SemaCXX/constant-expression-cxx1y.cpp === --- test/SemaCXX/constant-expression-cxx1y.cpp +++ test/SemaCXX/constant-expression-cxx1y.cpp @@ -356,6 +356,14 @@ 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) != ) return false; +if (a != 8) return false; return true; } static_assert(test_int(), ""); Index: lib/AST/ExprConstant.cpp === --- lib/AST/ExprConstant.cpp +++ lib/AST/ExprConstant.cpp @@ -3439,19 +3439,31 @@ 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 , QualType SubobjType) { return checkConst(SubobjType) && ___ cfe-commits mailing
[PATCH] D55413: [ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type
rjmccall accepted this revision. rjmccall added a comment. This revision is now accepted and ready to land. Thanks, that looks good to me. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D55413/new/ https://reviews.llvm.org/D55413 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D55413: [ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type
cpplearner marked 2 inline comments as done. cpplearner added inline comments. Comment at: clang/lib/AST/ExprConstant.cpp:3453 Value) && handleFloatFloatBinOp(Info, E, Value, Opcode, RHS.getFloat()) && HandleFloatToFloatCast(Info, E, PromotedLHSType, SubobjType, Value); rjmccall wrote: > rsmith wrote: > > Does this work for the float += int case? > IIRC, the RHS gets promoted to the computation type in Sema. Yes, in the float += int case, the RHS is the result of ImplicitCastExpr of kind IntegralToFloating. And `test_float()` contains test for that case. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D55413/new/ https://reviews.llvm.org/D55413 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D55413: [ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type
cpplearner updated this revision to Diff 178242. cpplearner marked an inline comment as done. 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 @@ -356,6 +356,14 @@ 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) != ) return false; +if (a != 8) return false; return true; } static_assert(test_int(), ""); Index: clang/lib/AST/ExprConstant.cpp === --- clang/lib/AST/ExprConstant.cpp +++ clang/lib/AST/ExprConstant.cpp @@ -3424,19 +3424,31 @@ 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 , QualType SubobjType) { return checkConst(SubobjType) && Index: clang/test/SemaCXX/constant-expression-cxx1y.cpp === --- clang/test/SemaCXX/constant-expression-cxx1y.cpp +++ clang/test/SemaCXX/constant-expression-cxx1y.cpp @@ -356,6 +356,14 @@ 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) != ) return false; +if (a != 8) return false; return true; } static_assert(test_int(), ""); Index: clang/lib/AST/ExprConstant.cpp === --- clang/lib/AST/ExprConstant.cpp +++ clang/lib/AST/ExprConstant.cpp @@ -3424,19 +3424,31 @@ 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 , QualType SubobjType) { return checkConst(SubobjType) && ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D55413: [ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type
rjmccall added inline comments. Comment at: clang/lib/AST/ExprConstant.cpp:3441 + Value); +} APSInt LHS = HandleIntToIntCast(Info, E, PromotedLHSType, cpplearner wrote: > rjmccall wrote: > > cpplearner wrote: > > > rjmccall wrote: > > > > Can we more fundamentally restructure this entire handler so that, if > > > > the compound assignment's computation result type is an arithmetic > > > > type, we just promote both operands to that type, do the arithmetic > > > > there, and then coerce back down? This is C++, so the LHS type imposes > > > > almost no restrictions on the RHS type; also, this is Clang, where we > > > > support way too many arithmetic types for our own good. > > > It seems the conditional statement is unavoidable, because `APSInt` and > > > `APFloat` can't be handled at the same time (i.e. you need to choose > > > among `Handle{Int,Float}To{Int,Float}Cast`, and between > > > `handleIntIntBinOp`/`handleFloatFloatBinOp`). Maybe it's possible to add > > > a layer that can accept both `APSInt` and `APFloat`, but it seems like an > > > overkill if it's only used in the compound assignment case. > > But we can have `HandleValueTo{Int,Float}Cast` functions that start with an > > arbitrary `APValue` and do the switch on that type, and we can have a > > `HandleValueValueBinOp` function that asserts that its operands have the > > same type and does the switch, and those two together should be good enough > > for what we need here. > That's what I mean by "add a layer", and I think it's unworthy. > > Maybe it makes more sense as part of a larger scale rewrite, but that's more > than I can deal with. Ah, I see that all three `found` methods here are called directly. I agree that this makes a rewrite that tries to handle the other cases here harder. Please at least adjust the code to make the ` || (!RHS.isInt() && !RHS.isFloat())` check redundant: put the int case in an `if (RHS.isInt())` block (which should probably come before the `isFloat()` block) and emit a diagnostic if none of the cases are triggered. Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D55413/new/ https://reviews.llvm.org/D55413 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D55413: [ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type
cpplearner marked an inline comment as done. cpplearner added inline comments. Comment at: clang/lib/AST/ExprConstant.cpp:3441 + Value); +} APSInt LHS = HandleIntToIntCast(Info, E, PromotedLHSType, rjmccall wrote: > cpplearner wrote: > > rjmccall wrote: > > > Can we more fundamentally restructure this entire handler so that, if the > > > compound assignment's computation result type is an arithmetic type, we > > > just promote both operands to that type, do the arithmetic there, and > > > then coerce back down? This is C++, so the LHS type imposes almost no > > > restrictions on the RHS type; also, this is Clang, where we support way > > > too many arithmetic types for our own good. > > It seems the conditional statement is unavoidable, because `APSInt` and > > `APFloat` can't be handled at the same time (i.e. you need to choose among > > `Handle{Int,Float}To{Int,Float}Cast`, and between > > `handleIntIntBinOp`/`handleFloatFloatBinOp`). Maybe it's possible to add a > > layer that can accept both `APSInt` and `APFloat`, but it seems like an > > overkill if it's only used in the compound assignment case. > But we can have `HandleValueTo{Int,Float}Cast` functions that start with an > arbitrary `APValue` and do the switch on that type, and we can have a > `HandleValueValueBinOp` function that asserts that its operands have the same > type and does the switch, and those two together should be good enough for > what we need here. That's what I mean by "add a layer", and I think it's unworthy. Maybe it makes more sense as part of a larger scale rewrite, but that's more than I can deal with. Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D55413/new/ https://reviews.llvm.org/D55413 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D55413: [ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type
rjmccall added inline comments. Comment at: clang/lib/AST/ExprConstant.cpp:3441 + Value); +} APSInt LHS = HandleIntToIntCast(Info, E, PromotedLHSType, cpplearner wrote: > rjmccall wrote: > > Can we more fundamentally restructure this entire handler so that, if the > > compound assignment's computation result type is an arithmetic type, we > > just promote both operands to that type, do the arithmetic there, and then > > coerce back down? This is C++, so the LHS type imposes almost no > > restrictions on the RHS type; also, this is Clang, where we support way too > > many arithmetic types for our own good. > It seems the conditional statement is unavoidable, because `APSInt` and > `APFloat` can't be handled at the same time (i.e. you need to choose among > `Handle{Int,Float}To{Int,Float}Cast`, and between > `handleIntIntBinOp`/`handleFloatFloatBinOp`). Maybe it's possible to add a > layer that can accept both `APSInt` and `APFloat`, but it seems like an > overkill if it's only used in the compound assignment case. But we can have `HandleValueTo{Int,Float}Cast` functions that start with an arbitrary `APValue` and do the switch on that type, and we can have a `HandleValueValueBinOp` function that asserts that its operands have the same type and does the switch, and those two together should be good enough for what we need here. Comment at: clang/lib/AST/ExprConstant.cpp:3453 Value) && handleFloatFloatBinOp(Info, E, Value, Opcode, RHS.getFloat()) && HandleFloatToFloatCast(Info, E, PromotedLHSType, SubobjType, Value); rsmith wrote: > Does this work for the float += int case? IIRC, the RHS gets promoted to the computation type in Sema. Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D55413/new/ https://reviews.llvm.org/D55413 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D55413: [ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type
rsmith added inline comments. Comment at: clang/lib/AST/ExprConstant.cpp:3453 Value) && handleFloatFloatBinOp(Info, E, Value, Opcode, RHS.getFloat()) && HandleFloatToFloatCast(Info, E, PromotedLHSType, SubobjType, Value); Does this work for the float += int case? Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D55413/new/ https://reviews.llvm.org/D55413 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D55413: [ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type
cpplearner marked an inline comment as done. cpplearner added inline comments. Comment at: clang/lib/AST/ExprConstant.cpp:3441 + Value); +} APSInt LHS = HandleIntToIntCast(Info, E, PromotedLHSType, rjmccall wrote: > Can we more fundamentally restructure this entire handler so that, if the > compound assignment's computation result type is an arithmetic type, we just > promote both operands to that type, do the arithmetic there, and then coerce > back down? This is C++, so the LHS type imposes almost no restrictions on > the RHS type; also, this is Clang, where we support way too many arithmetic > types for our own good. It seems the conditional statement is unavoidable, because `APSInt` and `APFloat` can't be handled at the same time (i.e. you need to choose among `Handle{Int,Float}To{Int,Float}Cast`, and between `handleIntIntBinOp`/`handleFloatFloatBinOp`). Maybe it's possible to add a layer that can accept both `APSInt` and `APFloat`, but it seems like an overkill if it's only used in the compound assignment case. Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D55413/new/ https://reviews.llvm.org/D55413 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D55413: [ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type
rjmccall added inline comments. Comment at: clang/lib/AST/ExprConstant.cpp:3441 + Value); +} APSInt LHS = HandleIntToIntCast(Info, E, PromotedLHSType, Can we more fundamentally restructure this entire handler so that, if the compound assignment's computation result type is an arithmetic type, we just promote both operands to that type, do the arithmetic there, and then coerce back down? This is C++, so the LHS type imposes almost no restrictions on the RHS type; also, this is Clang, where we support way too many arithmetic types for our own good. Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D55413/new/ https://reviews.llvm.org/D55413 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D55413: [ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type
cpplearner updated this revision to Diff 177719. cpplearner added a comment. Added parentheses. Restored the original tests and add more tests to the end of this function. 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 @@ -356,6 +356,14 @@ 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) != ) return false; +if (a != 8) return false; return true; } static_assert(test_int(), ""); 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)) Index: clang/test/SemaCXX/constant-expression-cxx1y.cpp === --- clang/test/SemaCXX/constant-expression-cxx1y.cpp +++ clang/test/SemaCXX/constant-expression-cxx1y.cpp @@ -356,6 +356,14 @@ 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) != ) return false; +if (a != 8) return false; return true; } static_assert(test_int(), ""); 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)) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D55413: [ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type
cpplearner marked an inline comment as done. cpplearner added inline comments. Comment at: clang/test/SemaCXX/constant-expression-cxx1y.cpp:343 if (a != 7) return false; -a *= 3; if (a != 21) return false; riccibruno wrote: > Why remove `a *= 3` instead of just adding `a *= 3.1`. Because adding `a *= 3.1` here will change the result of the whole calculation? Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D55413/new/ https://reviews.llvm.org/D55413 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D55413: [ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type
riccibruno added inline comments. Comment at: clang/lib/AST/ExprConstant.cpp:3427 -if (!SubobjType->isIntegerType() || !RHS.isInt()) { +if (!SubobjType->isIntegerType() || !RHS.isInt() && !RHS.isFloat()) { // We don't support compound assignment on integer-cast-to-pointer Parentheses ? It is always nicer to be able to read this without having to remember whether `||` has a higher precedence than `&&`. Comment at: clang/test/SemaCXX/constant-expression-cxx1y.cpp:343 if (a != 7) return false; -a *= 3; if (a != 21) return false; Why remove `a *= 3` instead of just adding `a *= 3.1`. Comment at: clang/test/SemaCXX/constant-expression-cxx1y.cpp:345 if (a != 21) return false; -if (&(a /= 10) != ) return false; if (a != 2) return false; same Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D55413/new/ https://reviews.llvm.org/D55413 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D55413: [ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type
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) != ) return false; +if (&(a /= 7.9) != ) 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)) 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) != ) return false; +if (&(a /= 7.9) != ) 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)) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D55413: [ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type
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) != ) return false; +if (&(a /= 7.9) != ) 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)) 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) != ) return false; +if (&(a /= 7.9) != ) 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)) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits