From: Melanie Blower Date: Fri, 8 May 2020 15:05:34 +0000 (-0700) Subject: [PATCH] #pragma float_control should be permitted in namespace scope. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7f2db993500923a51c0b0aed650a3e0d4241205b;p=platform%2Fupstream%2Fllvm.git [PATCH] #pragma float_control should be permitted in namespace scope. Summary: Erroneous error diagnostic observed in VS2017 header Also correction to propagate usesFPIntrin from template func to instantiation. Reviewers: rjmccall, erichkeane (no feedback received) Differential Revision: https://reviews.llvm.org/D79631 --- diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 44a3408..371e201 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; 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 01f30a9..222aaf3 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 a6541da..3270222 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 773cfcd..a80a4d3 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 +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(x, z); +} +#endif // EXCEPT diff --git a/clang/test/Parser/fp-floatcontrol-syntax.cpp b/clang/test/Parser/fp-floatcontrol-syntax.cpp index 4bdc34d..0593c2a 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; }