diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -710,10 +710,19 @@ return result; } + class FpPragmaStackSaveRAII { + public: + FpPragmaStackSaveRAII(Sema &S) : S(S), SavedStack(S.FpPragmaStack) {} + ~FpPragmaStackSaveRAII() { S.FpPragmaStack = std::move(SavedStack); } + private: + Sema &S; + PragmaStack SavedStack; + }; + void resetFPOptions(FPOptions FPO) { CurFPFeatures = FPO; FpPragmaStack.Stack.clear(); - FpPragmaStack.CurrentValue = FPO.getChangesFrom(FPOptions(LangOpts)); + FpPragmaStack.CurrentValue = FpPragmaStack.DefaultValue; } // RAII object to push / pop sentinel slots for all MS #pragma stacks. diff --git a/clang/lib/Parse/ParseTemplate.cpp b/clang/lib/Parse/ParseTemplate.cpp --- a/clang/lib/Parse/ParseTemplate.cpp +++ b/clang/lib/Parse/ParseTemplate.cpp @@ -1744,6 +1744,7 @@ // Parsing should occur with empty FP pragma stack and FP options used in the // point of the template definition. + Sema::FpPragmaStackSaveRAII SavedStack(Actions); Actions.resetFPOptions(LPT.FPO); assert(!LPT.Toks.empty() && "Empty body!"); diff --git a/clang/test/PCH/late-parsed-instantiations.cpp b/clang/test/PCH/late-parsed-instantiations.cpp --- a/clang/test/PCH/late-parsed-instantiations.cpp +++ b/clang/test/PCH/late-parsed-instantiations.cpp @@ -4,7 +4,9 @@ // RUN: %clang_cc1 -fdelayed-template-parsing -std=c++14 -emit-pch -fpch-instantiate-templates %s -o %t.pch -verify // RUN: %clang_cc1 -fdelayed-template-parsing -std=c++14 -include-pch %t.pch %s -verify -// XFAIL: target={{.*}}-aix{{.*}} +// Run this test for i686 as this is the target that modifies default FP options. +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fdelayed-template-parsing -std=c++14 -emit-pch -fpch-instantiate-templates %s -o %t.pch -verify +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fdelayed-template-parsing -std=c++14 -include-pch %t.pch %s -verify #ifndef HEADER_INCLUDED