From c622cbac398c94327e7d4bfd261badd10db1ad6c Mon Sep 17 00:00:00 2001 From: Jaden Weiss Date: Mon, 24 Feb 2020 15:43:27 -0500 Subject: [PATCH] compiler: mark abort as noreturn This marks the libc function abort as non-returning. This allows LLVM to optimize away code after panics. Also, this allows deadlocks to be properly propogated with the coroutines scheduler. --- compiler/compiler.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/compiler.go b/compiler/compiler.go index 4d3d50d2..ebfcc128 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -365,6 +365,12 @@ func (c *Compiler) Compile(mainPath string) []error { // See emitNilCheck in asserts.go. c.mod.NamedFunction("runtime.isnil").AddAttributeAtIndex(1, nocapture) + // On *nix systems, the "abort" functuion in libc is used to handle fatal panics. + // Mark it as noreturn so LLVM can optimize away code. + if abort := c.mod.NamedFunction("abort"); !abort.IsNil() && abort.IsDeclaration() { + abort.AddFunctionAttr(getAttr("noreturn")) + } + // This function is necessary for tracking pointers on the stack in a // portable way (see gc.go). Indicate to the optimizer that the only thing // we'll do is read the pointer.