Skip to content

Commit a7b7aa7

Browse files
authored
Merge branch 'main' into constexpr_cmp
2 parents 63a8621 + 1e84cb7 commit a7b7aa7

File tree

105 files changed

+1957
-179
lines changed

Some content is hidden

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

105 files changed

+1957
-179
lines changed

clang/include/clang/Basic/FileManager.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,12 @@ class FileManager : public RefCountedBase<FileManager> {
287287
/// If path is not absolute and FileSystemOptions set the working
288288
/// directory, the path is modified to be relative to the given
289289
/// working directory.
290-
/// \returns true if \c path changed.
291-
bool FixupRelativePath(SmallVectorImpl<char> &path) const;
290+
/// \returns true if \c Path changed.
291+
bool FixupRelativePath(SmallVectorImpl<char> &Path) const {
292+
return fixupRelativePath(FileSystemOpts, Path);
293+
}
294+
static bool fixupRelativePath(const FileSystemOptions &FileSystemOpts,
295+
SmallVectorImpl<char> &Path);
292296

293297
/// Makes \c Path absolute taking into account FileSystemOptions and the
294298
/// working directory option.

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ struct MissingFeatures {
231231
static bool coverageMapping() { return false; }
232232
static bool createInvariantGroup() { return false; }
233233
static bool createProfileWeightsForLoop() { return false; }
234+
static bool ctorConstLvalueToRvalueConversion() { return false; }
234235
static bool ctorMemcpyizer() { return false; }
235236
static bool cudaSupport() { return false; }
236237
static bool cxxRecordStaticMembers() { return false; }
@@ -240,6 +241,7 @@ struct MissingFeatures {
240241
static bool dataLayoutPtrHandlingBasedOnLangAS() { return false; }
241242
static bool deferredCXXGlobalInit() { return false; }
242243
static bool deleteArray() { return false; }
244+
static bool devirtualizeDestructor() { return false; }
243245
static bool devirtualizeMemberFunction() { return false; }
244246
static bool ehCleanupFlags() { return false; }
245247
static bool ehCleanupHasPrebranchedFallthrough() { return false; }

clang/lib/Basic/FileManager.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,16 +474,17 @@ OptionalFileEntryRef FileManager::getBypassFile(FileEntryRef VF) {
474474
return FileEntryRef(*Insertion.first);
475475
}
476476

477-
bool FileManager::FixupRelativePath(SmallVectorImpl<char> &path) const {
478-
StringRef pathRef(path.data(), path.size());
477+
bool FileManager::fixupRelativePath(const FileSystemOptions &FileSystemOpts,
478+
SmallVectorImpl<char> &Path) {
479+
StringRef pathRef(Path.data(), Path.size());
479480

480481
if (FileSystemOpts.WorkingDir.empty()
481482
|| llvm::sys::path::is_absolute(pathRef))
482483
return false;
483484

484485
SmallString<128> NewPath(FileSystemOpts.WorkingDir);
485486
llvm::sys::path::append(NewPath, pathRef);
486-
path = NewPath;
487+
Path = NewPath;
487488
return true;
488489
}
489490

clang/lib/CIR/CodeGen/CIRGenCXXABI.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ class CIRGenCXXABI {
187187
virtual void registerGlobalDtor(const VarDecl *vd, cir::FuncOp dtor,
188188
mlir::Value addr) = 0;
189189

190+
virtual void emitVirtualObjectDelete(CIRGenFunction &cgf,
191+
const CXXDeleteExpr *de, Address ptr,
192+
QualType elementType,
193+
const CXXDestructorDecl *dtor) = 0;
194+
190195
/// Checks if ABI requires extra virtual offset for vtable field.
191196
virtual bool
192197
isVirtualOffsetNeededForVTableField(CIRGenFunction &cgf,

clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,7 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
362362
cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitCXXTypeidExpr");
363363
}
364364
void VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *e) {
365-
cgf.cgm.errorNYI(e->getSourceRange(),
366-
"AggExprEmitter: VisitMaterializeTemporaryExpr");
365+
Visit(e->getSubExpr());
367366
}
368367
void VisitOpaqueValueExpr(OpaqueValueExpr *e) {
369368
cgf.cgm.errorNYI(e->getSourceRange(),

clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,10 @@ static void emitObjectDelete(CIRGenFunction &cgf, const CXXDeleteExpr *de,
565565
dtor = rd->getDestructor();
566566

567567
if (dtor->isVirtual()) {
568-
cgf.cgm.errorNYI(de->getSourceRange(),
569-
"emitObjectDelete: virtual destructor");
568+
assert(!cir::MissingFeatures::devirtualizeDestructor());
569+
cgf.cgm.getCXXABI().emitVirtualObjectDelete(cgf, de, ptr, elementType,
570+
dtor);
571+
return;
570572
}
571573
}
572574
}

clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,9 +1078,32 @@ class ConstExprEmitter
10781078

10791079
mlir::Attribute VisitCXXConstructExpr(CXXConstructExpr *e, QualType ty) {
10801080
if (!e->getConstructor()->isTrivial())
1081-
return nullptr;
1082-
cgm.errorNYI(e->getBeginLoc(), "trivial constructor const handling");
1083-
return {};
1081+
return {};
1082+
1083+
// Only default and copy/move constructors can be trivial.
1084+
if (e->getNumArgs()) {
1085+
assert(e->getNumArgs() == 1 && "trivial ctor with > 1 argument");
1086+
assert(e->getConstructor()->isCopyOrMoveConstructor() &&
1087+
"trivial ctor has argument but isn't a copy/move ctor");
1088+
1089+
Expr *arg = e->getArg(0);
1090+
assert(cgm.getASTContext().hasSameUnqualifiedType(ty, arg->getType()) &&
1091+
"argument to copy ctor is of wrong type");
1092+
1093+
// Look through the temporary; it's just converting the value to an lvalue
1094+
// to pass it to the constructor.
1095+
if (auto const *mte = dyn_cast<MaterializeTemporaryExpr>(arg))
1096+
return Visit(mte->getSubExpr(), ty);
1097+
1098+
// TODO: Investigate whether there are cases that can fall through to here
1099+
// that need to be handled. This is missing in classic codegen also.
1100+
assert(!cir::MissingFeatures::ctorConstLvalueToRvalueConversion());
1101+
1102+
// Don't try to support arbitrary lvalue-to-rvalue conversions for now.
1103+
return {};
1104+
}
1105+
1106+
return cgm.getBuilder().getZeroInitAttr(cgm.convertType(ty));
10841107
}
10851108

10861109
mlir::Attribute VisitStringLiteral(StringLiteral *e, QualType t) {

clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ class CIRGenItaniumCXXABI : public CIRGenCXXABI {
7474
QualType thisTy) override;
7575
void registerGlobalDtor(const VarDecl *vd, cir::FuncOp dtor,
7676
mlir::Value addr) override;
77+
void emitVirtualObjectDelete(CIRGenFunction &cgf, const CXXDeleteExpr *de,
78+
Address ptr, QualType elementType,
79+
const CXXDestructorDecl *dtor) override;
7780

7881
void emitRethrow(CIRGenFunction &cgf, bool isNoReturn) override;
7982
void emitThrow(CIRGenFunction &cgf, const CXXThrowExpr *e) override;
@@ -2175,6 +2178,21 @@ mlir::Value CIRGenItaniumCXXABI::emitDynamicCast(CIRGenFunction &cgf,
21752178
isRefCast, castInfo);
21762179
}
21772180

2181+
/// The Itanium ABI always places an offset to the complete object
2182+
/// at entry -2 in the vtable.
2183+
void CIRGenItaniumCXXABI::emitVirtualObjectDelete(
2184+
CIRGenFunction &cgf, const CXXDeleteExpr *delExpr, Address ptr,
2185+
QualType elementType, const CXXDestructorDecl *dtor) {
2186+
bool useGlobalDelete = delExpr->isGlobalDelete();
2187+
if (useGlobalDelete) {
2188+
cgf.cgm.errorNYI(delExpr->getSourceRange(),
2189+
"emitVirtualObjectDelete: global delete");
2190+
}
2191+
2192+
CXXDtorType dtorType = useGlobalDelete ? Dtor_Complete : Dtor_Deleting;
2193+
emitVirtualDestructorCall(cgf, dtor, dtorType, ptr, delExpr);
2194+
}
2195+
21782196
/************************** Array allocation cookies **************************/
21792197

21802198
CharUnits CIRGenItaniumCXXABI::getArrayCookieSizeImpl(QualType elementType) {

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ CompilerInstance::createOutputFileImpl(StringRef OutputPath, bool Binary,
882882
"File Manager is required to fix up relative path.\n");
883883

884884
AbsPath.emplace(OutputPath);
885-
FileMgr->FixupRelativePath(*AbsPath);
885+
FileManager::fixupRelativePath(getFileSystemOpts(), *AbsPath);
886886
OutputPath = *AbsPath;
887887
}
888888

clang/test/CIR/CodeGen/delete.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,42 @@ Container::~Container() { delete contents; }
8686
// These functions are declared/defined below the calls in OGCG.
8787
// OGCG: define linkonce_odr void @_ZN8ContentsD2Ev
8888
// OGCG: declare void @_ZdlPvm(ptr noundef, i64 noundef)
89+
90+
struct StructWithVirtualDestructor {
91+
virtual ~StructWithVirtualDestructor();
92+
};
93+
94+
void destroy(StructWithVirtualDestructor *x) {
95+
delete x;
96+
}
97+
98+
// CIR: cir.func {{.*}} @_Z7destroyP27StructWithVirtualDestructor(%[[X_ARG:.*]]: !cir.ptr<!rec_StructWithVirtualDestructor> {{.*}})
99+
// CIR: %[[X_ADDR:.*]] = cir.alloca !cir.ptr<!rec_StructWithVirtualDestructor>
100+
// CIR: cir.store %[[X_ARG]], %[[X_ADDR]]
101+
// CIR: %[[X:.*]] = cir.load{{.*}} %[[X_ADDR]]
102+
// CIR: %[[VTABLE_PTR:.*]] = cir.vtable.get_vptr %[[X]] : !cir.ptr<!rec_StructWithVirtualDestructor> -> !cir.ptr<!cir.vptr>
103+
// CIR: %[[VTABLE:.*]] = cir.load{{.*}} %[[VTABLE_PTR]] : !cir.ptr<!cir.vptr>, !cir.vptr
104+
// CIR: %[[DTOR_FN_ADDR_PTR:.*]] = cir.vtable.get_virtual_fn_addr %[[VTABLE]][1]
105+
// CIR: %[[DTOR_FN_ADDR:.*]] = cir.load{{.*}} %[[DTOR_FN_ADDR_PTR]]
106+
// CIR: cir.call %[[DTOR_FN_ADDR]](%[[X]])
107+
108+
// LLVM: define {{.*}} void @_Z7destroyP27StructWithVirtualDestructor(ptr %[[X_ARG:.*]])
109+
// LLVM: %[[X_ADDR:.*]] = alloca ptr
110+
// LLVM: store ptr %[[X_ARG]], ptr %[[X_ADDR]]
111+
// LLVM: %[[X:.*]] = load ptr, ptr %[[X_ADDR]]
112+
// LLVM: %[[VTABLE:.*]] = load ptr, ptr %[[X]]
113+
// LLVM: %[[DTOR_FN_ADDR_PTR:.*]] = getelementptr inbounds ptr, ptr %[[VTABLE]], i32 1
114+
// LLVM: %[[DTOR_FN_ADDR:.*]] = load ptr, ptr %[[DTOR_FN_ADDR_PTR]]
115+
// LLVM: call void %[[DTOR_FN_ADDR]](ptr %[[X]])
116+
117+
// OGCG: define {{.*}} void @_Z7destroyP27StructWithVirtualDestructor(ptr {{.*}} %[[X_ARG:.*]])
118+
// OGCG: %[[X_ADDR:.*]] = alloca ptr
119+
// OGCG: store ptr %[[X_ARG]], ptr %[[X_ADDR]]
120+
// OGCG: %[[X:.*]] = load ptr, ptr %[[X_ADDR]]
121+
// OGCG: %[[ISNULL:.*]] = icmp eq ptr %[[X]], null
122+
// OGCG: br i1 %[[ISNULL]], label %{{.*}}, label %[[DELETE_NOTNULL:.*]]
123+
// OGCG: [[DELETE_NOTNULL]]:
124+
// OGCG: %[[VTABLE:.*]] = load ptr, ptr %[[X]]
125+
// OGCG: %[[DTOR_FN_ADDR_PTR:.*]] = getelementptr inbounds ptr, ptr %[[VTABLE]], i64 1
126+
// OGCG: %[[DTOR_FN_ADDR:.*]] = load ptr, ptr %[[DTOR_FN_ADDR_PTR]]
127+
// OGCG: call void %[[DTOR_FN_ADDR]](ptr {{.*}} %[[X]])

0 commit comments

Comments
 (0)