Skip to content

Commit 446c4f3

Browse files
committed
Merge branch 'main' of https://github.com/llvm/llvm-project into fix/162953
2 parents ab1d0c7 + 32adfb5 commit 446c4f3

File tree

69 files changed

+3356
-910
lines changed

Some content is hidden

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

69 files changed

+3356
-910
lines changed

clang/include/clang/AST/OpenACCClause.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,17 +1325,11 @@ class OpenACCReductionClause final
13251325
Op(Operator) {
13261326
assert(VarList.size() == Recipes.size());
13271327
setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
1328-
llvm::uninitialized_copy(Recipes,
1329-
getTrailingObjects<OpenACCReductionRecipe>());
1328+
llvm::uninitialized_copy(Recipes, getTrailingObjects<
1329+
OpenACCReductionRecipe > ());
13301330
}
13311331

13321332
public:
1333-
~OpenACCReductionClause() {
1334-
for (unsigned I = 0; I < getExprs().size(); ++I) {
1335-
getTrailingObjects<OpenACCReductionRecipe>()[I].~OpenACCReductionRecipe();
1336-
}
1337-
}
1338-
13391333
static bool classof(const OpenACCClause *C) {
13401334
return C->getClauseKind() == OpenACCClauseKind::Reduction;
13411335
}

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13665,11 +13665,6 @@ def warn_acc_var_referenced_lacks_op
1366513665
"reference has no effect">,
1366613666
InGroup<DiagGroup<"openacc-var-lacks-operation">>,
1366713667
DefaultError;
13668-
def err_acc_reduction_recipe_no_op
13669-
: Error<"variable of type %0 referenced in OpenACC 'reduction' clause does "
13670-
"not have a valid operation available">;
13671-
def note_acc_reduction_recipe_noop_field
13672-
: Note<"while forming combiner for compound type %0">;
1367313668

1367413669
// AMDGCN builtins diagnostics
1367513670
def err_amdgcn_load_lds_size_invalid_value : Error<"invalid size value">;

clang/include/clang/Sema/SemaOpenACC.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,6 @@ class SemaOpenACC : public SemaBase {
228228

229229
bool DiagnoseAllowedClauses(OpenACCDirectiveKind DK, OpenACCClauseKind CK,
230230
SourceLocation ClauseLoc);
231-
bool CreateReductionCombinerRecipe(
232-
SourceLocation loc, OpenACCReductionOperator ReductionOperator,
233-
QualType VarTy,
234-
llvm::SmallVectorImpl<OpenACCReductionRecipe::CombinerRecipe>
235-
&CombinerRecipes);
236231

237232
public:
238233
// Needed from the visitor, so should be public.

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();

clang/lib/CIR/CodeGen/CIRGenTypes.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,8 @@ const CIRGenFunctionInfo &CIRGenTypes::arrangeGlobalDeclaration(GlobalDecl gd) {
619619
const auto *fd = cast<FunctionDecl>(gd.getDecl());
620620

621621
if (isa<CXXConstructorDecl>(gd.getDecl()) ||
622-
isa<CXXDestructorDecl>(gd.getDecl())) {
623-
cgm.errorNYI(SourceLocation(),
624-
"arrangeGlobalDeclaration for C++ constructor or destructor");
625-
}
622+
isa<CXXDestructorDecl>(gd.getDecl()))
623+
return arrangeCXXStructorDeclaration(gd);
626624

627625
return arrangeFunctionDeclaration(fd);
628626
}

0 commit comments

Comments
 (0)