Skip to content

Commit 6d69d18

Browse files
committed
[OpenACC] enable 'attach' clause sema for 'data' and 'enter data'
This is very similar to deviceptr, and is the same implementation as for combined/compute constructs, so this just enables that, and adds tests.
1 parent 003a721 commit 6d69d18

File tree

5 files changed

+135
-10
lines changed

5 files changed

+135
-10
lines changed

clang/lib/Sema/SemaOpenACC.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,13 +1013,6 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitCreateClause(
10131013

10141014
OpenACCClause *SemaOpenACCClauseVisitor::VisitAttachClause(
10151015
SemaOpenACC::OpenACCParsedClause &Clause) {
1016-
// Restrictions only properly implemented on 'compute'/'combined' constructs,
1017-
// and 'compute'/'combined' constructs are the only construct that can do
1018-
// anything with this yet, so skip/treat as unimplemented in this case.
1019-
if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()) &&
1020-
!isOpenACCCombinedDirectiveKind(Clause.getDirectiveKind()))
1021-
return isNotImplemented();
1022-
10231016
// ActOnVar ensured that everything is a valid variable reference, but we
10241017
// still have to make sure it is a pointer type.
10251018
llvm::SmallVector<Expr *> VarList{Clause.getVarList()};

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,8 @@ void foo() {
106106

107107
// CHECK: #pragma acc data default(none) deviceptr(iPtr, arrayPtr[0])
108108
#pragma acc data default(none) deviceptr(iPtr, arrayPtr[0])
109+
110+
// CHECK: #pragma acc data default(none) attach(iPtr, arrayPtr[0])
111+
#pragma acc data default(none) attach(iPtr, arrayPtr[0])
109112
;
110113
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
13+
void NormalUses(float *PointerParam) {
14+
// CHECK: FunctionDecl{{.*}}NormalUses
15+
// CHECK: ParmVarDecl
16+
// CHECK-NEXT: CompoundStmt
17+
18+
#pragma acc data default(present) attach(PointerParam)
19+
for(int i = 0; i < 5; ++i);
20+
// CHECK-NEXT: OpenACCDataConstruct{{.*}} data
21+
// CHECK-NEXT: default(present)
22+
// CHECK-NEXT: attach clause
23+
// CHECK-NEXT: DeclRefExpr{{.*}}'float *' lvalue ParmVar{{.*}} 'PointerParam' 'float *'
24+
// CHECK-NEXT: ForStmt
25+
// CHECK: NullStmt
26+
}
27+
28+
template<typename T>
29+
void TemplUses(T *t) {
30+
// CHECK-NEXT: FunctionTemplateDecl
31+
// CHECK-NEXT: TemplateTypeParmDecl{{.*}}typename depth 0 index 0 T
32+
// CHECK-NEXT: FunctionDecl{{.*}} TemplUses 'void (T *)'
33+
// CHECK-NEXT: ParmVarDecl{{.*}} referenced t 'T *'
34+
// CHECK-NEXT: CompoundStmt
35+
36+
#pragma acc data default(present) attach(t)
37+
for(int i = 0; i < 5; ++i);
38+
// CHECK-NEXT: OpenACCDataConstruct{{.*}} data
39+
// CHECK-NEXT: default(present)
40+
// CHECK-NEXT: attach clause
41+
// CHECK-NEXT: DeclRefExpr{{.*}}'T *' lvalue ParmVar{{.*}} 't' 'T *'
42+
// CHECK-NEXT: ForStmt
43+
// CHECK: NullStmt
44+
45+
46+
// Check the instantiated versions of the above.
47+
// CHECK-NEXT: FunctionDecl{{.*}} used TemplUses 'void (int *)' implicit_instantiation
48+
// CHECK-NEXT: TemplateArgument type 'int'
49+
// CHECK-NEXT: BuiltinType{{.*}} 'int'
50+
// CHECK-NEXT: ParmVarDecl{{.*}} used t 'int *'
51+
// CHECK-NEXT: CompoundStmt
52+
53+
// CHECK-NEXT: OpenACCDataConstruct{{.*}} data
54+
// CHECK-NEXT: default(present)
55+
// CHECK-NEXT: attach clause
56+
// CHECK-NEXT: DeclRefExpr{{.*}}'int *' lvalue ParmVar{{.*}} 't' 'int *'
57+
// CHECK-NEXT: ForStmt
58+
// CHECK: NullStmt
59+
60+
}
61+
62+
void Inst() {
63+
int i;
64+
TemplUses(&i);
65+
}
66+
#endif
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// RUN: %clang_cc1 %s -fopenacc -verify
2+
3+
struct S {
4+
int IntMem;
5+
int *PtrMem;
6+
};
7+
8+
void uses() {
9+
int LocalInt;
10+
int *LocalPtr;
11+
int Array[5];
12+
int *PtrArray[5];
13+
struct S s;
14+
15+
// expected-error@+1{{expected pointer in 'attach' clause, type is 'int'}}
16+
#pragma acc data default(none) attach(LocalInt)
17+
;
18+
19+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
20+
#pragma acc data default(none) attach(&LocalInt)
21+
;
22+
23+
24+
// expected-error@+1{{expected pointer in 'attach' clause, type is 'int[5]'}}
25+
#pragma acc enter data copyin(LocalInt) attach(Array)
26+
27+
// expected-error@+1{{expected pointer in 'attach' clause, type is 'int'}}
28+
#pragma acc data default(none) attach(Array[0])
29+
;
30+
31+
// expected-error@+2{{OpenACC sub-array is not allowed here}}
32+
// expected-note@+1{{expected variable of pointer type}}
33+
#pragma acc data default(none) attach(Array[0:1])
34+
;
35+
36+
// expected-error@+1{{expected pointer in 'attach' clause, type is 'int *[5]'}}
37+
#pragma acc data default(none) attach(PtrArray)
38+
;
39+
40+
#pragma acc data default(none) attach(PtrArray[0])
41+
;
42+
43+
// expected-error@+2{{OpenACC sub-array is not allowed here}}
44+
// expected-note@+1{{expected variable of pointer type}}
45+
#pragma acc data default(none) attach(PtrArray[0:1])
46+
;
47+
48+
// expected-error@+1{{expected pointer in 'attach' clause, type is 'struct S'}}
49+
#pragma acc data default(none) attach(s)
50+
;
51+
52+
// expected-error@+1{{expected pointer in 'attach' clause, type is 'int'}}
53+
#pragma acc data default(none) attach(s.IntMem)
54+
;
55+
56+
#pragma acc data default(none) attach(s.PtrMem)
57+
;
58+
59+
// expected-error@+1{{OpenACC 'attach' clause is not valid on 'exit data' directive}}
60+
#pragma acc exit data copyout(LocalInt) attach(PtrArray[0])
61+
// expected-warning@+2{{OpenACC clause 'use_device' not yet implemented}}
62+
// expected-error@+1{{OpenACC 'attach' clause is not valid on 'host_data' directive}}
63+
#pragma acc host_data use_device(LocalInt) attach(PtrArray[0])
64+
;
65+
}

clang/test/SemaOpenACC/data-construct.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ void AtLeastOneOf() {
3636
;
3737
#pragma acc data deviceptr(VarPtr)
3838
;
39-
// expected-warning@+1{{OpenACC clause 'attach' not yet implemented}}
4039
#pragma acc data attach(VarPtr)
4140
;
4241
#pragma acc data default(none)
@@ -62,8 +61,7 @@ void AtLeastOneOf() {
6261
// Enter Data
6362
#pragma acc enter data copyin(Var)
6463
#pragma acc enter data create(Var)
65-
// expected-warning@+1{{OpenACC clause 'attach' not yet implemented}}
66-
#pragma acc enter data attach(Var)
64+
#pragma acc enter data attach(VarPtr)
6765

6866
// OpenACC TODO: The following 'enter data' directives should diagnose, since
6967
// they don't have at least one of the above clauses.

0 commit comments

Comments
 (0)