bridge: make nil pointer dereference "defined"

Generally the LLVM backend treats nil pointer dereference as
undefined behavior. In Go, this is actually defined as triggering
a run-time panic. Set "null-pointer-is-valid" attribute to tell
the backend not to rewrite nil pointer dereference.

Due to the lack of non-call exceptions, this is not enough for us
to remove the explicit nil checks. But this is enough to make
sure intrinsified atomic operations, when the input is nil, will
seg fault.

Change-Id: Icd26acfcf94247bbb0213278842f8fcc3701bbc2
Reviewed-by: Than McIntosh <>
diff --git a/bridge/go-llvm.cpp b/bridge/go-llvm.cpp
index a8d1662..3e77a4f 100644
--- a/bridge/go-llvm.cpp
+++ b/bridge/go-llvm.cpp
@@ -2616,6 +2616,7 @@
     fcn->addFnAttr("disable-tail-calls", "true");
+    fcn->addFnAttr("null-pointer-is-valid", "true"); // Don't optimize nil pointer deref to undefined
     // inline/noinline
     if ((flags & Backend::function_is_inlinable) == 0 || noInline_)