]> granicus.if.org Git - llvm/commitdiff
The absence of noreturn doesn't ensure mayReturn
authorDavid Majnemer <david.majnemer@gmail.com>
Sat, 25 Jun 2016 00:55:12 +0000 (00:55 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sat, 25 Jun 2016 00:55:12 +0000 (00:55 +0000)
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

include/llvm/IR/Instruction.h
lib/IR/Instruction.cpp
test/Transforms/FunctionAttrs/noreturn.ll [deleted file]

index ea262def2c2cbe47504afdab959f1d1103474e2e..efcd26cc30f707673fc96a416cc873b5d6f492dc 100644 (file)
@@ -394,21 +394,13 @@ public:
   /// 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 {
index f90ebec06bd8945c3dd84976fa773400f5ab428d..6ca5c8c4637e396298b1d50e5a675bb03b7c0625 100644 (file)
@@ -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
diff --git a/test/Transforms/FunctionAttrs/noreturn.ll b/test/Transforms/FunctionAttrs/noreturn.ll
deleted file mode 100644 (file)
index 990bea9..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-; 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-LABEL: @main(
-;CHECK: endless_loop
-;CHECK: ret
-define i32 @main() noreturn nounwind ssp uwtable {
-entry:
-  tail call void @endless_loop()
-  unreachable
-}
-