Skip to content

Commit

Permalink
[OpenACC] Change 'not implemented' diagnostic to be more specific
Browse files Browse the repository at this point in the history
Currently we just emit a generic 'not implemented' diagnostic for all
OpenACC pragmas. This patch moves the diagnostic to 'Sema' and diagnoses
for a specific clause or construct, in preperation of implementing Sema
for constructs.
  • Loading branch information
erichkeane committed Feb 15, 2024
1 parent b497234 commit db4ea21
Show file tree
Hide file tree
Showing 14 changed files with 1,464 additions and 889 deletions.
3 changes: 0 additions & 3 deletions clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -1355,9 +1355,6 @@ def warn_pragma_acc_ignored
DefaultIgnore;
def err_acc_unexpected_directive
: Error<"unexpected OpenACC directive %select{|'#pragma acc %1'}0">;
def warn_pragma_acc_unimplemented
: Warning<"OpenACC directives not yet implemented, pragma ignored">,
InGroup<SourceUsesOpenACC>;
def err_acc_invalid_directive
: Error<"invalid OpenACC directive %select{%1|'%1 %2'}0">;
def err_acc_invalid_clause : Error<"invalid OpenACC clause %0">;
Expand Down
11 changes: 11 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -12186,4 +12186,15 @@ def err_wasm_builtin_arg_must_match_table_element_type : Error <
"%ordinal0 argument must match the element type of the WebAssembly table in the %ordinal1 argument">;
def err_wasm_builtin_arg_must_be_integer_type : Error <
"%ordinal0 argument must be an integer">;

// OpenACC diagnostics.
def warn_acc_construct_unimplemented
: Warning<"OpenACC construct '%0' not yet implemented, pragma ignored">,
InGroup<SourceUsesOpenACC>;
def warn_acc_clause_unimplemented
: Warning<"OpenACC clause '%0' not yet implemented, clause ignored">,
InGroup<SourceUsesOpenACC>;
def err_acc_construct_appertainment
: Error<"OpenACC construct '%0' cannot be used here; it can only "
"be used in a statement context">;
} // end of sema component.
1 change: 0 additions & 1 deletion clang/lib/Parse/ParseOpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,6 @@ Parser::OpenACCDirectiveParseInfo Parser::ParseOpenACCDirective() {
// Parses the list of clauses, if present.
ParseOpenACCClauseList(DirKind);

Diag(getCurToken(), diag::warn_pragma_acc_unimplemented);
assert(Tok.is(tok::annot_pragma_openacc_end) &&
"Didn't parse all OpenACC Clauses");
SourceLocation EndLoc = ConsumeAnnotationToken();
Expand Down
23 changes: 21 additions & 2 deletions clang/lib/Sema/SemaOpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,35 @@
///
//===----------------------------------------------------------------------===//

#include "clang/Basic/DiagnosticSema.h"
#include "clang/Basic/OpenACCKinds.h"
#include "clang/Sema/Sema.h"

using namespace clang;
bool Sema::ActOnOpenACCClause(OpenACCClauseKind ClauseKind,
SourceLocation StartLoc) {
return true;
if (ClauseKind == OpenACCClauseKind::Invalid)
return false;
// For now just diagnose that it is unsupported and leave the parsing to do
// whatever it can do. This function will eventually need to start returning
// some sort of Clause AST type, but for now just return true/false based on
// success.
return Diag(StartLoc, diag::warn_acc_clause_unimplemented) << ClauseKind;
}
void Sema::ActOnOpenACCConstruct(OpenACCDirectiveKind K,
SourceLocation StartLoc) {}
SourceLocation StartLoc) {
switch (K) {
case OpenACCDirectiveKind::Invalid:
// Nothing to do here, an invalid kind has nothing we can check here. We
// want to continue parsing clauses as far as we can, so we will just
// ensure that we can still work and don't check any construct-specific
// rules anywhere.
break;
default:
Diag(StartLoc, diag::warn_acc_construct_unimplemented) << K;
break;
}
}

