Skip to contentSkip to conversation

sparse, llvm: Fix 'void *' pointer code generation

PATCH In review Pekka Enberg 5 participants 7 messages Oct 24, 2011 Sparse checker

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sparse, llvm: Fix 'void *' pointer code generation

Sparse front-end generates SYM_PTR with SYM_BASETYPE with bit_size set to -1 for "void *" pointers. We currently map that to LLVMVoidType() but that no longer works with LLVM Subversion trunk:

  $ ./sparse-llvm validation/backend/struct.c
  sparse-llvm: Type.cpp:676: static llvm::PointerType* llvm::PointerType::get(llvm::Type*, unsigned int): Assertion `isValidElementType(EltTy) && "Invalid type for pointer element!"' failed.
Aborted

Fix the issue by switching to LLVMIntType(bits_per_pointer) in sym_basetype_type().

Cc Christopher Li <[email protected]>
Cc Jeff Garzik <[email protected]>
Cc Linus Torvalds <[email protected]>
---
 sparse-llvm.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
sparse-llvm.c +1 -1
index a85dfea..ec46a04 100644
@@ -80,7 +80,7 @@ static LLVMTypeRef sym_basetype_type(struct symbol *sym)
 	} else {
 		switch (sym->bit_size) {
 		case -1:
-			ret = LLVMVoidType();
+			ret = LLVMIntType(bits_in_pointer);
 			break;
 		case 8:
 			ret = LLVMInt8Type();
Signature · 1 line
1.7.6.4
#1 lore raw
Quoted 3 lines · Pekka Enberg

Fix the issue by switching to LLVMIntType(bits_per_pointer) in sym_basetype_type().

Why bits_per_pointer? Isn't this the "base type" of void *? A more logical choice would seem to be to make it equivalent to "char *", and just make it fall through to the "case 8" case?

Linus

#2 lore raw
Quoted 2 lines · Pekka Enberg
Quoted 2 lines

Fix the issue by switching to LLVMIntType(bits_per_pointer) in sym_basetype_type().

Quoted 3 lines · Linus Torvalds

Why bits_per_pointer? Isn't this the "base type" of void *? A more logical choice would seem to be to make it equivalent to "char *", and just make it fall through to the "case 8" case?

Indeed. Updated patch below.

Pekka

From f90242c21b21d91cfed57aa050b4726b6060dfdd Mon Sep 17 00:00:00 2001
From: Pekka Enberg <[email protected]>
Date: Mon, 24 Oct 2011 14:11:13 +0300
Subject: [PATCH] sparse, llvm: Fix 'void *' pointer code generation

Sparse front-end generates SYM_PTR with SYM_BASETYPE with bit_size set to -1 for "void *" pointers. We currently map that to LLVMVoidType() but that no longer works with LLVM Subversion trunk:

  $ ./sparse-llvm validation/backend/struct.c
  sparse-llvm: Type.cpp:676: static llvm::PointerType* llvm::PointerType::get(llvm::Type*, unsigned int): Assertion `isValidElementType(EltTy) && "Invalid type for pointer element!"' failed.
Aborted

Fix the issue by switching to LLVMIntType(bits_per_pointer) in sym_basetype_type().

Cc Christopher Li <[email protected]>
Cc Jeff Garzik <[email protected]>
Cc Linus Torvalds <[email protected]>
---
 sparse-llvm.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
sparse-llvm.c +1 -3
index a85dfea..fc0c2e9 100644
@@ -79,9 +79,7 @@ static LLVMTypeRef sym_basetype_type(struct symbol *sym)
 		}
 	} else {
 		switch (sym->bit_size) {
-		case -1:
-			ret = LLVMVoidType();
-			break;
+		case -1:	/* 'void *' is treated like 'char *' */
 		case 8:
 			ret = LLVMInt8Type();
 			break;
Signature · 1 line
1.7.6.4
#4 lore raw
Quoted 3 lines · Pekka Enberg
Quoted 2 lines

Fix the issue by switching to LLVMIntType(bits_per_pointer) in sym_basetype_type().

Quoted 1 line · Jonathan Neuschäfer

You didn't update the commit message.

Thanks for pointing that out. Jeff, does this look OK?

Pekka

From e6981551345b7284f6995556398b3564d02afc42 Mon Sep 17 00:00:00 2001
From: Pekka Enberg <[email protected]>
Date: Mon, 24 Oct 2011 14:11:13 +0300
Subject: [PATCH] sparse, llvm: Fix 'void *' pointer code generation

Sparse front-end generates SYM_PTR with SYM_BASETYPE with bit_size set to -1 for "void *" pointers. We currently map that to LLVMVoidType() but that no longer works with LLVM Subversion trunk:

  $ ./sparse-llvm validation/backend/struct.c
  sparse-llvm: Type.cpp:676: static llvm::PointerType* llvm::PointerType::get(llvm::Type*, unsigned int): Assertion `isValidElementType(EltTy) && "Invalid type for pointer element!"' failed.
Aborted

Fix the issue by treating 'void *' as 'char *' as suggested by Linus:

Quoted 3 lines · Linus Torvalds

Why bits_per_pointer? Isn't this the "base type" of void *? A more logical choice would seem to be to make it equivalent to "char *", and just make it fall through to the "case 8" case?

Cc Christopher Li <[email protected]>
Cc Jeff Garzik <[email protected]>
Cc Linus Torvalds <[email protected]>
---
 sparse-llvm.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
sparse-llvm.c +1 -3
index a85dfea..fc0c2e9 100644
@@ -79,9 +79,7 @@ static LLVMTypeRef sym_basetype_type(struct symbol *sym)
 		}
 	} else {
 		switch (sym->bit_size) {
-		case -1:
-			ret = LLVMVoidType();
-			break;
+		case -1:	/* 'void *' is treated like 'char *' */
 		case 8:
 			ret = LLVMInt8Type();
 			break;
Signature · 1 line
1.7.6.4
#5 lore raw
Quoted 8 lines · Pekka Enberg
Quoted 3 lines · Pekka Enberg
Quoted 2 lines

Fix the issue by switching to LLVMIntType(bits_per_pointer) in sym_basetype_type().

Quoted 1 line · Jonathan Neuschäfer

You didn't update the commit message.

Thanks for pointing that out. Jeff, does this look OK?

I don't know what bit_size==-1 means off the top of my head, so I assume yes ;-)

Jeff

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
Quoted 3 lines · Jeff Garzik
Quoted 1 line

Thanks for pointing that out. Jeff, does this look OK?

I don't know what bit_size==-1 means off the top of my head, so I assume yes

So

void *p;

looks as follows with test-inspect:

0: SYM_NODE: p
ctype.base_type: SYM_PTR: <noident>
ctype.base_type: SYM_BASETYPE: void

[ btw, is there a text mode version of test-inspect? ]

where the SYM_BASETYPE of 'void' has -1 set as bit_size by the frontend.

Pekka