[clang] 3d5b9fb - [OpenMP] Fix problems with the declare variant append_args clause
Mike Rice via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 14 11:15:08 PST 2022
Author: Mike Rice
Date: 2022-01-14T11:09:27-08:00
New Revision: 3d5b9fb3e3cd60d3bb755e43c1abdea42d2e7580
URL: https://github.com/llvm/llvm-project/commit/3d5b9fb3e3cd60d3bb755e43c1abdea42d2e7580
DIFF: https://github.com/llvm/llvm-project/commit/3d5b9fb3e3cd60d3bb755e43c1abdea42d2e7580.diff
LOG: [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
Added:
clang/test/OpenMP/declare_variant_clauses_ast_print.c
Modified:
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/declare_variant_clauses_messages.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 20b090faaf4c..ae91a6470471 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<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;
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 000000000000..6bebac90973b
--- /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 058b5d7675e6..5f63fa5eeb6d 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 at +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 at +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
More information about the cfe-commits
mailing list