gollvm: emit debug meta-data for global variables
Fill in debug meta-data for global variables. This required
reworking the DIBuildHelper class, which previously was active
only during control flow generation for a function, and is now
a module-scope entity.
Change-Id: I15d82e0fd862ff976c385eb09b53bfc42347ca8d
Reviewed-on: https://go-review.googlesource.com/46419
Reviewed-by: Cherry Zhang <cherryyz@google.com>
diff --git a/unittests/BackendCore/BackendDebugEmit.cpp b/unittests/BackendCore/BackendDebugEmit.cpp
index d9c8ad1..0fc3fcf 100644
--- a/unittests/BackendCore/BackendDebugEmit.cpp
+++ b/unittests/BackendCore/BackendDebugEmit.cpp
@@ -130,4 +130,29 @@
std::cerr << fdump;
}
+TEST(BackendVarTests, TestGlobalVarDebugEmit) {
+ FcnTestHarness h("foo");
+ Llvm_backend *be = h.be();
+ Location loc = h.loc();
+
+ Btype *bi32t = be->integer_type(false, 32);
+ Bvariable *g1 =
+ be->global_variable("_bar", "bar", bi32t,
+ true, /* is_external */
+ false, /* is_hidden */
+ false, /* unique_section */
+ loc);
+ be->global_variable_set_init(g1, mkInt32Const(be, 101));
+
+ bool broken = h.finish(PreserveDebugInfo);
+ EXPECT_FALSE(broken && "Module failed to verify.");
+
+ // This is a long way from verifying that the debug meta-data is in fact
+ // completely correct, but at least it checks that the global
+ // wasn't skipped.
+ bool ok = h.expectModuleDumpContains("!DIGlobalVariable(name: \"bar\",");
+ EXPECT_TRUE(ok);
+
+}
+
}