llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Aaron Ballman (AaronBallman)

<details>
<summary>Changes</summary>

We were trying to get type information out of an expression node which 
contained errors. That causes the type of the expression to be dependent, which 
the code was not expecting. Now we handle error conditions with an early return.

Fixes #<!-- -->139073

---
Full diff: https://github.com/llvm/llvm-project/pull/139118.diff


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+12-2) 
- (modified) clang/test/OpenMP/tile_messages.cpp (+9) 


``````````diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7f68fd877e4e2..e6d7a19051965 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -891,6 +891,8 @@ OpenMP Support
 - Added support 'no_openmp_constructs' assumption clause.
 - Added support for 'self_maps' in map and requirement clause.
 - Added support for 'omp stripe' directive.
+- Fixed a crashing bug with ``omp tile sizes`` if the argument to ``sizes`` was
+  an invalid expression. (#GH139073)
 
 Improvements
 ^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 835dba22a858d..2534822b72f80 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -14328,6 +14328,10 @@ StmtResult 
SemaOpenMP::ActOnOpenMPTileDirective(ArrayRef<OMPClause *> Clauses,
   auto MakeDimTileSize = [&SemaRef = this->SemaRef, &CopyTransformer, &Context,
                           SizesClause, CurScope](int I) -> Expr * {
     Expr *DimTileSizeExpr = SizesClause->getSizesRefs()[I];
+
+    if (DimTileSizeExpr->containsErrors())
+      return nullptr;
+
     if (isa<ConstantExpr>(DimTileSizeExpr))
       return AssertSuccess(CopyTransformer.TransformExpr(DimTileSizeExpr));
 
@@ -14397,10 +14401,13 @@ StmtResult 
SemaOpenMP::ActOnOpenMPTileDirective(ArrayRef<OMPClause *> Clauses,
 
     // For cond-expression:
     //   .tile.iv < min(.floor.iv + DimTileSize, NumIterations)
+    Expr *DimTileSize = MakeDimTileSize(I);
+    if (!DimTileSize)
+      return StmtError();
     ExprResult EndOfTile = SemaRef.BuildBinOp(
         CurScope, LoopHelper.Cond->getExprLoc(), BO_Add,
         makeFloorIVRef(SemaRef, FloorIndVars, I, IVTy, OrigCntVar),
-        MakeDimTileSize(I));
+        DimTileSize);
     if (!EndOfTile.isUsable())
       return StmtError();
     ExprResult IsPartialTile =
@@ -14482,10 +14489,13 @@ StmtResult 
SemaOpenMP::ActOnOpenMPTileDirective(ArrayRef<OMPClause *> Clauses,
       return StmtError();
 
     // For incr-statement: .floor.iv += DimTileSize
+    Expr *DimTileSize = MakeDimTileSize(I);
+    if (!DimTileSize)
+      return StmtError();
     ExprResult IncrStmt = SemaRef.BuildBinOp(
         CurScope, LoopHelper.Inc->getExprLoc(), BO_AddAssign,
         makeFloorIVRef(SemaRef, FloorIndVars, I, IVTy, OrigCntVar),
-        MakeDimTileSize(I));
+        DimTileSize);
     if (!IncrStmt.isUsable())
       return StmtError();
 
diff --git a/clang/test/OpenMP/tile_messages.cpp 
b/clang/test/OpenMP/tile_messages.cpp
index 5268dfe97e0c8..e1f5155c924e5 100644
--- a/clang/test/OpenMP/tile_messages.cpp
+++ b/clang/test/OpenMP/tile_messages.cpp
@@ -161,3 +161,12 @@ void template_inst() {
   // expected-note@+1 {{in instantiation of function template specialization 
'templated_func_type_dependent<int>' requested here}}
   templated_func_type_dependent<int>();
 }
+
+namespace GH139073 {
+void f(void) {
+  // Clang would previously crash on this because of the invalid DeclRefExpr.
+#pragma omp tile sizes(a) // expected-error {{use of undeclared identifier 
'a'}}
+  for (int i = 0; i < 10; i++)
+    ;
+}
+} // namespace GH139073

``````````

</details>


https://github.com/llvm/llvm-project/pull/139118
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to