Skip to content

Commit 9b7fd00

Browse files
authored
[OpenACC] Fix crash when checking an section in a 'link' clause (#168783)
I saw this while doing lowering, we were not properly looking into the array sections for the variable. Presumably we didn't do a good job of making sure we did this right when making this extension, and missed this spot.
1 parent 308185e commit 9b7fd00

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

clang/lib/Sema/SemaOpenACCClause.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,13 +1891,6 @@ SemaOpenACC::ActOnClause(ArrayRef<const OpenACCClause *> ExistingClauses,
18911891
if (DiagnoseAllowedClauses(Clause.getDirectiveKind(), Clause.getClauseKind(),
18921892
Clause.getBeginLoc()))
18931893
return nullptr;
1894-
//// Diagnose that we don't support this clause on this directive.
1895-
// if (!doesClauseApplyToDirective(Clause.getDirectiveKind(),
1896-
// Clause.getClauseKind())) {
1897-
// Diag(Clause.getBeginLoc(), diag::err_acc_clause_appertainment)
1898-
// << Clause.getDirectiveKind() << Clause.getClauseKind();
1899-
// return nullptr;
1900-
// }
19011894

19021895
if (const auto *DevTypeClause = llvm::find_if(
19031896
ExistingClauses, llvm::IsaPred<OpenACCDeviceTypeClause>);
@@ -2256,6 +2249,14 @@ SemaOpenACC::CheckLinkClauseVarList(ArrayRef<Expr *> VarExprs) {
22562249
continue;
22572250
}
22582251

2252+
while (isa<ArraySectionExpr, ArraySubscriptExpr>(VarExpr)) {
2253+
if (auto *ASE = dyn_cast<ArraySectionExpr>(VarExpr))
2254+
VarExpr = ASE->getBase()->IgnoreParenImpCasts();
2255+
else
2256+
VarExpr =
2257+
cast<ArraySubscriptExpr>(VarExpr)->getBase()->IgnoreParenImpCasts();
2258+
}
2259+
22592260
const auto *DRE = cast<DeclRefExpr>(VarExpr);
22602261
const VarDecl *Var = dyn_cast<VarDecl>(DRE->getDecl());
22612262

clang/test/SemaOpenACC/declare-construct.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,13 @@ struct Struct2 {
308308
// expected-error@+2{{variable referenced by 'link' clause not in global or namespace scope must be marked 'extern'}}
309309
// expected-error@+1{{variable referenced by 'link' clause not in global or namespace scope must be marked 'extern'}}
310310
#pragma acc declare link(I, Local, ExternLocal)
311+
312+
int Local2[5];
313+
int Local3[5];
314+
// expected-error@+3{{OpenACC variable on 'declare' construct is not a valid variable name or array name}}
315+
// expected-warning@+2{{sub-array as a variable on 'declare' construct is not a valid variable name or array name}}
316+
// expected-error@+1{{variable referenced by 'link' clause not in global or namespace scope must be marked 'extern'}}
317+
#pragma acc declare link(Local2[1], Local3[1:1])
311318
}
312319
};
313320

0 commit comments

Comments
 (0)