From 2069403cdf35da826937dc40453930c60d52487f Mon Sep 17 00:00:00 2001 From: "Kevin P. Neal" Date: Fri, 6 Nov 2020 10:44:13 -0500 Subject: [FPEnv] Use strictfp metadata in casting nodes The strictfp metadata was added to the casting AST nodes in D85960, but we aren't using that metadata yet. This patch adds that support. In order to avoid lots of ad-hoc passing around of the strictfp bits I updated the IRBuilder when moving from a function that has the Expr* to a function that lacks it. I believe we should switch to this pattern to keep the strictfp support from being overly invasive. For the purpose of testing that we're picking up the right metadata, I also made my tests use a pragma to make the AST's strictfp metadata not match the global strictfp metadata. This exposes issues that we need to deal with in subsequent patches, and I believe this is the right method for most all of our clang strictfp tests. Differential Revision: https://reviews.llvm.org/D88913 --- clang/lib/CodeGen/CodeGenFunction.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp') diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index ea33ea0..005ee74 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -25,6 +25,7 @@ #include "clang/AST/Attr.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" +#include "clang/AST/Expr.h" #include "clang/AST/StmtCXX.h" #include "clang/AST/StmtObjC.h" #include "clang/Basic/Builtins.h" @@ -131,10 +132,24 @@ void CodeGenFunction::SetFastMathFlags(FPOptions FPFeatures) { } CodeGenFunction::CGFPOptionsRAII::CGFPOptionsRAII(CodeGenFunction &CGF, + const Expr *E) + : CGF(CGF) { + ConstructorHelper(E->getFPFeaturesInEffect(CGF.getLangOpts())); +} + +CodeGenFunction::CGFPOptionsRAII::CGFPOptionsRAII(CodeGenFunction &CGF, FPOptions FPFeatures) - : CGF(CGF), OldFPFeatures(CGF.CurFPFeatures) { + : CGF(CGF) { + ConstructorHelper(FPFeatures); +} + +void CodeGenFunction::CGFPOptionsRAII::ConstructorHelper(FPOptions FPFeatures) { + OldFPFeatures = CGF.CurFPFeatures; CGF.CurFPFeatures = FPFeatures; + OldExcept = CGF.Builder.getDefaultConstrainedExcept(); + OldRounding = CGF.Builder.getDefaultConstrainedRounding(); + if (OldFPFeatures == FPFeatures) return; @@ -175,6 +190,8 @@ CodeGenFunction::CGFPOptionsRAII::CGFPOptionsRAII(CodeGenFunction &CGF, CodeGenFunction::CGFPOptionsRAII::~CGFPOptionsRAII() { CGF.CurFPFeatures = OldFPFeatures; + CGF.Builder.setDefaultConstrainedExcept(OldExcept); + CGF.Builder.setDefaultConstrainedRounding(OldRounding); } LValue CodeGenFunction::MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T) { -- cgit v1.1