[clang] Revert "[Clang][OpenMP] Allow array shaping as the base of array sections in target update" (PR #246790)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 27 19:02:15 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: theRonShark (ronlieb)
<details>
<summary>Changes</summary>
Reverts llvm/llvm-project#<!-- -->244591
asserts on test case attached in : https://github.com/llvm/llvm-project/pull/244591
---
Patch is 429.37 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/246790.diff
19 Files Affected:
- (modified) clang/docs/ReleaseNotes.md (-2)
- (modified) clang/include/clang/AST/ExprOpenMP.h (+4-15)
- (modified) clang/lib/AST/Expr.cpp (+19-23)
- (modified) clang/lib/AST/OpenMPClause.cpp (+8-16)
- (modified) clang/lib/CodeGen/CGExpr.cpp (-16)
- (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+14-60)
- (modified) clang/lib/Sema/SemaExpr.cpp (-8)
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+40-141)
- (modified) clang/lib/Serialization/ASTReaderStmt.cpp (-1)
- (modified) clang/lib/Serialization/ASTWriterStmt.cpp (-1)
- (removed) clang/test/OpenMP/GH136294.c (-364)
- (modified) clang/test/OpenMP/target_map_messages.cpp (-8)
- (modified) clang/test/OpenMP/target_update_ast_print.cpp (-9)
- (modified) clang/test/OpenMP/target_update_codegen.cpp (-43)
- (modified) clang/test/OpenMP/target_update_from_messages.cpp (+7-53)
- (modified) clang/test/OpenMP/target_update_to_messages.cpp (+8-55)
- (modified) clang/test/OpenMP/task_codegen.cpp (+1617-1626)
- (modified) clang/test/SemaOpenMP/arm-sve-acle-types.cpp (+1-6)
- (modified) clang/test/SemaOpenMP/riscv-vector-with-openmp.c (+2-5)
``````````diff
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 9199647b8e78d1..6bbc910d86b5aa 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -1815,8 +1815,6 @@ The `alpha.cplusplus.UseAfterLifetimeEnd` checker was renamed to `alpha.core.Use
this release.
- Added parsing and semantic support for `dims` modifier in `num_teams`,
`thread_limit` and `num_threads` clauses for OpenMP 6.1 or later.
-- Array shaping expressions can now be the base of array sections in the `to`
- and `from` clauses of `target update`. (#GH136294)
- Map-type-modifying modifiers applied to a list item with a user-defined mapper
are now propagated onto the maps the mapper expands to.
- Mapping of expressions with base-pointers through a user-defined mapper (e.g.
diff --git a/clang/include/clang/AST/ExprOpenMP.h b/clang/include/clang/AST/ExprOpenMP.h
index 322f4d9e5572a4..4d3c5f54ad7dde 100644
--- a/clang/include/clang/AST/ExprOpenMP.h
+++ b/clang/include/clang/AST/ExprOpenMP.h
@@ -29,13 +29,10 @@ class OMPArrayShapingExpr final
SourceLocation LPLoc; /// The location of the left paren
SourceLocation RPLoc; /// The location of the right paren
unsigned NumDims = 0; /// Number of dimensions in the shaping expression.
- /// The n-dimensional array type designated by the shaping operation.
- QualType ShapedType;
/// Construct full expression.
- OMPArrayShapingExpr(QualType ExprTy, QualType ShapedTy, Expr *Op,
- SourceLocation L, SourceLocation R,
- ArrayRef<Expr *> Dims);
+ OMPArrayShapingExpr(QualType ExprTy, Expr *Op, SourceLocation L,
+ SourceLocation R, ArrayRef<Expr *> Dims);
/// Construct an empty expression.
explicit OMPArrayShapingExpr(EmptyShell Shell, unsigned NumDims)
@@ -50,9 +47,6 @@ class OMPArrayShapingExpr final
/// Sets source ranges for the brackets in the array shaping operation.
void setBracketsRanges(ArrayRef<SourceRange> BR);
- /// Sets the array type designated by the array shaping operation.
- void setShapedType(QualType T) { ShapedType = T; }
-
unsigned numTrailingObjects(OverloadToken<Expr *>) const {
// Add an extra one for the base expression.
return NumDims + 1;
@@ -64,9 +58,8 @@ class OMPArrayShapingExpr final
public:
static OMPArrayShapingExpr *Create(const ASTContext &Context, QualType T,
- QualType ShapedTy, Expr *Op,
- SourceLocation L, SourceLocation R,
- ArrayRef<Expr *> Dims,
+ Expr *Op, SourceLocation L,
+ SourceLocation R, ArrayRef<Expr *> Dims,
ArrayRef<SourceRange> BracketRanges);
static OMPArrayShapingExpr *CreateEmpty(const ASTContext &Context,
@@ -97,10 +90,6 @@ class OMPArrayShapingExpr final
Expr *getBase() { return getTrailingObjects<Expr *>()[NumDims]; }
const Expr *getBase() const { return getTrailingObjects<Expr *>()[NumDims]; }
- /// Returns the n-dimensional array type designated by the shaping operation
- /// (OpenMP 5.0 [2.1.4]); array sections based on this expression index it.
- QualType getShapedType() const { return ShapedType; }
-
static bool classof(const Stmt *T) {
return T->getStmtClass() == OMPArrayShapingExprClass;
}
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 0e6f9ec24d25ea..1ba2ccdf697f9d 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -5451,15 +5451,10 @@ QualType ArraySectionExpr::getBaseOriginalType(const Expr *Base) {
++ArraySectionCount;
}
Base = Base->IgnoreParenImpCasts();
- QualType OriginalTy;
- if (const auto *OAShE = dyn_cast<OMPArrayShapingExpr>(Base)) {
- OriginalTy = OAShE->getShapedType();
- } else {
- OriginalTy = Base->getType();
- if (auto *DRE = dyn_cast<DeclRefExpr>(Base))
- if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl()))
- OriginalTy = PVD->getOriginalType().getNonReferenceType();
- }
+ auto OriginalTy = Base->getType();
+ if (auto *DRE = dyn_cast<DeclRefExpr>(Base))
+ if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl()))
+ OriginalTy = PVD->getOriginalType().getNonReferenceType();
for (unsigned Cnt = 0; Cnt < ArraySectionCount; ++Cnt) {
if (OriginalTy->isAnyPointerType())
@@ -5473,7 +5468,12 @@ QualType ArraySectionExpr::getBaseOriginalType(const Expr *Base) {
}
QualType ArraySectionExpr::getElementType() const {
- QualType BaseTy = getBaseType();
+ QualType BaseTy = getBase()->IgnoreParenImpCasts()->getType();
+ // We only have to look into the array section exprs, else we will get the
+ // type of the base, which should already be valid.
+ if (auto *ASE = dyn_cast<ArraySectionExpr>(getBase()->IgnoreParenImpCasts()))
+ BaseTy = ASE->getElementType();
+
if (BaseTy->isAnyPointerType())
return BaseTy->getPointeeType();
if (BaseTy->isArrayType())
@@ -5486,15 +5486,12 @@ QualType ArraySectionExpr::getElementType() const {
}
QualType ArraySectionExpr::getBaseType() const {
- const Expr *Base = getBase()->IgnoreParenImpCasts();
// We only have to look into the array section exprs, else we will get the
// type of the base, which should already be valid.
- if (const auto *ASE = dyn_cast<ArraySectionExpr>(Base))
+ if (auto *ASE = dyn_cast<ArraySectionExpr>(getBase()->IgnoreParenImpCasts()))
return ASE->getElementType();
- if (const auto *OAShE = dyn_cast<OMPArrayShapingExpr>(Base))
- return OAShE->getShapedType();
- return Base->getType();
+ return getBase()->IgnoreParenImpCasts()->getType();
}
RecoveryExpr::RecoveryExpr(ASTContext &Ctx, QualType T, SourceLocation BeginLoc,
@@ -5539,28 +5536,27 @@ void OMPArrayShapingExpr::setBracketsRanges(ArrayRef<SourceRange> BR) {
llvm::copy(BR, getTrailingObjects<SourceRange>());
}
-OMPArrayShapingExpr::OMPArrayShapingExpr(QualType ExprTy, QualType ShapedTy,
- Expr *Op, SourceLocation L,
- SourceLocation R,
+OMPArrayShapingExpr::OMPArrayShapingExpr(QualType ExprTy, Expr *Op,
+ SourceLocation L, SourceLocation R,
ArrayRef<Expr *> Dims)
: Expr(OMPArrayShapingExprClass, ExprTy, VK_LValue, OK_Ordinary), LPLoc(L),
- RPLoc(R), NumDims(Dims.size()), ShapedType(ShapedTy) {
+ RPLoc(R), NumDims(Dims.size()) {
setBase(Op);
setDimensions(Dims);
setDependence(computeDependence(this));
}
OMPArrayShapingExpr *
-OMPArrayShapingExpr::Create(const ASTContext &Context, QualType T,
- QualType ShapedTy, Expr *Op, SourceLocation L,
- SourceLocation R, ArrayRef<Expr *> Dims,
+OMPArrayShapingExpr::Create(const ASTContext &Context, QualType T, Expr *Op,
+ SourceLocation L, SourceLocation R,
+ ArrayRef<Expr *> Dims,
ArrayRef<SourceRange> BracketRanges) {
assert(Dims.size() == BracketRanges.size() &&
"Different number of dimensions and brackets ranges.");
void *Mem = Context.Allocate(
totalSizeToAlloc<Expr *, SourceRange>(Dims.size() + 1, Dims.size()),
alignof(OMPArrayShapingExpr));
- auto *E = new (Mem) OMPArrayShapingExpr(T, ShapedTy, Op, L, R, Dims);
+ auto *E = new (Mem) OMPArrayShapingExpr(T, Op, L, R, Dims);
E->setBracketsRanges(BracketRanges);
return E;
}
diff --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp
index b6a725628334dc..f0102720f7d33b 100644
--- a/clang/lib/AST/OpenMPClause.cpp
+++ b/clang/lib/AST/OpenMPClause.cpp
@@ -1180,34 +1180,26 @@ OMPClauseMappableExprCommon::findAttachPtrExpr(
// Only check for non-contiguous sections on target_update, since we can
// assume array-sections are contiguous on maps on other constructs, even if
- // we are not sure of it at compile-time, like for a[1:x][2]. For a shaped
- // non-contiguous section, only look past the shaping expression for the
- // shaped base pointer itself.
- size_t StartIdx = 1;
- if (Components.back().isNonContiguous() && CurDirKind == OMPD_target_update) {
- auto It = llvm::find_if(Components, [](const MappableComponent &Component) {
- return isa<OMPArrayShapingExpr>(Component.getAssociatedExpression());
- });
- if (It == Components.end())
- return {nullptr, std::nullopt};
- StartIdx = std::distance(Components.begin(), It) + 1;
- }
+ // we are not sure of it at compile-time, like for a[1:x][2].
+ if (Components.back().isNonContiguous() && CurDirKind == OMPD_target_update)
+ return {nullptr, std::nullopt};
// To find the attach base-pointer, we start with the second component,
// stripping away one component at a time, until we reach a pointer Expr
// (that is not a binary operator). The first such pointer should be the
// attach base-pointer for the component list.
for (auto [I, Component] : llvm::enumerate(Components)) {
- if (I < StartIdx)
+ // Skip past the first component.
+ if (I == 0)
continue;
const Expr *CurExpr = Component.getAssociatedExpression();
if (!CurExpr)
break;
- // If CurExpr is something like `p + 10` or `([n])p`, we need to ignore it,
- // since we are looking for `p`.
- if (isa<BinaryOperator, OMPArrayShapingExpr>(CurExpr))
+ // If CurExpr is something like `p + 10`, we need to ignore it, since
+ // we are looking for `p`.
+ if (isa<BinaryOperator>(CurExpr))
continue;
// Keep going until we reach an Expr of pointer type.
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index c66817faf7d1d0..64419f5d62519f 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5492,22 +5492,6 @@ static Address emitOMPArraySectionBase(CodeGenFunction &CGF, const Expr *Base,
return Address(CGF.Builder.CreateLoad(BaseLVal.getAddress()),
CGF.ConvertTypeForMem(ElTy), Align);
}
- if (auto *OAShE =
- dyn_cast<OMPArrayShapingExpr>(Base->IgnoreParenImpCasts())) {
- // The shaped pointer is the address of the array; capture the variable
- // dimensions of the shape first.
- QualType ShapedTy = OAShE->getShapedType();
- if (ShapedTy->isVariablyModifiedType())
- CGF.EmitVariablyModifiedType(ShapedTy);
- LValueBaseInfo TypeBaseInfo;
- TBAAAccessInfo TypeTBAAInfo;
- CharUnits Align =
- CGF.CGM.getNaturalTypeAlignment(ElTy, &TypeBaseInfo, &TypeTBAAInfo);
- BaseInfo.mergeForCast(TypeBaseInfo);
- TBAAInfo = CGF.CGM.mergeTBAAInfoForCast(TBAAInfo, TypeTBAAInfo);
- return Address(CGF.EmitScalarExpr(OAShE->getBase()),
- CGF.ConvertTypeForMem(ElTy), Align);
- }
return CGF.EmitPointerWithAlignment(Base, &BaseInfo, &TBAAInfo);
}
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index b828b63592cddd..855a69d208fb0d 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -3962,17 +3962,9 @@ getPointerAndSize(CodeGenFunction &CGF, const Expr *E) {
dyn_cast<ArraySectionExpr>(E->IgnoreParenImpCasts())) {
LValue UpAddrLVal = CGF.EmitArraySectionExpr(ASE, /*IsLowerBound=*/false);
Address UpAddrAddress = UpAddrLVal.getAddress();
- llvm::Value *UpAddr;
- // The address holds the innermost element of a variable length array
- // element; step over the whole element, whose size is a run time value.
- if (UpAddrLVal.getType()->isVariableArrayType())
- UpAddr =
- CGF.Builder.CreateGEP(CGF.Int8Ty, UpAddrAddress.emitRawPointer(CGF),
- CGF.getTypeSize(UpAddrLVal.getType()));
- else
- UpAddr = CGF.Builder.CreateConstGEP1_32(UpAddrAddress.getElementType(),
- UpAddrAddress.emitRawPointer(CGF),
- /*Idx0=*/1);
+ llvm::Value *UpAddr = CGF.Builder.CreateConstGEP1_32(
+ UpAddrAddress.getElementType(), UpAddrAddress.emitRawPointer(CGF),
+ /*Idx0=*/1);
SizeVal = CGF.Builder.CreatePtrDiff(UpAddr, Addr, "", /*IsNUW=*/true);
} else {
SizeVal = CGF.getTypeSize(Ty);
@@ -8492,24 +8484,8 @@ class MappableExprsHandler {
dyn_cast<OMPArrayShapingExpr>(I->getAssociatedExpression());
const auto *UO = dyn_cast<UnaryOperator>(I->getAssociatedExpression());
const auto *BO = dyn_cast<BinaryOperator>(I->getAssociatedExpression());
- // A non-contiguous section of a shaped array is based on the shaped
- // pointer. The attach pointer provides it, except after pointer
- // arithmetic (e.g. `([n])(p + 10)`), which the attach pointer skips.
- if (OAShE && Next != CE && IsNonContiguous) {
- if (!BP.isValid() ||
- isa<BinaryOperator>(OAShE->getBase()->IgnoreParenImpCasts()))
- BP = Address(CGF.EmitScalarExpr(OAShE->getBase()),
- CGF.ConvertTypeForMem(
- OAShE->getBase()->getType()->getPointeeType()),
- CGF.getContext().getTypeAlignInChars(
- OAShE->getBase()->getType()));
- continue;
- }
- // An array shaping expression maps the shaped storage only as the whole
- // list item; as the base of array sections it just reinterprets the
- // pointer.
bool IsPointer =
- (OAShE && Next == CE) ||
+ OAShE ||
(OASE && ArraySectionExpr::getBaseOriginalType(OASE)
.getCanonicalType()
->isAnyPointerType()) ||
@@ -8804,33 +8780,13 @@ class MappableExprsHandler {
MapValuesArrayTy CurCounts;
MapValuesArrayTy CurStrides = {llvm::ConstantInt::get(CGF.CGM.Int64Ty, 1)};
MapValuesArrayTy DimSizes{llvm::ConstantInt::get(CGF.CGM.Int64Ty, 1)};
- llvm::Value *ElementTypeSize = nullptr;
-
- // The attach pointer or the array shaping expression and everything past
- // it belong to the base, not to dimensions of the sectioned array.
- auto ArrayDimsEnd = llvm::find_if(
- Components,
- [AttachPtrExpr](
- const OMPClauseMappableExprCommon::MappableComponent &Component) {
- const Expr *E = Component.getAssociatedExpression();
- return (AttachPtrExpr && E == AttachPtrExpr) ||
- isa<OMPArrayShapingExpr>(E);
- });
- auto ArrayDimComponents =
- llvm::make_range(Components.begin(), ArrayDimsEnd);
- // Only array sections and subscripts add a dimension.
- unsigned NumArrayDims = llvm::count_if(
- ArrayDimComponents,
- [](const OMPClauseMappableExprCommon::MappableComponent &Component) {
- return isa<ArraySectionExpr, ArraySubscriptExpr>(
- Component.getAssociatedExpression());
- });
+ uint64_t ElementTypeSize;
// Collect Size information for each dimension and get the element size as
// the first Stride. For example, for `int arr[10][10]`, the DimSizes
// should be [10, 10] and the first stride is 4 btyes.
for (const OMPClauseMappableExprCommon::MappableComponent &Component :
- ArrayDimComponents) {
+ Components) {
const Expr *AssocExpr = Component.getAssociatedExpression();
const auto *OASE = dyn_cast<ArraySectionExpr>(AssocExpr);
@@ -8877,17 +8833,15 @@ class MappableExprsHandler {
// level of indirection.
if (&Component != &*Components.begin())
ElementType = ElementType->getPointeeOrArrayElementType();
- // The element may be a variable length array (a section of fewer
- // dimensions than the array), whose size is a run time value.
- ElementTypeSize = CGF.Builder.CreateIntCast(
- CGF.getTypeSize(QualType(ElementType, 0)), CGF.Int64Ty,
- /*isSigned=*/false);
- CurCounts.push_back(ElementTypeSize);
+ ElementTypeSize =
+ Context.getTypeSizeInChars(ElementType).getQuantity();
+ CurCounts.push_back(
+ llvm::ConstantInt::get(CGF.Int64Ty, ElementTypeSize));
}
}
// Get dimension value except for the last dimension since we don't need
// it.
- if (DimSizes.size() < NumArrayDims) {
+ if (DimSizes.size() < Components.size() - 1) {
if (CAT)
DimSizes.push_back(
llvm::ConstantInt::get(CGF.Int64Ty, CAT->getZExtSize()));
@@ -8901,8 +8855,8 @@ class MappableExprsHandler {
// Skip the dummy dimension since we have already have its information.
auto *DI = DimSizes.begin() + 1;
// Product of dimension.
- assert(ElementTypeSize && "Element size of the section is not known");
- llvm::Value *DimProd = ElementTypeSize;
+ llvm::Value *DimProd =
+ llvm::ConstantInt::get(CGF.CGM.Int64Ty, ElementTypeSize);
// Collect info for non-contiguous. Notice that offset, count, and stride
// are only meaningful for array-section, so we insert a null for anything
@@ -8912,7 +8866,7 @@ class MappableExprsHandler {
// count, and stride are the same as the number of non-contiguous
// declaration in target update to/from clause.
for (const OMPClauseMappableExprCommon::MappableComponent &Component :
- ArrayDimComponents) {
+ Components) {
const Expr *AssocExpr = Component.getAssociatedExpression();
if (const auto *AE = dyn_cast<ArraySubscriptExpr>(AssocExpr)) {
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 02fa1d8be333ef..bc3f6444b88bae 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5212,14 +5212,6 @@ ExprResult Sema::ActOnArraySubscriptExpr(Scope *S, Expr *base,
rbLoc);
}
- // A subscript of an OpenMP array shaping expression is a single-element
- // array section.
- if (base && !base->getType().isNull() && ArgExprs.size() == 1 &&
- base->hasPlaceholderType(BuiltinType::OMPArrayShaping))
- return OpenMP().ActOnOMPArraySectionExpr(
- base, lbLoc, ArgExprs.front(), SourceLocation(), SourceLocation(),
- /*Length=*/nullptr, /*Stride=*/nullptr, rbLoc);
-
// Since this might be a postfix expression, get rid of ParenListExprs.
if (isa<ParenListExpr>(base)) {
ExprResult result = MaybeConvertParenListExprToParenExpr(S, base);
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 484cf4ed3973fc..063d18843e45f5 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -140,11 +140,11 @@ class DSAStackTy {
using LCDeclInfo = std::pair<unsigned, VarDecl *>;
using LoopControlVariablesMapTy =
llvm::SmallDenseMap<const ValueDecl *, LCDeclInfo, 8>;
- /// Struct that associates component lists with the clause kinds where they
- /// are found.
+ /// Struct that associates a component with the clause kind where they are
+ /// found.
struct MappedExprComponentTy {
OMPClauseMappableExprCommon::MappableExprComponentLists Components;
- SmallVector<OpenMPClauseKind, 8> Kinds;
+ OpenMPClauseKind Kind = OMPC_unknown;
};
using MappedExprComponentsTy =
llvm::DenseMap<const ValueDecl *, MappedExprComponentTy>;
@@ -1083,9 +1083,9 @@ class DSAStackTy {
for (; SI != SE; ++SI) {
auto MI = SI->MappedExprComponents.find(VD);
if (MI != SI->MappedExprComponents.end())
- for (auto [L, K] :
- llvm::zip_equal(MI->second.Components, MI->second.Kinds))
- if (Check(L, K))
+ for (OMPClauseMappableExprCommon::MappableExprComponentListRef L :
+ MI->second.Components)
+ if (Check(L, MI->second.Kind))
return true;
}
return false;
@@ -1105,9 +1105,9 @@ class DSAStackTy {
const SharingMapTy &StackElem = getStackElemAtLevel(Level);
auto MI = StackElem.MappedExprComponents.find(VD);
if (MI != StackElem.MappedExprComponents.end())
- for (auto [L, K] :
- llvm::zip_equal(MI->second.Components, MI->second.Kinds))
- if (Check(L, K))
+ for (OMPClauseMappableExprCommon::MappableExprComponentListRef L :
+ MI->second.Components)
+ if (Check(L, MI->second.Kind))
...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/246790
More information about the cfe-commits
mailing list