1
0
mirror of https://github.com/exaloop/codon.git synced 2025-06-03 15:03:52 +08:00

Fix -disable-exceptions flag (#581)

This commit is contained in:
A. R. Shajii 2024-08-23 13:52:34 -04:00 committed by GitHub
parent c214e2c65d
commit 7b16b15f79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 7 deletions

View File

@ -1415,7 +1415,7 @@ int LLVMVisitor::getTypeIdx(types::Type *catchType) {
llvm::Value *LLVMVisitor::call(llvm::FunctionCallee callee,
llvm::ArrayRef<llvm::Value *> args) {
B->SetInsertPoint(block);
if (trycatch.empty()) {
if (trycatch.empty() || DisableExceptions) {
return B->CreateCall(callee, args);
} else {
auto *normalBlock = llvm::BasicBlock::Create(*context, "invoke.normal", func);
@ -2877,7 +2877,11 @@ void LLVMVisitor::visit(const TryCatchFlow *x) {
// rethrow if uncaught
B->SetInsertPoint(unwindResumeBlock);
B->CreateResume(B->CreateLoad(padType, tc.catchStore));
if (DisableExceptions) {
B->CreateUnreachable();
} else {
B->CreateResume(B->CreateLoad(padType, tc.catchStore));
}
// make sure we delegate to parent try-catch if necessary
std::vector<types::Type *> catchTypesFull(tc.catchTypes);
@ -2915,8 +2919,11 @@ void LLVMVisitor::visit(const TryCatchFlow *x) {
// exception handling
B->SetInsertPoint(tc.exceptionBlock);
llvm::LandingPadInst *caughtResult = B->CreateLandingPad(padType, catches.size());
caughtResult->setCleanup(true);
llvm::LandingPadInst *caughtResult = nullptr;
if (!DisableExceptions) {
caughtResult = B->CreateLandingPad(padType, catches.size());
caughtResult->setCleanup(true);
}
std::vector<llvm::Value *> typeIndices;
for (auto *catchType : catchTypesFull) {
@ -2925,11 +2932,15 @@ void LLVMVisitor::visit(const TryCatchFlow *x) {
"codon.typeidx." + (catchType ? catchType->getName() : "<all>");
llvm::GlobalVariable *tidx = getTypeIdxVar(catchType);
typeIndices.push_back(tidx);
caughtResult->addClause(tidx);
if (caughtResult)
caughtResult->addClause(tidx);
}
llvm::Value *unwindException = B->CreateExtractValue(caughtResult, 0);
B->CreateStore(caughtResult, tc.catchStore);
llvm::Value *caughtResultOrUndef = caughtResult
? llvm::cast<llvm::Value>(caughtResult)
: llvm::UndefValue::get(padType);
auto *unwindException = B->CreateExtractValue(caughtResultOrUndef, 0);
B->CreateStore(caughtResultOrUndef, tc.catchStore);
B->CreateStore(excStateThrown, tc.excFlag);
llvm::Value *depthMax = B->getInt64(trycatch.size());
B->CreateStore(depthMax, tc.delegateDepth);

View File

@ -27,6 +27,13 @@ Upgraded to LLVM 17 (from 15).
- Several improvements to dynamic polymorphism to match CPython more
closely.
## New compiler options
- `-disable-exceptions` will disable exceptions, potentially eliding
various runtime checks (e.g. bounds checks for lists). This flag
should only be used if you know that no exceptions will be raised
in the given program.
# v0.16
## Python extensions