Author: Aaron Ballman Date: 2025-05-09T06:52:06-04:00 New Revision: 187a83f86caef2cbeb0b4aaa1f15e507c3f99763
URL: https://github.com/llvm/llvm-project/commit/187a83f86caef2cbeb0b4aaa1f15e507c3f99763 DIFF: https://github.com/llvm/llvm-project/commit/187a83f86caef2cbeb0b4aaa1f15e507c3f99763.diff LOG: [OpenMP] No long crash on an invalid sizes argument (#139118) 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 Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaOpenMP.cpp clang/test/OpenMP/tile_messages.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 1f0dbe565db6b..6c32a7e9a5613 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -901,6 +901,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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits