diff options
author | Richard Smith <richard@metafoo.co.uk> | 2020-10-13 19:14:13 -0700 |
---|---|---|
committer | Richard Smith <richard@metafoo.co.uk> | 2020-10-16 13:26:15 -0700 |
commit | 7e801ca0efa99f7cec7a2aea30513ad282030b51 (patch) | |
tree | eb5c8a0d9c892bd88ba55e1b96395112ff63ef8a /clang/lib/AST/ExprConstant.cpp | |
parent | 48c70c1664aa4512cb7e08352dd8eb33dde4807c (diff) | |
download | llvm-7e801ca0efa99f7cec7a2aea30513ad282030b51.zip llvm-7e801ca0efa99f7cec7a2aea30513ad282030b51.tar.gz llvm-7e801ca0efa99f7cec7a2aea30513ad282030b51.tar.bz2 |
Treat constant contexts as being in the default rounding mode.
This addresses a regression where pretty much all C++ compilations using
-frounding-math now fail, due to rounding being performed in constexpr
function definitions in the standard library.
This follows the "manifestly constant evaluated" approach described in
https://reviews.llvm.org/D87528#2270676 -- evaluations that are required
to succeed at compile time are permitted even in regions with dynamic
rounding modes, as are (unfortunately) the evaluation of the
initializers of local variables of const integral types.
Differential Revision: https://reviews.llvm.org/D89360
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index fda5653..7afc44d 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -2528,6 +2528,11 @@ static llvm::RoundingMode getActiveRoundingMode(EvalInfo &Info, const Expr *E, /// Check if the given evaluation result is allowed for constant evaluation. static bool checkFloatingPointResult(EvalInfo &Info, const Expr *E, APFloat::opStatus St) { + // In a constant context, assume that any dynamic rounding mode or FP + // exception state matches the default floating-point environment. + if (Info.InConstantContext) + return true; + FPOptions FPO = E->getFPFeaturesInEffect(Info.Ctx.getLangOpts()); if ((St & APFloat::opInexact) && FPO.getRoundingMode() == llvm::RoundingMode::Dynamic) { |