Skip to content

Commit 187a83f

Browse files
authored
[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
1 parent f9f2bf8 commit 187a83f

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,8 @@ OpenMP Support
901901
- Added support 'no_openmp_constructs' assumption clause.
902902
- Added support for 'self_maps' in map and requirement clause.
903903
- Added support for 'omp stripe' directive.
904+
- Fixed a crashing bug with ``omp tile sizes`` if the argument to ``sizes`` was
905+
an invalid expression. (#GH139073)
904906

905907
Improvements
906908
^^^^^^^^^^^^

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14328,6 +14328,10 @@ StmtResult SemaOpenMP::ActOnOpenMPTileDirective(ArrayRef<OMPClause *> Clauses,
1432814328
auto MakeDimTileSize = [&SemaRef = this->SemaRef, &CopyTransformer, &Context,
1432914329
SizesClause, CurScope](int I) -> Expr * {
1433014330
Expr *DimTileSizeExpr = SizesClause->getSizesRefs()[I];
14331+
14332+
if (DimTileSizeExpr->containsErrors())
14333+
return nullptr;
14334+
1433114335
if (isa<ConstantExpr>(DimTileSizeExpr))
1433214336
return AssertSuccess(CopyTransformer.TransformExpr(DimTileSizeExpr));
1433314337

@@ -14397,10 +14401,13 @@ StmtResult SemaOpenMP::ActOnOpenMPTileDirective(ArrayRef<OMPClause *> Clauses,
1439714401

1439814402
// For cond-expression:
1439914403
// .tile.iv < min(.floor.iv + DimTileSize, NumIterations)
14404+
Expr *DimTileSize = MakeDimTileSize(I);
14405+
if (!DimTileSize)
14406+
return StmtError();
1440014407
ExprResult EndOfTile = SemaRef.BuildBinOp(
1440114408
CurScope, LoopHelper.Cond->getExprLoc(), BO_Add,
1440214409
makeFloorIVRef(SemaRef, FloorIndVars, I, IVTy, OrigCntVar),
14403-
MakeDimTileSize(I));
14410+
DimTileSize);
1440414411
if (!EndOfTile.isUsable())
1440514412
return StmtError();
1440614413
ExprResult IsPartialTile =
@@ -14482,10 +14489,13 @@ StmtResult SemaOpenMP::ActOnOpenMPTileDirective(ArrayRef<OMPClause *> Clauses,
1448214489
return StmtError();
1448314490

1448414491
// For incr-statement: .floor.iv += DimTileSize
14492+
Expr *DimTileSize = MakeDimTileSize(I);
14493+
if (!DimTileSize)
14494+
return StmtError();
1448514495
ExprResult IncrStmt = SemaRef.BuildBinOp(
1448614496
CurScope, LoopHelper.Inc->getExprLoc(), BO_AddAssign,
1448714497
makeFloorIVRef(SemaRef, FloorIndVars, I, IVTy, OrigCntVar),
14488-
MakeDimTileSize(I));
14498+
DimTileSize);
1448914499
if (!IncrStmt.isUsable())
1449014500
return StmtError();
1449114501

clang/test/OpenMP/tile_messages.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,12 @@ void template_inst() {
161161
// expected-note@+1 {{in instantiation of function template specialization 'templated_func_type_dependent<int>' requested here}}
162162
templated_func_type_dependent<int>();
163163
}
164+
165+
namespace GH139073 {
166+
void f(void) {
167+
// Clang would previously crash on this because of the invalid DeclRefExpr.
168+
#pragma omp tile sizes(a) // expected-error {{use of undeclared identifier 'a'}}
169+
for (int i = 0; i < 10; i++)
170+
;
171+
}
172+
} // namespace GH139073

0 commit comments

Comments
 (0)