Author: erichkeane
Date: 2024-12-13T06:23:05-08:00
New Revision: 7a3504a133437525f3e56f5811e313e4695f932f

URL: 
https://github.com/llvm/llvm-project/commit/7a3504a133437525f3e56f5811e313e4695f932f
DIFF: 
https://github.com/llvm/llvm-project/commit/7a3504a133437525f3e56f5811e313e4695f932f.diff

LOG: [OpenACC] Enable 'copy' clause sema for data clause

'copy' is another that is identical in behavior on 'data' as far as
semantic analysis is concerned as the compute constructs, so this patch
adds tests and enables 'copy'.

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

Modified: 
    clang/lib/Sema/SemaOpenACC.cpp
    clang/test/SemaOpenACC/data-construct.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index 99daa3eba6287a..84d2e2a7f5065a 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -949,11 +949,13 @@ OpenACCClause 
*SemaOpenACCClauseVisitor::VisitPresentClause(
 
 OpenACCClause *SemaOpenACCClauseVisitor::VisitCopyClause(
     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/SemaOpenACC/data-construct-copy-ast.cpp 
b/clang/test/SemaOpenACC/data-construct-copy-ast.cpp
new file mode 100644
index 00000000000000..de067f00a2b29b
--- /dev/null
+++ b/clang/test/SemaOpenACC/data-construct-copy-ast.cpp
@@ -0,0 +1,93 @@
+// RUN: %clang_cc1 %s -fopenacc -Wno-openacc-deprecated-clause-alias -ast-dump 
| FileCheck %s
+
+// Test this with PCH.
+// RUN: %clang_cc1 %s -fopenacc -Wno-openacc-deprecated-clause-alias -emit-pch 
-o %t %s
+// RUN: %clang_cc1 %s -fopenacc -Wno-openacc-deprecated-clause-alias 
-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 copy(GlobalArray) pcopy(PointerParam[Global]) 
present_or_copy(Global)
+  ;
+  // CHECK-NEXT: OpenACCDataConstruct{{.*}} data
+  // CHECK-NEXT: copy clause
+  // CHECK-NEXT: DeclRefExpr{{.*}}'short[5]' lvalue Var{{.*}}'GlobalArray' 
'short[5]'
+  // CHECK-NEXT: pcopy clause
+  // 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: present_or_copy clause
+  // CHECK-NEXT: DeclRefExpr{{.*}}'int' lvalue Var{{.*}}'Global' 'int'
+  // CHECK-NEXT: NullStmt
+}
+template<auto &NTTP, typename T, typename U>
+void TemplUses(T t, U u) {
+  // CHECK-NEXT: FunctionTemplateDecl
+  // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}referenced 'auto &' depth 0 
index 0 NTTP
+  // CHECK-NEXT: TemplateTypeParmDecl{{.*}}typename depth 0 index 1 T
+  // CHECK-NEXT: TemplateTypeParmDecl{{.*}}typename depth 0 index 2 U
+  // CHECK-NEXT: FunctionDecl{{.*}} TemplUses 'void (T, U)'
+  // CHECK-NEXT: ParmVarDecl{{.*}} referenced t 'T'
+  // CHECK-NEXT: ParmVarDecl{{.*}} referenced u 'U'
+  // CHECK-NEXT: CompoundStmt
+
+#pragma acc data copy(t) pcopy(NTTP, u) present_or_copy(u[0:t])
+  ;
+  // CHECK-NEXT: OpenACCDataConstruct{{.*}} data
+  // CHECK-NEXT: copy clause
+  // CHECK-NEXT: DeclRefExpr{{.*}}'T' lvalue ParmVar{{.*}} 't' 'T'
+  // CHECK-NEXT: pcopy clause
+  // CHECK-NEXT: DeclRefExpr{{.*}}'auto' lvalue NonTypeTemplateParm{{.*}} 
'NTTP' 'auto &'
+  // CHECK-NEXT: DeclRefExpr{{.*}}'U' lvalue ParmVar{{.*}} 'u' 'U'
+  // CHECK-NEXT: present_or_copy clause
+  // CHECK-NEXT: ArraySectionExpr
+  // CHECK-NEXT: DeclRefExpr{{.*}}'U' lvalue ParmVar{{.*}} 'u' 'U'
+  // CHECK-NEXT: IntegerLiteral{{.*}} 'int' 0
+  // CHECK-NEXT: DeclRefExpr{{.*}}'T' lvalue ParmVar{{.*}} 't' 'T'
+  // CHECK-NEXT: NullStmt
+
+  // Check the instantiated versions of the above.
+  // CHECK-NEXT: FunctionDecl{{.*}} used TemplUses 'void (int, 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: TemplateArgument type 'int *'
+  // CHECK-NEXT: PointerType{{.*}} 'int *'
+  // CHECK-NEXT: BuiltinType{{.*}} 'int'
+  // CHECK-NEXT: ParmVarDecl{{.*}} used t 'int'
+  // CHECK-NEXT: ParmVarDecl{{.*}} used u 'int *'
+  // CHECK-NEXT: CompoundStmt
+
+  // CHECK-NEXT: OpenACCDataConstruct{{.*}} data
+  // CHECK-NEXT: copy clause
+  // CHECK-NEXT: DeclRefExpr{{.*}}'int' lvalue ParmVar{{.*}} 't' 'int'
+  // CHECK-NEXT: pcopy 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: present_or_copy clause
+  // CHECK-NEXT: ArraySectionExpr
+  // CHECK-NEXT: ImplicitCastExpr{{.*}} 'int *' <LValueToRValue>
+  // CHECK-NEXT: DeclRefExpr{{.*}}'int *' lvalue ParmVar{{.*}} 'u' 'int *'
+  // CHECK-NEXT: IntegerLiteral{{.*}} 'int' 0
+  // CHECK-NEXT: ImplicitCastExpr{{.*}} 'int' <LValueToRValue>
+  // CHECK-NEXT: DeclRefExpr{{.*}}'int' lvalue ParmVar{{.*}} 't' 'int'
+  // CHECK-NEXT: NullStmt
+}
+void Inst() {
+  static constexpr unsigned CEVar = 1;
+  int i;
+  TemplUses<CEVar>(i, &i);
+}
+#endif

diff  --git a/clang/test/SemaOpenACC/data-construct-copy-clause.c 
b/clang/test/SemaOpenACC/data-construct-copy-clause.c
new file mode 100644
index 00000000000000..035463c22c688d
--- /dev/null
+++ b/clang/test/SemaOpenACC/data-construct-copy-clause.c
@@ -0,0 +1,66 @@
+// 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 copy(LocalInt)
+  ;
+
+  // expected-warning@+1{{OpenACC clause name 'pcopy' is a deprecated clause 
name and is now an alias for 'copy'}}
+#pragma acc data pcopy(LocalInt)
+  ;
+
+  // expected-warning@+1{{OpenACC clause name 'present_or_copy' is a 
deprecated clause name and is now an alias for 'copy'}}
+#pragma acc data present_or_copy(LocalInt)
+  ;
+
+  // Valid cases:
+#pragma acc data copy(LocalInt, LocalPointer, LocalArray)
+  ;
+#pragma acc data copy(LocalArray[2:1])
+  ;
+
+#pragma acc data copy(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 copy(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 copy(+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 copy(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 copy(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 copy((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 copy((float)ArrayParam[2])
+  ;
+
+  // expected-error@+1{{OpenACC 'copy' clause is not valid on 'enter data' 
directive}}
+#pragma acc enter data copy(LocalInt)
+  // expected-error@+1{{OpenACC 'pcopy' clause is not valid on 'exit data' 
directive}}
+#pragma acc exit data pcopy(LocalInt)
+  // expected-error@+1{{OpenACC 'present_or_copy' clause is not valid on 
'host_data' directive}}
+#pragma acc host_data present_or_copy(LocalInt)
+  ;
+}

diff  --git a/clang/test/SemaOpenACC/data-construct.cpp 
b/clang/test/SemaOpenACC/data-construct.cpp
index 2df68cc9bba4bb..68186579b98161 100644
--- a/clang/test/SemaOpenACC/data-construct.cpp
+++ b/clang/test/SemaOpenACC/data-construct.cpp
@@ -21,7 +21,6 @@ void HasStmt() {
 void AtLeastOneOf() {
   int Var;
 // Data
-  // expected-warning@+1{{OpenACC clause 'copy' not yet implemented}}
 #pragma acc data copy(Var)
   ;
   // expected-warning@+1{{OpenACC clause 'copyin' 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