Skip to content

Commit 983a35a

Browse files
authored
Merge pull request #8870 from drexin/wip-typed-throws
[CodeGen] Add typed error logic to SwiftAggLowering
2 parents 2d53850 + 7936f81 commit 983a35a

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

clang/include/clang/CodeGen/SwiftCallingConv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class SwiftAggLowering {
8888
/// passed indirectly as an argument
8989
bool shouldPassIndirectly(bool asReturnValue) const;
9090

91+
bool shouldReturnTypedErrorIndirectly() const;
92+
9193
using EnumerationCallback =
9294
llvm::function_ref<void(CharUnits offset, CharUnits end, llvm::Type *type)>;
9395

clang/lib/CodeGen/ABIInfo.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,15 @@ bool SwiftABIInfo::shouldPassIndirectly(ArrayRef<llvm::Type *> ComponentTys,
275275
return occupiesMoreThan(ComponentTys, /*total=*/4);
276276
}
277277

278+
bool SwiftABIInfo::shouldReturnTypedErrorIndirectly(
279+
ArrayRef<llvm::Type *> ComponentTys) const {
280+
for (llvm::Type *type : ComponentTys) {
281+
if (!type->isIntegerTy() && !type->isPointerTy())
282+
return true;
283+
}
284+
return shouldPassIndirectly(ComponentTys, /*AsReturnValue=*/true);
285+
}
286+
278287
bool SwiftABIInfo::isLegalVectorType(CharUnits VectorSize, llvm::Type *EltTy,
279288
unsigned NumElts) const {
280289
// The default implementation of this assumes that the target guarantees

clang/lib/CodeGen/ABIInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ class SwiftABIInfo {
151151

152152
/// Returns true if swifterror is lowered to a register by the target ABI.
153153
bool isSwiftErrorInRegister() const { return SwiftErrorInRegister; };
154+
155+
virtual bool
156+
shouldReturnTypedErrorIndirectly(ArrayRef<llvm::Type *> ComponentTys) const;
154157
};
155158
} // end namespace CodeGen
156159
} // end namespace clang

clang/lib/CodeGen/SwiftCallingConv.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,27 @@ bool SwiftAggLowering::shouldPassIndirectly(bool asReturnValue) const {
644644
return getSwiftABIInfo(CGM).shouldPassIndirectly(componentTys, asReturnValue);
645645
}
646646

647+
bool SwiftAggLowering::shouldReturnTypedErrorIndirectly() const {
648+
assert(Finished && "haven't yet finished lowering");
649+
650+
// Empty types don't need to be passed indirectly.
651+
if (Entries.empty())
652+
return false;
653+
654+
// Avoid copying the array of types when there's just a single element.
655+
if (Entries.size() == 1) {
656+
return getSwiftABIInfo(CGM).shouldReturnTypedErrorIndirectly(
657+
Entries.back().Type);
658+
}
659+
660+
SmallVector<llvm::Type *, 8> componentTys;
661+
componentTys.reserve(Entries.size());
662+
for (auto &entry : Entries) {
663+
componentTys.push_back(entry.Type);
664+
}
665+
return getSwiftABIInfo(CGM).shouldReturnTypedErrorIndirectly(componentTys);
666+
}
667+
647668
bool swiftcall::shouldPassIndirectly(CodeGenModule &CGM,
648669
ArrayRef<llvm::Type*> componentTys,
649670
bool asReturnValue) {

0 commit comments

Comments
 (0)