[clang] fix issue: [Clang][OpenMP] Implicit conversion with `pragma omp taskloop` #100536 (PR #101812)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 5 19:25:39 PDT 2024
https://github.com/HenryZ16 updated https://github.com/llvm/llvm-project/pull/101812
>From 217b910739f6bbc392cbb98f34fdd785bca2f57e Mon Sep 17 00:00:00 2001
From: HenryZ16 <1546169856 at qq.com>
Date: Sat, 3 Aug 2024 05:03:15 -0600
Subject: [PATCH 1/2] fix issue: [Clang][OpenMP] Implicit conversion with
`pragma omp taskloop` #100536
---
clang/include/clang/Sema/Sema.h | 9 +++-
clang/lib/Sema/SemaExprCXX.cpp | 6 ++-
clang/lib/Sema/SemaOpenMP.cpp | 76 ++++++++++++++++++++++++++-------
3 files changed, 73 insertions(+), 18 deletions(-)
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2ec6367eccea0..c62919cb13962 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8279,9 +8279,16 @@ class Sema final : public SemaBase {
return ActOnFinishFullExpr(
Expr, Expr ? Expr->getExprLoc() : SourceLocation(), DiscardedValue);
}
+ ExprResult ActOnFinishFullExprNoCheckExpr(Expr *Expr, bool DiscardedValue) {
+ return ActOnFinishFullExpr(
+ Expr, Expr ? Expr->getExprLoc() : SourceLocation(), DiscardedValue,
+ /*IsConstexpr=*/false, /*IsTemplateArgument=*/false,
+ /*PerformsCheckCompletedExpr=*/false);
+ }
ExprResult ActOnFinishFullExpr(Expr *Expr, SourceLocation CC,
bool DiscardedValue, bool IsConstexpr = false,
- bool IsTemplateArgument = false);
+ bool IsTemplateArgument = false,
+ bool PerformsCheckCompletedExpr = true);
StmtResult ActOnFinishFullStmt(Stmt *Stmt);
/// Process the expression contained within a decltype. For such expressions,
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index c5003d9ac0254..8d47602712d3a 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -9083,7 +9083,8 @@ Sema::CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl,
ExprResult Sema::ActOnFinishFullExpr(Expr *FE, SourceLocation CC,
bool DiscardedValue, bool IsConstexpr,
- bool IsTemplateArgument) {
+ bool IsTemplateArgument,
+ bool PerformsCheckCompletedExpr) {
ExprResult FullExpr = FE;
if (!FullExpr.get())
@@ -9117,7 +9118,8 @@ ExprResult Sema::ActOnFinishFullExpr(Expr *FE, SourceLocation CC,
if (FullExpr.isInvalid())
return ExprError();
- CheckCompletedExpr(FullExpr.get(), CC, IsConstexpr);
+ if (PerformsCheckCompletedExpr)
+ CheckCompletedExpr(FullExpr.get(), CC, IsConstexpr);
// At the end of this full expression (which could be a deeply nested
// lambda), if there is a potential capture within the nested lambda,
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index cecb80f8fb7fd..87a5457664fd1 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -9758,7 +9758,11 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
LastIteration.get(), UB.get());
EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(),
CondOp.get());
- EUB = SemaRef.ActOnFinishFullExpr(EUB.get(), /*DiscardedValue*/ false);
+ EUB =
+ isOpenMPTaskLoopDirective(DKind)
+ ? SemaRef.ActOnFinishFullExprNoCheckExpr(EUB.get(),
+ /*DiscardedValue*/ false)
+ : SemaRef.ActOnFinishFullExpr(EUB.get(), /*DiscardedValue*/ false);
// If we have a combined directive that combines 'distribute', 'for' or
// 'simd' we need to be able to access the bounds of the schedule of the
@@ -9788,7 +9792,11 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
CombEUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, CombUB.get(),
CombCondOp.get());
CombEUB =
- SemaRef.ActOnFinishFullExpr(CombEUB.get(), /*DiscardedValue*/ false);
+ isOpenMPTaskLoopDirective(DKind)
+ ? SemaRef.ActOnFinishFullExprNoCheckExpr(CombEUB.get(),
+ /*DiscardedValue*/ false)
+ : SemaRef.ActOnFinishFullExpr(CombEUB.get(),
+ /*DiscardedValue*/ false);
const CapturedDecl *CD = cast<CapturedStmt>(AStmt)->getCapturedDecl();
// We expect to have at least 2 more parameters than the 'parallel'
@@ -9857,7 +9865,13 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get())
.get();
BoundUB =
- SemaRef.ActOnFinishFullExpr(BoundUB, /*DiscardedValue*/ false).get();
+ isOpenMPTaskLoopDirective(DKind)
+ ? SemaRef
+ .ActOnFinishFullExprNoCheckExpr(BoundUB,
+ /*DiscardedValue*/ false)
+ .get()
+ : SemaRef.ActOnFinishFullExpr(BoundUB, /*DiscardedValue*/ false)
+ .get();
}
ExprResult Cond =
(isOpenMPWorksharingDirective(DKind) ||
@@ -9886,8 +9900,14 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get())
.get();
BoundCombUB =
- SemaRef.ActOnFinishFullExpr(BoundCombUB, /*DiscardedValue*/ false)
- .get();
+ isOpenMPTaskLoopDirective(DKind)
+ ? SemaRef
+ .ActOnFinishFullExprNoCheckExpr(BoundCombUB,
+ /*DiscardedValue*/ false)
+ .get()
+ : SemaRef
+ .ActOnFinishFullExpr(BoundCombUB, /*DiscardedValue*/ false)
+ .get();
}
CombCond =
SemaRef.BuildBinOp(CurScope, CondLoc, UseStrictCompare ? BO_LT : BO_LE,
@@ -9922,7 +9942,11 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
NextLB =
SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get());
NextLB =
- SemaRef.ActOnFinishFullExpr(NextLB.get(), /*DiscardedValue*/ false);
+ isOpenMPTaskLoopDirective(DKind)
+ ? SemaRef.ActOnFinishFullExprNoCheckExpr(NextLB.get(),
+ /*DiscardedValue*/ false)
+ : SemaRef.ActOnFinishFullExpr(NextLB.get(),
+ /*DiscardedValue*/ false);
if (!NextLB.isUsable())
return 0;
// UB + ST
@@ -9933,7 +9957,11 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
NextUB =
SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get());
NextUB =
- SemaRef.ActOnFinishFullExpr(NextUB.get(), /*DiscardedValue*/ false);
+ isOpenMPTaskLoopDirective(DKind)
+ ? SemaRef.ActOnFinishFullExprNoCheckExpr(NextUB.get(),
+ /*DiscardedValue*/ false)
+ : SemaRef.ActOnFinishFullExpr(NextUB.get(),
+ /*DiscardedValue*/ false);
if (!NextUB.isUsable())
return 0;
if (isOpenMPLoopBoundSharingDirective(DKind)) {
@@ -9944,8 +9972,12 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
// LB = LB + ST
CombNextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, CombLB.get(),
CombNextLB.get());
- CombNextLB = SemaRef.ActOnFinishFullExpr(CombNextLB.get(),
- /*DiscardedValue*/ false);
+ CombNextLB =
+ isOpenMPTaskLoopDirective(DKind)
+ ? SemaRef.ActOnFinishFullExprNoCheckExpr(CombNextLB.get(),
+ /*DiscardedValue*/ false)
+ : SemaRef.ActOnFinishFullExpr(CombNextLB.get(),
+ /*DiscardedValue*/ false);
if (!CombNextLB.isUsable())
return 0;
// UB + ST
@@ -9956,8 +9988,12 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
// UB = UB + ST
CombNextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, CombUB.get(),
CombNextUB.get());
- CombNextUB = SemaRef.ActOnFinishFullExpr(CombNextUB.get(),
- /*DiscardedValue*/ false);
+ CombNextUB =
+ isOpenMPTaskLoopDirective(DKind)
+ ? SemaRef.ActOnFinishFullExprNoCheckExpr(CombNextUB.get(),
+ /*DiscardedValue*/ false)
+ : SemaRef.ActOnFinishFullExpr(CombNextUB.get(),
+ /*DiscardedValue*/ false);
if (!CombNextUB.isUsable())
return 0;
}
@@ -10003,7 +10039,11 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
PrevEUB = SemaRef.BuildBinOp(CurScope, DistIncLoc, BO_Assign, UB.get(),
CondOp.get());
PrevEUB =
- SemaRef.ActOnFinishFullExpr(PrevEUB.get(), /*DiscardedValue*/ false);
+ isOpenMPTaskLoopDirective(DKind)
+ ? SemaRef.ActOnFinishFullExprNoCheckExpr(PrevEUB.get(),
+ /*DiscardedValue*/ false)
+ : SemaRef.ActOnFinishFullExpr(PrevEUB.get(),
+ /*DiscardedValue*/ false);
// Build IV <= PrevUB or IV < PrevUB + 1 for unsigned IV to be used in
// parallel for is in combination with a distribute directive with
@@ -10016,9 +10056,15 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
CurScope, CondLoc, BO_Add, BoundPrevUB,
SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get())
.get();
- BoundPrevUB =
- SemaRef.ActOnFinishFullExpr(BoundPrevUB, /*DiscardedValue*/ false)
- .get();
+ BoundPrevUB = isOpenMPTaskLoopDirective(DKind)
+ ? SemaRef
+ .ActOnFinishFullExprNoCheckExpr(
+ BoundPrevUB, /*DiscardedValue*/ false)
+ .get()
+ : SemaRef
+ .ActOnFinishFullExpr(BoundPrevUB,
+ /*DiscardedValue*/ false)
+ .get();
}
ParForInDistCond =
SemaRef.BuildBinOp(CurScope, CondLoc, UseStrictCompare ? BO_LT : BO_LE,
>From b105b392c4afe01c242c42054b1e0de8a74d9706 Mon Sep 17 00:00:00 2001
From: HenryZ16 <1546169856 at qq.com>
Date: Mon, 5 Aug 2024 20:25:04 -0600
Subject: [PATCH 2/2] Revert "fix issue: [Clang][OpenMP] Implicit conversion
with `pragma omp taskloop` #100536"
This reverts commit 217b910739f6bbc392cbb98f34fdd785bca2f57e.
---
clang/include/clang/Sema/Sema.h | 9 +---
clang/lib/Sema/SemaExprCXX.cpp | 6 +--
clang/lib/Sema/SemaOpenMP.cpp | 76 +++++++--------------------------
3 files changed, 18 insertions(+), 73 deletions(-)
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c62919cb13962..2ec6367eccea0 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8279,16 +8279,9 @@ class Sema final : public SemaBase {
return ActOnFinishFullExpr(
Expr, Expr ? Expr->getExprLoc() : SourceLocation(), DiscardedValue);
}
- ExprResult ActOnFinishFullExprNoCheckExpr(Expr *Expr, bool DiscardedValue) {
- return ActOnFinishFullExpr(
- Expr, Expr ? Expr->getExprLoc() : SourceLocation(), DiscardedValue,
- /*IsConstexpr=*/false, /*IsTemplateArgument=*/false,
- /*PerformsCheckCompletedExpr=*/false);
- }
ExprResult ActOnFinishFullExpr(Expr *Expr, SourceLocation CC,
bool DiscardedValue, bool IsConstexpr = false,
- bool IsTemplateArgument = false,
- bool PerformsCheckCompletedExpr = true);
+ bool IsTemplateArgument = false);
StmtResult ActOnFinishFullStmt(Stmt *Stmt);
/// Process the expression contained within a decltype. For such expressions,
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 8d47602712d3a..c5003d9ac0254 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -9083,8 +9083,7 @@ Sema::CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl,
ExprResult Sema::ActOnFinishFullExpr(Expr *FE, SourceLocation CC,
bool DiscardedValue, bool IsConstexpr,
- bool IsTemplateArgument,
- bool PerformsCheckCompletedExpr) {
+ bool IsTemplateArgument) {
ExprResult FullExpr = FE;
if (!FullExpr.get())
@@ -9118,8 +9117,7 @@ ExprResult Sema::ActOnFinishFullExpr(Expr *FE, SourceLocation CC,
if (FullExpr.isInvalid())
return ExprError();
- if (PerformsCheckCompletedExpr)
- CheckCompletedExpr(FullExpr.get(), CC, IsConstexpr);
+ CheckCompletedExpr(FullExpr.get(), CC, IsConstexpr);
// At the end of this full expression (which could be a deeply nested
// lambda), if there is a potential capture within the nested lambda,
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 87a5457664fd1..cecb80f8fb7fd 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -9758,11 +9758,7 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
LastIteration.get(), UB.get());
EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(),
CondOp.get());
- EUB =
- isOpenMPTaskLoopDirective(DKind)
- ? SemaRef.ActOnFinishFullExprNoCheckExpr(EUB.get(),
- /*DiscardedValue*/ false)
- : SemaRef.ActOnFinishFullExpr(EUB.get(), /*DiscardedValue*/ false);
+ EUB = SemaRef.ActOnFinishFullExpr(EUB.get(), /*DiscardedValue*/ false);
// If we have a combined directive that combines 'distribute', 'for' or
// 'simd' we need to be able to access the bounds of the schedule of the
@@ -9792,11 +9788,7 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
CombEUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, CombUB.get(),
CombCondOp.get());
CombEUB =
- isOpenMPTaskLoopDirective(DKind)
- ? SemaRef.ActOnFinishFullExprNoCheckExpr(CombEUB.get(),
- /*DiscardedValue*/ false)
- : SemaRef.ActOnFinishFullExpr(CombEUB.get(),
- /*DiscardedValue*/ false);
+ SemaRef.ActOnFinishFullExpr(CombEUB.get(), /*DiscardedValue*/ false);
const CapturedDecl *CD = cast<CapturedStmt>(AStmt)->getCapturedDecl();
// We expect to have at least 2 more parameters than the 'parallel'
@@ -9865,13 +9857,7 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get())
.get();
BoundUB =
- isOpenMPTaskLoopDirective(DKind)
- ? SemaRef
- .ActOnFinishFullExprNoCheckExpr(BoundUB,
- /*DiscardedValue*/ false)
- .get()
- : SemaRef.ActOnFinishFullExpr(BoundUB, /*DiscardedValue*/ false)
- .get();
+ SemaRef.ActOnFinishFullExpr(BoundUB, /*DiscardedValue*/ false).get();
}
ExprResult Cond =
(isOpenMPWorksharingDirective(DKind) ||
@@ -9900,14 +9886,8 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get())
.get();
BoundCombUB =
- isOpenMPTaskLoopDirective(DKind)
- ? SemaRef
- .ActOnFinishFullExprNoCheckExpr(BoundCombUB,
- /*DiscardedValue*/ false)
- .get()
- : SemaRef
- .ActOnFinishFullExpr(BoundCombUB, /*DiscardedValue*/ false)
- .get();
+ SemaRef.ActOnFinishFullExpr(BoundCombUB, /*DiscardedValue*/ false)
+ .get();
}
CombCond =
SemaRef.BuildBinOp(CurScope, CondLoc, UseStrictCompare ? BO_LT : BO_LE,
@@ -9942,11 +9922,7 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
NextLB =
SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get());
NextLB =
- isOpenMPTaskLoopDirective(DKind)
- ? SemaRef.ActOnFinishFullExprNoCheckExpr(NextLB.get(),
- /*DiscardedValue*/ false)
- : SemaRef.ActOnFinishFullExpr(NextLB.get(),
- /*DiscardedValue*/ false);
+ SemaRef.ActOnFinishFullExpr(NextLB.get(), /*DiscardedValue*/ false);
if (!NextLB.isUsable())
return 0;
// UB + ST
@@ -9957,11 +9933,7 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
NextUB =
SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get());
NextUB =
- isOpenMPTaskLoopDirective(DKind)
- ? SemaRef.ActOnFinishFullExprNoCheckExpr(NextUB.get(),
- /*DiscardedValue*/ false)
- : SemaRef.ActOnFinishFullExpr(NextUB.get(),
- /*DiscardedValue*/ false);
+ SemaRef.ActOnFinishFullExpr(NextUB.get(), /*DiscardedValue*/ false);
if (!NextUB.isUsable())
return 0;
if (isOpenMPLoopBoundSharingDirective(DKind)) {
@@ -9972,12 +9944,8 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
// LB = LB + ST
CombNextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, CombLB.get(),
CombNextLB.get());
- CombNextLB =
- isOpenMPTaskLoopDirective(DKind)
- ? SemaRef.ActOnFinishFullExprNoCheckExpr(CombNextLB.get(),
- /*DiscardedValue*/ false)
- : SemaRef.ActOnFinishFullExpr(CombNextLB.get(),
- /*DiscardedValue*/ false);
+ CombNextLB = SemaRef.ActOnFinishFullExpr(CombNextLB.get(),
+ /*DiscardedValue*/ false);
if (!CombNextLB.isUsable())
return 0;
// UB + ST
@@ -9988,12 +9956,8 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
// UB = UB + ST
CombNextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, CombUB.get(),
CombNextUB.get());
- CombNextUB =
- isOpenMPTaskLoopDirective(DKind)
- ? SemaRef.ActOnFinishFullExprNoCheckExpr(CombNextUB.get(),
- /*DiscardedValue*/ false)
- : SemaRef.ActOnFinishFullExpr(CombNextUB.get(),
- /*DiscardedValue*/ false);
+ CombNextUB = SemaRef.ActOnFinishFullExpr(CombNextUB.get(),
+ /*DiscardedValue*/ false);
if (!CombNextUB.isUsable())
return 0;
}
@@ -10039,11 +10003,7 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
PrevEUB = SemaRef.BuildBinOp(CurScope, DistIncLoc, BO_Assign, UB.get(),
CondOp.get());
PrevEUB =
- isOpenMPTaskLoopDirective(DKind)
- ? SemaRef.ActOnFinishFullExprNoCheckExpr(PrevEUB.get(),
- /*DiscardedValue*/ false)
- : SemaRef.ActOnFinishFullExpr(PrevEUB.get(),
- /*DiscardedValue*/ false);
+ SemaRef.ActOnFinishFullExpr(PrevEUB.get(), /*DiscardedValue*/ false);
// Build IV <= PrevUB or IV < PrevUB + 1 for unsigned IV to be used in
// parallel for is in combination with a distribute directive with
@@ -10056,15 +10016,9 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
CurScope, CondLoc, BO_Add, BoundPrevUB,
SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get())
.get();
- BoundPrevUB = isOpenMPTaskLoopDirective(DKind)
- ? SemaRef
- .ActOnFinishFullExprNoCheckExpr(
- BoundPrevUB, /*DiscardedValue*/ false)
- .get()
- : SemaRef
- .ActOnFinishFullExpr(BoundPrevUB,
- /*DiscardedValue*/ false)
- .get();
+ BoundPrevUB =
+ SemaRef.ActOnFinishFullExpr(BoundPrevUB, /*DiscardedValue*/ false)
+ .get();
}
ParForInDistCond =
SemaRef.BuildBinOp(CurScope, CondLoc, UseStrictCompare ? BO_LT : BO_LE,
More information about the cfe-commits
mailing list