diff --git a/cl/_testdata/cstr/out.ll b/cl/_testdata/cstr/out.ll index d5bfe25a..f7b5d255 100644 --- a/cl/_testdata/cstr/out.ll +++ b/cl/_testdata/cstr/out.ll @@ -2,6 +2,7 @@ source_filename = "main" @"main.init$guard" = global ptr null +@0 = private unnamed_addr constant [14 x i8] c"Hello, world\0A\00", align 1 define void @main.init() { _llgo_0: @@ -19,7 +20,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0 define void @main() { _llgo_0: call void @main.init() - call void (ptr, ...) @printf([14 x i8] c"Hello, world\0A\00") + call void (ptr, ...) @printf(ptr @0) ret void } diff --git a/cl/compile.go b/cl/compile.go index 20ba4cdd..1c10d564 100644 --- a/cl/compile.go +++ b/cl/compile.go @@ -275,7 +275,7 @@ func cstr(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) { if c, ok := args[0].(*ssa.Const); ok { if v := c.Value; v.Kind() == constant.String { sv := constant.StringVal(v) - return b.Prog.CStringVal(sv) + return b.CString(sv) } } } diff --git a/ssa/expr.go b/ssa/expr.go index 777f0da8..e38961eb 100644 --- a/ssa/expr.go +++ b/ssa/expr.go @@ -82,12 +82,6 @@ func (p Program) Null(t Type) Expr { return Expr{llvm.ConstNull(t.ll), t} } -// CStringVal returns a c-style string constant expression. -func (p Program) CStringVal(v string) Expr { - t := p.CString() - return Expr{llvm.ConstString(v, true), t} -} - // StringVal returns string constant expression. func (p Program) StringVal(v string) Expr { t := p.String() @@ -153,6 +147,11 @@ func (b Builder) Const(v constant.Value, typ Type) Expr { panic("todo") } +// CString returns a c-style string constant expression. +func (b Builder) CString(v string) Expr { + return Expr{llvm.CreateGlobalStringPtr(b.impl, v), b.Prog.CString()} +} + // ----------------------------------------------------------------------------- const (