[PATCH 2/5] llvm: gracefully catch impossible type/value

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

 



Until now, in sparse-llvm, an assert(0) was used each time
something which was not yet handled was encountered.

This is doubly annoying because:
- the assert gave no info about the cause
- it also hide possible further issuses.

Fix this by:
- removing the asserts
- use a warnng explaining what's at hand
- try to continue with the following instructions.

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

diff --git a/sparse-llvm.c b/sparse-llvm.c
index 3a68d09d9..9855ae403 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -353,18 +353,23 @@ static LLVMValueRef constant_value(unsigned long long val, LLVMTypeRef dtype)
 		result = LLVMConstInt(dtype, val, 1);
 		break;
 	default:
-		assert(0);
+		return NULL;
 	}
 	return result;
 }
 
 static LLVMValueRef val_to_value(unsigned long long val, struct symbol *ctype)
 {
+	LLVMValueRef result;
 	LLVMTypeRef dtype;
 
 	assert(ctype);
 	dtype = symbol_type(ctype);
-	return constant_value(val, dtype);
+	result = constant_value(val, dtype);
+	if (result)
+		return result;
+	sparse_error(ctype->pos, "no value possible for %s", show_typename(ctype));
+	return LLVMGetUndef(symbol_type(ctype));
 }
 
 static LLVMValueRef pseudo_to_value(struct function *fn, struct symbol *ctype, pseudo_t pseudo)
@@ -647,6 +652,8 @@ static void output_op_compare(struct function *fn, struct instruction *insn)
 		rhs = constant_value(insn->src2->value, LLVMTypeOf(lhs));
 	else
 		rhs = pseudo_to_value(fn, NULL, insn->src2);
+	if (!rhs)
+		rhs = LLVMGetUndef(symbol_type(insn->type));
 
 	pseudo_name(insn->target, target_name);
 
-- 
2.14.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