Skip to content

Commit

Permalink
Fix memory errors with some --debug program builds
Browse files Browse the repository at this point in the history
When we upgraded to LLVM 15, we accidentally changed our optimization
level for programs compiled with --debug. This uncovered a pre-existing
condition and caused issues like #4369.

This takes us back to LLVM 14 level but doesn't "fix" the underlying
issue which we are continuing to work on.
  • Loading branch information
SeanTAllen committed Aug 15, 2023
1 parent 3452bc4 commit 312a0d4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .release-notes/4369.md
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 7 additions & 3 deletions src/libponyc/codegen/genopt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/libponyc/codegen/host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ 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 :
target_is_arm(opt->triple) ? CodeGenOpt::Default : CodeGenOpt::None;
Expand Down
26 changes: 26 additions & 0 deletions test/libponyc-run/regression-4369/main.pony
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 312a0d4

Please sign in to comment.