Skip to content

Commit

Permalink
The absence of noreturn doesn't ensure mayReturn
Browse files Browse the repository at this point in the history
There are two separate issues:
- LLVM doesn't consider infinite loops to be side effects: we happily
  hoist/sink above/below loops whose bounds are unknown.
- The absence of the noreturn attribute is insufficient for us to know
  if a function will definitely return.  Relying on noreturn in the
  middle-end for any property is an accident waiting to happen.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273762 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
majnemer committed Jun 25, 2016
1 parent 7360cd1 commit 115455e
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 33 deletions.
10 changes: 1 addition & 9 deletions include/llvm/IR/Instruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,21 +394,13 @@ class Instruction : public User,
/// Return true if this instruction may throw an exception.
bool mayThrow() const;

/// 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;

/// Return true if the instruction may have side effects.
///
/// Note that this does not consider malloc and alloca to have side
/// effects because the newly allocated memory is completely invisible to
/// instructions which don't use the returned value. For cases where this
/// matters, isSafeToSpeculativelyExecute may be more appropriate.
bool mayHaveSideEffects() const {
return mayWriteToMemory() || mayThrow() || !mayReturn();
}
bool mayHaveSideEffects() const { return mayWriteToMemory() || mayThrow(); }

/// Return true if the instruction is a variety of EH-block.
bool isEHPad() const {
Expand Down
6 changes: 0 additions & 6 deletions lib/IR/Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,12 +545,6 @@ bool Instruction::mayThrow() const {
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
Expand Down
18 changes: 0 additions & 18 deletions test/Transforms/FunctionAttrs/noreturn.ll

This file was deleted.

0 comments on commit 115455e

Please sign in to comment.