diff --git a/.release-notes/4369.md b/.release-notes/4369.md new file mode 100644 index 0000000000..5358199aac --- /dev/null +++ b/.release-notes/4369.md @@ -0,0 +1,5 @@ +## Fix memory errors with some `--debug` program builds + +When we upgraded to LLVM 15, we accidentally changed the optimization level applied to `--debug` builds. That change in optimization levels surfaced a rather complicated bug that we've been looking into. The end result? Some programs would crash with memory errors like segfaults or bad access. + +We've updated to go back to the optimization setup we had with LLVM 14. We recommend updating your `ponyc` installation as soon as possible. diff --git a/src/libponyc/codegen/genopt.cc b/src/libponyc/codegen/genopt.cc index 3cb3d372af..f72be1a552 100644 --- a/src/libponyc/codegen/genopt.cc +++ b/src/libponyc/codegen/genopt.cc @@ -1013,9 +1013,13 @@ static void optimise(compile_t* c, bool pony_specific) // Create the top-level module pass manager using the default LLVM pipeline. // Choose the appropriate optimization level based on if we're in a release. - ModulePassManager MPM = PB.buildPerModuleDefaultPipeline( - c->opt->release ? OptimizationLevel::O3 : OptimizationLevel::O1 - ); + ModulePassManager MPM; + + if (c->opt->release) { + MPM = PB.buildPerModuleDefaultPipeline(OptimizationLevel::O3); + } else { + MPM = PB.buildO0DefaultPipeline(OptimizationLevel::O0); + } // Run the passes. MPM.run(*unwrap(c->module), MAM); diff --git a/src/libponyc/codegen/host.cc b/src/libponyc/codegen/host.cc index e7e3d89a65..10ce2cb09e 100644 --- a/src/libponyc/codegen/host.cc +++ b/src/libponyc/codegen/host.cc @@ -31,9 +31,7 @@ LLVMTargetMachineRef codegen_machine(LLVMTargetRef target, pass_opt_t* opt) // The Arm debug fix is a "temporary" fix for issue #3874 // https://github.com/ponylang/ponyc/issues/3874 - // Hopefully we get #3874 figured out in a reasonable amount of time. - CodeGenOpt::Level opt_level = - opt->release ? CodeGenOpt::Aggressive : + CodeGenOpt::Level opt_level = opt->release ? CodeGenOpt::Aggressive : target_is_arm(opt->triple) ? CodeGenOpt::Default : CodeGenOpt::None; TargetOptions options; diff --git a/test/libponyc-run/regression-4369/main.pony b/test/libponyc-run/regression-4369/main.pony new file mode 100644 index 0000000000..80c22131ec --- /dev/null +++ b/test/libponyc-run/regression-4369/main.pony @@ -0,0 +1,26 @@ +use "time" + +class TimerPrint is TimerNotify + var _count: U64 = 0 + + new iso create() => + None + + fun ref apply(timer: Timer, count: U64): Bool => + _count = _count + count + _count < 10 + + fun ref cancel(timer: Timer) => + None + +actor Main + new create(env: Env) => + let timers = Timers + + let t1 = Timer(TimerPrint, 500000000, 500000000) // 500 ms + let t2 = Timer(TimerPrint, 500000000, 500000000) // 500 ms + + let t1' = t1 + timers(consume t1) + timers.cancel(t1') + timers(consume t2)