[clang] 7f2db99 - [PATCH] #pragma float_control should be permitted in namespace scope.
Melanie Blower via cfe-commits
cfe-commits at lists.llvm.org
Tue May 12 06:10:39 PDT 2020
Author: Melanie Blower
Date: 2020-05-12T06:10:19-07:00
New Revision: 7f2db993500923a51c0b0aed650a3e0d4241205b
URL: https://github.com/llvm/llvm-project/commit/7f2db993500923a51c0b0aed650a3e0d4241205b
DIFF: https://github.com/llvm/llvm-project/commit/7f2db993500923a51c0b0aed650a3e0d4241205b.diff
LOG: [PATCH] #pragma float_control should be permitted in namespace scope.
Summary: Erroneous error diagnostic observed in VS2017 <numeric> header
Also correction to propagate usesFPIntrin from template func to instantiation.
Reviewers: rjmccall, erichkeane (no feedback received)
Differential Revision: https://reviews.llvm.org/D79631
Added:
Modified:
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaAttr.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/CodeGen/fp-floatcontrol-pragma.cpp
clang/test/Parser/fp-floatcontrol-syntax.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 44a34080b239..371e20183e1e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -860,7 +860,7 @@ def warn_pragma_pack_pop_identifier_and_alignment : Warning<
def warn_pragma_pop_failed : Warning<"#pragma %0(pop, ...) failed: %1">,
InGroup<IgnoredPragmas>;
def err_pragma_fc_pp_scope : Error<
- "'#pragma float_control push/pop' can only appear at file scope">;
+ "'#pragma float_control push/pop' can only appear at file scope or namespace scope">;
def err_pragma_fc_noprecise_requires_nofenv : Error<
"'#pragma float_control(precise, off)' is illegal when fenv_access is enabled">;
def err_pragma_fc_except_requires_precise : Error<
diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index 01f30a985935..222aaf3049ae 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -420,8 +420,8 @@ void Sema::ActOnPragmaFloatControl(SourceLocation Loc,
auto NewValue = FpPragmaStack.CurrentValue;
FPOptions NewFPFeatures(NewValue);
if ((Action == PSK_Push_Set || Action == PSK_Push || Action == PSK_Pop) &&
- !CurContext->isTranslationUnit()) {
- // Push and pop can only occur at file scope.
+ !(CurContext->isTranslationUnit()) && !CurContext->isNamespace()) {
+ // Push and pop can only occur at file or namespace scope.
Diag(Loc, diag::err_pragma_fc_pp_scope);
return;
}
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index a6541dabe6b2..327022218e01 100755
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1911,6 +1911,7 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(
D->hasWrittenPrototype(), D->getConstexprKind(),
TrailingRequiresClause);
Function->setRangeEnd(D->getSourceRange().getEnd());
+ Function->setUsesFPIntrin(D->usesFPIntrin());
}
if (D->isInlined())
diff --git a/clang/test/CodeGen/fp-floatcontrol-pragma.cpp b/clang/test/CodeGen/fp-floatcontrol-pragma.cpp
index 773cfcdd2829..a80a4d377660 100644
--- a/clang/test/CodeGen/fp-floatcontrol-pragma.cpp
+++ b/clang/test/CodeGen/fp-floatcontrol-pragma.cpp
@@ -1,3 +1,4 @@
+// RUN: %clang_cc1 -DEXCEPT=1 -fcxx-exceptions -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-NS %s
// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
// RUN: %clang_cc1 -verify -DFENV_ON=1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
@@ -59,3 +60,56 @@ void callt() {
z = z * z;
//CHECK: = fmul float
}
+
+#if EXCEPT
+namespace ns {
+// Check that pragma float_control can appear in namespace.
+#pragma float_control(except, on, push)
+float exc_on(double x, float zero) {
+// CHECK-NS: define {{.*}}exc_on{{.*}}
+ {} try {
+ x = 1.0 / zero; /* division by zero, the result unused */
+//CHECK-NS: llvm.experimental.constrained.fdiv{{.*}}
+ } catch (...) {}
+ return zero;
+}
+}
+
+// Check pragma is still effective after namespace closes
+float exc_still_on(double x, float zero) {
+// CHECK-NS: define {{.*}}exc_still_on{{.*}}
+ {} try {
+ x = 1.0 / zero; /* division by zero, the result unused */
+//CHECK-NS: llvm.experimental.constrained.fdiv{{.*}}
+ } catch (...) {}
+ return zero;
+}
+
+#pragma float_control(pop)
+float exc_off(double x, float zero) {
+// CHECK-NS: define {{.*}}exc_off{{.*}}
+ {} try {
+ x = 1.0 / zero; /* division by zero, the result unused */
+//CHECK-NS: fdiv contract double
+ } catch (...) {}
+ return zero;
+}
+
+namespace fc_template_namespace {
+#pragma float_control(except, on, push)
+template <class T>
+T exc_on(double x, T zero) {
+// CHECK-NS: define {{.*}}fc_template_namespace{{.*}}
+ {} try {
+ x = 1.0 / zero; /* division by zero, the result unused */
+//CHECK-NS: llvm.experimental.constrained.fdiv{{.*}}
+ } catch (...) {}
+ return zero;
+}
+}
+
+#pragma float_control(pop)
+float xx(double x, float z) {
+ return fc_template_namespace::exc_on<float>(x, z);
+}
+#endif // EXCEPT
diff --git a/clang/test/Parser/fp-floatcontrol-syntax.cpp b/clang/test/Parser/fp-floatcontrol-syntax.cpp
index 4bdc34dd5ee0..0593c2a0385e 100644
--- a/clang/test/Parser/fp-floatcontrol-syntax.cpp
+++ b/clang/test/Parser/fp-floatcontrol-syntax.cpp
@@ -10,10 +10,10 @@ float function_scope(float a) {
#pragma float_control(pop)
#pragma float_control(precise, on, push)
void check_stack() {
-#pragma float_control(push) // expected-error {{can only appear at file scope}}
-#pragma float_control(pop) // expected-error {{can only appear at file scope}}
-#pragma float_control(precise, on, push) // expected-error {{can only appear at file scope}}
-#pragma float_control(except, on, push) // expected-error {{can only appear at file scope}}
+#pragma float_control(push) // expected-error {{can only appear at file scope or namespace scope}}
+#pragma float_control(pop) // expected-error {{can only appear at file scope or namespace scope}}
+#pragma float_control(precise, on, push) // expected-error {{can only appear at file scope or namespace scope}}
+#pragma float_control(except, on, push) // expected-error {{can only appear at file scope or namespace scope}}
#pragma float_control(except, on, push, junk) // expected-error {{float_control is malformed}}
return;
}
More information about the cfe-commits
mailing list