Skip to content

Commit 7a3504a

Browse files
committed
[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'.
1 parent 4a0d53a commit 7a3504a

File tree

4 files changed

+165
-5
lines changed

4 files changed

+165
-5
lines changed

clang/lib/Sema/SemaOpenACC.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -949,11 +949,13 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitPresentClause(
949949

950950
OpenACCClause *SemaOpenACCClauseVisitor::VisitCopyClause(
951951
SemaOpenACC::OpenACCParsedClause &Clause) {
952-
// Restrictions only properly implemented on 'compute'/'combined' constructs,
953-
// and 'compute'/'combined' constructs are the only construct that can do
954-
// anything with this yet, so skip/treat as unimplemented in this case.
952+
// Restrictions only properly implemented on 'compute'/'combined'/'data'
953+
// constructs, and 'compute'/'combined'/'data' constructs are the only
954+
// construct that can do anything with this yet, so skip/treat as
955+
// unimplemented in this case.
955956
if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()) &&
956-
!isOpenACCCombinedDirectiveKind(Clause.getDirectiveKind()))
957+
!isOpenACCCombinedDirectiveKind(Clause.getDirectiveKind()) &&
958+
!isOpenACCDataDirectiveKind(Clause.getDirectiveKind()))
957959
return isNotImplemented();
958960
// ActOnVar ensured that everything is a valid variable reference, so there
959961
// really isn't anything to do here. GCC does some duplicate-finding, though
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// RUN: %clang_cc1 %s -fopenacc -Wno-openacc-deprecated-clause-alias -ast-dump | FileCheck %s
2+
3+
// Test this with PCH.
4+
// RUN: %clang_cc1 %s -fopenacc -Wno-openacc-deprecated-clause-alias -emit-pch -o %t %s
5+
// RUN: %clang_cc1 %s -fopenacc -Wno-openacc-deprecated-clause-alias -include-pch %t -ast-dump-all | FileCheck %s
6+
7+
#ifndef PCH_HELPER
8+
#define PCH_HELPER
9+
10+
int Global;
11+
short GlobalArray[5];
12+
13+
void NormalUses(float *PointerParam) {
14+
// CHECK: FunctionDecl{{.*}}NormalUses
15+
// CHECK: ParmVarDecl
16+
// CHECK-NEXT: CompoundStmt
17+
#pragma acc data copy(GlobalArray) pcopy(PointerParam[Global]) present_or_copy(Global)
18+
;
19+
// CHECK-NEXT: OpenACCDataConstruct{{.*}} data
20+
// CHECK-NEXT: copy clause
21+
// CHECK-NEXT: DeclRefExpr{{.*}}'short[5]' lvalue Var{{.*}}'GlobalArray' 'short[5]'
22+
// CHECK-NEXT: pcopy clause
23+
// CHECK-NEXT: ArraySubscriptExpr{{.*}}'float' lvalue
24+
// CHECK-NEXT: ImplicitCastExpr{{.*}} 'float *' <LValueToRValue>
25+
// CHECK-NEXT: DeclRefExpr{{.*}}'float *' lvalue ParmVar{{.*}}'PointerParam' 'float *'
26+
// CHECK-NEXT: ImplicitCastExpr{{.*}} 'int' <LValueToRValue>
27+
// CHECK-NEXT: DeclRefExpr{{.*}}'int' lvalue Var{{.*}}'Global' 'int'
28+
// CHECK-NEXT: present_or_copy clause
29+
// CHECK-NEXT: DeclRefExpr{{.*}}'int' lvalue Var{{.*}}'Global' 'int'
30+
// CHECK-NEXT: NullStmt
31+
}
32+
template<auto &NTTP, typename T, typename U>
33+
void TemplUses(T t, U u) {
34+
// CHECK-NEXT: FunctionTemplateDecl
35+
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}referenced 'auto &' depth 0 index 0 NTTP
36+
// CHECK-NEXT: TemplateTypeParmDecl{{.*}}typename depth 0 index 1 T
37+
// CHECK-NEXT: TemplateTypeParmDecl{{.*}}typename depth 0 index 2 U
38+
// CHECK-NEXT: FunctionDecl{{.*}} TemplUses 'void (T, U)'
39+
// CHECK-NEXT: ParmVarDecl{{.*}} referenced t 'T'
40+
// CHECK-NEXT: ParmVarDecl{{.*}} referenced u 'U'
41+
// CHECK-NEXT: CompoundStmt
42+
43+
#pragma acc data copy(t) pcopy(NTTP, u) present_or_copy(u[0:t])
44+
;
45+
// CHECK-NEXT: OpenACCDataConstruct{{.*}} data
46+
// CHECK-NEXT: copy clause
47+
// CHECK-NEXT: DeclRefExpr{{.*}}'T' lvalue ParmVar{{.*}} 't' 'T'
48+
// CHECK-NEXT: pcopy clause
49+
// CHECK-NEXT: DeclRefExpr{{.*}}'auto' lvalue NonTypeTemplateParm{{.*}} 'NTTP' 'auto &'
50+
// CHECK-NEXT: DeclRefExpr{{.*}}'U' lvalue ParmVar{{.*}} 'u' 'U'
51+
// CHECK-NEXT: present_or_copy clause
52+
// CHECK-NEXT: ArraySectionExpr
53+
// CHECK-NEXT: DeclRefExpr{{.*}}'U' lvalue ParmVar{{.*}} 'u' 'U'
54+
// CHECK-NEXT: IntegerLiteral{{.*}} 'int' 0
55+
// CHECK-NEXT: DeclRefExpr{{.*}}'T' lvalue ParmVar{{.*}} 't' 'T'
56+
// CHECK-NEXT: NullStmt
57+
58+
// Check the instantiated versions of the above.
59+
// CHECK-NEXT: FunctionDecl{{.*}} used TemplUses 'void (int, int *)' implicit_instantiation
60+
// CHECK-NEXT: TemplateArgument decl
61+
// CHECK-NEXT: Var{{.*}} 'CEVar' 'const unsigned int'
62+
// CHECK-NEXT: TemplateArgument type 'int'
63+
// CHECK-NEXT: BuiltinType{{.*}} 'int'
64+
// CHECK-NEXT: TemplateArgument type 'int *'
65+
// CHECK-NEXT: PointerType{{.*}} 'int *'
66+
// CHECK-NEXT: BuiltinType{{.*}} 'int'
67+
// CHECK-NEXT: ParmVarDecl{{.*}} used t 'int'
68+
// CHECK-NEXT: ParmVarDecl{{.*}} used u 'int *'
69+
// CHECK-NEXT: CompoundStmt
70+
71+
// CHECK-NEXT: OpenACCDataConstruct{{.*}} data
72+
// CHECK-NEXT: copy clause
73+
// CHECK-NEXT: DeclRefExpr{{.*}}'int' lvalue ParmVar{{.*}} 't' 'int'
74+
// CHECK-NEXT: pcopy clause
75+
// CHECK-NEXT: SubstNonTypeTemplateParmExpr{{.*}}'const unsigned int' lvalue
76+
// CHECK-NEXT: NonTypeTemplateParmDecl{{.*}} referenced 'auto &' depth 0 index 0 NTTP
77+
// CHECK-NEXT: DeclRefExpr{{.*}}'const unsigned int' lvalue Var{{.*}} 'CEVar' 'const unsigned int'
78+
// CHECK-NEXT: DeclRefExpr{{.*}}'int *' lvalue ParmVar{{.*}} 'u' 'int *'
79+
// CHECK-NEXT: present_or_copy clause
80+
// CHECK-NEXT: ArraySectionExpr
81+
// CHECK-NEXT: ImplicitCastExpr{{.*}} 'int *' <LValueToRValue>
82+
// CHECK-NEXT: DeclRefExpr{{.*}}'int *' lvalue ParmVar{{.*}} 'u' 'int *'
83+
// CHECK-NEXT: IntegerLiteral{{.*}} 'int' 0
84+
// CHECK-NEXT: ImplicitCastExpr{{.*}} 'int' <LValueToRValue>
85+
// CHECK-NEXT: DeclRefExpr{{.*}}'int' lvalue ParmVar{{.*}} 't' 'int'
86+
// CHECK-NEXT: NullStmt
87+
}
88+
void Inst() {
89+
static constexpr unsigned CEVar = 1;
90+
int i;
91+
TemplUses<CEVar>(i, &i);
92+
}
93+
#endif
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// RUN: %clang_cc1 %s -fopenacc -verify
2+
3+
typedef struct IsComplete {
4+
struct S { int A; } CompositeMember;
5+
int ScalarMember;
6+
float ArrayMember[5];
7+
void *PointerMember;
8+
} Complete;
9+
void uses(int IntParam, short *PointerParam, float ArrayParam[5], Complete CompositeParam) {
10+
int LocalInt;
11+
short *LocalPointer;
12+
float LocalArray[5];
13+
Complete LocalComposite;
14+
// Check Appertainment:
15+
#pragma acc data copy(LocalInt)
16+
;
17+
18+
// expected-warning@+1{{OpenACC clause name 'pcopy' is a deprecated clause name and is now an alias for 'copy'}}
19+
#pragma acc data pcopy(LocalInt)
20+
;
21+
22+
// expected-warning@+1{{OpenACC clause name 'present_or_copy' is a deprecated clause name and is now an alias for 'copy'}}
23+
#pragma acc data present_or_copy(LocalInt)
24+
;
25+
26+
// Valid cases:
27+
#pragma acc data copy(LocalInt, LocalPointer, LocalArray)
28+
;
29+
#pragma acc data copy(LocalArray[2:1])
30+
;
31+
32+
#pragma acc data copy(LocalComposite.ScalarMember, LocalComposite.ScalarMember)
33+
;
34+
35+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
36+
#pragma acc data copy(1 + IntParam)
37+
;
38+
39+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
40+
#pragma acc data copy(+IntParam)
41+
;
42+
43+
// expected-error@+1{{OpenACC sub-array length is unspecified and cannot be inferred because the subscripted value is not an array}}
44+
#pragma acc data copy(PointerParam[2:])
45+
;
46+
47+
// expected-error@+1{{OpenACC sub-array specified range [2:5] would be out of the range of the subscripted array size of 5}}
48+
#pragma acc data copy(ArrayParam[2:5])
49+
;
50+
51+
// expected-error@+2{{OpenACC sub-array specified range [2:5] would be out of the range of the subscripted array size of 5}}
52+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
53+
#pragma acc data copy((float*)ArrayParam[2:5])
54+
;
55+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
56+
#pragma acc data copy((float)ArrayParam[2])
57+
;
58+
59+
// expected-error@+1{{OpenACC 'copy' clause is not valid on 'enter data' directive}}
60+
#pragma acc enter data copy(LocalInt)
61+
// expected-error@+1{{OpenACC 'pcopy' clause is not valid on 'exit data' directive}}
62+
#pragma acc exit data pcopy(LocalInt)
63+
// expected-error@+1{{OpenACC 'present_or_copy' clause is not valid on 'host_data' directive}}
64+
#pragma acc host_data present_or_copy(LocalInt)
65+
;
66+
}

clang/test/SemaOpenACC/data-construct.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ void HasStmt() {
2121
void AtLeastOneOf() {
2222
int Var;
2323
// Data
24-
// expected-warning@+1{{OpenACC clause 'copy' not yet implemented}}
2524
#pragma acc data copy(Var)
2625
;
2726
// expected-warning@+1{{OpenACC clause 'copyin' not yet implemented}}

0 commit comments

Comments
 (0)