diff options
author | Serge Pavlov <sepavloff@gmail.com> | 2023-11-13 17:24:46 +0700 |
---|---|---|
committer | Tobias Hieta <tobias@hieta.se> | 2023-11-14 09:22:13 +0100 |
commit | aebee698ef16a4346c669e9f940c6dbf2247b7ef (patch) | |
tree | bedb59ab3a56c9e18033dc39e141613614f82e35 | |
parent | 529aa6eadb27257130cdf7b9e55ca522644ce32f (diff) | |
download | llvm-aebee698ef16a4346c669e9f940c6dbf2247b7ef.tar.gz |
[clang] Do not clear FP pragma stack when instantiating functions (#70646)
When instantiation function, a call to Sema::resetFPOption was used to
set the FP options associated with AST node. However this function also
cleared FP pragma stack, and it is incorrect. Template instantiation
takes place on AST representation and semantic information like the FP
pragma stack should not affect it. This was a reason for miscompilation
in some cases.
To make the Sema interface more consistent, now `resetFPOptions` does
not clear FP pragma stack anymore. It is cleared in
`FpPragmaStackSaveRAII`, which is used in parsing only.
This change must fix https://github.com/llvm/llvm-project/issues/69717
(Problems with float_control pragma stack in Clang 17.x).
(cherry picked from commit f6f625f4c6c3cbeb8cf6b889cdafc848dd4cb117)
-rw-r--r-- | clang/include/clang/Sema/Sema.h | 7 | ||||
-rw-r--r-- | clang/test/Sema/PR69717.cpp | 17 |
2 files changed, 22 insertions, 2 deletions
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index cfd1c0f977c0..3752a23faa85 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -710,9 +710,13 @@ public: return result; } + // Saves the current floating-point pragma stack and clear it in this Sema. class FpPragmaStackSaveRAII { public: - FpPragmaStackSaveRAII(Sema &S) : S(S), SavedStack(S.FpPragmaStack) {} + FpPragmaStackSaveRAII(Sema &S) + : S(S), SavedStack(std::move(S.FpPragmaStack)) { + S.FpPragmaStack.Stack.clear(); + } ~FpPragmaStackSaveRAII() { S.FpPragmaStack = std::move(SavedStack); } private: @@ -722,7 +726,6 @@ public: void resetFPOptions(FPOptions FPO) { CurFPFeatures = FPO; - FpPragmaStack.Stack.clear(); FpPragmaStack.CurrentValue = FPO.getChangesFrom(FPOptions(LangOpts)); } diff --git a/clang/test/Sema/PR69717.cpp b/clang/test/Sema/PR69717.cpp new file mode 100644 index 000000000000..3207092b948a --- /dev/null +++ b/clang/test/Sema/PR69717.cpp @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -verify -fsyntax-only %s +// expected-no-diagnostics + +// Testcase for https://github.com/llvm/llvm-project/issues/69717 + +#pragma float_control(precise, on, push) + +template<typename T> +constexpr T multi(T x, T y) { + return x * y; +} + +int multi_i(int x, int y) { + return multi<int>(x, y); +} + +#pragma float_control(pop) |