From 9ef137c5af216550775914c4fcdd184e7957db47 Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Wed, 2 May 2018 17:39:00 +0000 Subject: [PATCH] [OPENMP] Do not emit warning for implicitly declared target functions. Since upcoming OpenMP 5.0 functions can be mapped implicitly as declare target and we should not emit warnings for such functions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@331377 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaOpenMP.cpp | 30 +++++++++++++------------ test/OpenMP/declare_target_messages.cpp | 4 ++-- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index 896954fcf0..832f03b939 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -12964,21 +12964,23 @@ static void checkDeclInTargetContext(SourceLocation SL, SourceRange SR, if (LD && !LD->hasAttr() && ((isa(LD) && !isa(LD)) || isa(LD))) { // Outlined declaration is not declared target. - if (LD->isOutOfLine()) { - SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); - SemaRef.Diag(SL, diag::note_used_here) << SR; - } else { - const DeclContext *DC = LD->getDeclContext(); - while (DC && - (!isa(DC) || - !cast(DC)->hasAttr())) - DC = DC->getParent(); - if (DC) - return; + if (!isa(LD)) { + if (LD->isOutOfLine()) { + SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); + SemaRef.Diag(SL, diag::note_used_here) << SR; + } else { + const DeclContext *DC = LD->getDeclContext(); + while (DC && + (!isa(DC) || + !cast(DC)->hasAttr())) + DC = DC->getParent(); + if (DC) + return; - // Is not declared in target context. - SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); - SemaRef.Diag(SL, diag::note_used_here) << SR; + // Is not declared in target context. + SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); + SemaRef.Diag(SL, diag::note_used_here) << SR; + } } // Mark decl as declared target to prevent further diagnostic. auto *A = OMPDeclareTargetDeclAttr::CreateImplicit( diff --git a/test/OpenMP/declare_target_messages.cpp b/test/OpenMP/declare_target_messages.cpp index 72ea33cfc8..c8e73f6efb 100644 --- a/test/OpenMP/declare_target_messages.cpp +++ b/test/OpenMP/declare_target_messages.cpp @@ -19,7 +19,7 @@ void f(); #pragma omp declare target link(foo2) // expected-error {{use of undeclared identifier 'foo2'}} -void c(); // expected-warning {{declaration is not declared in any declare target region}} +void c(); void func() {} // expected-note {{'func' defined here}} @@ -98,7 +98,7 @@ void foo(int p) { g += object.method1(); g += object1.method() + p; f(); - c(); // expected-note {{used here}} + c(); } #pragma omp declare target // expected-error {{expected '#pragma omp end declare target'}} void foo1() {} -- 2.40.0