linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] sparse, llvm: Simplify output_data() type logic
@ 2012-06-08 12:34 Pekka Enberg
  2012-06-08 12:34 ` [PATCH 2/2] sparse, llvm: Fix string initializer code generation Pekka Enberg
  0 siblings, 1 reply; 3+ messages in thread
From: Pekka Enberg @ 2012-06-08 12:34 UTC (permalink / raw)
  To: linux-sparse
  Cc: Pekka Enberg, Benjamin Herrenschmidt, Christopher Li, Jeff Garzik

Use LLVMTypeOf() in output_data() to simplify type handling logic.

Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Christopher Li <sparse@chrisli.org>
Cc: Jeff Garzik <jgarzik@redhat.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
---
 sparse-llvm.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/sparse-llvm.c b/sparse-llvm.c
index 9226a21..a39bc02 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -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));
 
-- 
1.7.7.6


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] sparse, llvm: Fix string initializer code generation
  2012-06-08 12:34 [PATCH 1/2] sparse, llvm: Simplify output_data() type logic Pekka Enberg
@ 2012-06-08 12:34 ` Pekka Enberg
  2012-06-08 18:15   ` Jeff Garzik
  0 siblings, 1 reply; 3+ messages in thread
From: Pekka Enberg @ 2012-06-08 12:34 UTC (permalink / raw)
  To: linux-sparse
  Cc: Pekka Enberg, Benjamin Herrenschmidt, Christopher Li, Jeff Garzik

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: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Christopher Li <sparse@chrisli.org>
Cc: Jeff Garzik <jgarzik@redhat.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
---
 sparse-llvm.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/sparse-llvm.c b/sparse-llvm.c
index a39bc02..89c6a2e 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);
 		}
-- 
1.7.7.6


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2] sparse, llvm: Fix string initializer code generation
  2012-06-08 12:34 ` [PATCH 2/2] sparse, llvm: Fix string initializer code generation Pekka Enberg
@ 2012-06-08 18:15   ` Jeff Garzik
  0 siblings, 0 replies; 3+ messages in thread
From: Jeff Garzik @ 2012-06-08 18:15 UTC (permalink / raw)
  To: Pekka Enberg
  Cc: linux-sparse, Benjamin Herrenschmidt, Christopher Li, Jeff Garzik

On 06/08/2012 08:34 AM, Pekka Enberg wrote:
> 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: Benjamin Herrenschmidt<benh@kernel.crashing.org>
> Cc: Christopher Li<sparse@chrisli.org>
> Cc: Jeff Garzik<jgarzik@redhat.com>
> Signed-off-by: Pekka Enberg<penberg@kernel.org>
> ---
>   sparse-llvm.c |    6 ++++++
>   1 files changed, 6 insertions(+), 0 deletions(-)
>
> diff --git a/sparse-llvm.c b/sparse-llvm.c
> index a39bc02..89c6a2e 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:

ACK 1-2




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-06-08 18:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-08 12:34 [PATCH 1/2] sparse, llvm: Simplify output_data() type logic Pekka Enberg
2012-06-08 12:34 ` [PATCH 2/2] sparse, llvm: Fix string initializer code generation Pekka Enberg
2012-06-08 18:15   ` Jeff Garzik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).