sparse, llvm: Simplify output_data() type logic
PATCH 1/2 sparse, llvm: Simplify output_data() type logic
Use LLVMTypeOf() in output_data() to simplify type handling logic.
--- sparse-llvm.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
sparse-llvm.c +1 -1
@@ -1192,7 +1192,7 @@ static LLVMValueRef output_data(LLVMModuleRef module, struct symbol *sym) name =show_ident (sym->ident); - data =LLVMAddGlobal (module,symbol_type (module, sym->ctype.base_type), name); + data =LLVMAddGlobal (module,LLVMTypeOf (initial_value), name);LLVMSetLinkage (data,data_linkage (sym));
Signature · 1 line
1.7.7.6
PATCH 2/2 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>"
--- sparse-llvm.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
sparse-llvm.c +6 -0
@@ -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 ); }
Signature · 1 line
1.7.7.6
Re: [PATCH 2/2] sparse, llvm: Fix string initializer code generation
Quoted 29 lines · Pekka Enberg
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 ofsymbol_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<[email protected]>Cc Benjamin Herrenschmidt<[email protected]>Cc Christopher Li<[email protected]>Cc Jeff Garzik<[email protected]>Signed-off-by Pekka Enberg<[email protected]>--- sparse-llvm.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)sparse-llvm.c +0
-0
sparse-llvm.c static LLVMValueRef output_data(LLVMModuleRef module, struct symbol *sym) · line 1190
Quoted 10 lines
sparse-llvm.c +6
-0@@ -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 :
ACK 1-2