Referencing a static function defined in an opnemp clause, is

generating an erroneous warning.

See here: https://godbolt.org/z/ajKPc36M7
This commit is contained in:
Zahira Ammarguellat 2021-06-02 07:59:07 -07:00
parent 7b444a66b3
commit 150f7cedfb
2 changed files with 47 additions and 2 deletions

View file

@ -812,8 +812,21 @@ static void checkUndefinedButUsed(Sema &S) {
// FIXME: We can promote this to an error. The function or variable can't
// be defined anywhere else, so the program must necessarily violate the
// one definition rule.
S.Diag(VD->getLocation(), diag::warn_undefined_internal)
<< isa<VarDecl>(VD) << VD;
bool IsImplicitBase = false;
if (const auto *BaseD = dyn_cast<FunctionDecl>(VD)) {
auto *DVAttr = BaseD->getAttr<OMPDeclareVariantAttr>();
if (DVAttr && !DVAttr->getTraitInfo().isExtensionActive(
llvm::omp::TraitProperty::
implementation_extension_disable_implicit_base)) {
const auto *Func = cast<FunctionDecl>(
cast<DeclRefExpr>(DVAttr->getVariantFuncRef())->getDecl());
IsImplicitBase = BaseD->isImplicit() &&
Func->getIdentifier()->isMangledOpenMPVariantName();
}
}
if (!S.getLangOpts().OpenMP || !IsImplicitBase)
S.Diag(VD->getLocation(), diag::warn_undefined_internal)
<< isa<VarDecl>(VD) << VD;
} else if (auto *FD = dyn_cast<FunctionDecl>(VD)) {
(void)FD;
assert(FD->getMostRecentDecl()->isInlined() &&

View file

@ -0,0 +1,32 @@
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify %s
namespace {
// TODO this must be fixed. This warning shouldn't be generated.
// expected-warning@+1{{function '(anonymous namespace)::bar' has internal linkage but is not defined}}
void bar();
} // namespace
#pragma omp begin declare variant match(user = {condition(1)})
void bar() {
}
#pragma omp end declare variant
// expected-warning@+1{{function 'baz' has internal linkage but is not defined}}
static void baz();
#pragma omp begin declare variant match(device = {kind(nohost)})
static void baz() {}
#pragma omp end declare variant
#pragma omp begin declare variant match(device = {kind(host)})
static void foo() {}
#pragma omp end declare variant
int main() {
foo();
// expected-note@+1{{used here}}
baz();
// expected-note@+1{{used here}}
bar();
return 0;
}