we need max(src,tgt)+1
Thanks Juneyoung & Gil for the review & test case
ADD
tests/alive-tv/memory/nonlocalbid.srctgt.ll
+declare void @free(i8*)
+declare i8* @f(i32) readonly
+
+define i8 @src() {
+ %p1 = call i8* @f(i32 0)
+ %p2 = call i8* @f(i32 1)
+ %p3 = call i8* @f(i32 2)
+ %c1 = icmp eq i8* %p1, null
+ %c2 = icmp eq i8* %p2, null
+ %c3 = icmp eq i8* %p3, null
+ %cmp = or i1 %c1, %c2
+ %cmp2 = or i1 %cmp, %c3
+ br i1 %cmp2, label %A, label %B
+A:
+ ret i8 1
+B:
+ call void @free(i8* %p1)
+ call void @free(i8* %p2)
+ call void @free(i8* %p3)
+ ret i8 2
+}
+
+define i8 @tgt() {
+ ret i8 1
+}
+
+; ERROR: Value mismatch

MODIFY
tools/transform.cpp
tools/transform.cpp
@@ -671,8 +671,8 @@ static void calculateAndInitConstants(Transform &t) {
// + 1 is sufficient to give 1 degree of freedom for the target to trigger UB
// in case a different pointer from source is produced.
auto num_max_nonlocals_inst
- = min(num_nonlocals_inst_src, num_nonlocals_inst_tgt);
- if (num_nonlocals_inst_src || num_nonlocals_inst_tgt)
+ = max(num_nonlocals_inst_src, num_nonlocals_inst_tgt);
+ if (num_nonlocals_inst_src && num_nonlocals_inst_tgt)
++num_max_nonlocals_inst;
num_nonlocals_src = num_globals_src + num_ptrinputs + num_max_nonlocals_inst +

we need max(src,tgt)+1
Thanks Juneyoung & Gil for the review & test case