bridge: attach metadata to address-taken allocas to help liveness analysis

The liveness of address-taken allocas and non-address-taken
allocas are different. To help the liveness analysis here we
attach some metadata to allocas if the frontend tells us it is

The backend could inspect the IR to see if an alloca's address
is taken. But this is sometimes too conservative. For example,
certain functions take the address just to read or write (e.g.
the equality function of an aggregate type). The frontend does
not mark the variable address-taken in this case. And it is safe
for the liveness to treat it as non-address-taken.

Change the local variables in the unit tests to be non-address-
taken, so we don't need to add the metadata to the expected
outputs. Even if the variable's address is actually taken, it
doesn't really matter, as the address-taken information is only
used for stack map generation, which does not run in these unit

Change-Id: Ia25326c72c0e9571f9072ccfdd26f25468a3fbd4
Reviewed-by: Than McIntosh <>
diff --git a/bridge/go-llvm-bfunction.cpp b/bridge/go-llvm-bfunction.cpp
index cd94a99..7382331 100644
--- a/bridge/go-llvm-bfunction.cpp
+++ b/bridge/go-llvm-bfunction.cpp
@@ -251,6 +251,8 @@
   } else {
     inst = addAlloca(btype->type(), name);
+  if (is_address_taken)
+    inst->setMetadata("go_addrtaken", llvm::MDNode::get(inst->getContext(), {}));
   Bvariable *bv =
       new Bvariable(btype, location, name, LocalVar, is_address_taken, inst);
diff --git a/unittests/BackendCore/TestUtils.cpp b/unittests/BackendCore/TestUtils.cpp
index 02485d1..2699203 100644
--- a/unittests/BackendCore/TestUtils.cpp
+++ b/unittests/BackendCore/TestUtils.cpp
@@ -445,7 +445,7 @@
                                    Bexpression *init)
-  Bvariable *v = be()->local_variable(func_, name, typ, nullptr, true, loc_);
+  Bvariable *v = be()->local_variable(func_, name, typ, nullptr, false, loc_);
   if (!init)
     init = be()->zero_expression(typ);
   Bstatement *is = be()->init_statement(func_, v, init);