move the bounds checking pass to the instrumentation folder, where it belongs. I...
authorNuno Lopes <nunoplopes@sapo.pt>
Fri, 20 Jul 2012 22:39:33 +0000 (22:39 +0000)
committerNuno Lopes <nunoplopes@sapo.pt>
Fri, 20 Jul 2012 22:39:33 +0000 (22:39 +0000)
No functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160587 91177308-0d34-0410-b5e6-96231b3b80d8

14 files changed:
include/llvm/Transforms/Instrumentation.h
include/llvm/Transforms/Scalar.h
lib/Transforms/Instrumentation/BoundsChecking.cpp [new file with mode: 0644]
lib/Transforms/Instrumentation/CMakeLists.txt
lib/Transforms/Scalar/BoundsChecking.cpp [deleted file]
lib/Transforms/Scalar/CMakeLists.txt
test/Instrumentation/BoundsChecking/lit.local.cfg [new file with mode: 0644]
test/Instrumentation/BoundsChecking/many-trap.ll [new file with mode: 0644]
test/Instrumentation/BoundsChecking/phi.ll [new file with mode: 0644]
test/Instrumentation/BoundsChecking/simple.ll [new file with mode: 0644]
test/Transforms/BoundsChecking/lit.local.cfg [deleted file]
test/Transforms/BoundsChecking/many-trap.ll [deleted file]
test/Transforms/BoundsChecking/phi.ll [deleted file]
test/Transforms/BoundsChecking/simple.ll [deleted file]

index bbf3a69d246d79b086f7e01d5f9230825606dec3..4b0c448acfceb209cbd425190559f1d93a71d4cc 100644 (file)
@@ -38,6 +38,13 @@ ModulePass *createAddressSanitizerPass();
 // Insert ThreadSanitizer (race detection) instrumentation
 FunctionPass *createThreadSanitizerPass();
 
+
+// BoundsChecking - This pass instruments the code to perform run-time bounds
+// checking on loads, stores, and other memory intrinsics.
+// Penalty is the maximum run-time that is acceptable for the user.
+//
+FunctionPass *createBoundsCheckingPass(unsigned Penalty = 5);
+
 } // End llvm namespace
 
 #endif
index 67f2e377f72f63af865a380037a054e27539bff1..3dce6fe37fd44f8c7c5d26a0d10f87c404858a8e 100644 (file)
@@ -328,14 +328,6 @@ Pass *createLowerAtomicPass();
 //
 Pass *createCorrelatedValuePropagationPass();
 
-//===----------------------------------------------------------------------===//
-//
-// BoundsChecking - This pass instruments the code to perform run-time bounds
-// checking on loads, stores, and other memory intrinsics.
-// Penalty is the maximum run-time that is acceptable for the user.
-//
-FunctionPass *createBoundsCheckingPass(unsigned Penalty = 5);
-
 //===----------------------------------------------------------------------===//
 //
 // ObjCARCAPElim - ObjC ARC autorelease pool elimination.
