Skip to content

Commit 6e822ba

Browse files
authored
Merge branch 'llvm:main' into main
2 parents 369ee66 + 421399d commit 6e822ba

File tree

16 files changed

+153
-30
lines changed

16 files changed

+153
-30
lines changed

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ struct MissingFeatures {
255255
static bool devirtualizeDestructor() { return false; }
256256
static bool devirtualizeMemberFunction() { return false; }
257257
static bool dtorCleanups() { return false; }
258-
static bool ehCleanupFlags() { return false; }
258+
static bool ehCleanupActiveFlag() { return false; }
259259
static bool ehCleanupHasPrebranchedFallthrough() { return false; }
260260
static bool ehCleanupScope() { return false; }
261261
static bool ehCleanupScopeRequiresEHCleanup() { return false; }
@@ -335,6 +335,7 @@ struct MissingFeatures {
335335
static bool thunks() { return false; }
336336
static bool tryEmitAsConstant() { return false; }
337337
static bool typeChecks() { return false; }
338+
static bool useEHCleanupForArray() { return false; }
338339
static bool vaArgABILowering() { return false; }
339340
static bool vectorConstants() { return false; }
340341
static bool vlas() { return false; }

clang/include/clang/DependencyScanning/DependencyScannerImpl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_CLANG_TOOLING_DEPENDENCYSCANNING_DEPENDENCYSCANNER_H
10-
#define LLVM_CLANG_TOOLING_DEPENDENCYSCANNING_DEPENDENCYSCANNER_H
9+
#ifndef LLVM_CLANG_DEPENDENCYSCANNING_DEPENDENCYSCANNERIMPL_H
10+
#define LLVM_CLANG_DEPENDENCYSCANNING_DEPENDENCYSCANNERIMPL_H
1111

1212
#include "clang/DependencyScanning/DependencyScanningFilesystem.h"
1313
#include "clang/DependencyScanning/ModuleDepCollector.h"
@@ -193,4 +193,4 @@ class CompilerInstanceWithContext {
193193
} // namespace dependencies
194194
} // namespace clang
195195

196-
#endif
196+
#endif // LLVM_CLANG_DEPENDENCYSCANNING_DEPENDENCYSCANNERIMPL_H

clang/lib/CIR/CodeGen/CIRGenClass.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ struct CallBaseDtor final : EHScopeStack::Cleanup {
149149
CallBaseDtor(const CXXRecordDecl *base, bool baseIsVirtual)
150150
: baseClass(base), baseIsVirtual(baseIsVirtual) {}
151151

152-
void emit(CIRGenFunction &cgf) override {
152+
void emit(CIRGenFunction &cgf, Flags flags) override {
153153
const CXXRecordDecl *derivedClass =
154154
cast<CXXMethodDecl>(cgf.curFuncDecl)->getParent();
155155

@@ -924,7 +924,7 @@ mlir::Value loadThisForDtorDelete(CIRGenFunction &cgf,
924924
struct CallDtorDelete final : EHScopeStack::Cleanup {
925925
CallDtorDelete() {}
926926

927-
void emit(CIRGenFunction &cgf) override {
927+
void emit(CIRGenFunction &cgf, Flags flags) override {
928928
const CXXDestructorDecl *dtor = cast<CXXDestructorDecl>(cgf.curFuncDecl);
929929
const CXXRecordDecl *classDecl = dtor->getParent();
930930
cgf.emitDeleteCall(dtor->getOperatorDelete(),
@@ -941,7 +941,7 @@ class DestroyField final : public EHScopeStack::Cleanup {
941941
DestroyField(const FieldDecl *field, CIRGenFunction::Destroyer *destroyer)
942942
: field(field), destroyer(destroyer) {}
943943

944-
void emit(CIRGenFunction &cgf) override {
944+
void emit(CIRGenFunction &cgf, Flags flags) override {
945945
// Find the address of the field.
946946
Address thisValue = cgf.loadCXXThisAddress();
947947
CanQualType recordTy =
@@ -950,7 +950,7 @@ class DestroyField final : public EHScopeStack::Cleanup {
950950
LValue lv = cgf.emitLValueForField(thisLV, field);
951951
assert(lv.isSimple());
952952

953-
assert(!cir::MissingFeatures::ehCleanupFlags());
953+
assert(!cir::MissingFeatures::useEHCleanupForArray());
954954
cgf.emitDestroy(lv.getAddress(), field->getType(), destroyer);
955955
}
956956
};
@@ -1047,7 +1047,7 @@ void CIRGenFunction::enterDtorCleanups(const CXXDestructorDecl *dd,
10471047
continue;
10481048

10491049
CleanupKind cleanupKind = getCleanupKind(dtorKind);
1050-
assert(!cir::MissingFeatures::ehCleanupFlags());
1050+
assert(!cir::MissingFeatures::useEHCleanupForArray());
10511051
ehStack.pushCleanup<DestroyField>(cleanupKind, field,
10521052
getDestroyer(dtorKind));
10531053
}

clang/lib/CIR/CodeGen/CIRGenCleanup.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,12 @@ EHCatchScope *EHScopeStack::pushCatch(unsigned numHandlers) {
210210
return scope;
211211
}
212212

213-
static void emitCleanup(CIRGenFunction &cgf, EHScopeStack::Cleanup *cleanup) {
213+
static void emitCleanup(CIRGenFunction &cgf, EHScopeStack::Cleanup *cleanup,
214+
EHScopeStack::Cleanup::Flags flags) {
214215
// Ask the cleanup to emit itself.
215216
assert(cgf.haveInsertPoint() && "expected insertion point");
216-
assert(!cir::MissingFeatures::ehCleanupFlags());
217-
cleanup->emit(cgf);
217+
assert(!cir::MissingFeatures::ehCleanupActiveFlag());
218+
cleanup->emit(cgf, flags);
218219
assert(cgf.haveInsertPoint() && "cleanup ended with no insertion point?");
219220
}
220221

@@ -284,15 +285,19 @@ void CIRGenFunction::popCleanupBlock() {
284285
reinterpret_cast<EHScopeStack::Cleanup *>(cleanupBufferHeap.get());
285286
}
286287

287-
assert(!cir::MissingFeatures::ehCleanupFlags());
288+
EHScopeStack::Cleanup::Flags cleanupFlags;
289+
if (scope.isNormalCleanup())
290+
cleanupFlags.setIsNormalCleanupKind();
291+
if (scope.isEHCleanup())
292+
cleanupFlags.setIsEHCleanupKind();
288293

289294
// If we have a fallthrough and no other need for the cleanup,
290295
// emit it directly.
291296
if (hasFallthrough && !hasFixups) {
292297
assert(!cir::MissingFeatures::ehCleanupScopeRequiresEHCleanup());
293298
ehStack.popCleanup();
294299
scope.markEmitted();
295-
emitCleanup(*this, cleanup);
300+
emitCleanup(*this, cleanup, cleanupFlags);
296301
} else {
297302
// Otherwise, the best approach is to thread everything through
298303
// the cleanup block and then try to clean up after ourselves.
@@ -354,7 +359,7 @@ void CIRGenFunction::popCleanupBlock() {
354359
ehStack.popCleanup();
355360
assert(ehStack.hasNormalCleanups() == hasEnclosingCleanups);
356361

357-
emitCleanup(*this, cleanup);
362+
emitCleanup(*this, cleanup, cleanupFlags);
358363

359364
// Append the prepared cleanup prologue from above.
360365
assert(!cir::MissingFeatures::cleanupAppendInsts());

clang/lib/CIR/CodeGen/CIRGenCleanup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ class alignas(EHScopeStack::ScopeStackAlignment) EHCleanupScope
237237
void setNormalBlock(mlir::Block *bb) { normalBlock = bb; }
238238

239239
bool isNormalCleanup() const { return cleanupBits.isNormalCleanup; }
240+
bool isEHCleanup() const { return cleanupBits.isEHCleanup; }
240241

241242
bool isActive() const { return cleanupBits.isActive; }
242243
void setActive(bool isActive) { cleanupBits.isActive = isActive; }

clang/lib/CIR/CodeGen/CIRGenDecl.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -812,13 +812,16 @@ namespace {
812812
struct DestroyObject final : EHScopeStack::Cleanup {
813813
DestroyObject(Address addr, QualType type,
814814
CIRGenFunction::Destroyer *destroyer)
815-
: addr(addr), type(type), destroyer(destroyer) {}
815+
: addr(addr), type(type), destroyer(destroyer) {
816+
assert(!cir::MissingFeatures::useEHCleanupForArray());
817+
}
816818

817819
Address addr;
818820
QualType type;
819821
CIRGenFunction::Destroyer *destroyer;
820822

821-
void emit(CIRGenFunction &cgf) override {
823+
void emit(CIRGenFunction &cgf, Flags flags) override {
824+
assert(!cir::MissingFeatures::useEHCleanupForArray());
822825
cgf.emitDestroy(addr, type, destroyer);
823826
}
824827
};
@@ -831,7 +834,7 @@ template <class Derived> struct DestroyNRVOVariable : EHScopeStack::Cleanup {
831834
Address addr;
832835
QualType ty;
833836

834-
void emit(CIRGenFunction &cgf) override {
837+
void emit(CIRGenFunction &cgf, Flags flags) override {
835838
assert(!cir::MissingFeatures::cleanupDestroyNRVOVariable());
836839
}
837840

@@ -855,7 +858,7 @@ struct DestroyNRVOVariableCXX final
855858
struct CallStackRestore final : EHScopeStack::Cleanup {
856859
Address stack;
857860
CallStackRestore(Address stack) : stack(stack) {}
858-
void emit(CIRGenFunction &cgf) override {
861+
void emit(CIRGenFunction &cgf, Flags flags) override {
859862
mlir::Location loc = stack.getPointer().getLoc();
860863
mlir::Value v = cgf.getBuilder().createLoad(loc, stack);
861864
cgf.getBuilder().createStackRestore(loc, v);
@@ -957,6 +960,7 @@ void CIRGenFunction::emitDestroy(Address addr, QualType type,
957960
return;
958961

959962
mlir::Value begin = addr.getPointer();
963+
assert(!cir::MissingFeatures::useEHCleanupForArray());
960964
emitArrayDestroy(begin, length, type, elementAlign, destroyer);
961965

962966
// If the array destroy didn't use the length op, we can erase it.
@@ -1029,7 +1033,7 @@ void CIRGenFunction::emitAutoVarTypeCleanup(
10291033
if (!destroyer)
10301034
destroyer = getDestroyer(dtorKind);
10311035

1032-
assert(!cir::MissingFeatures::ehCleanupFlags());
1036+
assert(!cir::MissingFeatures::useEHCleanupForArray());
10331037
ehStack.pushCleanup<DestroyObject>(cleanupKind, addr, type, destroyer);
10341038
}
10351039

clang/lib/CIR/CodeGen/CIRGenDeclOpenACC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct OpenACCDeclareCleanup final : EHScopeStack::Cleanup {
4545
}
4646
}
4747

48-
void emit(CIRGenFunction &cgf) override {
48+
void emit(CIRGenFunction &cgf, Flags flags) override {
4949
auto exitOp = mlir::acc::DeclareExitOp::create(
5050
cgf.getBuilder(), enterOp.getLoc(), enterOp, {});
5151

clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ struct CallObjectDelete final : EHScopeStack::Cleanup {
690690
QualType elementType)
691691
: ptr(ptr), operatorDelete(operatorDelete), elementType(elementType) {}
692692

693-
void emit(CIRGenFunction &cgf) override {
693+
void emit(CIRGenFunction &cgf, Flags flags) override {
694694
cgf.emitDeleteCall(operatorDelete, ptr, elementType);
695695
}
696696
};

clang/lib/CIR/CodeGen/EHScopeStack.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,43 @@ class EHScopeStack {
127127

128128
virtual ~Cleanup() = default;
129129

130+
/// Generation flags.
131+
class Flags {
132+
enum {
133+
F_IsForEH = 0x1,
134+
F_IsNormalCleanupKind = 0x2,
135+
F_IsEHCleanupKind = 0x4,
136+
F_HasExitSwitch = 0x8,
137+
};
138+
unsigned flags = 0;
139+
140+
public:
141+
Flags() = default;
142+
143+
/// isForEH - true if the current emission is for an EH cleanup.
144+
bool isForEHCleanup() const { return flags & F_IsForEH; }
145+
bool isForNormalCleanup() const { return !isForEHCleanup(); }
146+
void setIsForEHCleanup() { flags |= F_IsForEH; }
147+
148+
bool isNormalCleanupKind() const { return flags & F_IsNormalCleanupKind; }
149+
void setIsNormalCleanupKind() { flags |= F_IsNormalCleanupKind; }
150+
151+
/// isEHCleanupKind - true if the cleanup was pushed as an EH
152+
/// cleanup.
153+
bool isEHCleanupKind() const { return flags & F_IsEHCleanupKind; }
154+
void setIsEHCleanupKind() { flags |= F_IsEHCleanupKind; }
155+
156+
bool hasExitSwitch() const { return flags & F_HasExitSwitch; }
157+
void setHasExitSwitch() { flags |= F_HasExitSwitch; }
158+
};
159+
130160
/// Emit the cleanup. For normal cleanups, this is run in the
131161
/// same EH context as when the cleanup was pushed, i.e. the
132162
/// immediately-enclosing context of the cleanup scope. For
133163
/// EH cleanups, this is run in a terminate context.
134164
///
135165
// \param flags cleanup kind.
136-
virtual void emit(CIRGenFunction &cgf) = 0;
166+
virtual void emit(CIRGenFunction &cgf, Flags flags) = 0;
137167
};
138168

139169
private:

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3212,8 +3212,8 @@ void CodeGenModule::finalizeKCFITypes() {
32123212
continue;
32133213

32143214
std::string Asm = (".weak __kcfi_typeid_" + Name + "\n.set __kcfi_typeid_" +
3215-
Name + ", " + Twine(Type->getZExtValue()) + " # " +
3216-
Twine(Type->getSExtValue()) + "\n")
3215+
Name + ", " + Twine(Type->getZExtValue()) + " /* " +
3216+
Twine(Type->getSExtValue()) + " */\n")
32173217
.str();
32183218
M.appendModuleInlineAsm(Asm);
32193219
}

0 commit comments

Comments
 (0)