[OpenMP] Fix problems with the declare variant append_args clause

Use ASTContext::getTypeDeclType() to get type of omp_interop_t since
TypeDecl::getTypeForDecl() may return null if TypeForDecl is not
setup yet.

Handle functions where the function type is under an AttributedType.

Differential Revision: https://reviews.llvm.org/D117172
This commit is contained in:
Mike Rice 2022-01-12 15:34:37 -08:00
parent e43b2e4f48
commit 3d5b9fb3e3
3 changed files with 64 additions and 4 deletions

View File

@ -7052,7 +7052,8 @@ Sema::checkOpenMPDeclareVariantFunction(Sema::DeclGroupPtrTy DG,
QualType AdjustedFnType = FD->getType();
if (NumAppendArgs) {
if (isa<FunctionNoProtoType>(FD->getType())) {
const auto *PTy = AdjustedFnType->getAsAdjusted<FunctionProtoType>();
if (!PTy) {
Diag(FD->getLocation(), diag::err_omp_declare_variant_prototype_required)
<< SR;
return None;
@ -7070,8 +7071,7 @@ Sema::checkOpenMPDeclareVariantFunction(Sema::DeclGroupPtrTy DG,
Diag(SR.getBegin(), diag::err_omp_interop_type_not_found) << SR;
return None;
}
QualType InteropType = QualType(TD->getTypeForDecl(), 0);
auto *PTy = cast<FunctionProtoType>(FD->getType());
QualType InteropType = Context.getTypeDeclType(TD);
if (PTy->isVariadic()) {
Diag(FD->getLocation(), diag::err_omp_append_args_with_varargs) << SR;
return None;

View File

@ -0,0 +1,51 @@
//RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
//RUN: -Wno-source-uses-openmp -Wno-openmp-clauses \
//RUN: -ast-print -o - %s | FileCheck %s --check-prefix=PRINT
//RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -fopenmp -fopenmp-version=51 \
//RUN: -Wno-source-uses-openmp -Wno-openmp-clauses -DWIN -fms-compatibility \
//RUN: -ast-print -o - %s | FileCheck %s --check-prefixes=PRINT,PRINTW
//RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 \
//RUN: -Wno-source-uses-openmp -Wno-openmp-clauses \
//RUN: -ast-dump -o - %s | FileCheck %s --check-prefix=DUMP
//RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -fopenmp -fopenmp-version=51 \
//RUN: -Wno-source-uses-openmp -Wno-openmp-clauses -DWIN -fms-compatibility \
//RUN: -ast-dump -o - %s | FileCheck %s --check-prefixes=DUMP,DUMPW
typedef void *omp_interop_t;
#ifdef WIN
//DUMPW: FunctionDecl{{.*}}win_foov
//PRINTW: void win_foov(int n, double *y, void *interop_obj);
void win_foov(int n, double *y, void *interop_obj);
//DUMPW: FunctionDecl{{.*}}win_foo
//DUMPW: OMPDeclareVariantAttr
//DUMPW-NEXT: DeclRefExpr{{.*}}win_foov
//PRINTW: #pragma omp declare variant(win_foov) match(construct={dispatch}, device={arch(x86_64)}) append_args(interop(targetsync))
//PRINTW: void win_foo(int n, double *y);
#pragma omp declare variant (win_foov) \
match(construct={dispatch}, device={arch(x86_64)}) \
append_args(interop(targetsync))
void _cdecl win_foo(int n, double *y);
#endif // WIN
//DUMP: FunctionDecl{{.*}}c_foov
//PRINT: void c_foov(int n, double *y, void *interop_obj);
void c_foov(int n, double *y, void *interop_obj);
//DUMP: FunctionDecl{{.*}}c_foo
//DUMP: OMPDeclareVariantAttr
//DUMP-NEXT: DeclRefExpr{{.*}}c_foov
//PRINT: #pragma omp declare variant(c_foov) match(construct={dispatch}, device={arch(x86_64)}) append_args(interop(targetsync))
//PRINT: void c_foo(int n, double *y);
#pragma omp declare variant (c_foov) \
match(construct={dispatch}, device={arch(x86_64)}) \
append_args(interop(targetsync))
void c_foo(int n, double *y);

View File

@ -3,6 +3,8 @@
// RUN: -DNO_INTEROP_T_DEF -o - %s
// RUN: %clang_cc1 -verify -triple x86_64-unknown-linux -fopenmp -fopenmp-version=50 -std=c++11 -o - %s
// RUN: %clang_cc1 -verify -triple x86_64-unknown-linux -fopenmp -fopenmp-version=51 -DC -x c -o - %s
// RUN: %clang_cc1 -verify -triple x86_64-pc-windows-msvc -fms-compatibility \
// RUN: -fopenmp -fopenmp-version=51 -DC -DWIN -x c -o - %s
#ifdef NO_INTEROP_T_DEF
void foo_v1(float *, void *);
@ -201,7 +203,14 @@ void foo(float *AAA, float *BBB, int *I) { return; }
#ifdef C
void c_variant(omp_interop_t);
// expected-error@+3 {{function with '#pragma omp declare variant' must have a prototype when 'append_args' is used}}
#pragma omp declare variant(foo_v1) \
#pragma omp declare variant(c_variant) \
append_args(interop(target)) match(construct={dispatch})
void c_base() {}
#ifdef WIN
void _cdecl win_c_variant(omp_interop_t);
// expected-error@+3 {{function with '#pragma omp declare variant' must have a prototype when 'append_args' is used}}
#pragma omp declare variant(win_c_variant) \
append_args(interop(target)) match(construct={dispatch})
void _cdecl win_c_base() {}
#endif // WIN
#endif