diff --git a/lib/Transforms/Instrumentation/BoundsChecking.cpp b/lib/Transforms/Instrumentation/BoundsChecking.cpp
new file mode 100644 (file)
index 0000000..09e0f14
--- /dev/null
@@ -0,0 +1,209 @@
+//===- BoundsChecking.cpp - Instrumentation for run-time bounds checking --===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements a pass that instruments the code to perform run-time
+// bounds checking on loads, stores, and other memory intrinsics.
+//
+//===----------------------------------------------------------------------===//
+
+#define DEBUG_TYPE "bounds-checking"
+#include "llvm/IRBuilder.h"
+#include "llvm/Intrinsics.h"
+#include "llvm/Pass.h"
+#include "llvm/ADT/Statistic.h"
+#include "llvm/Analysis/MemoryBuiltins.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/InstIterator.h"
+#include "llvm/Support/TargetFolder.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Target/TargetData.h"
+#include "llvm/Transforms/Instrumentation.h"
+using namespace llvm;
+
+static cl::opt<bool> SingleTrapBB("bounds-checking-single-trap",
+                                  cl::desc("Use one trap block per function"));
+
+STATISTIC(ChecksAdded, "Bounds checks added");
+STATISTIC(ChecksSkipped, "Bounds checks skipped");
+STATISTIC(ChecksUnable, "Bounds checks unable to add");
+
+typedef IRBuilder<true, TargetFolder> BuilderTy;
+
+namespace {
+  struct BoundsChecking : public FunctionPass {
+    static char ID;
+
+    BoundsChecking(unsigned _Penalty = 5) : FunctionPass(ID), Penalty(_Penalty){
+      initializeBoundsCheckingPass(*PassRegistry::getPassRegistry());
+    }
+
+    virtual bool runOnFunction(Function &F);
+
+    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+      AU.addRequired<TargetData>();
+    }
+
+  private:
+    const TargetData *TD;
+    ObjectSizeOffsetEvaluator *ObjSizeEval;
+    BuilderTy *Builder;
+    Instruction *Inst;
+    BasicBlock *TrapBB;
+    unsigned Penalty;
+
+    BasicBlock *getTrapBB();
+    void emitBranchToTrap(Value *Cmp = 0);
+    bool computeAllocSize(Value *Ptr, APInt &Offset, Value* &OffsetValue,
+                          APInt &Size, Value* &SizeValue);
+    bool instrument(Value *Ptr, Value *Val);
+ };
+}
+
+char BoundsChecking::ID = 0;
+INITIALIZE_PASS(BoundsChecking, "bounds-checking", "Run-time bounds checking",
+                false, false)
+
+
+/// getTrapBB - create a basic block that traps. All overflowing conditions
+/// branch to this block. There's only one trap block per function.
+BasicBlock *BoundsChecking::getTrapBB() {
+  if (TrapBB && SingleTrapBB)
+    return TrapBB;
+
+  Function *Fn = Inst->getParent()->getParent();
+  BasicBlock::iterator PrevInsertPoint = Builder->GetInsertPoint();
+  TrapBB = BasicBlock::Create(Fn->getContext(), "trap", Fn);
+  Builder->SetInsertPoint(TrapBB);
+
+  llvm::Value *F = Intrinsic::getDeclaration(Fn->getParent(), Intrinsic::trap);
+  CallInst *TrapCall = Builder->CreateCall(F);
+  TrapCall->setDoesNotReturn();
+  TrapCall->setDoesNotThrow();
+  TrapCall->setDebugLoc(Inst->getDebugLoc());
+  Builder->CreateUnreachable();
+
+  Builder->SetInsertPoint(PrevInsertPoint);
+  return TrapBB;
+}
+
+
+/// emitBranchToTrap - emit a branch instruction to a trap block.
+/// If Cmp is non-null, perform a jump only if its value evaluates to true.
+void BoundsChecking::emitBranchToTrap(Value *Cmp) {
+  // check if the comparison is always false
+  ConstantInt *C = dyn_cast_or_null<ConstantInt>(Cmp);
+  if (C) {
+    ++ChecksSkipped;
+    if (!C->getZExtValue())
+      return;
+    else
+      Cmp = 0; // unconditional branch
+  }
+
+  Instruction *Inst = Builder->GetInsertPoint();
+  BasicBlock *OldBB = Inst->getParent();
+  BasicBlock *Cont = OldBB->splitBasicBlock(Inst);
+  OldBB->getTerminator()->eraseFromParent();
+
+  if (Cmp)
+    BranchInst::Create(getTrapBB(), Cont, Cmp, OldBB);
+  else
+    BranchInst::Create(getTrapBB(), OldBB);
+}
+
+
+/// instrument - adds run-time bounds checks to memory accessing instructions.
+/// Ptr is the pointer that will be read/written, and InstVal is either the
+/// result from the load or the value being stored. It is used to determine the
+/// size of memory block that is touched.
+/// Returns true if any change was made to the IR, false otherwise.
+bool BoundsChecking::instrument(Value *Ptr, Value *InstVal) {
+  uint64_t NeededSize = TD->getTypeStoreSize(InstVal->getType());
+  DEBUG(dbgs() << "Instrument " << *Ptr << " for " << Twine(NeededSize)
+              << " bytes\n");
+
+  SizeOffsetEvalType SizeOffset = ObjSizeEval->compute(Ptr);
+
+  if (!ObjSizeEval->bothKnown(SizeOffset)) {
+    ++ChecksUnable;
+    return false;
+  }
+
+  Value *Size   = SizeOffset.first;
+  Value *Offset = SizeOffset.second;
+  ConstantInt *SizeCI = dyn_cast<ConstantInt>(Size);
+
+  IntegerType *IntTy = TD->getIntPtrType(Inst->getContext());
+  Value *NeededSizeVal = ConstantInt::get(IntTy, NeededSize);
+
+  // three checks are required to ensure safety:
+  // . Offset >= 0  (since the offset is given from the base ptr)
+  // . Size >= Offset  (unsigned)
+  // . Size - Offset >= NeededSize  (unsigned)
+  //
+  // optimization: if Size >= 0 (signed), skip 1st check
+  // FIXME: add NSW/NUW here?  -- we dont care if the subtraction overflows
+  Value *ObjSize = Builder->CreateSub(Size, Offset);
+  Value *Cmp2 = Builder->CreateICmpULT(Size, Offset);
+  Value *Cmp3 = Builder->CreateICmpULT(ObjSize, NeededSizeVal);
+  Value *Or = Builder->CreateOr(Cmp2, Cmp3);
+  if (!SizeCI || SizeCI->getValue().slt(0)) {
+    Value *Cmp1 = Builder->CreateICmpSLT(Offset, ConstantInt::get(IntTy, 0));
+    Or = Builder->CreateOr(Cmp1, Or);
+  }
+  emitBranchToTrap(Or);
+
+  ++ChecksAdded;
+  return true;
+}
+
+bool BoundsChecking::runOnFunction(Function &F) {
+  TD = &getAnalysis<TargetData>();
+
+  TrapBB = 0;
+  BuilderTy TheBuilder(F.getContext(), TargetFolder(TD));
+  Builder = &TheBuilder;
+  ObjectSizeOffsetEvaluator TheObjSizeEval(TD, F.getContext());
+  ObjSizeEval = &TheObjSizeEval;
+
+  // check HANDLE_MEMORY_INST in include/llvm/Instruction.def for memory
+  // touching instructions
+  std::vector<Instruction*> WorkList;
+  for (inst_iterator i = inst_begin(F), e = inst_end(F); i != e; ++i) {
+    Instruction *I = &*i;
+    if (isa<LoadInst>(I) || isa<StoreInst>(I) || isa<AtomicCmpXchgInst>(I) ||
+        isa<AtomicRMWInst>(I))
+        WorkList.push_back(I);
+  }
+
+  bool MadeChange = false;
+  for (std::vector<Instruction*>::iterator i = WorkList.begin(),
+       e = WorkList.end(); i != e; ++i) {
+    Inst = *i;
+
+    Builder->SetInsertPoint(Inst);
+    if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
+      MadeChange |= instrument(LI->getPointerOperand(), LI);
+    } else if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
+      MadeChange |= instrument(SI->getPointerOperand(), SI->getValueOperand());
+    } else if (AtomicCmpXchgInst *AI = dyn_cast<AtomicCmpXchgInst>(Inst)) {
+      MadeChange |= instrument(AI->getPointerOperand(),AI->getCompareOperand());
+    } else if (AtomicRMWInst *AI = dyn_cast<AtomicRMWInst>(Inst)) {
+      MadeChange |= instrument(AI->getPointerOperand(), AI->getValOperand());
+    } else {
+      llvm_unreachable("unknown Instruction type");
+    }
+  }
+  return MadeChange;
+}
+
+FunctionPass *llvm::createBoundsCheckingPass(unsigned Penalty) {
+  return new BoundsChecking(Penalty);
+}
index eaa3a4000f887810960ac7c3a1426803f15e0c4d..00de882f17117a8867510066cef8399ea578c1e0 100644 (file)
@@ -1,5 +1,6 @@
 add_llvm_library(LLVMInstrumentation
   AddressSanitizer.cpp
+  BoundsChecking.cpp
   EdgeProfiling.cpp
   FunctionBlackList.cpp
   GCOVProfiling.cpp
diff --git a/lib/Transforms/Scalar/BoundsChecking.cpp b/lib/Transforms/Scalar/BoundsChecking.cpp
deleted file mode 100644 (file)
index ef2f39d..0000000
+++ /dev/null
@@ -1,209 +0,0 @@
-//===- BoundsChecking.cpp - Instrumentation for run-time bounds checking --===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements a pass that instruments the code to perform run-time
-// bounds checking on loads, stores, and other memory intrinsics.
-//
-//===----------------------------------------------------------------------===//
-
-#define DEBUG_TYPE "bounds-checking"
-#include "llvm/Transforms/Scalar.h"
-#include "llvm/IRBuilder.h"
-#include "llvm/Intrinsics.h"
-#include "llvm/Pass.h"
-#include "llvm/ADT/Statistic.h"
-#include "llvm/Analysis/MemoryBuiltins.h"
-#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/Debug.h"
-#include "llvm/Support/InstIterator.h"
-#include "llvm/Support/TargetFolder.h"
-#include "llvm/Support/raw_ostream.h"
-#include "llvm/Target/TargetData.h"
-using namespace llvm;
-
-static cl::opt<bool> SingleTrapBB("bounds-checking-single-trap",
-                                  cl::desc("Use one trap block per function"));
-
-STATISTIC(ChecksAdded, "Bounds checks added");
-STATISTIC(ChecksSkipped, "Bounds checks skipped");
-STATISTIC(ChecksUnable, "Bounds checks unable to add");
-
-typedef IRBuilder<true, TargetFolder> BuilderTy;
-
-namespace {
-  struct BoundsChecking : public FunctionPass {
-    static char ID;
-
-    BoundsChecking(unsigned _Penalty = 5) : FunctionPass(ID), Penalty(_Penalty){
-      initializeBoundsCheckingPass(*PassRegistry::getPassRegistry());
-    }
-
-    virtual bool runOnFunction(Function &F);
-
-    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-      AU.addRequired<TargetData>();
-    }
-
-  private:
-    const TargetData *TD;
-    ObjectSizeOffsetEvaluator *ObjSizeEval;
-    BuilderTy *Builder;
-    Instruction *Inst;
-    BasicBlock *TrapBB;
-    unsigned Penalty;
-
-    BasicBlock *getTrapBB();
-    void emitBranchToTrap(Value *Cmp = 0);
-    bool computeAllocSize(Value *Ptr, APInt &Offset, Value* &OffsetValue,
-                          APInt &Size, Value* &SizeValue);
-    bool instrument(Value *Ptr, Value *Val);
- };
-}
-
-char BoundsChecking::ID = 0;
-INITIALIZE_PASS(BoundsChecking, "bounds-checking", "Run-time bounds checking",
-                false, false)
-
-
-/// getTrapBB - create a basic block that traps. All overflowing conditions
-/// branch to this block. There's only one trap block per function.
-BasicBlock *BoundsChecking::getTrapBB() {
-  if (TrapBB && SingleTrapBB)
-    return TrapBB;
-
-  Function *Fn = Inst->getParent()->getParent();
-  BasicBlock::iterator PrevInsertPoint = Builder->GetInsertPoint();
-  TrapBB = BasicBlock::Create(Fn->getContext(), "trap", Fn);
-  Builder->SetInsertPoint(TrapBB);
-
-  llvm::Value *F = Intrinsic::getDeclaration(Fn->getParent(), Intrinsic::trap);
-  CallInst *TrapCall = Builder->CreateCall(F);
-  TrapCall->setDoesNotReturn();
-  TrapCall->setDoesNotThrow();
-  TrapCall->setDebugLoc(Inst->getDebugLoc());
-  Builder->CreateUnreachable();
-
-  Builder->SetInsertPoint(PrevInsertPoint);
-  return TrapBB;
-}
-
-
-/// emitBranchToTrap - emit a branch instruction to a trap block.
-/// If Cmp is non-null, perform a jump only if its value evaluates to true.
-void BoundsChecking::emitBranchToTrap(Value *Cmp) {
-  // check if the comparison is always false
-  ConstantInt *C = dyn_cast_or_null<ConstantInt>(Cmp);
-  if (C) {
-    ++ChecksSkipped;
-    if (!C->getZExtValue())
-      return;
-    else
-      Cmp = 0; // unconditional branch
-  }
-
-  Instruction *Inst = Builder->GetInsertPoint();
-  BasicBlock *OldBB = Inst->getParent();
-  BasicBlock *Cont = OldBB->splitBasicBlock(Inst);
-  OldBB->getTerminator()->eraseFromParent();
-
-  if (Cmp)
-    BranchInst::Create(getTrapBB(), Cont, Cmp, OldBB);
-  else
-    BranchInst::Create(getTrapBB(), OldBB);
-}
-
-
-/// instrument - adds run-time bounds checks to memory accessing instructions.
-/// Ptr is the pointer that will be read/written, and InstVal is either the
-/// result from the load or the value being stored. It is used to determine the
-/// size of memory block that is touched.
-/// Returns true if any change was made to the IR, false otherwise.
-bool BoundsChecking::instrument(Value *Ptr, Value *InstVal) {
-  uint64_t NeededSize = TD->getTypeStoreSize(InstVal->getType());
-  DEBUG(dbgs() << "Instrument " << *Ptr << " for " << Twine(NeededSize)
-              << " bytes\n");
-
-  SizeOffsetEvalType SizeOffset = ObjSizeEval->compute(Ptr);
-
-  if (!ObjSizeEval->bothKnown(SizeOffset)) {
-    ++ChecksUnable;
-    return false;
-  }
-
-  Value *Size   = SizeOffset.first;
-  Value *Offset = SizeOffset.second;
-  ConstantInt *SizeCI = dyn_cast<ConstantInt>(Size);
-
-  IntegerType *IntTy = TD->getIntPtrType(Inst->getContext());
-  Value *NeededSizeVal = ConstantInt::get(IntTy, NeededSize);
-
-  // three checks are required to ensure safety:
-  // . Offset >= 0  (since the offset is given from the base ptr)
-  // . Size >= Offset  (unsigned)
-  // . Size - Offset >= NeededSize  (unsigned)
-  //
-  // optimization: if Size >= 0 (signed), skip 1st check
-  // FIXME: add NSW/NUW here?  -- we dont care if the subtraction overflows
-  Value *ObjSize = Builder->CreateSub(Size, Offset);
-  Value *Cmp2 = Builder->CreateICmpULT(Size, Offset);
-  Value *Cmp3 = Builder->CreateICmpULT(ObjSize, NeededSizeVal);
-  Value *Or = Builder->CreateOr(Cmp2, Cmp3);
-  if (!SizeCI || SizeCI->getValue().slt(0)) {
-    Value *Cmp1 = Builder->CreateICmpSLT(Offset, ConstantInt::get(IntTy, 0));
-    Or = Builder->CreateOr(Cmp1, Or);
-  }
-  emitBranchToTrap(Or);
-
-  ++ChecksAdded;
-  return true;
-}
-
-bool BoundsChecking::runOnFunction(Function &F) {
-  TD = &getAnalysis<TargetData>();
-
-  TrapBB = 0;
-  BuilderTy TheBuilder(F.getContext(), TargetFolder(TD));
-  Builder = &TheBuilder;
-  ObjectSizeOffsetEvaluator TheObjSizeEval(TD, F.getContext());
-  ObjSizeEval = &TheObjSizeEval;
-
-  // check HANDLE_MEMORY_INST in include/llvm/Instruction.def for memory
-  // touching instructions
-  std::vector<Instruction*> WorkList;
-  for (inst_iterator i = inst_begin(F), e = inst_end(F); i != e; ++i) {
-    Instruction *I = &*i;
-    if (isa<LoadInst>(I) || isa<StoreInst>(I) || isa<AtomicCmpXchgInst>(I) ||
-        isa<AtomicRMWInst>(I))
-        WorkList.push_back(I);
-  }
-
-  bool MadeChange = false;
-  for (std::vector<Instruction*>::iterator i = WorkList.begin(),
-       e = WorkList.end(); i != e; ++i) {
-    Inst = *i;
-
-    Builder->SetInsertPoint(Inst);
-    if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
-      MadeChange |= instrument(LI->getPointerOperand(), LI);
-    } else if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
-      MadeChange |= instrument(SI->getPointerOperand(), SI->getValueOperand());
-    } else if (AtomicCmpXchgInst *AI = dyn_cast<AtomicCmpXchgInst>(Inst)) {
-      MadeChange |= instrument(AI->getPointerOperand(),AI->getCompareOperand());
-    } else if (AtomicRMWInst *AI = dyn_cast<AtomicRMWInst>(Inst)) {
-      MadeChange |= instrument(AI->getPointerOperand(), AI->getValOperand());
-    } else {
-      llvm_unreachable("unknown Instruction type");
-    }
-  }
-  return MadeChange;
-}
-
-FunctionPass *llvm::createBoundsCheckingPass(unsigned Penalty) {
-  return new BoundsChecking(Penalty);
-}
index bf9cc66392ac5126889491837132c7e0fe9b09a4..a01e0661b1ffc172a6b1725a73e020737c08d558 100644 (file)
@@ -1,7 +1,6 @@
 add_llvm_library(LLVMScalarOpts
   ADCE.cpp
   BasicBlockPlacement.cpp
-  BoundsChecking.cpp
   CodeGenPrepare.cpp
   ConstantProp.cpp
   CorrelatedValuePropagation.cpp
diff --git a/test/Instrumentation/BoundsChecking/lit.local.cfg b/test/Instrumentation/BoundsChecking/lit.local.cfg
new file mode 100644 (file)
index 0000000..19eebc0
--- /dev/null
@@ -0,0 +1 @@
+config.suffixes = ['.ll', '.c', '.cpp']
diff --git a/test/Instrumentation/BoundsChecking/many-trap.ll b/test/Instrumentation/BoundsChecking/many-trap.ll
new file mode 100644 (file)
index 0000000..0bbb959
--- /dev/null
@@ -0,0 +1,16 @@
+; RUN: opt < %s -bounds-checking -S | FileCheck %s
+; RUN: opt < %s -bounds-checking -bounds-checking-single-trap -S | FileCheck -check-prefix=SINGLE %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+
+; CHECK: @f1
+define void @f1(i64 %x) nounwind {
+  %1 = alloca i128, i64 %x
+  %2 = load i128* %1, align 4
+  %3 = load i128* %1, align 4
+  ret void
+; CHECK: call void @llvm.trap()
+; CHECK: call void @llvm.trap()
+; CHECK-NOT: call void @llvm.trap()
+; SINGLE: call void @llvm.trap()
+; SINGLE-NOT: call void @llvm.trap()
+}
diff --git a/test/Instrumentation/BoundsChecking/phi.ll b/test/Instrumentation/BoundsChecking/phi.ll
new file mode 100644 (file)
index 0000000..86b5922
--- /dev/null
@@ -0,0 +1,52 @@
+; RUN: opt < %s -bounds-checking -S | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+
+@global = private unnamed_addr constant [10 x i8] c"ola\00mundo\00", align 1
+
+; CHECK: f1
+; no checks are possible here
+; CHECK-NOT: trap
+define void @f1(i8* nocapture %c) {
+entry:
+  %0 = load i8* %c, align 1
+  %tobool1 = icmp eq i8 %0, 0
+  br i1 %tobool1, label %while.end, label %while.body
+
+while.body:
+  %c.addr.02 = phi i8* [ %incdec.ptr, %while.body ], [ %c, %entry ]
+  %incdec.ptr = getelementptr inbounds i8* %c.addr.02, i64 -1
+  store i8 100, i8* %c.addr.02, align 1
+  %1 = load i8* %incdec.ptr, align 1
+  %tobool = icmp eq i8 %1, 0
+  br i1 %tobool, label %while.end, label %while.body
+
+while.end:
+  ret void
+}
+
+
+; CHECK: f2
+define void @f2() {
+while.body.i.preheader:
+  %addr = getelementptr inbounds [10 x i8]* @global, i64 0, i64 9
+  br label %while.body.i
+
+while.body.i:
+; CHECK: phi
+; CHECK-NEXT: phi
+; CHECK-NOT: phi
+  %c.addr.02.i = phi i8* [ %incdec.ptr.i, %while.body.i ], [ %addr, %while.body.i.preheader ]
+  %incdec.ptr.i = getelementptr inbounds i8* %c.addr.02.i, i64 -1
+; CHECK: sub i64 10, %0
+; CHECK-NEXT: icmp ult i64 10, %0
+; CHECK-NEXT: icmp ult i64 {{.*}}, 1
+; CHECK-NEXT: or i1
+; CHECK-NEXT: br {{.*}}, label %trap
+  store i8 100, i8* %c.addr.02.i, align 1
+  %0 = load i8* %incdec.ptr.i, align 1
+  %tobool.i = icmp eq i8 %0, 0
+  br i1 %tobool.i, label %fn.exit, label %while.body.i
+
+fn.exit:
+  ret void
+}
diff --git a/test/Instrumentation/BoundsChecking/simple.ll b/test/Instrumentation/BoundsChecking/simple.ll
new file mode 100644 (file)
index 0000000..3d532c3
--- /dev/null
@@ -0,0 +1,118 @@
+; RUN: opt < %s -bounds-checking -S | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+
+@.str = private constant [8 x i8] c"abcdefg\00"   ; <[8 x i8]*>
+
+declare noalias i8* @malloc(i64) nounwind
+declare noalias i8* @calloc(i64, i64) nounwind
+declare noalias i8* @realloc(i8* nocapture, i64) nounwind
+
+; CHECK: @f1
+define void @f1() nounwind {
+  %1 = tail call i8* @malloc(i64 32)
+  %2 = bitcast i8* %1 to i32*
+  %idx = getelementptr inbounds i32* %2, i64 2
+; CHECK-NOT: trap
+  store i32 3, i32* %idx, align 4
+  ret void
+}
+
+; CHECK: @f2
+define void @f2() nounwind {
+  %1 = tail call i8* @malloc(i64 32)
+  %2 = bitcast i8* %1 to i32*
+  %idx = getelementptr inbounds i32* %2, i64 8
+; CHECK: trap
+  store i32 3, i32* %idx, align 4
+  ret void
+}
+
+; CHECK: @f3
+define void @f3(i64 %x) nounwind {
+  %1 = tail call i8* @calloc(i64 4, i64 %x)
+  %2 = bitcast i8* %1 to i32*
+  %idx = getelementptr inbounds i32* %2, i64 8
+; CHECK: mul i64 4, %
+; CHECK: sub i64 {{.*}}, 32
+; CHECK-NEXT: icmp ult i64 {{.*}}, 32
+; CHECK-NEXT: icmp ult i64 {{.*}}, 4
+; CHECK-NEXT: or i1
+; CHECK: trap
+  store i32 3, i32* %idx, align 4
+  ret void
+}
+
+; CHECK: @f4
+define void @f4(i64 %x) nounwind {
+  %1 = tail call i8* @realloc(i8* null, i64 %x) nounwind
+  %2 = bitcast i8* %1 to i32*
+  %idx = getelementptr inbounds i32* %2, i64 8
+; CHECK: trap
+  %3 = load i32* %idx, align 4
+  ret void
+}
+
+; CHECK: @f5
+define void @f5(i64 %x) nounwind {
+  %idx = getelementptr inbounds [8 x i8]* @.str, i64 0, i64 %x
+; CHECK: trap
+  %1 = load i8* %idx, align 4
+  ret void
+}
+
+; CHECK: @f6
+define void @f6(i64 %x) nounwind {
+  %1 = alloca i128
+; CHECK-NOT: trap
+  %2 = load i128* %1, align 4
+  ret void
+}
+
+; CHECK: @f7
+define void @f7(i64 %x) nounwind {
+  %1 = alloca i128, i64 %x
+; CHECK: mul i64 16,
+; CHECK: trap
+  %2 = load i128* %1, align 4
+  ret void
+}
+
+; CHECK: @f8
+define void @f8() nounwind {
+  %1 = alloca i128
+  %2 = alloca i128
+  %3 = select i1 undef, i128* %1, i128* %2
+; CHECK-NOT: trap
+  %4 = load i128* %3, align 4
+  ret void
+}
+
+; CHECK: @f9
+define void @f9(i128* %arg) nounwind {
+  %1 = alloca i128
+  %2 = select i1 undef, i128* %arg, i128* %1
+; CHECK-NOT: trap
+  %3 = load i128* %2, align 4
+  ret void
+}
+
+; CHECK: @f10
+define void @f10(i64 %x, i64 %y) nounwind {
+  %1 = alloca i128, i64 %x
+  %2 = alloca i128, i64 %y
+  %3 = select i1 undef, i128* %1, i128* %2
+; CHECK: select
+; CHECK: select
+; CHECK: trap
+  %4 = load i128* %3, align 4
+  ret void
+}
+
+; CHECK: @f11
+define void @f11(i128* byval %x) nounwind {
+  %1 = bitcast i128* %x to i8*
+  %2 = getelementptr inbounds i8* %1, i64 16
+; CHECK: br label
+  %3 = load i8* %2, align 4
+  ret void
+}
diff --git a/test/Transforms/BoundsChecking/lit.local.cfg b/test/Transforms/BoundsChecking/lit.local.cfg
deleted file mode 100644 (file)
index 19eebc0..0000000
+++ /dev/null
@@ -1 +0,0 @@
-config.suffixes = ['.ll', '.c', '.cpp']
diff --git a/test/Transforms/BoundsChecking/many-trap.ll b/test/Transforms/BoundsChecking/many-trap.ll
deleted file mode 100644 (file)
index 0bbb959..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-; RUN: opt < %s -bounds-checking -S | FileCheck %s
-; RUN: opt < %s -bounds-checking -bounds-checking-single-trap -S | FileCheck -check-prefix=SINGLE %s
-target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
-
-; CHECK: @f1
-define void @f1(i64 %x) nounwind {
-  %1 = alloca i128, i64 %x
-  %2 = load i128* %1, align 4
-  %3 = load i128* %1, align 4
-  ret void
-; CHECK: call void @llvm.trap()
-; CHECK: call void @llvm.trap()
-; CHECK-NOT: call void @llvm.trap()
-; SINGLE: call void @llvm.trap()
-; SINGLE-NOT: call void @llvm.trap()
-}
diff --git a/test/Transforms/BoundsChecking/phi.ll b/test/Transforms/BoundsChecking/phi.ll
deleted file mode 100644 (file)
index 86b5922..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-; RUN: opt < %s -bounds-checking -S | FileCheck %s
-target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
-
-@global = private unnamed_addr constant [10 x i8] c"ola\00mundo\00", align 1
-
-; CHECK: f1
-; no checks are possible here
-; CHECK-NOT: trap
-define void @f1(i8* nocapture %c) {
-entry:
-  %0 = load i8* %c, align 1
-  %tobool1 = icmp eq i8 %0, 0
-  br i1 %tobool1, label %while.end, label %while.body
-
-while.body:
-  %c.addr.02 = phi i8* [ %incdec.ptr, %while.body ], [ %c, %entry ]
-  %incdec.ptr = getelementptr inbounds i8* %c.addr.02, i64 -1
-  store i8 100, i8* %c.addr.02, align 1
-  %1 = load i8* %incdec.ptr, align 1
-  %tobool = icmp eq i8 %1, 0
-  br i1 %tobool, label %while.end, label %while.body
-
-while.end:
-  ret void
-}
-
-
-; CHECK: f2
-define void @f2() {
-while.body.i.preheader:
-  %addr = getelementptr inbounds [10 x i8]* @global, i64 0, i64 9
-  br label %while.body.i
-
-while.body.i:
-; CHECK: phi
-; CHECK-NEXT: phi
-; CHECK-NOT: phi
-  %c.addr.02.i = phi i8* [ %incdec.ptr.i, %while.body.i ], [ %addr, %while.body.i.preheader ]
-  %incdec.ptr.i = getelementptr inbounds i8* %c.addr.02.i, i64 -1
-; CHECK: sub i64 10, %0
-; CHECK-NEXT: icmp ult i64 10, %0
-; CHECK-NEXT: icmp ult i64 {{.*}}, 1
-; CHECK-NEXT: or i1
-; CHECK-NEXT: br {{.*}}, label %trap
-  store i8 100, i8* %c.addr.02.i, align 1
-  %0 = load i8* %incdec.ptr.i, align 1
-  %tobool.i = icmp eq i8 %0, 0
-  br i1 %tobool.i, label %fn.exit, label %while.body.i
-
-fn.exit:
-  ret void
-}
diff --git a/test/Transforms/BoundsChecking/simple.ll b/test/Transforms/BoundsChecking/simple.ll
deleted file mode 100644 (file)
index 3d532c3..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-; RUN: opt < %s -bounds-checking -S | FileCheck %s
-target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
-
-@.str = private constant [8 x i8] c"abcdefg\00"   ; <[8 x i8]*>
-
-declare noalias i8* @malloc(i64) nounwind
-declare noalias i8* @calloc(i64, i64) nounwind
-declare noalias i8* @realloc(i8* nocapture, i64) nounwind
-
-; CHECK: @f1
-define void @f1() nounwind {
-  %1 = tail call i8* @malloc(i64 32)
-  %2 = bitcast i8* %1 to i32*
-  %idx = getelementptr inbounds i32* %2, i64 2
-; CHECK-NOT: trap
-  store i32 3, i32* %idx, align 4
-  ret void
-}
-
-; CHECK: @f2
-define void @f2() nounwind {
-  %1 = tail call i8* @malloc(i64 32)
-  %2 = bitcast i8* %1 to i32*
-  %idx = getelementptr inbounds i32* %2, i64 8
-; CHECK: trap
-  store i32 3, i32* %idx, align 4
-  ret void
-}
-
-; CHECK: @f3
-define void @f3(i64 %x) nounwind {
-  %1 = tail call i8* @calloc(i64 4, i64 %x)
-  %2 = bitcast i8* %1 to i32*
-  %idx = getelementptr inbounds i32* %2, i64 8
-; CHECK: mul i64 4, %
-; CHECK: sub i64 {{.*}}, 32
-; CHECK-NEXT: icmp ult i64 {{.*}}, 32
-; CHECK-NEXT: icmp ult i64 {{.*}}, 4
-; CHECK-NEXT: or i1
-; CHECK: trap
-  store i32 3, i32* %idx, align 4
-  ret void
-}
-
-; CHECK: @f4
-define void @f4(i64 %x) nounwind {
-  %1 = tail call i8* @realloc(i8* null, i64 %x) nounwind
-  %2 = bitcast i8* %1 to i32*
-  %idx = getelementptr inbounds i32* %2, i64 8
-; CHECK: trap
-  %3 = load i32* %idx, align 4
-  ret void
-}
-
-; CHECK: @f5
-define void @f5(i64 %x) nounwind {
-  %idx = getelementptr inbounds [8 x i8]* @.str, i64 0, i64 %x
-; CHECK: trap
-  %1 = load i8* %idx, align 4
-  ret void
-}
-
-; CHECK: @f6
-define void @f6(i64 %x) nounwind {
-  %1 = alloca i128
-; CHECK-NOT: trap
-  %2 = load i128* %1, align 4
-  ret void
-}
-
-; CHECK: @f7
-define void @f7(i64 %x) nounwind {
-  %1 = alloca i128, i64 %x
-; CHECK: mul i64 16,
-; CHECK: trap
-  %2 = load i128* %1, align 4
-  ret void
-}
-
-; CHECK: @f8
-define void @f8() nounwind {
-  %1 = alloca i128
-  %2 = alloca i128
-  %3 = select i1 undef, i128* %1, i128* %2
-; CHECK-NOT: trap
-  %4 = load i128* %3, align 4
-  ret void
-}
-
-; CHECK: @f9
-define void @f9(i128* %arg) nounwind {
-  %1 = alloca i128
-  %2 = select i1 undef, i128* %arg, i128* %1
-; CHECK-NOT: trap
-  %3 = load i128* %2, align 4
-  ret void
-}
-
-; CHECK: @f10
-define void @f10(i64 %x, i64 %y) nounwind {
-  %1 = alloca i128, i64 %x
-  %2 = alloca i128, i64 %y
-  %3 = select i1 undef, i128* %1, i128* %2
-; CHECK: select
-; CHECK: select
-; CHECK: trap
-  %4 = load i128* %3, align 4
-  ret void
-}
-
-; CHECK: @f11
-define void @f11(i128* byval %x) nounwind {
-  %1 = bitcast i128* %x to i8*
-  %2 = getelementptr inbounds i8* %1, i64 16
-; CHECK: br label
-  %3 = load i8* %2, align 4
-  ret void
-}