aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/RuntimeCheck.cc
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-18 08:04:15 +0000
committer_ov4 <ov4@ov4.org>2026-10-18 08:04:15 +0000
commit927e3fc0384c941f9ad313a28768660c3cdb1777 (patch)
treeee82bef8d8332dad79d05db87f33979f0e7eb423 /lib/CodeGen/RuntimeCheck.cc
parent34a4998658674411ef3b5a392483990467a5d6e2 (diff)
feat(driver): add #LIB directive hiding library lines in runtime errors
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'lib/CodeGen/RuntimeCheck.cc')
-rw-r--r--lib/CodeGen/RuntimeCheck.cc17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/CodeGen/RuntimeCheck.cc b/lib/CodeGen/RuntimeCheck.cc
index 0515f1e..4cee16f 100644
--- a/lib/CodeGen/RuntimeCheck.cc
+++ b/lib/CodeGen/RuntimeCheck.cc
@@ -11,9 +11,20 @@ using namespace cps;
RuntimeCheck::RuntimeCheck(Module &M, LLVMContext &C, IRBuilder<> &B, ExceptionHandler &EH)
: TheModule(M), TheContext(C), Builder(B), Exceptions(EH) {
+ UserLine = new GlobalVariable(TheModule, Builder.getInt32Ty(), false,
+ GlobalValue::ExternalLinkage, Builder.getInt32(0), "__cps_user_line");
setupExternalFunctions();
}
+Value *RuntimeCheck::lineValue(int Line) {
+ return LibraryMode ? Builder.CreateLoad(Builder.getInt32Ty(), UserLine, "user_line")
+ : static_cast<Value *>(Builder.getInt32(Line));
+}
+
+void RuntimeCheck::setUserLine(int Line) {
+ Builder.CreateStore(Builder.getInt32(Line), UserLine);
+}
+
void RuntimeCheck::setupExternalFunctions() {
Type *PtrTy = PointerType::getUnqual(TheContext);
Type *I32 = Type::getInt32Ty(TheContext);
@@ -54,7 +65,7 @@ void RuntimeCheck::emitStderr(Value *Msg, ArrayRef<Value *> FmtArgs) {
}
void RuntimeCheck::emitCheck(Value *Condition, Value *Msg, int Line) {
- emitCheck(Condition, Msg, {ConstantInt::get(TheContext, APInt(32, Line))});
+ emitCheck(Condition, Msg, {lineValue(Line)});
}
void RuntimeCheck::emitCheck(Value *Condition, Value *Msg, ArrayRef<Value *> FmtArgs) {
@@ -105,7 +116,7 @@ void RuntimeCheck::emitEnumRangeCheck(Value *Ordinal, uint64_t ValueCount,
Value *NameStr = Builder.CreateGlobalString(TypeName, "enum_name", 0, &TheModule);
emitCheck(OutOfRange, EnumRangeMsg,
- {ConstantInt::get(TheContext, APInt(32, Line)), NameStr});
+ {lineValue(Line), NameStr});
}
void RuntimeCheck::emitNullDerefCheck(Value *Ptr, int Line) {
@@ -125,6 +136,6 @@ void RuntimeCheck::emitArrayArgBoundsCheck(Value *ActualLower, Value *ActualUppe
Value *Mismatch = Builder.CreateOr(LoDiff, HiDiff, "arg_bounds_ne");
emitCheck(Mismatch, ArrayArgBoundsMsg,
- {ConstantInt::get(TheContext, APInt(32, Line)),
+ {lineValue(Line),
ActualLower, ActualUpper, DeclLo, DeclHi});
}