Skip to content

Commit

Permalink
Pallas: replace fatalError of Swift with requires false-contract
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertMensing committed Feb 24, 2025
1 parent 6e2fe6e commit c3c95bc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/llvm/include/Util/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const std::string METADATA_GLOBAL_KEYWORD = VC_PREFIX + "global";

// Other constants
const std::string SWIFT_ENTRY_SECTION = "swift5_entry";
const std::string SWIFT_FATAL_ERROR =
"$ss10fatalError_4file4lines5NeverOSSyXK_s12StaticStringVSutFfA_SSycfu_";

} // namespace pallas::constants

Expand Down
11 changes: 11 additions & 0 deletions src/llvm/lib/Passes/Function/FunctionBodyTransformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Transform/BlockTransform.h"
#include "Transform/Transform.h"
#include "Util/BlockUtils.h"
#include "Util/Constants.h"
#include "Util/Exceptions.h"
#include <llvm/Support/raw_ostream.h>

Expand Down Expand Up @@ -203,6 +204,16 @@ FunctionBodyTransformerPass::run(Function &F, FunctionAnalysisManager &FAM) {
funcCursor.addVariableMapEntry(
A, FAM.getResult<FunctionDeclarer>(F).getFuncArgMapEntry(A));
}

// Skip the body of the fatalError-function from Swift
// (As it uses currently unsupported instructions). We generate an
// requires false; - contract instead.
if (F.getName().str() == constants::SWIFT_FATAL_ERROR) {
ErrorReporter::addWarning(
SOURCE_LOC, "Skipping body of swift fatalError", F);
return PreservedAnalyses::all();
}

// start recursive block code gen with basic block
llvm::BasicBlock &entryBlock = F.getEntryBlock();
llvm2col::transformLLVMBlock(entryBlock, funcCursor);
Expand Down
12 changes: 12 additions & 0 deletions src/llvm/lib/Passes/Function/FunctionContractDeclarer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ FunctionContractDeclarerPass::run(Function &F, FunctionAnalysisManager &FAM) {
.mutable_vcllvm_function_contract();
colContract->set_allocated_blame(new col::Blame());
colContract->set_name(F.getName());

// Add a "requires false"-contract to Swift's fatalError-function
// (Since we currently do not support all instructions that it uses).
if (F.getName().str() == constants::SWIFT_FATAL_ERROR) {
ErrorReporter::addWarning(
SOURCE_LOC, "Generating contract forswift fatalError", F);
colContract->set_value("requires false;");
colContract->set_allocated_origin(
llvm2col::generateFunctionContractOrigin(F, "requires false;"));
return PreservedAnalyses::all();
}

// check if contract keyword is present
if (!F.hasMetadata(pallas::constants::METADATA_CONTRACT_KEYWORD)) {
// set contract to a tautology
Expand Down
4 changes: 2 additions & 2 deletions src/llvm/lib/Transform/Instruction/OtherOpTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ void llvm2col::transformExtractValueInst(
*extrVal->mutable_result_type());
// Value
llvm2col::transformAndSetExpr(funcCursor, llvmInstruction,
*llvmInstruction.getAggregateOperand(),
*extrVal->mutable_value());
*llvmInstruction.getAggregateOperand(),
*extrVal->mutable_value());
// Indices
for (auto &index : llvmInstruction.indices()) {
extrVal->add_indices(index);
Expand Down

0 comments on commit c3c95bc

Please sign in to comment.