aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2008-01-26 01:43:44 +0000
committerBill Wendling <isanbard@gmail.com>2008-01-26 01:43:44 +0000
commitf69d5d73986dce2941fff432a212e04ae855407f (patch)
treeb37318e4866a40a2737fee80ddff4275919762d5 /lib
parent15b86db37610bf4172b08475b2cd0e15eb6ae007 (diff)
downloadexternal_llvm-f69d5d73986dce2941fff432a212e04ae855407f.zip
external_llvm-f69d5d73986dce2941fff432a212e04ae855407f.tar.gz
external_llvm-f69d5d73986dce2941fff432a212e04ae855407f.tar.bz2
If we have a function like this:
void bork() { int *address = 0; *address = 0; } It's compiled into LLVM code that looks like this: define void @bork() noreturn nounwind { entry: unreachable } This is bad on some platforms (like PPC) because it will generate the label for the function but no body. The label could end up being associated with some non-code related stuff, like a section. This places a "trap" instruction if the SimplifyCFG pass removed all code from the function leaving only one "unreachable" instruction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46387 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/SimplifyCFG.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/SimplifyCFG.cpp b/lib/Transforms/Scalar/SimplifyCFG.cpp
index 3d1a5be..9d0757a 100644
--- a/lib/Transforms/Scalar/SimplifyCFG.cpp
+++ b/lib/Transforms/Scalar/SimplifyCFG.cpp
@@ -26,6 +26,7 @@
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Constants.h"
#include "llvm/Instructions.h"
+#include "llvm/Intrinsics.h"
#include "llvm/Module.h"
#include "llvm/ParameterAttributes.h"
#include "llvm/Support/CFG.h"
@@ -154,8 +155,20 @@ static bool RemoveUnreachableBlocks(Function &F) {
bool Changed = MarkAliveBlocks(F.begin(), Reachable);
// If there are unreachable blocks in the CFG...
- if (Reachable.size() == F.size())
+ if (Reachable.size() == F.size()) {
+ if (F.size() == 1) {
+ // If the function has only one block with an "unreachable" instruction,
+ // then we should create *some* code for it. Issue a "trap" instead.
+ BasicBlock &BB = F.front();
+
+ if (BB.size() == 1 && dyn_cast<UnreachableInst>(&BB.front()))
+ new CallInst(Intrinsic::getDeclaration(F.getParent(),
+ Intrinsic::trap),
+ "", &BB.front());
+ }
+
return Changed;
+ }
assert(Reachable.size() < F.size());
NumSimpl += F.size()-Reachable.size();