Author: Erich Keane
Date: 2025-11-19T22:47:23Z
New Revision: 9b7fd0099e79b0f5b824027cbae8a25356486ac9

URL: 
https://github.com/llvm/llvm-project/commit/9b7fd0099e79b0f5b824027cbae8a25356486ac9
DIFF: 
https://github.com/llvm/llvm-project/commit/9b7fd0099e79b0f5b824027cbae8a25356486ac9.diff

LOG: [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.

Added: 
    

Modified: 
    clang/lib/Sema/SemaOpenACCClause.cpp
    clang/test/SemaOpenACC/declare-construct.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaOpenACCClause.cpp 
b/clang/lib/Sema/SemaOpenACCClause.cpp
index 17078e8814a43..2a54d984cdffb 100644
--- a/clang/lib/Sema/SemaOpenACCClause.cpp
+++ b/clang/lib/Sema/SemaOpenACCClause.cpp
@@ -1891,13 +1891,6 @@ SemaOpenACC::ActOnClause(ArrayRef<const OpenACCClause *> 
ExistingClauses,
   if (DiagnoseAllowedClauses(Clause.getDirectiveKind(), Clause.getClauseKind(),
                              Clause.getBeginLoc()))
     return nullptr;
-  //// Diagnose that we don't support this clause on this directive.
-  // if (!doesClauseApplyToDirective(Clause.getDirectiveKind(),
-  //                                 Clause.getClauseKind())) {
-  //   Diag(Clause.getBeginLoc(), diag::err_acc_clause_appertainment)
-  //       << Clause.getDirectiveKind() << Clause.getClauseKind();
-  //   return nullptr;
-  // }
 
   if (const auto *DevTypeClause = llvm::find_if(
           ExistingClauses, llvm::IsaPred<OpenACCDeviceTypeClause>);
@@ -2256,6 +2249,14 @@ SemaOpenACC::CheckLinkClauseVarList(ArrayRef<Expr *> 
VarExprs) {
       continue;
     }
 
+    while (isa<ArraySectionExpr, ArraySubscriptExpr>(VarExpr)) {
+      if (auto *ASE = dyn_cast<ArraySectionExpr>(VarExpr))
+        VarExpr = ASE->getBase()->IgnoreParenImpCasts();
+      else
+        VarExpr =
+            
cast<ArraySubscriptExpr>(VarExpr)->getBase()->IgnoreParenImpCasts();
+    }
+
     const auto *DRE = cast<DeclRefExpr>(VarExpr);
     const VarDecl *Var = dyn_cast<VarDecl>(DRE->getDecl());
 

diff  --git a/clang/test/SemaOpenACC/declare-construct.cpp 
b/clang/test/SemaOpenACC/declare-construct.cpp
index 6828ecdf9ebc1..c2ac72122ee74 100644
--- a/clang/test/SemaOpenACC/declare-construct.cpp
+++ b/clang/test/SemaOpenACC/declare-construct.cpp
@@ -308,6 +308,13 @@ struct Struct2 {
   // expected-error@+2{{variable referenced by 'link' clause not in global or 
namespace scope must be marked 'extern'}}
   // expected-error@+1{{variable referenced by 'link' clause not in global or 
namespace scope must be marked 'extern'}}
 #pragma acc declare link(I, Local, ExternLocal)
+
+    int Local2[5];
+    int Local3[5];
+  // expected-error@+3{{OpenACC variable on 'declare' construct is not a valid 
variable name or array name}}
+  // expected-warning@+2{{sub-array as a variable on 'declare' construct is 
not a valid variable name or array name}}
+  // expected-error@+1{{variable referenced by 'link' clause not in global or 
namespace scope must be marked 'extern'}}
+#pragma acc declare link(Local2[1], Local3[1:1])
 }
 };
 


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to