Skip to content

Commit 54cb334

Browse files
committed
[LVI] Fix miscompilation
1 parent 074099d commit 54cb334

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,12 @@ LazyValueInfoImpl::solveBlockValueImpl(Value *Val, BasicBlock *BB) {
622622
return getFromRangeMetadata(BBI);
623623
}
624624

625-
static void AddNonNullPointer(Value *Ptr, NonNullPointerSet &PtrSet) {
625+
static void AddNonNullPointer(Value *Ptr, NonNullPointerSet &PtrSet,
626+
bool IsDereferenced = true) {
626627
// TODO: Use NullPointerIsDefined instead.
627628
if (Ptr->getType()->getPointerAddressSpace() == 0)
628-
PtrSet.insert(getUnderlyingObject(Ptr));
629+
PtrSet.insert(IsDereferenced ? getUnderlyingObject(Ptr)
630+
: Ptr->stripInBoundsOffsets());
629631
}
630632

631633
static void AddNonNullPointersByInstruction(
@@ -649,7 +651,7 @@ static void AddNonNullPointersByInstruction(
649651
if (U->getType()->isPointerTy() &&
650652
CB->paramHasNonNullAttr(CB->getArgOperandNo(&U),
651653
/*AllowUndefOrPoison=*/false))
652-
AddNonNullPointer(U.get(), PtrSet);
654+
AddNonNullPointer(U.get(), PtrSet, /*IsDereferenced=*/false);
653655
}
654656
}
655657
}

llvm/test/Transforms/CorrelatedValuePropagation/non-null.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ define i1 @test_known_nonnull_at_callsite_gep_without_inbounds(ptr %src, i64 %x)
433433
; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[SRC:%.*]], i64 [[X:%.*]]
434434
; CHECK-NEXT: call void @callee(ptr noundef nonnull [[GEP]])
435435
; CHECK-NEXT: [[NONNULL:%.*]] = icmp eq ptr [[SRC]], null
436-
; CHECK-NEXT: ret i1 false
436+
; CHECK-NEXT: ret i1 [[NONNULL]]
437437
;
438438
entry:
439439
%gep = getelementptr i8, ptr %src, i64 %x

0 commit comments

Comments
 (0)