[PATCH] D109233: [hwasan] Respect returns attribute when tracking values.
Florian Mayer via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 3 08:27:21 PDT 2021
fmayer created this revision.
Herald added a subscriber: hiraditya.
fmayer updated this revision to Diff 370572.
fmayer added a comment.
fmayer updated this revision to Diff 370573.
fmayer updated this revision to Diff 370574.
fmayer retitled this revision from "[hwasan] Respect returns attribute when following to Alloca." to "[hwasan] Respect returns attribute when tracking values.".
fmayer published this revision for review.
fmayer added a reviewer: vitalybuka.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
formatting
fmayer added a comment.
format
fmayer added a comment.
comments
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D109233
Files:
llvm/lib/Analysis/StackSafetyAnalysis.cpp
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Instrumentation/HWAddressSanitizer/stack-safety-analysis.ll
Index: llvm/test/Instrumentation/HWAddressSanitizer/stack-safety-analysis.ll
===================================================================
--- llvm/test/Instrumentation/HWAddressSanitizer/stack-safety-analysis.ll
+++ llvm/test/Instrumentation/HWAddressSanitizer/stack-safety-analysis.ll
@@ -136,6 +136,24 @@
ret i32 0
}
+; Check whether we see through the returns attribute of functions.
+define i32 @test_retptr(i32* %a) sanitize_hwaddress {
+entry:
+ ; CHECK-LABEL: @test_retptr
+ ; NOSAFETY: call {{.*}}__hwasan_generate_tag
+ ; NOSAFETY: call {{.*}}__hwasan_store
+ ; SAFETY: call {{.*}}__hwasan_generate_tag
+ ; SAFETY-NOT: call {{.*}}__hwasan_store
+ ; NOSTACK-NOT: call {{.*}}__hwasan_generate_tag
+ ; 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)
+ store volatile i8 0, i8* %ptr, align 4, !tbaa !8
+ call void @llvm.lifetime.end.p0i8(i64 1, i8* nonnull %buf.sroa.0)
+ ret i32 0
+}
+
; Function Attrs: argmemonly mustprogress nofree nosync nounwind willreturn
declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture)
@@ -145,6 +163,7 @@
declare void @use(i8* nocapture)
declare i32 @getoffset()
declare i8* @getptr(i8* nocapture)
+declare i8* @retptr(i8* returned)
!8 = !{!9, !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -4533,6 +4533,12 @@
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;
}
Index: llvm/lib/Analysis/StackSafetyAnalysis.cpp
===================================================================
--- llvm/lib/Analysis/StackSafetyAnalysis.cpp
+++ llvm/lib/Analysis/StackSafetyAnalysis.cpp
@@ -414,6 +414,11 @@
}
const auto &CB = cast<CallBase>(*I);
+ if (CB.getReturnedArgOperand() == V) {
+ if (Visited.insert(I).second)
+ WorkList.push_back(cast<const Instruction>(I));
+ }
+
if (!CB.isArgOperand(&UI)) {
US.addRange(I, UnknownRange);
break;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109233.370574.patch
Type: text/x-patch
Size: 2541 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210903/8a267981/attachment.bin>
More information about the llvm-commits
mailing list