r356752 - [OPENMP]Emit error message for allocate directive without allocator

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 22 07:41:40 PDT 2019


Author: abataev
Date: Fri Mar 22 07:41:39 2019
New Revision: 356752

URL: http://llvm.org/viewvc/llvm-project?rev=356752&view=rev
Log:
[OPENMP]Emit error message for allocate directive without allocator
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.

Added:
    cfe/trunk/test/OpenMP/nvptx_allocate_messages.cpp
      - copied, changed from r356749, cfe/trunk/test/OpenMP/nvptx_allocate_codegen.cpp
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaOpenMP.cpp
    cfe/trunk/test/OpenMP/nvptx_allocate_codegen.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=356752&r1=356751&r2=356752&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Mar 22 07:41:39 2019
@@ -9152,6 +9152,9 @@ def warn_omp_used_different_allocator :
   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 {

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=356752&r1=356751&r2=356752&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Fri Mar 22 07:41:39 2019
@@ -2243,8 +2243,12 @@ Sema::DeclGroupPtrTy Sema::ActOnOpenMPAl
     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;

Modified: cfe/trunk/test/OpenMP/nvptx_allocate_codegen.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_allocate_codegen.cpp?rev=356752&r1=356751&r2=356752&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/nvptx_allocate_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/nvptx_allocate_codegen.cpp Fri Mar 22 07:41:39 2019
@@ -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>());
 }
 

Copied: cfe/trunk/test/OpenMP/nvptx_allocate_messages.cpp (from r356749, cfe/trunk/test/OpenMP/nvptx_allocate_codegen.cpp)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_allocate_messages.cpp?p2=cfe/trunk/test/OpenMP/nvptx_allocate_messages.cpp&p1=cfe/trunk/test/OpenMP/nvptx_allocate_codegen.cpp&r1=356749&r2=356752&rev=356752&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/nvptx_allocate_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/nvptx_allocate_messages.cpp Fri Mar 22 07:41:39 2019
@@ -1,10 +1,21 @@
 // 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 -fopenmp -triple nvptx64-nvidia-cuda -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -o - | FileCheck %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 at +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;
@@ -16,14 +27,6 @@ extern const omp_allocator_handle_t omp_
 extern const omp_allocator_handle_t omp_pteam_mem_alloc;
 extern const omp_allocator_handle_t omp_thread_mem_alloc;
 
-// CHECK-DAG: @{{.+}}St1{{.+}}b{{.+}} = external global i32,
-// CHECK-DAG: @a = global i32 0,
-// CHECK-DAG: @b = addrspace(4) global i32 0,
-// CHECK-DAG: @c = global i32 0,
-// CHECK-DAG: @d = global %struct.St1 zeroinitializer,
-// CHECK-DAG: @{{.+}}ns{{.+}}a{{.+}} = addrspace(3) global i32 0,
-// CHECK-DAG: @{{.+}}main{{.+}}a{{.*}} = internal global i32 0,
-// CHECK-DAG: @{{.+}}ST{{.+}}m{{.+}} = external global i32,
 struct St{
  int a;
 };
@@ -57,20 +60,21 @@ namespace ns{
 }
 #pragma omp allocate(ns::a) allocator(omp_pteam_mem_alloc)
 
-// CHECK-LABEL: @main
 int main () {
-  // CHECK: alloca double,
   static int a;
 #pragma omp allocate(a) allocator(omp_thread_mem_alloc)
   a=2;
   double b = 3;
+#ifdef DEVICE
+// expected-error at +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)
-  return (foo<int>());
+#ifdef DEVICE
+// expected-note at +2 {{called by 'main'}}
+#endif // DEVICE
+  return (foo<int>() + bar());
 }
 
-// CHECK: define {{.*}}i32 @{{.+}}foo{{.+}}()
-// CHECK: alloca i32,
-
 extern template int ST<int>::m;
 #pragma omp end declare target
 #endif




More information about the cfe-commits mailing list