diff --git a/cl/_testdata/importpkg/out.ll b/cl/_testdata/importpkg/out.ll index dc48a001..7097b520 100644 --- a/cl/_testdata/importpkg/out.ll +++ b/cl/_testdata/importpkg/out.ll @@ -1,7 +1,7 @@ ; ModuleID = 'main' source_filename = "main" -@main.hello = global ptr null +@main.hello = global [7 x i8] undef @"main.init$guard" = global ptr null @__llgo_argc = global ptr null @__llgo_argv = global ptr null diff --git a/cl/_testdata/method/out.ll b/cl/_testdata/method/out.ll index cbec5de4..c8a40fd1 100644 --- a/cl/_testdata/method/out.ll +++ b/cl/_testdata/method/out.ll @@ -1,7 +1,7 @@ ; ModuleID = 'main' source_filename = "main" -@main.format = global ptr null +@main.format = global [10 x i8] undef @"main.init$guard" = global ptr null @__llgo_argc = global ptr null @__llgo_argv = global ptr null diff --git a/cl/_testdata/printf/out.ll b/cl/_testdata/printf/out.ll index 02d042b6..fd92dcbe 100644 --- a/cl/_testdata/printf/out.ll +++ b/cl/_testdata/printf/out.ll @@ -1,7 +1,7 @@ ; ModuleID = 'main' source_filename = "main" -@main.hello = global ptr null +@main.hello = global [7 x i8] undef @"main.init$guard" = global ptr null @__llgo_argc = global ptr null @__llgo_argv = global ptr null diff --git a/cl/_testdata/printval/out.ll b/cl/_testdata/printval/out.ll index 6b97f9ef..28677659 100644 --- a/cl/_testdata/printval/out.ll +++ b/cl/_testdata/printval/out.ll @@ -1,7 +1,7 @@ ; ModuleID = 'main' source_filename = "main" -@main.format = global ptr null +@main.format = global [10 x i8] undef @"main.init$guard" = global ptr null @__llgo_argc = global ptr null @__llgo_argv = global ptr null diff --git a/cl/_testdata/ptrmthd/out.ll b/cl/_testdata/ptrmthd/out.ll index 79d70308..ff58cec0 100644 --- a/cl/_testdata/ptrmthd/out.ll +++ b/cl/_testdata/ptrmthd/out.ll @@ -1,7 +1,7 @@ ; ModuleID = 'main' source_filename = "main" -@main.format = global ptr null +@main.format = global [10 x i8] undef @"main.init$guard" = global ptr null @__llgo_argc = global ptr null @__llgo_argv = global ptr null diff --git a/cl/_testrt/gblarray/out.ll b/cl/_testrt/gblarray/out.ll index d0f42446..c722d6d0 100644 --- a/cl/_testrt/gblarray/out.ll +++ b/cl/_testrt/gblarray/out.ll @@ -3,9 +3,9 @@ source_filename = "main" %"github.com/goplus/llgo/internal/abi.Type" = type { i64, i64, i32, i8, i8, i8, i8, { ptr, ptr }, ptr, i32, i32 } -@main.basicTypes = global ptr null +@main.basicTypes = global [25 x ptr] undef @"main.init$guard" = global ptr null -@main.sizeBasicTypes = global ptr null +@main.sizeBasicTypes = global [25 x i64] undef @__llgo_argc = global ptr null @__llgo_argv = global ptr null @0 = private unnamed_addr constant [20 x i8] c"Kind: %d, Size: %d\0A\00", align 1 diff --git a/cl/_testrt/hello/out.ll b/cl/_testrt/hello/out.ll index f71fe323..f8cd7298 100644 --- a/cl/_testrt/hello/out.ll +++ b/cl/_testrt/hello/out.ll @@ -1,7 +1,7 @@ ; ModuleID = 'main' source_filename = "main" -@main.format = global ptr null +@main.format = global [10 x i8] undef @"main.init$guard" = global ptr null @__llgo_argc = global ptr null @__llgo_argv = global ptr null diff --git a/cl/_testrt/strlen/out.ll b/cl/_testrt/strlen/out.ll index f71fe323..f8cd7298 100644 --- a/cl/_testrt/strlen/out.ll +++ b/cl/_testrt/strlen/out.ll @@ -1,7 +1,7 @@ ; ModuleID = 'main' source_filename = "main" -@main.format = global ptr null +@main.format = global [10 x i8] undef @"main.init$guard" = global ptr null @__llgo_argc = global ptr null @__llgo_argv = global ptr null diff --git a/cl/_testrt/struct/out.ll b/cl/_testrt/struct/out.ll index 04ab01fc..2888d80f 100644 --- a/cl/_testrt/struct/out.ll +++ b/cl/_testrt/struct/out.ll @@ -3,7 +3,7 @@ source_filename = "main" %main.Foo = type { i32, i1 } -@main.format = global ptr null +@main.format = global [10 x i8] undef @"main.init$guard" = global ptr null @__llgo_argc = global ptr null @__llgo_argv = global ptr null diff --git a/cl/_testrt/typalias/out.ll b/cl/_testrt/typalias/out.ll index b77f76a7..bb9068ea 100644 --- a/cl/_testrt/typalias/out.ll +++ b/cl/_testrt/typalias/out.ll @@ -1,7 +1,7 @@ ; ModuleID = 'main' source_filename = "main" -@main.format = global ptr null +@main.format = global [10 x i8] undef @"main.init$guard" = global ptr null @__llgo_argc = global ptr null @__llgo_argv = global ptr null diff --git a/internal/runtime/llgo_autogen.lla b/internal/runtime/llgo_autogen.lla index ebb1ce75..4f9b4461 100644 Binary files a/internal/runtime/llgo_autogen.lla and b/internal/runtime/llgo_autogen.lla differ diff --git a/ssa/decl.go b/ssa/decl.go index fd8ecefc..7a30aac3 100644 --- a/ssa/decl.go +++ b/ssa/decl.go @@ -60,6 +60,7 @@ type NamedConst = *aNamedConst type aGlobal struct { Expr + array bool } // A Global is a named Value holding the address of a package-level @@ -72,8 +73,17 @@ func (p Package) NewVar(name string, typ types.Type, bg Background) Global { return v } t := p.Prog.Type(typ, bg) - gbl := llvm.AddGlobal(p.mod, t.ll, name) - ret := &aGlobal{Expr{gbl, t}} + var gbl llvm.Value + var array bool + if t.kind == vkPtr && p.Prog.Elem(t).kind == vkArray { + typ := p.Prog.Elem(t).ll + gbl = llvm.AddGlobal(p.mod, typ, name) + gbl.SetInitializer(llvm.Undef(typ)) + array = true + } else { + gbl = llvm.AddGlobal(p.mod, t.ll, name) + } + ret := &aGlobal{Expr{gbl, t}, array} p.vars[name] = ret return ret } @@ -85,6 +95,9 @@ func (p Package) VarOf(name string) Global { // Init initializes the global variable with the given value. func (g Global) Init(v Expr) { + if g.array && v.kind == vkPtr { + return + } g.impl.SetInitializer(v.impl) }