aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPekka Enberg <penberg@kernel.org>2012-06-08 14:58:02 +0300
committerPekka Enberg <penberg@kernel.org>2012-06-08 23:31:40 +0300
commit9084e55561e9aa11d291c1a9acaf1a7584651b73 (patch)
tree5e7ecd7ab225fe582acc9582d7419c7db5e6e96c
parentee2ca87d9bd18850518c8bca95d61df6010d9351 (diff)
downloadsparse-9084e55561e9aa11d291c1a9acaf1a7584651b73.tar.gz
sparse, llvm: Fix string initializer code generation
This fixes code generation for string initializer such as: static char *foo = "Foo !\n"; It's the same fix Ben proposed earlier with the small difference that we now use LLVMTypeOf() instead of symbol_type() to resolve the type. The generated LLVM IR looks as follows: [penberg@tux sparse]$ ./sparse-llvm foo.c |llvm-dis ; ModuleID = '<stdin>' @"<noident>" = private global [7 x i8] c"Foo !\0A\00" @foo = private global [7 x i8]* @"<noident>" Reported-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Christopher Li <sparse@chrisli.org> Acked-by: Jeff Garzik <jgarzik@redhat.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
-rw-r--r--sparse-llvm.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/sparse-llvm.c b/sparse-llvm.c
index a39bc027..89c6a2e6 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -1181,6 +1181,12 @@ static LLVMValueRef output_data(LLVMModuleRef module, struct symbol *sym)
initial_value = output_data(module, sym);
break;
}
+ case EXPR_STRING: {
+ const char *s = initializer->string->data;
+
+ initial_value = LLVMConstString(strdup(s), strlen(s) + 1, true);
+ break;
+ }
default:
assert(0);
}