From b9b7f048b0874df0f034f6b1e15e1a4ee2131475 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 26 Jul 2026 12:12:59 +0000 Subject: refactor: centralize libc declarations, move '&' concat into StringHandler CodeGen declares its own MallocFunc in SetupExternalFunctions and uses it for char->STRING coercion and INPUT STRING buffers, removing two bare getFunction("malloc") calls that null-deref'd if no handler happened to declare malloc first. The CHR branch reuses the char->STRING coercion path instead of a second hand-rolled heap wrapper. String concatenation moves from ArithmeticHandler (which re-declared four externs per '&' and was the LLVM 19 build-pin root cause) to StringHandler::emitConcat; ArithmeticHandler no longer touches the Module. Dead FreeFunc declarations removed. Co-Authored-By: Claude Fable 5 --- include/cps/StringHandler.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include/cps/StringHandler.h') diff --git a/include/cps/StringHandler.h b/include/cps/StringHandler.h index a31fd2b..7226b85 100644 --- a/include/cps/StringHandler.h +++ b/include/cps/StringHandler.h @@ -14,9 +14,10 @@ class StringHandler { std::map &NamedValues; llvm::FunctionCallee MallocFunc; - llvm::FunctionCallee FreeFunc; llvm::FunctionCallee StrLenFunc; llvm::FunctionCallee MemCpyFunc; + llvm::FunctionCallee StrCpyFunc; + llvm::FunctionCallee StrCatFunc; llvm::FunctionCallee ToUpperFunc; llvm::FunctionCallee ToLowerFunc; @@ -29,6 +30,7 @@ public: llvm::Value *createLiteral(const std::string &Val); llvm::Value *emitLength(llvm::Value *Str); + llvm::Value *emitConcat(llvm::Value *LHS, llvm::Value *RHS); llvm::Value *emitMid(llvm::Value *Str, llvm::Value *Start, llvm::Value *Len); llvm::Value *emitRight(llvm::Value *Str, llvm::Value *Len); llvm::Value *emitLeft(llvm::Value *Str, llvm::Value *Len); -- cgit v1.3.1-4-g156e