bool Sema::ActOnStartOpenACCStmtDirective(OpenACCDirectiveKind K,
SourceLocation StartLoc) {
Expand Down
58 changes: 29 additions & 29 deletions clang/test/ParserOpenACC/parse-cache-construct.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,58 +13,58 @@ void func() {

for (int i = 0; i < 10; ++i) {
// expected-error@+2{{expected '('}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache
}

for (int i = 0; i < 10; ++i) {
// expected-error@+3{{expected '('}}
// expected-error@+2{{invalid OpenACC clause 'clause'}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache clause list
}

for (int i = 0; i < 10; ++i) {
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache()
}

for (int i = 0; i < 10; ++i) {
// expected-error@+2{{invalid OpenACC clause 'clause'}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache() clause-list
}

for (int i = 0; i < 10; ++i) {
// expected-error@+3{{expected ')'}}
// expected-note@+2{{to match this '('}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(
}

for (int i = 0; i < 10; ++i) {
// expected-error@+4{{use of undeclared identifier 'invalid'}}
// expected-error@+3{{expected ')'}}
// expected-note@+2{{to match this '('}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(invalid
}

for (int i = 0; i < 10; ++i) {
// expected-error@+3{{expected ')'}}
// expected-note@+2{{to match this '('}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(ArrayPtr
}

for (int i = 0; i < 10; ++i) {
// expected-error@+2{{use of undeclared identifier 'invalid'}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(invalid)
}

for (int i = 0; i < 10; ++i) {
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(ArrayPtr)
}

Expand All @@ -74,28 +74,28 @@ void func() {
// expected-note@+4{{to match this '['}}
// expected-error@+3{{expected ')'}}
// expected-note@+2{{to match this '('}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(ArrayPtr[
}

for (int i = 0; i < 10; ++i) {
// expected-error@+4{{expected expression}}
// expected-error@+3{{expected ']'}}
// expected-note@+2{{to match this '['}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(ArrayPtr[, 5)
}

for (int i = 0; i < 10; ++i) {
// expected-error@+4{{expected expression}}
// expected-error@+3{{expected ']'}}
// expected-note@+2{{to match this '['}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(Array[)
}

for (int i = 0; i < 10; ++i) {
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(Array[*readonly])
}

Expand All @@ -105,92 +105,92 @@ void func() {
// expected-note@+4{{to match this '['}}
// expected-error@+3{{expected ')'}}
// expected-note@+2{{to match this '('}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(Array[*readonly:
}

for (int i = 0; i < 10; ++i) {
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(readonly)
}

for (int i = 0; i < 10; ++i) {
// expected-error@+2{{invalid tag 'devnum' on 'cache' directive}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(devnum:ArrayPtr)
}

for (int i = 0; i < 10; ++i) {
// expected-error@+2{{invalid tag 'invalid' on 'cache' directive}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(invalid:ArrayPtr)
}

for (int i = 0; i < 10; ++i) {
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(readonly:ArrayPtr)
}

for (int i = 0; i < 10; ++i) {
// expected-error@+2{{expected expression}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(readonly:ArrayPtr[5:])
}

for (int i = 0; i < 10; ++i) {
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(readonly:ArrayPtr[5:*readonly])
}

for (int i = 0; i < 10; ++i) {
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(readonly:ArrayPtr[5:*readonly], Array)
}

for (int i = 0; i < 10; ++i) {
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(readonly:ArrayPtr[5:*readonly], Array[*readonly:3])
}

for (int i = 0; i < 10; ++i) {
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(readonly:ArrayPtr[5 + i:*readonly], Array[*readonly + i:3])
}

for (int i = 0; i < 10; ++i) {
// expected-error@+4{{expected expression}}
// expected-error@+3{{expected ')'}}
// expected-note@+2{{to match this '('}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(readonly:ArrayPtr[5:*readonly],
}

for (int i = 0; i < 10; ++i) {
// expected-error@+2{{expected expression}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(readonly:ArrayPtr[5:*readonly],)
}

for (int i = 0; i < 10; ++i) {
// expected-warning@+2{{left operand of comma operator has no effect}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(readonly:ArrayPtr[5,6:*readonly])
}

for (int i = 0; i < 10; ++i) {
// expected-warning@+2{{left operand of comma operator has no effect}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(readonly:ArrayPtr[5:3, *readonly], ArrayPtr[0])
}

for (int i = 0; i < 10; ++i) {
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(readonly:s.foo)
}

for (int i = 0; i < 10; ++i) {
// expected-warning@+2{{left operand of comma operator has no effect}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(readonly:s.Array[1,2])
}
}
32 changes: 16 additions & 16 deletions clang/test/ParserOpenACC/parse-cache-construct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,34 @@ template<typename T, int I>
void func() {
char *ArrayPtr = getArrayPtr();
for (int i = 0; i < 10; ++i) {
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(ArrayPtr[T::value + I:I + 5], T::array[(i + T::value, 5): 6])
}
for (int i = 0; i < 10; ++i) {
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(NS::NSArray[NS::NSInt])
}

for (int i = 0; i < 10; ++i) {
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(NS::NSArray[NS::NSInt : NS::NSInt])
}

for (int i = 0; i < 10; ++i) {
// expected-error@+2{{use of undeclared identifier 'NSArray'; did you mean 'NS::NSArray'}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(NSArray[NS::NSInt : NS::NSInt])
}

for (int i = 0; i < 10; ++i) {
// expected-error@+2{{use of undeclared identifier 'NSInt'; did you mean 'NS::NSInt'}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(NS::NSArray[NSInt : NS::NSInt])
}

for (int i = 0; i < 10; ++i) {
// expected-error@+2{{use of undeclared identifier 'NSInt'; did you mean 'NS::NSInt'}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(NS::NSArray[NS::NSInt : NSInt])
}
}
Expand All @@ -59,56 +59,56 @@ void use() {

Members s;
for (int i = 0; i < 10; ++i) {
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(s.array[s.value])
}
HasMembersArray Arrs;
for (int i = 0; i < 10; ++i) {
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(Arrs.MemArr[3].array[4])
}
for (int i = 0; i < 10; ++i) {
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(Arrs.MemArr[3].array[1:4])
}
for (int i = 0; i < 10; ++i) {
// FIXME: Once we have a new array-section type to represent OpenACC as
// well, change this error message.
// expected-error@+2{{OpenMP array section is not allowed here}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(Arrs.MemArr[3:4].array[1:4])
}
for (int i = 0; i < 10; ++i) {
// expected-error@+2{{OpenMP array section is not allowed here}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(Arrs.MemArr[3:4].array[4])
}
for (int i = 0; i < 10; ++i) {
// expected-error@+3{{expected ']'}}
// expected-note@+2{{to match this '['}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(Arrs.MemArr[3:4:].array[4])
}
for (int i = 0; i < 10; ++i) {
// expected-error@+2{{expected expression}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(Arrs.MemArr[:].array[4])
}
for (int i = 0; i < 10; ++i) {
// expected-error@+2{{expected unqualified-id}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(Arrs.MemArr[::].array[4])
}
for (int i = 0; i < 10; ++i) {
// expected-error@+4{{expected expression}}
// expected-error@+3{{expected ']'}}
// expected-note@+2{{to match this '['}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(Arrs.MemArr[: :].array[4])
}
for (int i = 0; i < 10; ++i) {
// expected-error@+2{{expected expression}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
// expected-warning@+1{{OpenACC construct 'cache' not yet implemented, pragma ignored}}
#pragma acc cache(Arrs.MemArr[3:].array[4])
}
func<S, 5>();
Expand Down

0 comments on commit db4ea21

Please sign in to comment.