@@ -586,9 +586,8 @@ static void output_op_compare(struct function *fn, struct instruction *insn)
char target_name[64];
lhs = pseudo_to_value(fn, insn, insn->src1);
-
if (insn->src2->type == PSEUDO_VAL)
- rhs = LLVMConstInt(LLVMTypeOf(lhs), insn->src2->value, 1);
+ rhs = constant_value(insn->src2->value, LLVMTypeOf(lhs));
else
rhs = pseudo_to_value(fn, insn, insn->src2);
new file mode 100644
@@ -0,0 +1,12 @@
+int tstv(void *p) { return !p; }
+int cmpv(void *p) { return p == ((void*)0); }
+
+int tsti(int *p) { return !p; }
+int cmpi(int *p) { return p == ((int *)0); }
+int cmpx(int *p) { return p == ((void*)0); }
+
+/*
+ * check-name: compare-with-null
+ * check-command: sparsec -Wno-decl -c $file -o tmp.o
+ * check-output-ignore
+ */
Since sparse's constant are typeless comparing a pointer with an address constant lack correct type information. Fix this by casting the constant to the same type as the LHS. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- sparse-llvm.c | 3 +-- validation/backend/compare-with-null.c | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 validation/backend/compare-with-null.c