[PATCH 1/2] llvm: simplify emit of null pointers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Most pointers with a constant value are simply null-pointers.
The only exception is when a known address is casted to pointer.

The current code only handle code for the general case:
emit code for a constant integer and then cast this to a pointer.
This obfuscate a bit the ouput, making it hard to read.

Change this by special handling the normal case of null-pointers
by directly using LLVM's LLVMConstPointerNull().

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 sparse-llvm.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/sparse-llvm.c b/sparse-llvm.c
index a8186df5b..4c64f1aaa 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -340,14 +340,16 @@ static LLVMValueRef get_sym_value(struct function *fn, struct symbol *sym)
 
 static LLVMValueRef constant_value(unsigned long long val, LLVMTypeRef dtype)
 {
-	LLVMTypeRef itype;
 	LLVMValueRef result;
 
 	switch (LLVMGetTypeKind(dtype)) {
 	case LLVMPointerTypeKind:
-		itype = LLVMIntType(bits_in_pointer);
-		result = LLVMConstInt(itype, val, 1);
-		result = LLVMConstIntToPtr(result, dtype);
+		if (val != 0) {	 // for example: ... = (void*) 0x123;
+			LLVMTypeRef itype = LLVMIntType(bits_in_pointer);
+			result = LLVMConstInt(itype, val, 1);
+			result = LLVMConstIntToPtr(result, dtype);
+		}
+		result = LLVMConstPointerNull(dtype);
 		break;
 	case LLVMIntegerTypeKind:
 		result = LLVMConstInt(dtype, val, 1);
-- 
2.15.0

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



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux