[value-tracking] see through returned attribute.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D109675
This commit is contained in:
Florian Mayer 2021-09-13 10:01:55 +01:00
parent 5b5d774f5d
commit 0a22510f3e
3 changed files with 23 additions and 2 deletions

View File

@ -4533,6 +4533,12 @@ AllocaInst *llvm::findAllocaForValue(Value *V, bool OffsetZero) {
if (OffsetZero && !GEP->hasAllZeroIndices())
return nullptr;
AddWork(GEP->getPointerOperand());
} else if (CallBase *CB = dyn_cast<CallBase>(V)) {
Value *Returned = CB->getReturnedArgOperand();
if (Returned)
AddWork(Returned);
else
return nullptr;
} else {
return nullptr;
}

View File

@ -164,8 +164,7 @@ entry:
; SAFETY: call {{.*}}__hwasan_generate_tag
; SAFETY-NOT: call {{.*}}__hwasan_store
; NOSTACK-NOT: call {{.*}}__hwasan_generate_tag
; TODO: Do not emit this store.
; NOSTACK: call {{.*}}__hwasan_store
; NOSTACK-NOT: call {{.*}}__hwasan_store
%buf.sroa.0 = alloca i8, align 4
call void @llvm.lifetime.start.p0i8(i64 1, i8* nonnull %buf.sroa.0)
%ptr = call i8* @retptr(i8* %buf.sroa.0)

View File

@ -2256,6 +2256,22 @@ const FindAllocaForValueTestParams FindAllocaForValueTests[] = {
ret void
})",
false, false},
{R"(
declare i32* @retptr(i32* returned)
define void @test(i1 %cond) {
%a = alloca i32
%r = call i32* @retptr(i32* %a)
ret void
})",
true, true},
{R"(
declare i32* @fun(i32*)
define void @test(i1 %cond) {
%a = alloca i32
%r = call i32* @fun(i32* %a)
ret void
})",
false, false},
};
TEST_P(FindAllocaForValueTest, findAllocaForValue) {