[clang] [clang] Store FPOptions earlier when parsing function (PR #92146)
Serge Pavlov via cfe-commits
cfe-commits at lists.llvm.org
Tue May 14 22:23:24 PDT 2024
https://github.com/spavloff updated https://github.com/llvm/llvm-project/pull/92146
>From 4f6f0acb47d21b25e4e86733a81d609f4de7dc3c Mon Sep 17 00:00:00 2001
From: Serge Pavlov <sepavloff at gmail.com>
Date: Tue, 14 May 2024 23:11:21 +0700
Subject: [PATCH 1/2] [clang] Store FPOptions earlier when parsing function
After https://github.com/llvm/llvm-project/pull/85605 ([clang] Set
correct FPOptions if attribute 'optnone' presents) the current FP options
in Sema are saved during parsing function because Sema can modify them if
optnone is present. However they were saved too late, it caused fails in
some cases when precompiled headers are used. This patch moves the
storing earlier.
---
clang/lib/Parse/Parser.cpp | 4 ++--
clang/test/PCH/optnone.cpp | 6 ++++++
2 files changed, 8 insertions(+), 2 deletions(-)
create mode 100644 clang/test/PCH/optnone.cpp
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index adcbe5858bc78..869b9c6669c27 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -1439,6 +1439,8 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D,
}
}
+ Sema::FPFeaturesStateRAII SaveFPFeatures(Actions);
+
// Tell the actions module that we have entered a function definition with the
// specified Declarator for the function.
SkipBodyInfo SkipBody;
@@ -1497,8 +1499,6 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D,
return Actions.ActOnFinishFunctionBody(Res, nullptr, false);
}
- Sema::FPFeaturesStateRAII SaveFPFeatures(Actions);
-
if (Tok.is(tok::kw_try))
return ParseFunctionTryBlock(Res, BodyScope);
diff --git a/clang/test/PCH/optnone.cpp b/clang/test/PCH/optnone.cpp
new file mode 100644
index 0000000000000..734527b0d3f7d
--- /dev/null
+++ b/clang/test/PCH/optnone.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -emit-pch -DHEADER -x c++-header %s -o %t.pch
+// RUN: %clang_cc1 -emit-llvm -include-pch %t.pch %s -o /dev/null
+
+#ifdef HEADER
+__attribute__((optnone)) void foo() {}
+#endif
\ No newline at end of file
>From b1d061a0085a734f7e0fab5e541175f4751ca238 Mon Sep 17 00:00:00 2001
From: Serge Pavlov <sepavloff at gmail.com>
Date: Wed, 15 May 2024 12:22:38 +0700
Subject: [PATCH 2/2] Fix test
---
clang/test/PCH/optnone.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/clang/test/PCH/optnone.cpp b/clang/test/PCH/optnone.cpp
index 734527b0d3f7d..8351bd9de70dd 100644
--- a/clang/test/PCH/optnone.cpp
+++ b/clang/test/PCH/optnone.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -emit-pch -DHEADER -x c++-header %s -o %t.pch
-// RUN: %clang_cc1 -emit-llvm -include-pch %t.pch %s -o /dev/null
+// RUN: %clang_cc1 -emit-pch -x c++-header %s -o %t.pch
+// RUN: %clang_cc1 -emit-llvm -DMAIN -include-pch %t.pch %s -o /dev/null
-#ifdef HEADER
+#ifndef MAIN
__attribute__((optnone)) void foo() {}
-#endif
\ No newline at end of file
+#endif
More information about the cfe-commits
mailing list