From: Mike Rice Date: Wed, 12 Jan 2022 23:34:37 +0000 (-0800) Subject: [OpenMP] Fix problems with the declare variant append_args clause X-Git-Tag: upstream/15.0.7~20413 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3d5b9fb3e3cd60d3bb755e43c1abdea42d2e7580;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 20b090f..ae91a64 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -7052,7 +7052,8 @@ Sema::checkOpenMPDeclareVariantFunction(Sema::DeclGroupPtrTy DG, QualType AdjustedFnType = FD->getType(); if (NumAppendArgs) { - if (isa(FD->getType())) { + const auto *PTy = AdjustedFnType->getAsAdjusted(); + 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(FD->getType()); + QualType InteropType = Context.getTypeDeclType(TD); if (PTy->isVariadic()) { Diag(FD->getLocation(), diag::err_omp_append_args_with_varargs) << SR; return None; diff --git a/clang/test/OpenMP/declare_variant_clauses_ast_print.c b/clang/test/OpenMP/declare_variant_clauses_ast_print.c new file mode 100644 index 0000000..6bebac9 --- /dev/null +++ b/clang/test/OpenMP/declare_variant_clauses_ast_print.c @@ -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); diff --git a/clang/test/OpenMP/declare_variant_clauses_messages.cpp b/clang/test/OpenMP/declare_variant_clauses_messages.cpp index 058b5d7..5f63fa5 100644 --- a/clang/test/OpenMP/declare_variant_clauses_messages.cpp +++ b/clang/test/OpenMP/declare_variant_clauses_messages.cpp @@ -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