[llvm] r277068 - Do not remove empty lifetime.start/lifetime.end ranges
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 28 15:50:48 PDT 2016
Author: vitalybuka
Date: Thu Jul 28 17:50:48 2016
New Revision: 277068
URL: http://llvm.org/viewvc/llvm-project?rev=277068&view=rev
Log:
Do not remove empty lifetime.start/lifetime.end ranges
Summary:
Asan stack-use-after-scope check should poison alloca even if there is
no access between start and end.
This is possible for code like this:
for (int i = 0; i < 3; i++) {
int x;
p = &x;
}
"Loop Invariant Code Motion" will move "p = &x;" out of the loop, making
start/end range empty.
PR27453
Reviewers: eugenis
Differential Revision: https://reviews.llvm.org/D22842
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/trunk/test/Transforms/InstCombine/lifetime-asan.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=277068&r1=277067&r2=277068&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Thu Jul 28 17:50:48 2016
@@ -30,8 +30,6 @@ using namespace PatternMatch;
STATISTIC(NumSimplified, "Number of library calls simplified");
-extern cl::opt<bool> ClUseAfterScope;
-
/// Return the specified type promoted as it would be to pass though a va_arg
/// area.
static Type *getPromotedType(Type *Ty) {
@@ -2244,18 +2242,16 @@ Instruction *InstCombiner::visitCallInst
return eraseInstFromFunction(CI);
break;
}
- case Intrinsic::lifetime_start: {
- const Function *func = II->getFunction();
- // Asan needs to poison memory to detect invalid access possible even for
- // empty lifetime range.
- if (func && func->hasFnAttribute(Attribute::SanitizeAddress))
+ case Intrinsic::lifetime_start:
+ // Asan needs to poison memory to detect invalid access which is possible
+ // even for empty lifetime range.
+ if (II->getFunction()->hasFnAttribute(Attribute::SanitizeAddress))
break;
if (removeTriviallyEmptyRange(*II, Intrinsic::lifetime_start,
Intrinsic::lifetime_end, *this))
return nullptr;
break;
- }
case Intrinsic::assume: {
Value *IIOperand = II->getArgOperand(0);
// Remove an assume if it is immediately followed by an identical assume.
@@ -2486,6 +2482,7 @@ static IntrinsicInst *findInitTrampoline
/// Improvements for call and invoke instructions.
Instruction *InstCombiner::visitCallSite(CallSite CS) {
+
if (isAllocLikeFn(CS.getInstruction(), TLI))
return visitAllocSite(*CS.getInstruction());
Modified: llvm/trunk/test/Transforms/InstCombine/lifetime-asan.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/lifetime-asan.ll?rev=277068&r1=277067&r2=277068&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/lifetime-asan.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/lifetime-asan.ll Thu Jul 28 17:50:48 2016
@@ -7,15 +7,14 @@ declare void @foo(i8* nocapture)
define void @asan() sanitize_address {
entry:
; CHECK-LABEL: @asan(
- %text = alloca [1 x i8], align 1
- %0 = getelementptr inbounds [1 x i8], [1 x i8]* %text, i64 0, i64 0
+ %text = alloca i8, align 1
- call void @llvm.lifetime.start(i64 1, i8* %0)
- call void @llvm.lifetime.end(i64 1, i8* %0)
+ call void @llvm.lifetime.start(i64 1, i8* %text)
+ call void @llvm.lifetime.end(i64 1, i8* %text)
; CHECK: call void @llvm.lifetime.start
; CHECK-NEXT: call void @llvm.lifetime.end
- call void @foo(i8* %0) ; Keep alloca alive
+ call void @foo(i8* %text) ; Keep alloca alive
ret void
}
@@ -24,14 +23,13 @@ entry:
define void @no_asan() {
entry:
; CHECK-LABEL: @no_asan(
- %text = alloca [1 x i8], align 1
- %0 = getelementptr inbounds [1 x i8], [1 x i8]* %text, i64 0, i64 0
+ %text = alloca i8, align 1
- call void @llvm.lifetime.start(i64 1, i8* %0)
- call void @llvm.lifetime.end(i64 1, i8* %0)
+ call void @llvm.lifetime.start(i64 1, i8* %text)
+ call void @llvm.lifetime.end(i64 1, i8* %text)
; CHECK-NO: call void @llvm.lifetime
- call void @foo(i8* %0) ; Keep alloca alive
+ call void @foo(i8* %text) ; Keep alloca alive
ret void
}
More information about the llvm-commits
mailing list