Author: erichkeane
Date: 2024-12-13T08:11:28-08:00
New Revision: 331f3cc94b3c66eebf5ec462a8f1ee0d7704dd26

URL: 
https://github.com/llvm/llvm-project/commit/331f3cc94b3c66eebf5ec462a8f1ee0d7704dd26
DIFF: 
https://github.com/llvm/llvm-project/commit/331f3cc94b3c66eebf5ec462a8f1ee0d7704dd26.diff

LOG: [OpenACC] enable 'present' clause for 'data' construct

No additional sema is required once again, so this patch adds testing
and enables the clause.

Added: 
    clang/test/SemaOpenACC/data-construct-present-ast.cpp
    clang/test/SemaOpenACC/data-construct-present-clause.c

Modified: 
    clang/lib/Sema/SemaOpenACC.cpp
    clang/test/AST/ast-print-openacc-data-construct.cpp
    clang/test/SemaOpenACC/data-construct-no_create-ast.cpp
    clang/test/SemaOpenACC/data-construct.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index 6906fd00822fcb..dd52d509fd5729 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -926,11 +926,13 @@ OpenACCClause 
*SemaOpenACCClauseVisitor::VisitNoCreateClause(
 
 OpenACCClause *SemaOpenACCClauseVisitor::VisitPresentClause(
     SemaOpenACC::OpenACCParsedClause &Clause) {
-  // Restrictions only properly implemented on 'compute'/'combined constructs,
-  // and 'compute'/'combined' constructs are the only construct that can do
-  // anything with this yet, so skip/treat as unimplemented in this case.
+  // Restrictions only properly implemented on 'compute'/'combined'/'data'
+  // constructs, and 'compute'/'combined'/'data' constructs are the only
+  // construct that can do anything with this yet, so skip/treat as
+  // unimplemented in this case.
   if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()) &&
-      !isOpenACCCombinedDirectiveKind(Clause.getDirectiveKind()))
+      !isOpenACCCombinedDirectiveKind(Clause.getDirectiveKind()) &&
+      !isOpenACCDataDirectiveKind(Clause.getDirectiveKind()))
     return isNotImplemented();
   // ActOnVar ensured that everything is a valid variable reference, so there
   // really isn't anything to do here. GCC does some duplicate-finding, though

diff  --git a/clang/test/AST/ast-print-openacc-data-construct.cpp 
b/clang/test/AST/ast-print-openacc-data-construct.cpp
index 65ab0158b4852d..c93b22e92f6252 100644
--- a/clang/test/AST/ast-print-openacc-data-construct.cpp
+++ b/clang/test/AST/ast-print-openacc-data-construct.cpp
@@ -82,10 +82,12 @@ void foo() {
 #pragma acc data default(none) no_create(i, array[1], array, array[1:2])
   ;
 
-// CHECK: #pragma acc data default(none) no_create(i, array[1], array, 
array[1:2])
-// CHECK-NOT: present(i, array[1], array, array[1:2])
+// CHECK: #pragma acc data default(none) no_create(i, array[1], array, 
array[1:2]) present(i, array[1], array, array[1:2])
 #pragma acc data default(none) no_create(i, array[1], array, array[1:2]) 
present(i, array[1], array, array[1:2])
   ;
+// CHECK: #pragma acc data present(i, array[1], array, array[1:2])
+#pragma acc data present(i, array[1], array, array[1:2])
+  ;
 
 // CHECK: #pragma acc data default(none) copy(i, array[1], array, array[1:2]) 
pcopy(i, array[1], array, array[1:2]) present_or_copy(i, array[1], array, 
array[1:2])
 #pragma acc data default(none) copy(i, array[1], array, array[1:2]) pcopy(i, 
array[1], array, array[1:2]) present_or_copy(i, array[1], array, array[1:2])

