aboutsummaryrefslogtreecommitdiff
path: root/include/cps/RuntimeCheck.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/cps/RuntimeCheck.h')
-rw-r--r--include/cps/RuntimeCheck.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/cps/RuntimeCheck.h b/include/cps/RuntimeCheck.h
index 97f4765..5996409 100644
--- a/include/cps/RuntimeCheck.h
+++ b/include/cps/RuntimeCheck.h
@@ -2,6 +2,8 @@
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
+#include <cstdint>
+#include <string>
namespace cps {
@@ -14,6 +16,8 @@ class RuntimeCheck {
llvm::FunctionCallee ExitFunc;
llvm::Value *DivZeroMsg;
llvm::Value *OutOfBoundsMsg;
+ llvm::Value *EnumRangeMsg;
+ llvm::Value *NullDerefMsg;
void setupExternalFunctions();
void emitErrorAndExit(llvm::Value *Condition, llvm::Value *Msg, int Line);
@@ -24,6 +28,13 @@ public:
void emitDivZeroCheck(llvm::Value *Divisor, int Line);
void emitIndexCheck(llvm::Value *Index, llvm::Value *Lower, llvm::Value *Upper, int Line);
+ // Enum +/- INTEGER results must stay inside the enum's value range.
+ void emitEnumRangeCheck(llvm::Value *Ordinal, uint64_t ValueCount,
+ const std::string &TypeName, int Line);
+
+ // Dereferencing an unset (null) pointer dies instead of segfaulting.
+ void emitNullDerefCheck(llvm::Value *Ptr, int Line);
+
// Runtime-computed variant: FmtArgs are the printf varargs after Msg
// (e.g. {i32 line, ptr filename}). Needed when the failure site is inside
// a synthesized helper function, where the line number is an argument