Index: clang/lib/Sema/SemaOpenMP.cpp =================================================================== --- clang/lib/Sema/SemaOpenMP.cpp +++ clang/lib/Sema/SemaOpenMP.cpp @@ -7052,26 +7052,26 @@ 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; } // Adjust the function type to account for an extra omp_interop_t for each // specified in the append_args clause. - const TypeDecl *TD = nullptr; + const TypedefNameDecl *TD = nullptr; LookupResult Result(*this, &Context.Idents.get("omp_interop_t"), SR.getBegin(), Sema::LookupOrdinaryName); if (LookupName(Result, getCurScope())) { NamedDecl *ND = Result.getFoundDecl(); - TD = dyn_cast_or_null(ND); + TD = dyn_cast_or_null(ND); } if (!TD) { 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.getTypedefType(TD); if (PTy->isVariadic()) { Diag(FD->getLocation(), diag::err_omp_append_args_with_varargs) << SR; return None; Index: clang/test/OpenMP/declare_variant_clauses_ast_print.c =================================================================== --- /dev/null +++ clang/test/OpenMP/declare_variant_clauses_ast_print.c @@ -0,0 +1,48 @@ +//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); Index: clang/test/OpenMP/declare_variant_clauses_messages.cpp =================================================================== --- clang/test/OpenMP/declare_variant_clauses_messages.cpp +++ 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 @@ #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