mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
Fix a bug in mayHaveSideEffects. Functions that do not return are now considered as instructions with side effects.
rdar://13227456 llvm-svn: 175553
This commit is contained in:
parent
9eca7cc973
commit
f1aab5f6b7
@ -309,6 +309,12 @@ public:
|
||||
///
|
||||
bool mayThrow() const;
|
||||
|
||||
/// mayReturn - Return true if this is a function that may return.
|
||||
/// this is true for all normal instructions. The only exception
|
||||
/// is functions that are marked with the 'noreturn' attribute.
|
||||
///
|
||||
bool mayReturn() const;
|
||||
|
||||
/// mayHaveSideEffects - Return true if the instruction may have side effects.
|
||||
///
|
||||
/// Note that this does not consider malloc and alloca to have side
|
||||
@ -316,7 +322,7 @@ public:
|
||||
/// instructions which don't used the returned value. For cases where this
|
||||
/// matters, isSafeToSpeculativelyExecute may be more appropriate.
|
||||
bool mayHaveSideEffects() const {
|
||||
return mayWriteToMemory() || mayThrow();
|
||||
return mayWriteToMemory() || mayThrow() || !mayReturn();
|
||||
}
|
||||
|
||||
/// clone() - Create a copy of 'this' instruction that is identical in all
|
||||
|
@ -455,14 +455,18 @@ bool Instruction::mayWriteToMemory() const {
|
||||
}
|
||||
}
|
||||
|
||||
/// mayThrow - Return true if this instruction may throw an exception.
|
||||
///
|
||||
bool Instruction::mayThrow() const {
|
||||
if (const CallInst *CI = dyn_cast<CallInst>(this))
|
||||
return !CI->doesNotThrow();
|
||||
return isa<ResumeInst>(this);
|
||||
}
|
||||
|
||||
bool Instruction::mayReturn() const {
|
||||
if (const CallInst *CI = dyn_cast<CallInst>(this))
|
||||
return !CI->doesNotReturn();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// isAssociative - Return true if the instruction is associative:
|
||||
///
|
||||
/// Associative operators satisfy: x op (y op z) === (x op y) op z
|
||||
|
18
test/Transforms/FunctionAttrs/noreturn.ll
Normal file
18
test/Transforms/FunctionAttrs/noreturn.ll
Normal file
@ -0,0 +1,18 @@
|
||||
; RUN: opt < %s -functionattrs -instcombine -S | FileCheck %s
|
||||
|
||||
define void @endless_loop() noreturn nounwind readnone ssp uwtable {
|
||||
entry:
|
||||
br label %while.body
|
||||
|
||||
while.body:
|
||||
br label %while.body
|
||||
}
|
||||
;CHECK: @main
|
||||
;CHECK: endless_loop
|
||||
;CHECK: ret
|
||||
define i32 @main() noreturn nounwind ssp uwtable {
|
||||
entry:
|
||||
tail call void @endless_loop()
|
||||
unreachable
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user