From 78ac4d7f0aff7c07b442bcc936448ecdd9883b61 Mon Sep 17 00:00:00 2001 From: adazem009 <68537469+adazem009@users.noreply.github.com> Date: Wed, 4 Nov 2026 15:59:37 +0100 Subject: [PATCH 1/5] Add string stack to ExecutionContext --- include/scratchcpp/executioncontext.h | 35 +++++++++++++++++-- src/engine/executioncontext.cpp | 12 +++++++ .../executioncontext_test.cpp | 27 ++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/include/scratchcpp/executioncontext.h b/include/scratchcpp/executioncontext.h index 23f6ce73c..dc0b0111f 100644 --- a/include/scratchcpp/executioncontext.h +++ b/include/scratchcpp/executioncontext.h @@ -2,7 +2,10 @@ #pragma once -#include "global.h" +#include +#include + +#include "string_pool.h" #include "spimpl.h" namespace libscratchcpp @@ -13,6 +16,7 @@ class IEngine; class Promise; class IStackTimer; class IRandomGenerator; +struct StringPtr; class ExecutionContextPrivate; /*! \brief The ExecutionContext represents the execution context of a target (can be a clone) with variables, lists, etc. */ @@ -21,7 +25,7 @@ class LIBSCRATCHCPP_EXPORT ExecutionContext public: ExecutionContext(Thread *thread); ExecutionContext(const ExecutionContext &) = delete; - virtual ~ExecutionContext() { } + virtual ~ExecutionContext(); Thread *thread() const; IEngine *engine() const; @@ -35,8 +39,35 @@ class LIBSCRATCHCPP_EXPORT ExecutionContext IRandomGenerator *rng() const; void setRng(IRandomGenerator *newRng); + inline StringPtr **pushStringStack(size_t stringCount) + { + m_stringStack.push({}); + + auto &strings = m_stringStack.top(); + + for (size_t i = 0; i < stringCount; i++) { + StringPtr *str = string_pool_new(); + strings.push_back(str); + } + + return strings.data(); + } + + inline void popStringStack() + { + assert(!m_stringStack.empty()); + const auto &strings = m_stringStack.top(); + + for (StringPtr *str : strings) + string_pool_free(str); + + m_stringStack.pop(); + } + private: spimpl::unique_impl_ptr impl; + + std::stack> m_stringStack; }; } // namespace libscratchcpp diff --git a/src/engine/executioncontext.cpp b/src/engine/executioncontext.cpp index 06109d55d..fbf3cbbd9 100644 --- a/src/engine/executioncontext.cpp +++ b/src/engine/executioncontext.cpp @@ -13,6 +13,18 @@ ExecutionContext::ExecutionContext(Thread *thread) : { } +/*! Destroys ExecutionContext. */ +ExecutionContext::~ExecutionContext() +{ + // Deallocate strings + // NOTE: The stack should be already empty + assert(m_stringStack.empty()); + + while (!m_stringStack.empty()) { + popStringStack(); + } +} + /*! Returns the thread of this context. */ Thread *ExecutionContext::thread() const { diff --git a/test/executioncontext/executioncontext_test.cpp b/test/executioncontext/executioncontext_test.cpp index f38191087..22635d235 100644 --- a/test/executioncontext/executioncontext_test.cpp +++ b/test/executioncontext/executioncontext_test.cpp @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include #include @@ -51,3 +53,28 @@ TEST(ExecutionContextTest, Rng) ctx.setRng(&rng); ASSERT_EQ(ctx.rng(), &rng); } + +TEST(ExecutionContextTest, StringStack) +{ + EngineMock engine; + ExecutionContext ctx(nullptr); + + StringPtr **frame1 = ctx.pushStringStack(3); + + for (int i = 0; i < 3; i++) { + string_assign_cstring(frame1[i], "test"); // address sanitizer will detect potential buffer overflow + } + + StringPtr **frame2 = ctx.pushStringStack(5); + + for (int i = 0; i < 5; i++) { + string_assign_cstring(frame2[i], "foo bar"); + } + + ctx.popStringStack(); + + StringPtr testString("test"); + ASSERT_EQ(string_compare_case_sensitive(frame1[2], &testString), 0); + + ctx.popStringStack(); +} From 2bac780b27cb89732d4b515a818522e042dd4127 Mon Sep 17 00:00:00 2001 From: adazem009 <68537469+adazem009@users.noreply.github.com> Date: Thu, 5 Nov 2026 11:35:25 +0100 Subject: [PATCH 2/5] Use string stack in the LLVM backend --- .../internal/codegen/llvm/llvmbuildutils.cpp | 57 +++++++++++++----- .../internal/codegen/llvm/llvmbuildutils.h | 7 ++- .../internal/codegen/llvm/llvmcodebuilder.cpp | 2 +- .../codegen/llvm/llvmexecutablecode.cpp | 14 +---- .../codegen/llvm/llvmexecutablecode.h | 10 +-- .../codegen/llvm/llvmexecutioncontext.cpp | 25 -------- .../codegen/llvm/llvmexecutioncontext.h | 9 --- .../internal/codegen/llvm/llvmfunctions.cpp | 23 +++++-- .../internal/codegen/llvm/llvmfunctions.h | 3 +- test/codegen/llvm/llvmexecutablecode_test.cpp | 31 +++------- test/engine/engine_test.cpp | 17 ++++++ .../704_string_stack_race_condition.sb3 | Bin 0 -> 1836 bytes 12 files changed, 98 insertions(+), 100 deletions(-) create mode 100644 test/regtest_projects/704_string_stack_race_condition.sb3 diff --git a/src/engine/internal/codegen/llvm/llvmbuildutils.cpp b/src/engine/internal/codegen/llvm/llvmbuildutils.cpp index 7eeb36683..31e4685b1 100644 --- a/src/engine/internal/codegen/llvm/llvmbuildutils.cpp +++ b/src/engine/internal/codegen/llvm/llvmbuildutils.cpp @@ -79,14 +79,25 @@ void LLVMBuildUtils::init(llvm::Function *function, BlockPrototype *procedurePro reg->intValue = llvm::ConstantInt::get(m_builder.getInt64Ty(), reg->constValue().toDouble(), true); } + // Create string count variable (LLVM should optimize it into a constant later) + m_stringCountVar = m_builder.CreateAlloca(m_builder.getInt64Ty(), nullptr, "stringCount"); + + // Create string array variable + m_stringArrayVar = m_builder.CreateAlloca(m_stringPtrType->getPointerTo(), nullptr, "stringArray"); + + // Create string count block (string count is known after all instructions are processed) + m_stringCountBlock = llvm::BasicBlock::Create(m_llvmCtx, "getStringCount", m_function); + m_builder.CreateBr(m_stringCountBlock); + // NOTE: This block is terminated later + // Create string allocation block + m_builder.SetInsertPoint(m_stringCountBlock); m_stringAllocaBlock = llvm::BasicBlock::Create(m_llvmCtx, "stringAlloca", m_function); - m_builder.CreateBr(m_stringAllocaBlock); + // NOTE: This block is terminated later - // Get string array + // Push string stack (load string array) m_builder.SetInsertPoint(m_stringAllocaBlock); - m_stringArray = m_builder.CreateCall(m_functions.resolve_llvm_get_string_array(), { m_executionContextPtr, m_functionIdValue }); - // NOTE: This block is terminated later + pushStringStack(); // Create next block m_stringAllocaNextBlock = llvm::BasicBlock::Create(m_llvmCtx, "entry.next", m_function); @@ -146,11 +157,13 @@ void LLVMBuildUtils::init(llvm::Function *function, BlockPrototype *procedurePro void LLVMBuildUtils::end(LLVMInstruction *lastInstruction, LLVMRegister *lastConstant) { - // Terminate string allocation block - if (m_stringCount == 0) - m_stringAllocaBlock->erase(m_stringAllocaBlock->begin(), m_stringAllocaBlock->end()); - + // Terminate string count and allocation blocks llvm::BasicBlock *previousBlock = m_builder.GetInsertBlock(); + m_builder.SetInsertPoint(m_stringCountBlock); + m_builder.CreateStore(m_builder.getInt64(m_stringCount), m_stringCountVar); + + m_builder.CreateBr(m_stringAllocaBlock); + m_builder.SetInsertPoint(m_stringAllocaBlock); m_builder.CreateBr(m_stringAllocaNextBlock); m_builder.SetInsertPoint(previousBlock); @@ -165,6 +178,7 @@ void LLVMBuildUtils::end(LLVMInstruction *lastInstruction, LLVMRegister *lastCon // End branch m_builder.SetInsertPoint(m_endBranch); + popStringStack(); llvm::PointerType *pointerType = llvm::PointerType::get(llvm::Type::getInt8Ty(m_llvmCtx), 0); @@ -198,6 +212,7 @@ void LLVMBuildUtils::end(LLVMInstruction *lastInstruction, LLVMRegister *lastCon // Thread end branch (stop the entire thread, including procedure callers) m_builder.SetInsertPoint(m_endThreadBranch); + popStringStack(); switch (m_codeType) { case Compiler::CodeType::Script: @@ -497,15 +512,11 @@ llvm::Value *LLVMBuildUtils::addAlloca(llvm::Type *type) llvm::Value *LLVMBuildUtils::addStringAlloca() { - // All temporary strings are allocated before the script is called - llvm::BasicBlock *block = m_builder.GetInsertBlock(); - m_builder.SetInsertPoint(m_stringAllocaBlock); - + // All temporary strings are allocated when the string stack is pushed + llvm::Value *stringArray = m_builder.CreateLoad(m_stringPtrType->getPointerTo(), m_stringArrayVar, "loadedStringArray"); llvm::Value *index = m_builder.getInt64(m_stringCount++); - llvm::Value *elementPtr = m_builder.CreateGEP(m_stringPtrType->getPointerTo(), m_stringArray, index); + llvm::Value *elementPtr = m_builder.CreateGEP(m_stringPtrType->getPointerTo(), stringArray, index); llvm::Value *ret = m_builder.CreateLoad(m_stringPtrType->getPointerTo(), elementPtr, "localString"); - - m_builder.SetInsertPoint(block); return ret; } @@ -1417,10 +1428,14 @@ void LLVMBuildUtils::createSuspend() m_builder.SetInsertPoint(suspendBranch); } + popStringStack(); syncVariables(); + m_coroutine->createSuspend(); + reloadVariables(); reloadLists(); + pushStringStack(); if (m_warpArg) { m_builder.CreateBr(nextBranch); @@ -2190,3 +2205,15 @@ llvm::Value *LLVMBuildUtils::getListDataPtr(const LLVMListPtr &listPtr) { return m_builder.CreateLoad(m_valueDataType->getPointerTo(), m_builder.CreateLoad(m_valueDataType->getPointerTo()->getPointerTo(), listPtr.dataPtr)); } + +void LLVMBuildUtils::pushStringStack() +{ + llvm::Value *stringCount = m_builder.CreateLoad(m_builder.getInt64Ty(), m_stringCountVar, "strCount"); + llvm::Value *strings = m_builder.CreateCall(m_functions.resolve_llvm_push_string_stack(), { m_executionContextPtr, stringCount }); + m_builder.CreateStore(strings, m_stringArrayVar); +} + +void LLVMBuildUtils::popStringStack() +{ + m_builder.CreateCall(m_functions.resolve_llvm_pop_string_stack(), { m_executionContextPtr }); +} diff --git a/src/engine/internal/codegen/llvm/llvmbuildutils.h b/src/engine/internal/codegen/llvm/llvmbuildutils.h index 2dd8b2df9..64d88d6af 100644 --- a/src/engine/internal/codegen/llvm/llvmbuildutils.h +++ b/src/engine/internal/codegen/llvm/llvmbuildutils.h @@ -154,6 +154,9 @@ class LIBSCRATCHCPP_TEST_EXPORT LLVMBuildUtils llvm::Value *getListPtr(llvm::Value *targetLists, List *list); llvm::Value *getListDataPtr(const LLVMListPtr &listPtr); + void pushStringStack(); + void popStringStack(); + LLVMCompilerContext *m_ctx = nullptr; llvm::LLVMContext &m_llvmCtx; llvm::IRBuilder<> &m_builder; @@ -194,9 +197,11 @@ class LIBSCRATCHCPP_TEST_EXPORT LLVMBuildUtils std::vector m_ifStatements; std::vector m_loops; + llvm::BasicBlock *m_stringCountBlock = nullptr; llvm::BasicBlock *m_stringAllocaBlock = nullptr; llvm::BasicBlock *m_stringAllocaNextBlock = nullptr; - llvm::Value *m_stringArray = nullptr; + llvm::Value *m_stringCountVar = nullptr; + llvm::Value *m_stringArrayVar = nullptr; size_t m_stringCount = 0; }; diff --git a/src/engine/internal/codegen/llvm/llvmcodebuilder.cpp b/src/engine/internal/codegen/llvm/llvmcodebuilder.cpp index d2f6fd7f4..32d445ada 100644 --- a/src/engine/internal/codegen/llvm/llvmcodebuilder.cpp +++ b/src/engine/internal/codegen/llvm/llvmcodebuilder.cpp @@ -94,7 +94,7 @@ std::shared_ptr LLVMCodeBuilder::build() m_utils.end(m_instructions.empty() ? nullptr : m_instructions.last(), m_lastConstValue); verifyFunction(m_function); - return std::make_shared(m_ctx, m_utils.scriptFunctionId(), m_function->getName().str(), m_ctx->coroutineResumeFunction()->getName().str(), m_utils.stringCount(), m_codeType); + return std::make_shared(m_ctx, m_utils.scriptFunctionId(), m_function->getName().str(), m_ctx->coroutineResumeFunction()->getName().str(), m_codeType); } CompilerValue *LLVMCodeBuilder::addFunctionCall(const std::string &functionName, Compiler::StaticType returnType, const Compiler::ArgTypes &argTypes, const Compiler::Args &args) diff --git a/src/engine/internal/codegen/llvm/llvmexecutablecode.cpp b/src/engine/internal/codegen/llvm/llvmexecutablecode.cpp index ce645a007..d8a95c180 100644 --- a/src/engine/internal/codegen/llvm/llvmexecutablecode.cpp +++ b/src/engine/internal/codegen/llvm/llvmexecutablecode.cpp @@ -18,18 +18,11 @@ using namespace libscratchcpp; static const void *END_THREAD_SENTINEL = (void *)0x1; -LLVMExecutableCode::LLVMExecutableCode( - LLVMCompilerContext *ctx, - function_id_t functionId, - const std::string &mainFunctionName, - const std::string &resumeFunctionName, - size_t stringCount, - Compiler::CodeType codeType) : +LLVMExecutableCode::LLVMExecutableCode(LLVMCompilerContext *ctx, function_id_t functionId, const std::string &mainFunctionName, const std::string &resumeFunctionName, Compiler::CodeType codeType) : m_ctx(ctx), m_functionId(functionId), m_mainFunctionName(mainFunctionName), m_resumeFunctionName(resumeFunctionName), - m_stringCount(stringCount), m_codeType(codeType) { assert(m_ctx); @@ -153,11 +146,6 @@ function_id_t LLVMExecutableCode::functionId() const return m_functionId; } -size_t LLVMExecutableCode::stringCount() const -{ - return m_stringCount; -} - LLVMExecutionContext *LLVMExecutableCode::getContext(ExecutionContext *context) { assert(dynamic_cast(context)); diff --git a/src/engine/internal/codegen/llvm/llvmexecutablecode.h b/src/engine/internal/codegen/llvm/llvmexecutablecode.h index 62837597d..308180ae0 100644 --- a/src/engine/internal/codegen/llvm/llvmexecutablecode.h +++ b/src/engine/internal/codegen/llvm/llvmexecutablecode.h @@ -18,13 +18,7 @@ class LLVMExecutionContext; class LIBSCRATCHCPP_TEST_EXPORT LLVMExecutableCode : public ExecutableCode { public: - LLVMExecutableCode( - LLVMCompilerContext *ctx, - function_id_t functionId, - const std::string &mainFunctionName, - const std::string &resumeFunctionName, - size_t stringCount, - Compiler::CodeType codeType); + LLVMExecutableCode(LLVMCompilerContext *ctx, function_id_t functionId, const std::string &mainFunctionName, const std::string &resumeFunctionName, Compiler::CodeType codeType); void run(ExecutionContext *context) override; ValueData runReporter(ExecutionContext *context) override; @@ -37,7 +31,6 @@ class LIBSCRATCHCPP_TEST_EXPORT LLVMExecutableCode : public ExecutableCode std::shared_ptr createExecutionContext(Thread *thread) const override; function_id_t functionId() const; - size_t stringCount() const; private: using MainFunctionType = void *(*)(ExecutionContext *, Target *, ValueData **, List **); @@ -52,7 +45,6 @@ class LIBSCRATCHCPP_TEST_EXPORT LLVMExecutableCode : public ExecutableCode std::string m_mainFunctionName; std::string m_predicateFunctionName; std::string m_resumeFunctionName; - size_t m_stringCount = 0; Compiler::CodeType m_codeType; mutable std::variant m_mainFunction; diff --git a/src/engine/internal/codegen/llvm/llvmexecutioncontext.cpp b/src/engine/internal/codegen/llvm/llvmexecutioncontext.cpp index 40f35990f..7757c3e70 100644 --- a/src/engine/internal/codegen/llvm/llvmexecutioncontext.cpp +++ b/src/engine/internal/codegen/llvm/llvmexecutioncontext.cpp @@ -11,25 +11,6 @@ LLVMExecutionContext::LLVMExecutionContext(LLVMCompilerContext *compilerCtx, Thr ExecutionContext(thread), m_compilerCtx(compilerCtx) { - // Allocate strings for all scripts in the target - // TODO: Allocate strings for this script and procedures it calls - const auto &codeMap = compilerCtx->codeMap(); - - for (const auto &[functionId, code] : codeMap) { - size_t count = code->stringCount(); - - if (count > 0) { - m_stringVectors[functionId] = {}; - - auto &strings = m_stringVectors[functionId]; - strings.reserve(count); - - for (size_t i = 0; i < count; i++) - strings.push_back(string_pool_new()); - - m_stringArrays[functionId] = strings.data(); - } - } } LLVMExecutionContext::~LLVMExecutionContext() @@ -41,12 +22,6 @@ LLVMExecutionContext::~LLVMExecutionContext() } else assert(false); } - - // Deallocate strings - for (const auto &[functionId, strings] : m_stringVectors) { - for (StringPtr *str : strings) - string_pool_free(str); - } } void *LLVMExecutionContext::coroutineHandle() const diff --git a/src/engine/internal/codegen/llvm/llvmexecutioncontext.h b/src/engine/internal/codegen/llvm/llvmexecutioncontext.h index 4af3b8677..ac2f671da 100644 --- a/src/engine/internal/codegen/llvm/llvmexecutioncontext.h +++ b/src/engine/internal/codegen/llvm/llvmexecutioncontext.h @@ -24,19 +24,10 @@ class LIBSCRATCHCPP_TEST_EXPORT LLVMExecutionContext : public ExecutionContext bool finished() const; void setFinished(bool newFinished); - inline StringPtr **getStringArray(function_id_t functionId) - { - assert(m_stringArrays.find(functionId) != m_stringArrays.cend()); - return m_stringArrays[functionId]; - } - private: LLVMCompilerContext *m_compilerCtx = nullptr; void *m_coroutineHandle = nullptr; bool m_finished = false; - - std::unordered_map> m_stringVectors; - std::unordered_map m_stringArrays; }; } // namespace libscratchcpp diff --git a/src/engine/internal/codegen/llvm/llvmfunctions.cpp b/src/engine/internal/codegen/llvm/llvmfunctions.cpp index c0c6fd83f..f5597ce02 100644 --- a/src/engine/internal/codegen/llvm/llvmfunctions.cpp +++ b/src/engine/internal/codegen/llvm/llvmfunctions.cpp @@ -34,9 +34,14 @@ extern "C" return ctx->rng()->randint(from, to); } - LIBSCRATCHCPP_EXPORT StringPtr **llvm_get_string_array(ExecutionContext *ctx, function_id_t functionId) + LIBSCRATCHCPP_EXPORT StringPtr **llvm_push_string_stack(ExecutionContext *ctx, size_t stringCount) { - return static_cast(ctx)->getStringArray(functionId); + return ctx->pushStringStack(stringCount); + } + + LIBSCRATCHCPP_EXPORT void llvm_pop_string_stack(ExecutionContext *ctx) + { + return ctx->popStringStack(); } LIBSCRATCHCPP_EXPORT void llvm_mark_thread_as_finished(ExecutionContext *ctx) @@ -290,12 +295,22 @@ llvm::FunctionCallee LLVMFunctions::resolve_llvm_random_bool() return resolveFunction("llvm_random_bool", llvm::FunctionType::get(m_builder->getDoubleTy(), { pointerType, m_builder->getInt1Ty(), m_builder->getInt1Ty() }, false)); } -llvm::FunctionCallee LLVMFunctions::resolve_llvm_get_string_array() +llvm::FunctionCallee LLVMFunctions::resolve_llvm_push_string_stack() { llvm::Type *stringPtr = m_stringPtrType->getPointerTo(); llvm::Type *pointerType = llvm::PointerType::get(llvm::Type::getInt8Ty(*m_ctx->llvmCtx()), 0); - llvm::FunctionCallee callee = resolveFunction("llvm_get_string_array", llvm::FunctionType::get(stringPtr->getPointerTo(), { pointerType, m_functionIdType }, false)); + llvm::FunctionCallee callee = resolveFunction("llvm_push_string_stack", llvm::FunctionType::get(stringPtr->getPointerTo(), { pointerType, m_builder->getInt64Ty() }, false)); + llvm::Function *func = llvm::cast(callee.getCallee()); + func->addFnAttr(llvm::Attribute::ReadOnly); + return callee; +} + +llvm::FunctionCallee LLVMFunctions::resolve_llvm_pop_string_stack() +{ + llvm::Type *pointerType = llvm::PointerType::get(llvm::Type::getInt8Ty(*m_ctx->llvmCtx()), 0); + + llvm::FunctionCallee callee = resolveFunction("llvm_pop_string_stack", llvm::FunctionType::get(m_builder->getVoidTy(), { pointerType }, false)); llvm::Function *func = llvm::cast(callee.getCallee()); func->addFnAttr(llvm::Attribute::ReadOnly); return callee; diff --git a/src/engine/internal/codegen/llvm/llvmfunctions.h b/src/engine/internal/codegen/llvm/llvmfunctions.h index 7ead2168c..212e827b1 100644 --- a/src/engine/internal/codegen/llvm/llvmfunctions.h +++ b/src/engine/internal/codegen/llvm/llvmfunctions.h @@ -47,7 +47,8 @@ class LLVMFunctions llvm::FunctionCallee resolve_llvm_random_double(); llvm::FunctionCallee resolve_llvm_random_int64(); llvm::FunctionCallee resolve_llvm_random_bool(); - llvm::FunctionCallee resolve_llvm_get_string_array(); + llvm::FunctionCallee resolve_llvm_push_string_stack(); + llvm::FunctionCallee resolve_llvm_pop_string_stack(); llvm::FunctionCallee resolve_llvm_mark_thread_as_finished(); llvm::FunctionCallee resolve_llvm_is_thread_finished(); llvm::FunctionCallee resolve_llvm_print(); diff --git a/test/codegen/llvm/llvmexecutablecode_test.cpp b/test/codegen/llvm/llvmexecutablecode_test.cpp index 6f14485b8..b35bf16e0 100644 --- a/test/codegen/llvm/llvmexecutablecode_test.cpp +++ b/test/codegen/llvm/llvmexecutablecode_test.cpp @@ -119,29 +119,16 @@ class LLVMExecutableCodeTest : public testing::Test TEST_F(LLVMExecutableCodeTest, FunctionId) { { - auto code = std::make_shared(m_ctx.get(), 8, "script", "resume", 0, Compiler::CodeType::Script); + auto code = std::make_shared(m_ctx.get(), 8, "script", "resume", Compiler::CodeType::Script); ASSERT_EQ(code->functionId(), 8); } { - auto code = std::make_shared(m_ctx.get(), 3, "script", "resume", 0, Compiler::CodeType::Script); + auto code = std::make_shared(m_ctx.get(), 3, "script", "resume", Compiler::CodeType::Script); ASSERT_EQ(code->functionId(), 3); } } -TEST_F(LLVMExecutableCodeTest, StringCount) -{ - { - auto code = std::make_shared(m_ctx.get(), 0, "script", "resume", 2, Compiler::CodeType::Script); - ASSERT_EQ(code->stringCount(), 2); - } - - { - auto code = std::make_shared(m_ctx.get(), 1, "script", "resume", 56, Compiler::CodeType::Script); - ASSERT_EQ(code->stringCount(), 56); - } -} - TEST_F(LLVMExecutableCodeTest, CreateExecutionContext) { llvm::Function *mainFunc = beginMainFunction(); @@ -151,7 +138,7 @@ TEST_F(LLVMExecutableCodeTest, CreateExecutionContext) endFunction(m_builder->getInt1(true)); { - auto code = std::make_shared(m_ctx.get(), 0, mainFunc->getName().str(), resumeFunc->getName().str(), 0, Compiler::CodeType::Script); + auto code = std::make_shared(m_ctx.get(), 0, mainFunc->getName().str(), resumeFunc->getName().str(), Compiler::CodeType::Script); m_script->setCode(code); Thread thread(&m_target, &m_engine, m_script.get()); auto ctx = code->createExecutionContext(&thread); @@ -170,7 +157,7 @@ TEST_F(LLVMExecutableCodeTest, CreatePredicateExecutionContext) endFunction(m_builder->getInt1(true)); { - auto code = std::make_shared(m_ctx.get(), 0, mainFunc->getName().str(), resumeFunc->getName().str(), 0, Compiler::CodeType::HatPredicate); + auto code = std::make_shared(m_ctx.get(), 0, mainFunc->getName().str(), resumeFunc->getName().str(), Compiler::CodeType::HatPredicate); m_script->setCode(code); Thread thread(&m_target, &m_engine, m_script.get()); auto ctx = code->createExecutionContext(&thread); @@ -189,7 +176,7 @@ TEST_F(LLVMExecutableCodeTest, CreateReporterExecutionContext) endFunction(m_builder->getInt1(true)); { - auto code = std::make_shared(m_ctx.get(), 0, mainFunc->getName().str(), resumeFunc->getName().str(), 0, Compiler::CodeType::Reporter); + auto code = std::make_shared(m_ctx.get(), 0, mainFunc->getName().str(), resumeFunc->getName().str(), Compiler::CodeType::Reporter); m_script->setCode(code); Thread thread(&m_target, &m_engine, m_script.get()); auto ctx = code->createExecutionContext(&thread); @@ -211,7 +198,7 @@ TEST_F(LLVMExecutableCodeTest, MainFunction) llvm::Function *resumeFunc = beginResumeFunction(); endFunction(m_builder->getInt1(true)); - auto code = std::make_shared(m_ctx.get(), 0, mainFunc->getName().str(), resumeFunc->getName().str(), 0, Compiler::CodeType::Script); + auto code = std::make_shared(m_ctx.get(), 0, mainFunc->getName().str(), resumeFunc->getName().str(), Compiler::CodeType::Script); m_script->setCode(code); Thread thread(&m_target, &m_engine, m_script.get()); auto ctx = code->createExecutionContext(&thread); @@ -266,7 +253,7 @@ TEST_F(LLVMExecutableCodeTest, PredicateFunction) llvm::Function *resumeFunc = beginResumeFunction(); endFunction(m_builder->getInt1(true)); - auto code = std::make_shared(m_ctx.get(), 0, mainFunc->getName().str(), resumeFunc->getName().str(), 0, Compiler::CodeType::HatPredicate); + auto code = std::make_shared(m_ctx.get(), 0, mainFunc->getName().str(), resumeFunc->getName().str(), Compiler::CodeType::HatPredicate); m_script->setCode(code); Thread thread(&m_target, &m_engine, m_script.get()); auto ctx = code->createExecutionContext(&thread); @@ -295,7 +282,7 @@ TEST_F(LLVMExecutableCodeTest, ReporterFunction) llvm::Function *resumeFunc = beginResumeFunction(); endFunction(m_builder->getInt1(true)); - auto code = std::make_shared(m_ctx.get(), 0, mainFunc->getName().str(), resumeFunc->getName().str(), 0, Compiler::CodeType::Reporter); + auto code = std::make_shared(m_ctx.get(), 0, mainFunc->getName().str(), resumeFunc->getName().str(), Compiler::CodeType::Reporter); m_script->setCode(code); Thread thread(&m_target, &m_engine, m_script.get()); auto ctx = code->createExecutionContext(&thread); @@ -314,7 +301,7 @@ TEST_F(LLVMExecutableCodeTest, Promise) llvm::Function *resumeFunc = beginResumeFunction(); endFunction(m_builder->getInt1(true)); - auto code = std::make_shared(m_ctx.get(), 0, mainFunc->getName().str(), resumeFunc->getName().str(), 0, Compiler::CodeType::Script); + auto code = std::make_shared(m_ctx.get(), 0, mainFunc->getName().str(), resumeFunc->getName().str(), Compiler::CodeType::Script); m_script->setCode(code); Thread thread(&m_target, &m_engine, m_script.get()); auto ctx = code->createExecutionContext(&thread); diff --git a/test/engine/engine_test.cpp b/test/engine/engine_test.cpp index ebeab4a7d..175eefb80 100644 --- a/test/engine/engine_test.cpp +++ b/test/engine/engine_test.cpp @@ -2382,3 +2382,20 @@ TEST(EngineTest, ScriptsAreStoppedFromProcedureStoppingAll_Nested) ASSERT_VAR(stage, "passed"); ASSERT_TRUE(GET_VAR(stage, "passed")->value().toBool()); } + +TEST(EngineTest, NoStringStackRaceConditionInRecursiveProcedures) +{ + // Regtest for #704 + Project p("regtest_projects/704_string_stack_race_condition.sb3"); + ASSERT_TRUE(p.load()); + + auto engine = p.engine(); + + Stage *stage = engine->stage(); + ASSERT_TRUE(stage); + + engine->run(); + + ASSERT_VAR(stage, "passed"); + ASSERT_TRUE(GET_VAR(stage, "passed")->value().toBool()); +} diff --git a/test/regtest_projects/704_string_stack_race_condition.sb3 b/test/regtest_projects/704_string_stack_race_condition.sb3 new file mode 100644 index 0000000000000000000000000000000000000000..377c7ca3451444cbe96db286d88d20e354ff4568 GIT binary patch literal 1836 zcma)7X*3&%7LKhLlok`Q>!7uZ%9D8ZWlAhf?KO(j5_?jVT8av7Y6(hJXvSJ%ZBi

