diff options
| -rw-r--r-- | sparse-llvm.c | 13 | ||||
| -rw-r--r-- | validation/backend/int-cond.c | 30 |
2 files changed, 41 insertions, 2 deletions
diff --git a/sparse-llvm.c b/sparse-llvm.c index 213d42d3..e4929e9b 100644 --- a/sparse-llvm.c +++ b/sparse-llvm.c @@ -650,10 +650,19 @@ static void output_op_store(struct function *fn, struct instruction *insn) insn->target->priv = target; } +static LLVMValueRef bool_value(struct function *fn, LLVMValueRef value) +{ + if (LLVMTypeOf(value) != LLVMInt1Type()) + value = LLVMBuildIsNotNull(fn->builder, value, "cond"); + + return value; +} + static void output_op_br(struct function *fn, struct instruction *br) { if (br->cond) { - LLVMValueRef cond = pseudo_to_value(fn, br, br->cond); + LLVMValueRef cond = bool_value(fn, + pseudo_to_value(fn, br, br->cond)); LLVMBuildCondBr(fn->builder, cond, br->bb_true->priv, @@ -668,7 +677,7 @@ static void output_op_sel(struct function *fn, struct instruction *insn) { LLVMValueRef target, src1, src2, src3; - src1 = pseudo_to_value(fn, insn, insn->src1); + src1 = bool_value(fn, pseudo_to_value(fn, insn, insn->src1)); src2 = pseudo_to_value(fn, insn, insn->src2); src3 = pseudo_to_value(fn, insn, insn->src3); diff --git a/validation/backend/int-cond.c b/validation/backend/int-cond.c new file mode 100644 index 00000000..48b25a77 --- /dev/null +++ b/validation/backend/int-cond.c @@ -0,0 +1,30 @@ +static long foo(long a, long b, long c) +{ + return a? b:c; +} + +static long foo_bool(_Bool a, long b, long c) +{ + return a? b:c; +} + +static long bar(long a, long b, long c) +{ + if (a) + return b; + else + return b + c; +} + +static long bar_bool(_Bool a, long b, long c) +{ + if (a) + return b; + else + return b + c; +} + +/* + * check-name: Non-bool condition values in branch/select + * check-command: ./sparsec -c $file -o tmp.o + */ |
