]> granicus.if.org Git - clang/commitdiff
[OPENMP]Emit error message for allocate directive without allocator
authorAlexey Bataev <a.bataev@hotmail.com>
Fri, 22 Mar 2019 14:41:39 +0000 (14:41 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Fri, 22 Mar 2019 14:41:39 +0000 (14:41 +0000)
clause in target region.

According to the OpenMP 5.0, 2.11.3 allocate Directive, Restrictions,
allocate directives that appear in a target region must specify an
allocator clause unless a requires directive with the dynamic_allocators
clause is present in the same compilation unit.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356752 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaOpenMP.cpp
test/OpenMP/nvptx_allocate_codegen.cpp
test/OpenMP/nvptx_allocate_messages.cpp [new file with mode: 0644]

index 8b5ce4277133b83e4f4c83d0c38f6bb4b1c125bb..a8776d9b433470d946e0a1d3c39c0ab7b45ce817 100644 (file)
@@ -9152,6 +9152,9 @@ def warn_omp_used_different_allocator : Warning<
   InGroup<OpenMPClauses>;
 def note_omp_previous_allocator : Note<
   "previous allocator is specified here">;
+def err_expected_allocator_clause : Error<"expected an 'allocator' clause "
+  "inside of the target region; provide an 'allocator' clause or use 'requires'"
+  " directive with the 'dynamic_allocators' clause">;
 } // end of OpenMP category
 
 let CategoryName = "Related Result Type Issue" in {
index e54652650ede6f59539b28d72bf07d73e062b1a9..9232ab9d6e81501c94bb13c62041c0c52de929c4 100644 (file)
@@ -2243,8 +2243,12 @@ Sema::DeclGroupPtrTy Sema::ActOnOpenMPAllocateDirective(
     ArrayRef<OMPClause *> Clauses, DeclContext *Owner) {
   assert(Clauses.size() <= 1 && "Expected at most one clause.");
   Expr *Allocator = nullptr;
-  if (!Clauses.empty())
+  if (Clauses.empty()) {
+    if (LangOpts.OpenMPIsDevice)
+      targetDiag(Loc, diag::err_expected_allocator_clause);
+  } else {
     Allocator = cast<OMPAllocatorClause>(Clauses.back())->getAllocator();
+  }
   OMPAllocateDeclAttr::AllocatorTypeTy AllocatorKind =
       getAllocatorKind(*this, DSAStack, Allocator);
   SmallVector<Expr *, 8> Vars;
index df6a727c7acffd69cd01d3f2a53a3da2bd26dfea..ec1faff42659d41632b1bf0890f59e2f5fce67cc 100644 (file)
@@ -64,7 +64,7 @@ int main () {
 #pragma omp allocate(a) allocator(omp_thread_mem_alloc)
   a=2;
   double b = 3;
-#pragma omp allocate(b)
+#pragma omp allocate(b) allocator(omp_default_mem_alloc)
   return (foo<int>());
 }
 
diff --git a/test/OpenMP/nvptx_allocate_messages.cpp b/test/OpenMP/nvptx_allocate_messages.cpp
new file mode 100644 (file)
index 0000000..99aef43
--- /dev/null
@@ -0,0 +1,80 @@
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-apple-darwin10.6.0 -fopenmp-targets=nvptx64-nvidia-cuda  -emit-llvm-bc -o %t-host.bc %s
+// RUN: %clang_cc1 -verify -DDEVICE -fopenmp -triple nvptx64-nvidia-cuda -fopenmp-targets=nvptx64-nvidia-cuda -fsyntax-only %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc
+#ifndef DEVICE
+// expected-no-diagnostics
+#endif // DEVICE
+
+#ifndef HEADER
+#define HEADER
+
+int bar() {
+  int res = 0;
+#ifdef DEVICE
+// expected-error@+2 {{expected an 'allocator' clause inside of the target region; provide an 'allocator' clause or use 'requires' directive with the 'dynamic_allocators' clause}}
+#endif // DEVICE
+#pragma omp allocate(res)
+  return 0;
+}
+
+#pragma omp declare target
+typedef void **omp_allocator_handle_t;
+extern const omp_allocator_handle_t omp_default_mem_alloc;
+extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
+extern const omp_allocator_handle_t omp_const_mem_alloc;
+extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
+extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
+extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
+extern const omp_allocator_handle_t omp_pteam_mem_alloc;
+extern const omp_allocator_handle_t omp_thread_mem_alloc;
+
+struct St{
+ int a;
+};
+
+struct St1{
+ int a;
+ static int b;
+#pragma omp allocate(b) allocator(omp_default_mem_alloc)
+} d;
+
+int a, b, c;
+#pragma omp allocate(a) allocator(omp_large_cap_mem_alloc)
+#pragma omp allocate(b) allocator(omp_const_mem_alloc)
+#pragma omp allocate(d, c) allocator(omp_high_bw_mem_alloc)
+
+template <class T>
+struct ST {
+  static T m;
+  #pragma omp allocate(m) allocator(omp_low_lat_mem_alloc)
+};
+
+template <class T> T foo() {
+  T v;
+  #pragma omp allocate(v) allocator(omp_cgroup_mem_alloc)
+  v = ST<T>::m;
+  return v;
+}
+
+namespace ns{
+  int a;
+}
+#pragma omp allocate(ns::a) allocator(omp_pteam_mem_alloc)
+
+int main () {
+  static int a;
+#pragma omp allocate(a) allocator(omp_thread_mem_alloc)
+  a=2;
+  double b = 3;
+#ifdef DEVICE
+// expected-error@+2 {{expected an 'allocator' clause inside of the target region; provide an 'allocator' clause or use 'requires' directive with the 'dynamic_allocators' clause}}
+#endif // DEVICE
+#pragma omp allocate(b)
+#ifdef DEVICE
+// expected-note@+2 {{called by 'main'}}
+#endif // DEVICE
+  return (foo<int>() + bar());
+}
+
+extern template int ST<int>::m;
+#pragma omp end declare target
+#endif