@@g zwD{_k$p-*1Bmn^7(<>$t9TMOdtsN4Dj$n99Mza1U@%^!|Dlyo(U-c#Qp|>a6p#T~= z@JP-8Uw2Ocm&$iuA21Z-w8Kg;&(%}Q$FD$%yVg8Nr4PnS5p-Y`MVRD9irVD^Gnmja zQe}XJoW!hH|C?c05MG7m=ZIVbZoea#ni}77T}?zsBA15i_ee zT;NDGCF*DoClO9|=5|m6Y}oOgHrjO2YO#9u)8_I?qe5sO)W3 ze?5?av7t7w&}tCV)WLUPj*(A z>w3o*tE5BH1d!gTUf5Tooad4)KqTWpsWWkT3#@&okn+|tIeG<@;=OPYo{1?i0r}oJ zTcMUASozfdxvR51ePPr@YmUdT#%OOtV=TBUT8vC(couCzMtn)>-T3A61ipMrp300j z+NF@INg6ESw7B_#q7h@;UDv*I*u7|q;TsNS8LEO9d=d%$;i zrer356RX#xjiu8?FRxjlO4T>+TG0C3<^?7L$>$y{xFUYI=!KG5`KL-DB~GL0-j70l z!Fg|wzSxX<*sLGtjXtvOy#((Ax5bJyw%CN`L8D*X#dM;b&%Uz6!=OjfM6x5CZ0{{~ z;EWS0PB`2@?Ej`)_ZXVov-I?(?3eOc4Bzy%*n}ltQ_-BE5zzEP8O+yAIjIDOHKB^FM$$j4>;X)Hdtj>WW2e*6wQS~G9ON?G` zS`d;m6F)pAx6(sx7z|l5=Vu?!RJ+$jJR9fMP{7g$=krPMHeV658;-&Hv(R3)}+6kl0KuD&VzVdYx7u0*cdL7)JYHry)8Xo>Ph?l6jQ& z)PSjX-;*RmTix*1ow%LEuH)qsg7-oDVIwcA!O856n$k?3$H$);`qc$Z?6wFYYVuqD}{~DHf(NH1YHSaxShT&IjDXVZz<<3p# z!aaqyZc=-v#|fwJGEh9jyh+2w$Dpxmy?$cpNDTStaGc}5_?&K@^2rZ03&VAHF9ri? z2jZF{XZ%OfF5H~yn!H`8RP!Q(kUjo*CAOh9MrCctxw#Pm^|Eb3C}itYJyGsr8K@dj z;68d4HOoQp>$;3(F->$$Ar+lh0p)3*w){XGy?HWQpCwbhTePXdm^|J->@V_IZm<(? z7E@!PRNp`G=a8&r!eu9PJ-{FDy9W~UzC~;m*Y9d=xQ$n$3zaouWA7c;DQCOQ|6QX&!(v?dr)E8L3guJy`RjopV10jG z$YpS#e_-HEJv}{L{Q%tnKS+Q-R3E7w6@vWijON(V_OWtT4HwKc~>ke5fd-JW$M@}0S2 zaLj80o2yP1^tA`B?%5>+5O!SL5`h1oMW>(rq5hame`fw!kpI$No@U!$kq2SNcjn(L N?$gdXof-ex{so97PM`n) literal 0 HcmV?d00001 From b25312e20216654eb7dfbd1337d6edfdd89f12f8 Mon Sep 17 00:00:00 2001 From: adazem009 <68537469+adazem009@users.noreply.github.com> Date: Sat, 7 Nov 2026 00:33:00 +0100 Subject: [PATCH 3/5] ExecutionContext: Add clearStringStack() method --- include/scratchcpp/executioncontext.h | 17 ++++++++++++++++- src/engine/executioncontext.cpp | 7 +------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/include/scratchcpp/executioncontext.h b/include/scratchcpp/executioncontext.h index dc0b0111f..b3a71f57b 100644 --- a/include/scratchcpp/executioncontext.h +++ b/include/scratchcpp/executioncontext.h @@ -41,6 +41,7 @@ class LIBSCRATCHCPP_EXPORT ExecutionContext inline StringPtr **pushStringStack(size_t stringCount) { + m_stringStackCleared = false; m_stringStack.push({}); auto &strings = m_stringStack.top(); @@ -55,7 +56,11 @@ class LIBSCRATCHCPP_EXPORT ExecutionContext inline void popStringStack() { - assert(!m_stringStack.empty()); + if (m_stringStackCleared) // avoid UB when popping after killing a thread + return; + + assert(!m_stringStack.empty()); // check only in debug mode to maximize performance + const auto &strings = m_stringStack.top(); for (StringPtr *str : strings) @@ -64,10 +69,20 @@ class LIBSCRATCHCPP_EXPORT ExecutionContext m_stringStack.pop(); } + inline void clearStringStack() + { + while (!m_stringStack.empty()) { + popStringStack(); + } + + m_stringStackCleared = true; + } + private: spimpl::unique_impl_ptr impl; std::stack> m_stringStack; + bool m_stringStackCleared = false; }; } // namespace libscratchcpp diff --git a/src/engine/executioncontext.cpp b/src/engine/executioncontext.cpp index fbf3cbbd9..c24ba0ccc 100644 --- a/src/engine/executioncontext.cpp +++ b/src/engine/executioncontext.cpp @@ -17,12 +17,7 @@ ExecutionContext::ExecutionContext(Thread *thread) : ExecutionContext::~ExecutionContext() { // Deallocate strings - // NOTE: The stack should be already empty - assert(m_stringStack.empty()); - - while (!m_stringStack.empty()) { - popStringStack(); - } + clearStringStack(); } /*! Returns the thread of this context. */ From 237857ca4850258db3eea2b9c50245e569a2739d Mon Sep 17 00:00:00 2001 From: adazem009 <68537469+adazem009@users.noreply.github.com> Date: Sat, 7 Nov 2026 00:58:19 +0100 Subject: [PATCH 4/5] Pop string stack correctly --- include/scratchcpp/thread.h | 1 + .../internal/codegen/llvm/llvmbuildutils.cpp | 33 ++++++------------ .../internal/codegen/llvm/llvmbuildutils.h | 5 +-- src/engine/thread.cpp | 9 +++++ test/engine/engine_test.cpp | 17 +++++++++ ..._string_stack_with_procedure_arguments.sb3 | Bin 0 -> 1793 bytes 6 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 test/regtest_projects/704_string_stack_with_procedure_arguments.sb3 diff --git a/include/scratchcpp/thread.h b/include/scratchcpp/thread.h index 353d9aeed..7a61529f5 100644 --- a/include/scratchcpp/thread.h +++ b/include/scratchcpp/thread.h @@ -20,6 +20,7 @@ class LIBSCRATCHCPP_EXPORT Thread public: Thread(Target *target, IEngine *engine, Script *script); Thread(const Thread &) = delete; + ~Thread(); Target *target() const; IEngine *engine() const; diff --git a/src/engine/internal/codegen/llvm/llvmbuildutils.cpp b/src/engine/internal/codegen/llvm/llvmbuildutils.cpp index 31e4685b1..e45cb64a8 100644 --- a/src/engine/internal/codegen/llvm/llvmbuildutils.cpp +++ b/src/engine/internal/codegen/llvm/llvmbuildutils.cpp @@ -82,9 +82,6 @@ void LLVMBuildUtils::init(llvm::Function *function, BlockPrototype *procedurePro // Create string count variable (LLVM should optimize it into a constant later) m_stringCountVar = m_builder.CreateAlloca(m_builder.getInt64Ty(), nullptr, "stringCount"); - // Create string array variable - m_stringArrayVar = m_builder.CreateAlloca(m_stringPtrType->getPointerTo(), nullptr, "stringArray"); - // Create string count block (string count is known after all instructions are processed) m_stringCountBlock = llvm::BasicBlock::Create(m_llvmCtx, "getStringCount", m_function); m_builder.CreateBr(m_stringCountBlock); @@ -97,7 +94,9 @@ void LLVMBuildUtils::init(llvm::Function *function, BlockPrototype *procedurePro // Push string stack (load string array) m_builder.SetInsertPoint(m_stringAllocaBlock); - pushStringStack(); + + llvm::Value *stringCount = m_builder.CreateLoad(m_builder.getInt64Ty(), m_stringCountVar, "strCount"); + m_stringArray = m_builder.CreateCall(m_functions.resolve_llvm_push_string_stack(), { m_executionContextPtr, stringCount }); // Create next block m_stringAllocaNextBlock = llvm::BasicBlock::Create(m_llvmCtx, "entry.next", m_function); @@ -178,7 +177,7 @@ void LLVMBuildUtils::end(LLVMInstruction *lastInstruction, LLVMRegister *lastCon // End branch m_builder.SetInsertPoint(m_endBranch); - popStringStack(); + m_builder.CreateCall(m_functions.resolve_llvm_pop_string_stack(), { m_executionContextPtr }); llvm::PointerType *pointerType = llvm::PointerType::get(llvm::Type::getInt8Ty(m_llvmCtx), 0); @@ -212,7 +211,7 @@ void LLVMBuildUtils::end(LLVMInstruction *lastInstruction, LLVMRegister *lastCon // Thread end branch (stop the entire thread, including procedure callers) m_builder.SetInsertPoint(m_endThreadBranch); - popStringStack(); + m_builder.CreateCall(m_functions.resolve_llvm_pop_string_stack(), { m_executionContextPtr }); switch (m_codeType) { case Compiler::CodeType::Script: @@ -513,10 +512,14 @@ llvm::Value *LLVMBuildUtils::addAlloca(llvm::Type *type) llvm::Value *LLVMBuildUtils::addStringAlloca() { // All temporary strings are allocated when the string stack is pushed - llvm::Value *stringArray = m_builder.CreateLoad(m_stringPtrType->getPointerTo(), m_stringArrayVar, "loadedStringArray"); + llvm::BasicBlock *block = m_builder.GetInsertBlock(); + m_builder.SetInsertPoint(m_stringAllocaBlock); + llvm::Value *index = m_builder.getInt64(m_stringCount++); - llvm::Value *elementPtr = m_builder.CreateGEP(m_stringPtrType->getPointerTo(), stringArray, index); + llvm::Value *elementPtr = m_builder.CreateGEP(m_stringPtrType->getPointerTo(), m_stringArray, index); llvm::Value *ret = m_builder.CreateLoad(m_stringPtrType->getPointerTo(), elementPtr, "localString"); + + m_builder.SetInsertPoint(block); return ret; } @@ -1428,14 +1431,12 @@ void LLVMBuildUtils::createSuspend() m_builder.SetInsertPoint(suspendBranch); } - popStringStack(); syncVariables(); m_coroutine->createSuspend(); reloadVariables(); reloadLists(); - pushStringStack(); if (m_warpArg) { m_builder.CreateBr(nextBranch); @@ -2205,15 +2206,3 @@ llvm::Value *LLVMBuildUtils::getListDataPtr(const LLVMListPtr &listPtr) { return m_builder.CreateLoad(m_valueDataType->getPointerTo(), m_builder.CreateLoad(m_valueDataType->getPointerTo()->getPointerTo(), listPtr.dataPtr)); } - -void LLVMBuildUtils::pushStringStack() -{ - llvm::Value *stringCount = m_builder.CreateLoad(m_builder.getInt64Ty(), m_stringCountVar, "strCount"); - llvm::Value *strings = m_builder.CreateCall(m_functions.resolve_llvm_push_string_stack(), { m_executionContextPtr, stringCount }); - m_builder.CreateStore(strings, m_stringArrayVar); -} - -void LLVMBuildUtils::popStringStack() -{ - m_builder.CreateCall(m_functions.resolve_llvm_pop_string_stack(), { m_executionContextPtr }); -} diff --git a/src/engine/internal/codegen/llvm/llvmbuildutils.h b/src/engine/internal/codegen/llvm/llvmbuildutils.h index 64d88d6af..febb86d83 100644 --- a/src/engine/internal/codegen/llvm/llvmbuildutils.h +++ b/src/engine/internal/codegen/llvm/llvmbuildutils.h @@ -154,9 +154,6 @@ class LIBSCRATCHCPP_TEST_EXPORT LLVMBuildUtils llvm::Value *getListPtr(llvm::Value *targetLists, List *list); llvm::Value *getListDataPtr(const LLVMListPtr &listPtr); - void pushStringStack(); - void popStringStack(); - LLVMCompilerContext *m_ctx = nullptr; llvm::LLVMContext &m_llvmCtx; llvm::IRBuilder<> &m_builder; @@ -201,7 +198,7 @@ class LIBSCRATCHCPP_TEST_EXPORT LLVMBuildUtils llvm::BasicBlock *m_stringAllocaBlock = nullptr; llvm::BasicBlock *m_stringAllocaNextBlock = nullptr; llvm::Value *m_stringCountVar = nullptr; - llvm::Value *m_stringArrayVar = nullptr; + llvm::Value *m_stringArray = nullptr; size_t m_stringCount = 0; }; diff --git a/src/engine/thread.cpp b/src/engine/thread.cpp index 3ab120c54..4e554e703 100644 --- a/src/engine/thread.cpp +++ b/src/engine/thread.cpp @@ -25,6 +25,13 @@ Thread::Thread(Target *target, IEngine *engine, Script *script) : } } +/*! Destroys Thread. */ +Thread::~Thread() +{ + if (impl->executionContext) + impl->executionContext->clearStringStack(); +} + /*! Returns the Target of the script. */ Target *Thread::target() const { @@ -70,12 +77,14 @@ bool Thread::runPredicate() void Thread::kill() { impl->code->kill(impl->executionContext.get()); + impl->executionContext->clearStringStack(); } /*! Resets the script to run from the start. */ void Thread::reset() { impl->code->reset(impl->executionContext.get()); + impl->executionContext->clearStringStack(); } /*! Returns true if the script is stopped or finished. */ diff --git a/test/engine/engine_test.cpp b/test/engine/engine_test.cpp index 175eefb80..fdc03fb48 100644 --- a/test/engine/engine_test.cpp +++ b/test/engine/engine_test.cpp @@ -2399,3 +2399,20 @@ TEST(EngineTest, NoStringStackRaceConditionInRecursiveProcedures) ASSERT_VAR(stage, "passed"); ASSERT_TRUE(GET_VAR(stage, "passed")->value().toBool()); } + +TEST(EngineTest, NoStaleStringStackInNonWarpProceduresWithArguments) +{ + // Regtest for #704 + Project p("regtest_projects/704_string_stack_with_procedure_arguments.sb3"); + ASSERT_TRUE(p.load()); + + auto engine = p.engine(); + + Stage *stage = engine->stage(); + ASSERT_TRUE(stage); + + engine->run(); + + ASSERT_VAR(stage, "passed"); + ASSERT_TRUE(GET_VAR(stage, "passed")->value().toBool()); +} diff --git a/test/regtest_projects/704_string_stack_with_procedure_arguments.sb3 b/test/regtest_projects/704_string_stack_with_procedure_arguments.sb3 new file mode 100644 index 0000000000000000000000000000000000000000..eb1ef022184bcb38f90b9e0d3fa30ee73ead8b74 GIT binary patch literal 1793 zcma)7X*3&%7LFwyT2)&ulZdgzK5B_=tixE-6h*8pkyxiC6)A>Rkrc6v$S59pmTGA0 zSxTE|8_P&EwmgGObYcn7sty(7p{=E3-k&$`z4Oj__nzA2y7G%jZf!FMm&U8TuCn~ zh=B`WW9773s_CUm{06=7xbsEEKKA{uH~Vyrpx2EblSKIa7Y!`k!*}!Z4kW%eN>Lda zkd7^FT{i(M&jjlj$opQCL}M216K(_961ve@rHs87l$Exevkd0Z(OQRt%lj-p)S2eO zAc*?i#{A38&lZc7SMlrH`HXt-{ysH1QKV+WJy@aVe%${cWcKf*87#bEE`ERuFrmIm z8h3m1)hj<=ww99`yr!}&h#wwGw2;rNDDSD0#c2!IpjF2FGR7|hC4Zw6vn1qO$if;= zO%yQ-M~((6r>YK_l)7tvBL;i+@wa{<3lcL$36ApFi|GOu6jktz;HuoP&y2R(gWL_; zd?c25_SG7Ez=!29vmMzvnWT=xZSJX&Ra`xodr^%jOd<@&v3w= zhFm;M=O9!V6sOLSITt_=?7Ph{MgaWCmvN0{nJ&6|b>L+f7XfLuN8{qPErzQ{h~pgT zVAeAV=(LEaL-7jZ=rTj}GrXH373@izYFdyLz@g=iKlRoyFgC!xkQSC~Lv)3+Ddd+L zvs+-8O_&vp;K5!Tl`VV!p;U?#Ux4upt$C}~Dp>@BLBmd1aYI1@H1GXIj_sCWYDM1^zUwMSZ)w1dX?M75xx|9 zZujou$rGt--sL5yIAU^89&O8Tf&#e6xIMe2(^Wjv=#qZMZ?`Q0;JosNIMktdavLLy zC!@J7~?1(>YzkLo$nL3ZrA9EWr+uo!8`>E2Jfx5j*`6u~rc+7C#F zK1mJvDnjSCEnfOi_r|=f%g8Qe@BsbmY81qUuE3^m_})YygC!yZL#A$4r`5H$K99$b znt+TuoIfHVr68la(1PC{J>I+6D<3+&V@qhLQ8j2q;*&@~$@U}NFZ*(Ma}zi4IY#n* zrfl?O1D1rU2}j(Vi2n;WGvD%|>4nV*a8Ux9m7%z`qFtz^4;>+$RG%@5o^_Q-ab7p+ zKL9OpA9hz|j}A7-r!k~IZfs^T=kJF6b!0 zvH5eR?u3x;*DuPHrq>r^7|y7EPA9S|I1R&dXk4axg8VCmZC-luy_HusbFh9vc=*gg z8E4wowZe^jt`2qyH%W-{=@|7;Jge7pdGn1|u1LK$7Ptg0?0br#ZCUNgoGO(_gvk~t zTdA=(n)F*9J@0AceUX(s9m~*z-_s9UVvT498<9d*^LxpU4rgeqa@}($KGu0A#ds>a ziHa=UvCq-q&FtYKjLPhHQeXbm8B;Iz`1*8ZN2?q#fXM9CpN1f5d*P1%(0Yv;i>fNF zoH~qFE9Qzj4c|G=cyYoF5f#3iw@qbAP2&bky^-@(XOgZyt!?kyA;^>F5Q~n&+0lmU z-=nNgWKI^J^swi84EXI>$ic$R=igV3V$#2buW8(H6|CqiAojq+NdZ5+3K3^flLF#PAeEc8yWK{hZmCXT#It$U$(=pZyqdJF zFl|a_V;*8`+Rlr3Cn1sGZM2p4+F7p2c Date: Sat, 7 Nov 2026 01:00:28 +0100 Subject: [PATCH 5/5] Remove read only attributes from string stack functions --- src/engine/internal/codegen/llvm/llvmfunctions.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/engine/internal/codegen/llvm/llvmfunctions.cpp b/src/engine/internal/codegen/llvm/llvmfunctions.cpp index f5597ce02..98495db75 100644 --- a/src/engine/internal/codegen/llvm/llvmfunctions.cpp +++ b/src/engine/internal/codegen/llvm/llvmfunctions.cpp @@ -302,7 +302,6 @@ llvm::FunctionCallee LLVMFunctions::resolve_llvm_push_string_stack() llvm::FunctionCallee callee = resolveFunction("llvm_push_string_stack", llvm::FunctionType::get(stringPtr->getPointerTo(), { pointerType, m_builder->getInt64Ty() }, false)); llvm::Function *func = llvm::cast(callee.getCallee()); - func->addFnAttr(llvm::Attribute::ReadOnly); return callee; } @@ -312,7 +311,6 @@ llvm::FunctionCallee LLVMFunctions::resolve_llvm_pop_string_stack() llvm::FunctionCallee callee = resolveFunction("llvm_pop_string_stack", llvm::FunctionType::get(m_builder->getVoidTy(), { pointerType }, false)); llvm::Function *func = llvm::cast(callee.getCallee()); - func->addFnAttr(llvm::Attribute::ReadOnly); return callee; }