diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-12-27 17:21:46 +0100 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-12-28 18:42:34 +0100 |
| commit | 18434703507423b58ecefe941438755525ec834a (patch) | |
| tree | 48c6001fba038946c036778b896848ca1629e092 | |
| parent | 69a789a78d4e64052628307f25310e195a50f5ee (diff) | |
| download | sparse-dev-18434703507423b58ecefe941438755525ec834a.tar.gz | |
llvm: simplify emit of null pointers
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@gmail.com>
| -rw-r--r-- | sparse-llvm.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/sparse-llvm.c b/sparse-llvm.c index a8186df5..4c64f1aa 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); |
