Skip to content

Commit 8c1bd97

Browse files
committed
[OpenACC] Expose 'no_create' clause in combined constructs
Once again, not much work besides ensuring they are supposed to work the same.
1 parent d681e10 commit 8c1bd97

File tree

6 files changed

+268
-16
lines changed

6 files changed

+268
-16
lines changed

clang/lib/Sema/SemaOpenACC.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -843,10 +843,11 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitFirstPrivateClause(
843843

844844
OpenACCClause *SemaOpenACCClauseVisitor::VisitNoCreateClause(
845845
SemaOpenACC::OpenACCParsedClause &Clause) {
846-
// Restrictions only properly implemented on 'compute' constructs, and
847-
// 'compute' constructs are the only construct that can do anything with
848-
// this yet, so skip/treat as unimplemented in this case.
849-
if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()))
846+
// Restrictions only properly implemented on 'compute'/'combined' constructs,
847+
// and 'compute'/'combined' constructs are the only construct that can do
848+
// anything with this yet, so skip/treat as unimplemented in this case.
849+
if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()) &&
850+
!isOpenACCCombinedDirectiveKind(Clause.getDirectiveKind()))
850851
return isNotImplemented();
851852
// ActOnVar ensured that everything is a valid variable reference, so there
852853
// really isn't anything to do here. GCC does some duplicate-finding, though

clang/test/AST/ast-print-openacc-combined-construct.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,12 @@ void foo() {
162162
#pragma acc serial loop attach(iPtr, arrayPtr[0])
163163
for(int i = 0;i<5;++i);
164164

165+
// CHECK: #pragma acc parallel loop no_create(i, array[1], array, array[1:2])
166+
#pragma acc parallel loop no_create(i, array[1], array, array[1:2])
167+
for(int i = 0;i<5;++i);
168+
169+
// CHECK: #pragma acc parallel loop no_create(i, array[1], array, array[1:2]) present(i, array[1], array, array[1:2])
170+
#pragma acc parallel loop no_create(i, array[1], array, array[1:2]) present(i, array[1], array, array[1:2])
171+
for(int i = 0;i<5;++i);
172+
165173
}

clang/test/SemaOpenACC/combined-construct-auto_seq_independent-clauses.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ void uses() {
102102
// expected-warning@+1{{OpenACC clause 'link' not yet implemented}}
103103
#pragma acc parallel loop auto link(Var)
104104
for(unsigned i = 0; i < 5; ++i);
105-
// TODOexpected-error@+1{{OpenACC 'no_create' clause is not valid on 'parallel loop' directive}}
106-
// expected-warning@+1{{OpenACC clause 'no_create' not yet implemented}}
107105
#pragma acc parallel loop auto no_create(Var)
108106
for(unsigned i = 0; i < 5; ++i);
109107
#pragma acc parallel loop auto present(Var)
@@ -257,8 +255,6 @@ void uses() {
257255
// expected-warning@+1{{OpenACC clause 'link' not yet implemented}}
258256
#pragma acc parallel loop link(Var) auto
259257
for(unsigned i = 0; i < 5; ++i);
260-
// TODOexpected-error@+1{{OpenACC 'no_create' clause is not valid on 'parallel loop' directive}}
261-
// expected-warning@+1{{OpenACC clause 'no_create' not yet implemented}}
262258
#pragma acc parallel loop no_create(Var) auto
263259
for(unsigned i = 0; i < 5; ++i);
264260
#pragma acc parallel loop present(Var) auto
@@ -413,8 +409,6 @@ void uses() {
413409
// expected-warning@+1{{OpenACC clause 'link' not yet implemented}}
414410
#pragma acc parallel loop independent link(Var)
415411
for(unsigned i = 0; i < 5; ++i);
416-
// TODOexpected-error@+1{{OpenACC 'no_create' clause is not valid on 'parallel loop' directive}}
417-
// expected-warning@+1{{OpenACC clause 'no_create' not yet implemented}}
418412
#pragma acc parallel loop independent no_create(Var)
419413
for(unsigned i = 0; i < 5; ++i);
420414
#pragma acc parallel loop independent present(Var)
@@ -568,8 +562,6 @@ void uses() {
568562
// expected-warning@+1{{OpenACC clause 'link' not yet implemented}}
569563
#pragma acc parallel loop link(Var) independent
570564
for(unsigned i = 0; i < 5; ++i);
571-
// TODOexpected-error@+1{{OpenACC 'no_create' clause is not valid on 'parallel loop' directive}}
572-
// expected-warning@+1{{OpenACC clause 'no_create' not yet implemented}}
573565
#pragma acc parallel loop no_create(Var) independent
574566
for(unsigned i = 0; i < 5; ++i);
575567
#pragma acc parallel loop present(Var) independent
@@ -730,8 +722,6 @@ void uses() {
730722
// expected-warning@+1{{OpenACC clause 'link' not yet implemented}}
731723
#pragma acc parallel loop seq link(Var)
732724
for(unsigned i = 0; i < 5; ++i);
733-
// TODOexpected-error@+1{{OpenACC 'no_create' clause is not valid on 'parallel loop' directive}}
734-
// expected-warning@+1{{OpenACC clause 'no_create' not yet implemented}}
735725
#pragma acc parallel loop seq no_create(Var)
736726
for(unsigned i = 0; i < 5; ++i);
737727
#pragma acc parallel loop seq present(Var)
@@ -891,8 +881,6 @@ void uses() {
891881
// expected-warning@+1{{OpenACC clause 'link' not yet implemented}}
892882
#pragma acc parallel loop link(Var) seq
893883
for(unsigned i = 0; i < 5; ++i);
894-
// TODOexpected-error@+1{{OpenACC 'no_create' clause is not valid on 'parallel loop' directive}}
895-
// expected-warning@+1{{OpenACC clause 'no_create' not yet implemented}}
896884
#pragma acc parallel loop no_create(Var) seq
897885
for(unsigned i = 0; i < 5; ++i);
898886
#pragma acc parallel loop present(Var) seq
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// RUN: %clang_cc1 %s -fopenacc -ast-dump | FileCheck %s
2+
3+
// Test this with PCH.
4+
// RUN: %clang_cc1 %s -fopenacc -emit-pch -o %t %s
5+
// RUN: %clang_cc1 %s -fopenacc -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+
void NormalUses(float *PointerParam) {
13+
// CHECK: FunctionDecl{{.*}}NormalUses
14+
// CHECK: ParmVarDecl
15+
// CHECK-NEXT: CompoundStmt
16+
17+
#pragma acc parallel loop no_create(GlobalArray, PointerParam[Global])
18+
for (unsigned i = 0; i < 5; ++i);
19+
// CHECK-NEXT: OpenACCCombinedConstruct{{.*}} parallel loop
20+
// CHECK-NEXT: no_create clause
21+
// CHECK-NEXT: DeclRefExpr{{.*}}'short[5]' lvalue Var{{.*}}'GlobalArray' 'short[5]'
22+
// CHECK-NEXT: ArraySubscriptExpr{{.*}}'float' lvalue
23+
// CHECK-NEXT: ImplicitCastExpr{{.*}} 'float *' <LValueToRValue>
24+
// CHECK-NEXT: DeclRefExpr{{.*}}'float *' lvalue ParmVar{{.*}}'PointerParam' 'float *'
25+
// CHECK-NEXT: ImplicitCastExpr{{.*}} 'int' <LValueToRValue>
26+
// CHECK-NEXT: DeclRefExpr{{.*}}'int' lvalue Var{{.*}}'Global' 'int'
27+
// CHECK-NEXT: ForStmt
28+
// CHECK: NullStmt
29+
}
30+
31+
template<auto &NTTP, typename T, typename U>
32+
void TemplUses(T t, U u) {
33+
// CHECK-NEXT: FunctionTemplateDecl
34+
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}referenced 'auto &' depth 0 index 0 NTTP
35+
// CHECK-NEXT: TemplateTypeParmDecl{{.*}}typename depth 0 index 1 T
36+
// CHECK-NEXT: TemplateTypeParmDecl{{.*}}typename depth 0 index 2 U
37+
// CHECK-NEXT: FunctionDecl{{.*}} TemplUses 'void (T, U)'
38+
// CHECK-NEXT: ParmVarDecl{{.*}} referenced t 'T'
39+
// CHECK-NEXT: ParmVarDecl{{.*}} referenced u 'U'
40+
// CHECK-NEXT: CompoundStmt
41+
42+
43+
#pragma acc parallel loop no_create(t) present(NTTP, u)
44+
for (unsigned i = 0; i < 5; ++i);
45+
// CHECK-NEXT: OpenACCCombinedConstruct{{.*}} parallel loop
46+
// CHECK-NEXT: no_create clause
47+
// CHECK-NEXT: DeclRefExpr{{.*}}'T' lvalue ParmVar{{.*}} 't' 'T'
48+
// CHECK-NEXT: present clause
49+
// CHECK-NEXT: DeclRefExpr{{.*}}'auto' lvalue NonTypeTemplateParm{{.*}} 'NTTP' 'auto &'
50+
// CHECK-NEXT: DeclRefExpr{{.*}}'U' lvalue ParmVar{{.*}} 'u' 'U'
51+
// CHECK-NEXT: ForStmt
52+
// CHECK: NullStmt
53+
54+
// Check the instantiated versions of the above.
55+
// CHECK-NEXT: FunctionDecl{{.*}} used TemplUses 'void (int, int *)' implicit_instantiation
56+
// CHECK-NEXT: TemplateArgument decl
57+
// CHECK-NEXT: Var{{.*}} 'CEVar' 'const unsigned int'
58+
// CHECK-NEXT: TemplateArgument type 'int'
59+
// CHECK-NEXT: BuiltinType{{.*}} 'int'
60+
// CHECK-NEXT: TemplateArgument type 'int *'
61+
// CHECK-NEXT: PointerType{{.*}} 'int *'
62+
// CHECK-NEXT: BuiltinType{{.*}} 'int'
63+
// CHECK-NEXT: ParmVarDecl{{.*}} used t 'int'
64+
// CHECK-NEXT: ParmVarDecl{{.*}} used u 'int *'
65+
// CHECK-NEXT: CompoundStmt
66+
67+
// #pragma acc parallel loop no_create(t) present(NTTP, u)
68+
// CHECK-NEXT: OpenACCCombinedConstruct{{.*}} parallel loop
69+
// CHECK-NEXT: no_create clause
70+
// CHECK-NEXT: DeclRefExpr{{.*}}'int' lvalue ParmVar{{.*}} 't' 'int'
71+
// CHECK-NEXT: present clause
72+
// CHECK-NEXT: SubstNonTypeTemplateParmExpr{{.*}}'const unsigned int' lvalue
73+
// CHECK-NEXT: NonTypeTemplateParmDecl{{.*}} referenced 'auto &' depth 0 index 0 NTTP
74+
// CHECK-NEXT: DeclRefExpr{{.*}}'const unsigned int' lvalue Var{{.*}} 'CEVar' 'const unsigned int'
75+
// CHECK-NEXT: DeclRefExpr{{.*}}'int *' lvalue ParmVar{{.*}} 'u' 'int *'
76+
// CHECK-NEXT: ForStmt
77+
// CHECK: NullStmt
78+
}
79+
80+
void Inst() {
81+
static constexpr unsigned CEVar = 1;
82+
int i;
83+
TemplUses<CEVar>(i, &i);
84+
}
85+
#endif
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 parallel loop no_create(LocalInt)
16+
for (unsigned i = 0; i < 5; ++i);
17+
#pragma acc serial loop no_create(LocalInt)
18+
for (unsigned i = 0; i < 5; ++i);
19+
#pragma acc kernels loop no_create(LocalInt)
20+
for (unsigned i = 0; i < 5; ++i);
21+
22+
// Valid cases:
23+
#pragma acc parallel loop no_create(LocalInt, LocalPointer, LocalArray)
24+
for (unsigned i = 0; i < 5; ++i);
25+
#pragma acc parallel loop no_create(LocalArray[2:1])
26+
for (unsigned i = 0; i < 5; ++i);
27+
28+
#pragma acc parallel loop no_create(LocalComposite.ScalarMember, LocalComposite.ScalarMember)
29+
for (unsigned i = 0; i < 5; ++i);
30+
31+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
32+
#pragma acc parallel loop no_create(1 + IntParam)
33+
for (unsigned i = 0; i < 5; ++i);
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 parallel loop no_create(+IntParam)
37+
for (unsigned i = 0; i < 5; ++i);
38+
39+
// expected-error@+1{{OpenACC sub-array length is unspecified and cannot be inferred because the subscripted value is not an array}}
40+
#pragma acc parallel loop no_create(PointerParam[2:])
41+
for (unsigned i = 0; i < 5; ++i);
42+
43+
// expected-error@+1{{OpenACC sub-array specified range [2:5] would be out of the range of the subscripted array size of 5}}
44+
#pragma acc parallel loop no_create(ArrayParam[2:5])
45+
for (unsigned i = 0; i < 5; ++i);
46+
47+
// expected-error@+2{{OpenACC sub-array specified range [2:5] would be out of the range of the subscripted array size of 5}}
48+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
49+
#pragma acc parallel loop no_create((float*)ArrayParam[2:5])
50+
for (unsigned i = 0; i < 5; ++i);
51+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
52+
#pragma acc parallel loop no_create((float)ArrayParam[2])
53+
for (unsigned i = 0; i < 5; ++i);
54+
55+
// expected-error@+1{{OpenACC 'no_create' clause is not valid on 'loop' directive}}
56+
#pragma acc loop no_create(LocalInt)
57+
for(int i = 5; i < 10;++i);
58+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// RUN: %clang_cc1 %s -fopenacc -verify
2+
3+
enum SomeE{};
4+
typedef struct IsComplete {
5+
struct S { int A; } CompositeMember;
6+
int ScalarMember;
7+
float ArrayMember[5];
8+
SomeE EnumMember;
9+
char *PointerMember;
10+
} Complete;
11+
12+
void uses(int IntParam, char *PointerParam, float ArrayParam[5], Complete CompositeParam, int &IntParamRef) {
13+
int LocalInt;
14+
char *LocalPointer;
15+
float LocalArray[5];
16+
// Check Appertainment:
17+
#pragma acc parallel loop no_create(LocalInt)
18+
for (unsigned i = 0; i < 5; ++i);
19+
#pragma acc serial loop no_create(LocalInt)
20+
for (unsigned i = 0; i < 5; ++i);
21+
#pragma acc kernels loop no_create(LocalInt)
22+
for (unsigned i = 0; i < 5; ++i);
23+
24+
// Valid cases:
25+
#pragma acc parallel loop no_create(LocalInt, LocalPointer, LocalArray)
26+
for (unsigned i = 0; i < 5; ++i);
27+
#pragma acc parallel loop no_create(LocalArray[2:1])
28+
for (unsigned i = 0; i < 5; ++i);
29+
30+
Complete LocalComposite2;
31+
#pragma acc parallel loop no_create(LocalComposite2.ScalarMember, LocalComposite2.ScalarMember)
32+
for (unsigned i = 0; i < 5; ++i);
33+
34+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
35+
#pragma acc parallel loop no_create(1 + IntParam)
36+
for (unsigned i = 0; i < 5; ++i);
37+
38+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
39+
#pragma acc parallel loop no_create(+IntParam)
40+
for (unsigned i = 0; i < 5; ++i);
41+
42+
// expected-error@+1{{OpenACC sub-array length is unspecified and cannot be inferred because the subscripted value is not an array}}
43+
#pragma acc parallel loop no_create(PointerParam[2:])
44+
for (unsigned i = 0; i < 5; ++i);
45+
46+
// expected-error@+1{{OpenACC sub-array specified range [2:5] would be out of the range of the subscripted array size of 5}}
47+
#pragma acc parallel loop no_create(ArrayParam[2:5])
48+
for (unsigned i = 0; i < 5; ++i);
49+
50+
// expected-error@+2{{OpenACC sub-array specified range [2:5] would be out of the range of the subscripted array size of 5}}
51+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
52+
#pragma acc parallel loop no_create((float*)ArrayParam[2:5])
53+
for (unsigned i = 0; i < 5; ++i);
54+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
55+
#pragma acc parallel loop no_create((float)ArrayParam[2])
56+
for (unsigned i = 0; i < 5; ++i);
57+
}
58+
59+
template<typename T, unsigned I, typename V>
60+
void TemplUses(T t, T (&arrayT)[I], V TemplComp) {
61+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
62+
#pragma acc parallel loop no_create(+t)
63+
for (unsigned i = 0; i < 5; ++i);
64+
65+
// NTTP's are only valid if it is a reference to something.
66+
// expected-error@+2{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
67+
// expected-note@#TEMPL_USES_INST{{in instantiation of}}
68+
#pragma acc parallel loop no_create(I)
69+
for (unsigned i = 0; i < 5; ++i);
70+
71+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
72+
#pragma acc parallel loop no_create(t, I)
73+
for (unsigned i = 0; i < 5; ++i);
74+
75+
#pragma acc parallel loop no_create(arrayT)
76+
for (unsigned i = 0; i < 5; ++i);
77+
78+
#pragma acc parallel loop no_create(TemplComp)
79+
for (unsigned i = 0; i < 5; ++i);
80+
81+
#pragma acc parallel loop no_create(TemplComp.PointerMember[5])
82+
for (unsigned i = 0; i < 5; ++i);
83+
int *Pointer;
84+
#pragma acc parallel loop no_create(Pointer[:I])
85+
for (unsigned i = 0; i < 5; ++i);
86+
#pragma acc parallel loop no_create(Pointer[:t])
87+
for (unsigned i = 0; i < 5; ++i);
88+
// expected-error@+1{{OpenACC sub-array length is unspecified and cannot be inferred because the subscripted value is not an array}}
89+
#pragma acc parallel loop no_create(Pointer[1:])
90+
for (unsigned i = 0; i < 5; ++i);
91+
}
92+
93+
template<unsigned I, auto &NTTP_REF>
94+
void NTTP() {
95+
// NTTP's are only valid if it is a reference to something.
96+
// expected-error@+2{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
97+
// expected-note@#NTTP_INST{{in instantiation of}}
98+
#pragma acc parallel loop no_create(I)
99+
for (unsigned i = 0; i < 5; ++i);
100+
101+
#pragma acc parallel loop no_create(NTTP_REF)
102+
for (unsigned i = 0; i < 5; ++i);
103+
}
104+
105+
void Inst() {
106+
static constexpr int NTTP_REFed = 1;
107+
int i;
108+
int Arr[5];
109+
Complete C;
110+
TemplUses(i, Arr, C); // #TEMPL_USES_INST
111+
NTTP<5, NTTP_REFed>(); // #NTTP_INST
112+
}

0 commit comments

Comments
 (0)