Skip to content

Commit 4174aa6

Browse files
committed
[𝘀𝗽𝗿] changes introduced through rebase
Created using spr 1.3.7 [skip ci]
2 parents 18bd65c + c5bd68c commit 4174aa6

File tree

68 files changed

+1636
-434
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1636
-434
lines changed

clang/include/clang/AST/OpenACCClause.h

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,7 @@ class OpenACCCreateClause final
12771277
};
12781278

12791279
// A structure to stand in for the recipe on a reduction. RecipeDecl is the
1280-
// 'main' declaration used for initializaiton, which is fixed.
1280+
// 'main' declaration used for initializaiton, which is fixed.
12811281
struct OpenACCReductionRecipe {
12821282
VarDecl *AllocaDecl;
12831283

@@ -1297,45 +1297,72 @@ struct OpenACCReductionRecipe {
12971297
// -For a struct without the operator, this will be 1 element per field, which
12981298
// should be the combiner for that element.
12991299
// -For an array of any of the above, it will be the above for the element.
1300-
llvm::SmallVector<CombinerRecipe, 1> CombinerRecipes;
1300+
// Note: These are necessarily stored in either Trailing Storage (when in the
1301+
// AST), or in a separate collection when being semantically analyzed.
1302+
llvm::ArrayRef<CombinerRecipe> CombinerRecipes;
13011303

13021304
OpenACCReductionRecipe(VarDecl *A, llvm::ArrayRef<CombinerRecipe> Combiners)
13031305
: AllocaDecl(A), CombinerRecipes(Combiners) {}
13041306

13051307
bool isSet() const { return AllocaDecl; }
1306-
static OpenACCReductionRecipe Empty() {
1307-
return OpenACCReductionRecipe(/*AllocaDecl=*/nullptr, {});
1308+
};
1309+
1310+
// A version of the above that is used for semantic analysis, at a time before
1311+
// the OpenACCReductionClause node has been created. This one has storage for
1312+
// the CombinerRecipe, since Trailing storage for it doesn't exist yet.
1313+
struct OpenACCReductionRecipeWithStorage : OpenACCReductionRecipe {
1314+
llvm::SmallVector<CombinerRecipe, 1> CombinerRecipeStorage;
1315+
1316+
OpenACCReductionRecipeWithStorage(VarDecl *A,
1317+
llvm::ArrayRef<CombinerRecipe> Combiners)
1318+
: OpenACCReductionRecipe(A, {}), CombinerRecipeStorage(Combiners) {
1319+
CombinerRecipes = CombinerRecipeStorage;
1320+
}
1321+
static OpenACCReductionRecipeWithStorage Empty() {
1322+
return OpenACCReductionRecipeWithStorage(/*AllocaDecl=*/nullptr, {});
13081323
}
13091324
};
13101325

13111326
class OpenACCReductionClause final
13121327
: public OpenACCClauseWithVarList,
13131328
private llvm::TrailingObjects<OpenACCReductionClause, Expr *,
1314-
OpenACCReductionRecipe> {
1329+
OpenACCReductionRecipe,
1330+
OpenACCReductionRecipe::CombinerRecipe> {
13151331
friend TrailingObjects;
13161332
OpenACCReductionOperator Op;
13171333

13181334
OpenACCReductionClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
13191335
OpenACCReductionOperator Operator,
13201336
ArrayRef<Expr *> VarList,
1321-
ArrayRef<OpenACCReductionRecipe> Recipes,
1337+
ArrayRef<OpenACCReductionRecipeWithStorage> Recipes,
13221338
SourceLocation EndLoc)
13231339
: OpenACCClauseWithVarList(OpenACCClauseKind::Reduction, BeginLoc,
13241340
LParenLoc, EndLoc),
13251341
Op(Operator) {
1326-
assert(VarList.size() == Recipes.size());
1342+
assert(VarList.size() == Recipes.size());
13271343
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
1328-
llvm::uninitialized_copy(Recipes,
1329-
getTrailingObjects<OpenACCReductionRecipe>());
1330-
}
13311344

1332-
public:
1333-
~OpenACCReductionClause() {
1334-
for (unsigned I = 0; I < getExprs().size(); ++I) {
1335-
getTrailingObjects<OpenACCReductionRecipe>()[I].~OpenACCReductionRecipe();
1345+
// Since we're using trailing storage on this node to store the 'combiner'
1346+
// recipes of the Reduction Recipes (which have a 1:M relationship), we need
1347+
// to ensure we get the ArrayRef of each of our combiner 'correct'.
1348+
OpenACCReductionRecipe::CombinerRecipe *CurCombinerLoc =
1349+
getTrailingObjects<OpenACCReductionRecipe::CombinerRecipe>();
1350+
for (const auto &[Idx, R] : llvm::enumerate(Recipes)) {
1351+
1352+
// ArrayRef to the 'correct' data location in trailing storage.
1353+
llvm::MutableArrayRef<OpenACCReductionRecipe::CombinerRecipe>
1354+
NewCombiners{CurCombinerLoc, R.CombinerRecipes.size()};
1355+
CurCombinerLoc += R.CombinerRecipes.size();
1356+
1357+
llvm::uninitialized_copy(R.CombinerRecipes, NewCombiners.begin());
1358+
1359+
// Placement new into the correct location in trailng storage.
1360+
new (&getTrailingObjects<OpenACCReductionRecipe>()[Idx])
1361+
OpenACCReductionRecipe(R.AllocaDecl, NewCombiners);
13361362
}
13371363
}
13381364

1365+
public:
13391366
static bool classof(const OpenACCClause *C) {
13401367
return C->getClauseKind() == OpenACCClauseKind::Reduction;
13411368
}
@@ -1353,13 +1380,17 @@ class OpenACCReductionClause final
13531380
static OpenACCReductionClause *
13541381
Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
13551382
OpenACCReductionOperator Operator, ArrayRef<Expr *> VarList,
1356-
ArrayRef<OpenACCReductionRecipe> Recipes, SourceLocation EndLoc);
1383+
ArrayRef<OpenACCReductionRecipeWithStorage> Recipes,
1384+
SourceLocation EndLoc);
13571385

13581386
OpenACCReductionOperator getReductionOp() const { return Op; }
13591387

13601388
size_t numTrailingObjects(OverloadToken<Expr *>) const {
13611389
return getExprs().size();
13621390
}
1391+
size_t numTrailingObjects(OverloadToken<OpenACCReductionRecipe>) const {
1392+
return getExprs().size();
1393+
}
13631394
};
13641395

13651396
class OpenACCLinkClause final

clang/include/clang/Sema/SemaHLSL.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ class SemaHLSL : public SemaBase {
215215
bool diagnosePositionType(QualType T, const ParsedAttr &AL);
216216

217217
bool CanPerformScalarCast(QualType SrcTy, QualType DestTy);
218-
bool ContainsBitField(QualType BaseTy);
219218
bool CanPerformElementwiseCast(Expr *Src, QualType DestType);
220219
bool CanPerformAggregateSplatCast(Expr *Src, QualType DestType);
221220
ExprResult ActOnOutParamExpr(ParmVarDecl *Param, Expr *Arg);

clang/include/clang/Sema/SemaOpenACC.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class SemaOpenACC : public SemaBase {
245245

246246
OpenACCPrivateRecipe CreatePrivateInitRecipe(const Expr *VarExpr);
247247
OpenACCFirstPrivateRecipe CreateFirstPrivateInitRecipe(const Expr *VarExpr);
248-
OpenACCReductionRecipe
248+
OpenACCReductionRecipeWithStorage
249249
CreateReductionInitRecipe(OpenACCReductionOperator ReductionOperator,
250250
const Expr *VarExpr);
251251

@@ -951,12 +951,14 @@ class SemaOpenACC : public SemaBase {
951951
ArrayRef<Expr *> IntExprs, SourceLocation EndLoc);
952952
// Does the checking for a 'reduction ' clause that needs to be done in
953953
// dependent and not dependent cases.
954-
OpenACCClause *CheckReductionClause(
955-
ArrayRef<const OpenACCClause *> ExistingClauses,
956-
OpenACCDirectiveKind DirectiveKind, SourceLocation BeginLoc,
957-
SourceLocation LParenLoc, OpenACCReductionOperator ReductionOp,
958-
ArrayRef<Expr *> Vars, ArrayRef<OpenACCReductionRecipe> Recipes,
959-
SourceLocation EndLoc);
954+
OpenACCClause *
955+
CheckReductionClause(ArrayRef<const OpenACCClause *> ExistingClauses,
956+
OpenACCDirectiveKind DirectiveKind,
957+
SourceLocation BeginLoc, SourceLocation LParenLoc,
958+
OpenACCReductionOperator ReductionOp,
959+
ArrayRef<Expr *> Vars,
960+
ArrayRef<OpenACCReductionRecipeWithStorage> Recipes,
961+
SourceLocation EndLoc);
960962

961963
ExprResult BuildOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc);
962964
ExprResult ActOnOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc);

clang/lib/AST/OpenACCClause.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,11 +506,17 @@ OpenACCDeviceTypeClause *OpenACCDeviceTypeClause::Create(
506506
OpenACCReductionClause *OpenACCReductionClause::Create(
507507
const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
508508
OpenACCReductionOperator Operator, ArrayRef<Expr *> VarList,
509-
ArrayRef<OpenACCReductionRecipe> Recipes,
509+
ArrayRef<OpenACCReductionRecipeWithStorage> Recipes,
510510
SourceLocation EndLoc) {
511-
void *Mem = C.Allocate(
512-
OpenACCReductionClause::totalSizeToAlloc<Expr *, OpenACCReductionRecipe>(
513-
VarList.size(), Recipes.size()));
511+
size_t NumCombiners = llvm::accumulate(
512+
Recipes, 0, [](size_t Num, const OpenACCReductionRecipe &R) {
513+
return Num + R.CombinerRecipes.size();
514+
});
515+
516+
void *Mem = C.Allocate(OpenACCReductionClause::totalSizeToAlloc<
517+
Expr *, OpenACCReductionRecipe,
518+
OpenACCReductionRecipe::CombinerRecipe>(
519+
VarList.size(), Recipes.size(), NumCombiners));
514520
return new (Mem) OpenACCReductionClause(BeginLoc, LParenLoc, Operator,
515521
VarList, Recipes, EndLoc);
516522
}

clang/lib/CIR/CodeGen/Address.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "mlir/IR/Value.h"
1818
#include "clang/AST/CharUnits.h"
1919
#include "clang/CIR/Dialect/IR/CIRTypes.h"
20+
#include "clang/CIR/MissingFeatures.h"
2021
#include "llvm/ADT/PointerIntPair.h"
2122

2223
namespace clang::CIRGen {
@@ -90,6 +91,13 @@ class Address {
9091
return getPointer();
9192
}
9293

94+
/// Return the pointer contained in this class after authenticating it and
95+
/// adding offset to it if necessary.
96+
mlir::Value emitRawPointer() const {
97+
assert(!cir::MissingFeatures::addressPointerAuthInfo());
98+
return getBasePointer();
99+
}
100+
93101
mlir::Type getType() const {
94102
assert(mlir::cast<cir::PointerType>(
95103
pointerAndKnownNonNull.getPointer().getType())

clang/lib/CIR/CodeGen/CIRGenCXXABI.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ class CIRGenCXXABI {
191191
virtual void emitVTableDefinitions(CIRGenVTables &cgvt,
192192
const CXXRecordDecl *rd) = 0;
193193

194+
using DeleteOrMemberCallExpr =
195+
llvm::PointerUnion<const CXXDeleteExpr *, const CXXMemberCallExpr *>;
196+
197+
virtual mlir::Value emitVirtualDestructorCall(CIRGenFunction &cgf,
198+
const CXXDestructorDecl *dtor,
199+
CXXDtorType dtorType,
200+
Address thisAddr,
201+
DeleteOrMemberCallExpr e) = 0;
202+
194203
/// Emit any tables needed to implement virtual inheritance. For Itanium,
195204
/// this emits virtual table tables.
196205
virtual void emitVirtualInheritanceTables(const CXXRecordDecl *rd) = 0;

clang/lib/CIR/CodeGen/CIRGenClass.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,26 @@ void CIRGenFunction::destroyCXXObject(CIRGenFunction &cgf, Address addr,
895895
}
896896

897897
namespace {
898+
mlir::Value loadThisForDtorDelete(CIRGenFunction &cgf,
899+
const CXXDestructorDecl *dd) {
900+
if (Expr *thisArg = dd->getOperatorDeleteThisArg())
901+
return cgf.emitScalarExpr(thisArg);
902+
return cgf.loadCXXThis();
903+
}
904+
905+
/// Call the operator delete associated with the current destructor.
906+
struct CallDtorDelete final : EHScopeStack::Cleanup {
907+
CallDtorDelete() {}
908+
909+
void emit(CIRGenFunction &cgf) override {
910+
const CXXDestructorDecl *dtor = cast<CXXDestructorDecl>(cgf.curFuncDecl);
911+
const CXXRecordDecl *classDecl = dtor->getParent();
912+
cgf.emitDeleteCall(dtor->getOperatorDelete(),
913+
loadThisForDtorDelete(cgf, dtor),
914+
cgf.getContext().getCanonicalTagType(classDecl));
915+
}
916+
};
917+
898918
class DestroyField final : public EHScopeStack::Cleanup {
899919
const FieldDecl *field;
900920
CIRGenFunction::Destroyer *destroyer;
@@ -932,7 +952,18 @@ void CIRGenFunction::enterDtorCleanups(const CXXDestructorDecl *dd,
932952
// The deleting-destructor phase just needs to call the appropriate
933953
// operator delete that Sema picked up.
934954
if (dtorType == Dtor_Deleting) {
935-
cgm.errorNYI(dd->getSourceRange(), "deleting destructor cleanups");
955+
assert(dd->getOperatorDelete() &&
956+
"operator delete missing - EnterDtorCleanups");
957+
if (cxxStructorImplicitParamValue) {
958+
cgm.errorNYI(dd->getSourceRange(), "deleting destructor with vtt");
959+
} else {
960+
if (dd->getOperatorDelete()->isDestroyingOperatorDelete()) {
961+
cgm.errorNYI(dd->getSourceRange(),
962+
"deleting destructor with destroying operator delete");
963+
} else {
964+
ehStack.pushCleanup<CallDtorDelete>(NormalAndEHCleanup);
965+
}
966+
}
936967
return;
937968
}
938969

clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,11 @@ RValue CIRGenFunction::emitCXXMemberOrOperatorMemberCallExpr(
130130
const CXXMethodDecl *calleeDecl =
131131
devirtualizedMethod ? devirtualizedMethod : md;
132132
const CIRGenFunctionInfo *fInfo = nullptr;
133-
if (isa<CXXDestructorDecl>(calleeDecl)) {
134-
cgm.errorNYI(ce->getSourceRange(),
135-
"emitCXXMemberOrOperatorMemberCallExpr: destructor call");
136-
return RValue::get(nullptr);
137-
}
138-
139-
fInfo = &cgm.getTypes().arrangeCXXMethodDeclaration(calleeDecl);
133+
if (const auto *dtor = dyn_cast<CXXDestructorDecl>(calleeDecl))
134+
fInfo = &cgm.getTypes().arrangeCXXStructorDeclaration(
135+
GlobalDecl(dtor, Dtor_Complete));
136+
else
137+
fInfo = &cgm.getTypes().arrangeCXXMethodDeclaration(calleeDecl);
140138

141139
cir::FuncType ty = cgm.getTypes().getFunctionType(*fInfo);
142140

@@ -151,9 +149,34 @@ RValue CIRGenFunction::emitCXXMemberOrOperatorMemberCallExpr(
151149
// because then we know what the type is.
152150
bool useVirtualCall = canUseVirtualCall && !devirtualizedMethod;
153151

154-
if (isa<CXXDestructorDecl>(calleeDecl)) {
155-
cgm.errorNYI(ce->getSourceRange(),
156-
"emitCXXMemberOrOperatorMemberCallExpr: destructor call");
152+
if (const auto *dtor = dyn_cast<CXXDestructorDecl>(calleeDecl)) {
153+
assert(ce->arg_begin() == ce->arg_end() &&
154+
"Destructor shouldn't have explicit parameters");
155+
assert(returnValue.isNull() && "Destructor shouldn't have return value");
156+
if (useVirtualCall) {
157+
cgm.getCXXABI().emitVirtualDestructorCall(*this, dtor, Dtor_Complete,
158+
thisPtr.getAddress(),
159+
cast<CXXMemberCallExpr>(ce));
160+
} else {
161+
GlobalDecl globalDecl(dtor, Dtor_Complete);
162+
CIRGenCallee callee;
163+
assert(!cir::MissingFeatures::appleKext());
164+
if (!devirtualizedMethod) {
165+
callee = CIRGenCallee::forDirect(
166+
cgm.getAddrOfCXXStructor(globalDecl, fInfo, ty), globalDecl);
167+
} else {
168+
cgm.errorNYI(ce->getSourceRange(), "devirtualized destructor call");
169+
return RValue::get(nullptr);
170+
}
171+
172+
QualType thisTy =
173+
isArrow ? base->getType()->getPointeeType() : base->getType();
174+
// CIRGen does not pass CallOrInvoke here (different from OG LLVM codegen)
175+
// because in practice it always null even in OG.
176+
emitCXXDestructorCall(globalDecl, callee, thisPtr.getPointer(), thisTy,
177+
/*implicitParam=*/nullptr,
178+
/*implicitParamTy=*/QualType(), ce);
179+
}
157180
return RValue::get(nullptr);
158181
}
159182

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,13 @@ void CIRGenFunction::emitDestructorBody(FunctionArgList &args) {
678678
// possible to delegate the destructor body to the complete
679679
// destructor. Do so.
680680
if (dtorType == Dtor_Deleting) {
681-
cgm.errorNYI(dtor->getSourceRange(), "deleting destructor");
681+
RunCleanupsScope dtorEpilogue(*this);
682+
enterDtorCleanups(dtor, Dtor_Deleting);
683+
if (haveInsertPoint()) {
684+
QualType thisTy = dtor->getFunctionObjectParameterType();
685+
emitCXXDestructorCall(dtor, Dtor_Complete, /*forVirtualBase=*/false,
686+
/*delegating=*/false, loadCXXThisAddress(), thisTy);
687+
}
682688
return;
683689
}
684690

clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ class CIRGenItaniumCXXABI : public CIRGenCXXABI {
9595
clang::GlobalDecl gd, Address thisAddr,
9696
mlir::Type ty,
9797
SourceLocation loc) override;
98-
98+
mlir::Value emitVirtualDestructorCall(CIRGenFunction &cgf,
99+
const CXXDestructorDecl *dtor,
100+
CXXDtorType dtorType, Address thisAddr,
101+
DeleteOrMemberCallExpr e) override;
99102
mlir::Value getVTableAddressPoint(BaseSubobject base,
100103
const CXXRecordDecl *vtableClass) override;
101104
mlir::Value getVTableAddressPointInStructorWithVTT(
@@ -465,6 +468,29 @@ void CIRGenItaniumCXXABI::emitVTableDefinitions(CIRGenVTables &cgvt,
465468
}
466469
}
467470

471+
mlir::Value CIRGenItaniumCXXABI::emitVirtualDestructorCall(
472+
CIRGenFunction &cgf, const CXXDestructorDecl *dtor, CXXDtorType dtorType,
473+
Address thisAddr, DeleteOrMemberCallExpr expr) {
474+
auto *callExpr = dyn_cast<const CXXMemberCallExpr *>(expr);
475+
auto *delExpr = dyn_cast<const CXXDeleteExpr *>(expr);
476+
assert((callExpr != nullptr) ^ (delExpr != nullptr));
477+
assert(callExpr == nullptr || callExpr->arg_begin() == callExpr->arg_end());
478+
assert(dtorType == Dtor_Deleting || dtorType == Dtor_Complete);
479+
480+
GlobalDecl globalDecl(dtor, dtorType);
481+
const CIRGenFunctionInfo *fnInfo =
482+
&cgm.getTypes().arrangeCXXStructorDeclaration(globalDecl);
483+
const cir::FuncType &fnTy = cgm.getTypes().getFunctionType(*fnInfo);
484+
auto callee = CIRGenCallee::forVirtual(callExpr, globalDecl, thisAddr, fnTy);
485+
486+
QualType thisTy =
487+
callExpr ? callExpr->getObjectType() : delExpr->getDestroyedType();
488+
489+
cgf.emitCXXDestructorCall(globalDecl, callee, thisAddr.emitRawPointer(),
490+
thisTy, nullptr, QualType(), nullptr);
491+
return nullptr;
492+
}
493+
468494
void CIRGenItaniumCXXABI::emitVirtualInheritanceTables(
469495
const CXXRecordDecl *rd) {
470496
CIRGenVTables &vtables = cgm.getVTables();

0 commit comments

Comments
 (0)