diff --git a/ir/instr.cpp b/ir/instr.cpp index 27b036d02..b0d288c6a 100644 --- a/ir/instr.cpp +++ b/ir/instr.cpp @@ -3783,7 +3783,9 @@ bool AssumeVal::propagatesPoison() const { } bool AssumeVal::hasSideEffects() const { - return false; + // A well-defined assumption is UB when it fails, so it must stay even if its + // result is unused. + return is_welldefined; } DEFINE_AS_RETZERO(AssumeVal, getMaxGEPOffset) diff --git a/tests/alive-tv/attrs/range-param-unused-narrow.srctgt.ll b/tests/alive-tv/attrs/range-param-unused-narrow.srctgt.ll new file mode 100644 index 000000000..4e0846379 --- /dev/null +++ b/tests/alive-tv/attrs/range-param-unused-narrow.srctgt.ll @@ -0,0 +1,10 @@ +; ERROR: Source is more defined than target + +; Narrowing the range of an unused parameter makes tgt UB for 8 and 9. +define i8 @src(i8 noundef range(i8 4, 10) %x) { + ret i8 0 +} + +define i8 @tgt(i8 noundef range(i8 4, 8) %x) { + ret i8 0 +} diff --git a/tests/alive-tv/attrs/range-param-unused.srctgt.ll b/tests/alive-tv/attrs/range-param-unused.srctgt.ll new file mode 100644 index 000000000..b29c87098 --- /dev/null +++ b/tests/alive-tv/attrs/range-param-unused.srctgt.ll @@ -0,0 +1,14 @@ +; %x is unused in src, but a value outside the range is still UB there, so tgt +; may assume the range. +define i8 @src(i8 noundef range(i8 4, 8) %x) { + ret i8 0 +} + +define i8 @tgt(i8 noundef range(i8 4, 8) %x) { + %d = sub i8 %x, 4 + %in = icmp ult i8 %d, 4 + call void @llvm.assume(i1 %in) + ret i8 0 +} + +declare void @llvm.assume(i1)