diff  --git a/clang/test/SemaOpenACC/data-construct-no_create-ast.cpp 
b/clang/test/SemaOpenACC/data-construct-no_create-ast.cpp
index 6ff521eb4be07e..9a0465d455942b 100644
--- a/clang/test/SemaOpenACC/data-construct-no_create-ast.cpp
+++ b/clang/test/SemaOpenACC/data-construct-no_create-ast.cpp
@@ -44,9 +44,9 @@ void TemplUses(T t, U u) {
   // CHECK-NEXT: OpenACCDataConstruct{{.*}} data
   // CHECK-NEXT: no_create clause
   // CHECK-NEXT: DeclRefExpr{{.*}}'T' lvalue ParmVar{{.*}} 't' 'T'
-  // TODO_CHECK-NEXT: present clause
-  // TODO_CHECK-NEXT: DeclRefExpr{{.*}}'auto' lvalue NonTypeTemplateParm{{.*}} 
'NTTP' 'auto &'
-  // TODO_CHECK-NEXT: DeclRefExpr{{.*}}'U' lvalue ParmVar{{.*}} 'u' 'U'
+  // CHECK-NEXT: present clause
+  // CHECK-NEXT: DeclRefExpr{{.*}}'auto' lvalue NonTypeTemplateParm{{.*}} 
'NTTP' 'auto &'
+  // CHECK-NEXT: DeclRefExpr{{.*}}'U' lvalue ParmVar{{.*}} 'u' 'U'
   // CHECK-NEXT: NullStmt
 
   // Check the instantiated versions of the above.
@@ -66,11 +66,11 @@ void TemplUses(T t, U u) {
   // CHECK-NEXT: OpenACCDataConstruct{{.*}} data
   // CHECK-NEXT: no_create clause
   // CHECK-NEXT: DeclRefExpr{{.*}}'int' lvalue ParmVar{{.*}} 't' 'int'
-  // TODO_CHECK-NEXT: present clause
-  // TODO_CHECK-NEXT: SubstNonTypeTemplateParmExpr{{.*}}'const unsigned int' 
lvalue
-  // TODO_CHECK-NEXT: NonTypeTemplateParmDecl{{.*}} referenced 'auto &' depth 
0 index 0 NTTP
-  // TODO_CHECK-NEXT: DeclRefExpr{{.*}}'const unsigned int' lvalue Var{{.*}} 
'CEVar' 'const unsigned int'
-  // TODO_CHECK-NEXT: DeclRefExpr{{.*}}'int *' lvalue ParmVar{{.*}} 'u' 'int *'
+  // CHECK-NEXT: present clause
+  // CHECK-NEXT: SubstNonTypeTemplateParmExpr{{.*}}'const unsigned int' lvalue
+  // CHECK-NEXT: NonTypeTemplateParmDecl{{.*}} referenced 'auto &' depth 0 
index 0 NTTP
+  // CHECK-NEXT: DeclRefExpr{{.*}}'const unsigned int' lvalue Var{{.*}} 
'CEVar' 'const unsigned int'
+  // CHECK-NEXT: DeclRefExpr{{.*}}'int *' lvalue ParmVar{{.*}} 'u' 'int *'
   // CHECK-NEXT: NullStmt
 }
 

diff  --git a/clang/test/SemaOpenACC/data-construct-present-ast.cpp 
b/clang/test/SemaOpenACC/data-construct-present-ast.cpp
new file mode 100644
index 00000000000000..2a2d81f3f24832
--- /dev/null
+++ b/clang/test/SemaOpenACC/data-construct-present-ast.cpp
@@ -0,0 +1,79 @@
+// RUN: %clang_cc1 %s -fopenacc -ast-dump | FileCheck %s
+
+// Test this with PCH.
+// RUN: %clang_cc1 %s -fopenacc -emit-pch -o %t %s
+// RUN: %clang_cc1 %s -fopenacc -include-pch %t -ast-dump-all | FileCheck %s
+
+#ifndef PCH_HELPER
+#define PCH_HELPER
+
+int Global;
+short GlobalArray[5];
+
+void NormalUses(float *PointerParam) {
+  // CHECK: FunctionDecl{{.*}}NormalUses
+  // CHECK: ParmVarDecl
+  // CHECK-NEXT: CompoundStmt
+
+#pragma acc data default(none) present(GlobalArray, PointerParam[Global])
+  for(int i = 0; i < 5; ++i);
+  // CHECK-NEXT: OpenACCDataConstruct{{.*}} data
+  // CHECK-NEXT: default(none)
+  // CHECK-NEXT: present clause
+  // CHECK-NEXT: DeclRefExpr{{.*}}'short[5]' lvalue Var{{.*}}'GlobalArray' 
'short[5]'
+  // CHECK-NEXT: ArraySubscriptExpr{{.*}}'float' lvalue
+  // CHECK-NEXT: ImplicitCastExpr{{.*}} 'float *' <LValueToRValue>
+  // CHECK-NEXT: DeclRefExpr{{.*}}'float *' lvalue ParmVar{{.*}}'PointerParam' 
'float *'
+  // CHECK-NEXT: ImplicitCastExpr{{.*}} 'int' <LValueToRValue>
+  // CHECK-NEXT: DeclRefExpr{{.*}}'int' lvalue Var{{.*}}'Global' 'int'
+  // CHECK-NEXT: ForStmt
+  // CHECK: NullStmt
+}
+
+template<auto &NTTP, typename T>
+void TemplUses(T t) {
+  // CHECK-NEXT: FunctionTemplateDecl
+  // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}referenced 'auto &' depth 0 
index 0 NTTP
+  // CHECK-NEXT: TemplateTypeParmDecl{{.*}}typename depth 0 index 1 T
+  // CHECK-NEXT: FunctionDecl{{.*}} TemplUses 'void (T)'
+  // CHECK-NEXT: ParmVarDecl{{.*}} referenced t 'T'
+  // CHECK-NEXT: CompoundStmt
+
+#pragma acc data default(none) present(NTTP, t)
+  for(int i = 0; i < 5; ++i);
+  // CHECK-NEXT: OpenACCDataConstruct{{.*}} data
+  // CHECK-NEXT: default(none)
+  // CHECK-NEXT: present clause
+  // CHECK-NEXT: DeclRefExpr{{.*}}'auto' lvalue NonTypeTemplateParm{{.*}} 
'NTTP' 'auto &'
+  // CHECK-NEXT: DeclRefExpr{{.*}}'T' lvalue ParmVar{{.*}} 't' 'T'
+  // CHECK-NEXT: ForStmt
+  // CHECK: NullStmt
+
+
+  // Check the instantiated versions of the above.
+  // CHECK-NEXT: FunctionDecl{{.*}} used TemplUses 'void (int)' 
implicit_instantiation
+  // CHECK-NEXT: TemplateArgument decl
+  // CHECK-NEXT: Var{{.*}} 'CEVar' 'const unsigned int'
+  // CHECK-NEXT: TemplateArgument type 'int'
+  // CHECK-NEXT: BuiltinType{{.*}} 'int'
+  // CHECK-NEXT: ParmVarDecl{{.*}} used t 'int'
+  // CHECK-NEXT: CompoundStmt
+
+// #pragma acc parallel seq present(NTTP, t)
+  // CHECK-NEXT: OpenACCDataConstruct{{.*}} data
+  // CHECK-NEXT: default(none)
+  // CHECK-NEXT: present clause
+  // CHECK-NEXT: SubstNonTypeTemplateParmExpr{{.*}}'const unsigned int' lvalue
+  // CHECK-NEXT: NonTypeTemplateParmDecl{{.*}} referenced 'auto &' depth 0 
index 0 NTTP
+  // CHECK-NEXT: DeclRefExpr{{.*}}'const unsigned int' lvalue Var{{.*}} 
'CEVar' 'const unsigned int'
+  // CHECK-NEXT: DeclRefExpr{{.*}}'int' lvalue ParmVar{{.*}} 't' 'int'
+  // CHECK-NEXT: ForStmt
+  // CHECK: NullStmt
+
+}
+
+void Inst() {
+  static constexpr unsigned CEVar = 1;
+  TemplUses<CEVar>(5);
+}
+#endif

diff  --git a/clang/test/SemaOpenACC/data-construct-present-clause.c 
b/clang/test/SemaOpenACC/data-construct-present-clause.c
new file mode 100644
index 00000000000000..3128f532faf3f0
--- /dev/null
+++ b/clang/test/SemaOpenACC/data-construct-present-clause.c
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 %s -fopenacc -verify
+
+typedef struct IsComplete {
+  struct S { int A; } CompositeMember;
+  int ScalarMember;
+  float ArrayMember[5];
+  void *PointerMember;
+} Complete;
+void uses(int IntParam, short *PointerParam, float ArrayParam[5], Complete 
CompositeParam) {
+  int LocalInt;
+  short *LocalPointer;
+  float LocalArray[5];
+  Complete LocalComposite;
+  // Check Appertainment:
+#pragma acc data default(none) present(LocalInt)
+  ;
+
+  // Valid cases:
+#pragma acc data default(none) present(LocalInt, LocalPointer, LocalArray)
+  ;
+#pragma acc data default(none) present(LocalArray[2:1])
+  ;
+
+#pragma acc data default(none) present(LocalComposite.ScalarMember, 
LocalComposite.ScalarMember)
+  ;
+
+  // expected-error@+1{{OpenACC variable is not a valid variable name, 
sub-array, array element, member of a composite variable, or composite variable 
member}}
+#pragma acc data default(none) present(1 + IntParam)
+  ;
+
+  // expected-error@+1{{OpenACC variable is not a valid variable name, 
sub-array, array element, member of a composite variable, or composite variable 
member}}
+#pragma acc data default(none) present(+IntParam)
+  ;
+
+  // expected-error@+1{{OpenACC sub-array length is unspecified and cannot be 
inferred because the subscripted value is not an array}}
+#pragma acc data default(none) present(PointerParam[2:])
+  ;
+
+  // expected-error@+1{{OpenACC sub-array specified range [2:5] would be out 
of the range of the subscripted array size of 5}}
+#pragma acc data default(none) present(ArrayParam[2:5])
+  ;
+
+  // expected-error@+2{{OpenACC sub-array specified range [2:5] would be out 
of the range of the subscripted array size of 5}}
+  // expected-error@+1{{OpenACC variable is not a valid variable name, 
sub-array, array element, member of a composite variable, or composite variable 
member}}
+#pragma acc data default(none) present((float*)ArrayParam[2:5])
+  ;
+  // expected-error@+1{{OpenACC variable is not a valid variable name, 
sub-array, array element, member of a composite variable, or composite variable 
member}}
+#pragma acc data default(none) present((float)ArrayParam[2])
+  ;
+
+  // expected-error@+1{{OpenACC 'present' clause is not valid on 'enter data' 
directive}}
+#pragma acc enter data copyin(LocalInt) present(LocalInt)
+  // expected-error@+1{{OpenACC 'present' clause is not valid on 'exit data' 
directive}}
+#pragma acc exit data copyout(LocalInt) present(LocalInt)
+  // expected-warning@+2{{OpenACC clause 'use_device' not yet implemented}}
+  // expected-error@+1{{OpenACC 'present' clause is not valid on 'host_data' 
directive}}
+#pragma acc host_data use_device(LocalInt) present(LocalInt)
+  ;
+}

diff  --git a/clang/test/SemaOpenACC/data-construct.cpp 
b/clang/test/SemaOpenACC/data-construct.cpp
index 01ccaeba81b488..79c65d06d0052f 100644
--- a/clang/test/SemaOpenACC/data-construct.cpp
+++ b/clang/test/SemaOpenACC/data-construct.cpp
@@ -31,7 +31,6 @@ void AtLeastOneOf() {
   ;
 #pragma acc data no_create(Var)
   ;
-  // expected-warning@+1{{OpenACC clause 'present' not yet implemented}}
 #pragma acc data present(Var)
   ;
   // expected-warning@+1{{OpenACC clause 'deviceptr' not yet implemented}}


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to