fix regression in last patch in calloc not taking np into account for precondition
MODIFY
ir/instr.cpp
ir/instr.cpp
@@ -2453,10 +2453,11 @@ StateValue Calloc::toSMT(State &s) const {
s.addUB(np_sz);
unsigned align = heap_block_alignment;
+ auto np = np_num && np_sz;
expr size = nm * sz;
expr nonnull = expr::mkBoolVar("malloc_never_fails");
auto [p, allocated] = s.getMemory().alloc(size, align, Memory::MALLOC,
- nm.mul_no_uoverflow(sz),
+ np && nm.mul_no_uoverflow(sz),
nonnull);
p = p.subst(allocated, true).simplify();

ADD
tests/alive-tv/memory/malloc-calloc.srctgt.ll
+define i8* @src(i32 %size) {
+ %call1 = call i8* @malloc(i32 %size)
+ ret i8* %call1
+}
+
+define i8* @tgt(i32 %size) {
+; %calloc = call i8* @malloc(i32 %size)
+ %calloc = call i8* @calloc(i32 1, i32 %size)
+ ret i8* %calloc
+}
+
+declare i8* @calloc(i32, i32)
+declare i8* @malloc(i32)

fix #471: regression in last patch in calloc not taking np into account for precondition