Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

JL #74

Open
wants to merge 90 commits into
base: master
Choose a base branch
from
Open

JL #74

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
75e093b
Creating release_70 branch off revision 338536
zmodem Aug 1, 2018
02181d6
Drop 'svn' suffix from the version number.
zmodem Aug 1, 2018
3332f06
Merging r338658:
zmodem Aug 2, 2018
9dbe7c7
Merging r338682:
zmodem Aug 2, 2018
d030aee
Merging r338554:
zmodem Aug 2, 2018
4f6e104
Release notes: fix -fno-strict-float-cast-overflow quoting
zmodem Aug 2, 2018
9cc4d9e
Merging r338703 and r338709:
zmodem Aug 3, 2018
5aa2b5a
Merging r338751:
zmodem Aug 3, 2018
ed621a5
Merging r338762:
zmodem Aug 3, 2018
731482e
Merging r338599:
zmodem Aug 3, 2018
491b046
Release note for DWARF v5 support
pogo59 Aug 3, 2018
1a7200c
Merging r338817:
zmodem Aug 7, 2018
7fe11a1
Merging r338665:
zmodem Aug 7, 2018
9d9705f
Merging r338968:
zmodem Aug 7, 2018
7afafa5
Merging r338569:
zmodem Aug 7, 2018
07e3ee9
Merging r338610:
zmodem Aug 7, 2018
c5aadce
Merging r338915:
zmodem Aug 7, 2018
7205f34
ReleaseNotes: the new vs integration
zmodem Aug 7, 2018
b87385f
Merging r338716:
zmodem Aug 8, 2018
62ca9ef
Merging r339190:
zmodem Aug 8, 2018
f208a0a
Merging r338902:
zmodem Aug 8, 2018
ef7dd70
Merging r339319:
zmodem Aug 9, 2018
f7ec630
Merging r339316:
zmodem Aug 9, 2018
387b5e3
[7.0 branch] Update release notes (SystemZ, TableGen)
uweigand Aug 9, 2018
c7b3270
Merging r339225:
zmodem Aug 13, 2018
5a09a6b
Merging r339073:
zmodem Aug 13, 2018
c2e9eb3
Merging r339179 and r339184:
zmodem Aug 13, 2018
b4d5f64
Merging r339492:
zmodem Aug 13, 2018
18c17c4
Merging r339411:
zmodem Aug 13, 2018
1415ff0
[ReleaseNotes] Mention various windows related changes in 7.0
mstorsjo Aug 14, 2018
9360946
Merging r339600:
zmodem Aug 14, 2018
36b087d
Merging r339636:
rnk Aug 14, 2018
12eb6bc
[ReleaseNotes] Add release notes for Hexagon
Aug 14, 2018
ef7c5cc
[ReleaseNotes] Fix a typo
Aug 14, 2018
8684e0b
Merging r339166:
zmodem Aug 16, 2018
0caaac0
Merging r339533:
zmodem Aug 16, 2018
bb6ad81
Merging r339535:
zmodem Aug 16, 2018
f6ce3c5
Merging r339536:
zmodem Aug 16, 2018
2c9adfa
Merging r339769:
zmodem Aug 16, 2018
02e459e
Merging r339515:
zmodem Aug 17, 2018
e7782a9
Merging r339883:
zmodem Aug 17, 2018
dff83e9
Merging r339945:
zmodem Aug 17, 2018
98aa61b
Merging r338841:
zmodem Aug 17, 2018
39ee064
Merging r339822:
zmodem Aug 21, 2018
1215ec5
Merging r339895 and r339896:
zmodem Aug 21, 2018
9a7960e
Merging r339091:
zmodem Aug 21, 2018
fbe3346
Merging r340158:
zmodem Aug 21, 2018
57aa5d9
Merging r339674:
zmodem Aug 21, 2018
9df0977
Merging r340303:
zmodem Aug 21, 2018
4a4bff5
Merging r340691:
zmodem Aug 27, 2018
d6e617b
Merging r340641:
zmodem Aug 27, 2018
3d019e2
Merging r340839:
zmodem Aug 30, 2018
4a19487
Merging r340820:
zmodem Aug 30, 2018
400322b
Merging r340455:
zmodem Aug 30, 2018
8be2375
Merging r340416:
zmodem Aug 30, 2018
9f22831
Merging r340417:
zmodem Aug 30, 2018
c19f813
Merging r340751:
zmodem Aug 30, 2018
224408d
Merging r340900:
zmodem Aug 30, 2018
485d211
[docs][mips] 7.0 Release notes
atanasyan Aug 31, 2018
8be5c4f
Merging r341094:
zmodem Aug 31, 2018
1a55853
Merging r341244:
zmodem Sep 4, 2018
8111e8d
Merging r340959:
zmodem Sep 4, 2018
600f7a2
ReleaseNotes for PowerPC
zmodem Sep 5, 2018
738f19a
ReleaseNotes: support for new-pm passes in the opt tool
zmodem Sep 6, 2018
80cc9fc
ReleaseNotes: ARM SVE asm/disasm support
zmodem Sep 6, 2018
033c772
Merging r341416:
zmodem Sep 6, 2018
a5b9a59
Merging r341512:
zmodem Sep 6, 2018
cd197f3
ReleaseNotes: tidy up for the release
zmodem Sep 7, 2018
4a05921
Merging r341642:
zmodem Sep 10, 2018
82250ed
ReleaseNotes: minor tweaks
zmodem Sep 10, 2018
0d41278
docs: drop another in-progress warning
zmodem Sep 10, 2018
627a2d5
ReleaseNotes.rst: Add Zig to External Open Source Projects Using LLVM 7
zmodem Sep 11, 2018
65ce2e5
ReleaseNotes: some notes from Andres Freund
zmodem Sep 11, 2018
6c2e5a1
Merging r343347:
tstellar Oct 19, 2018
9a0352f
Merging r343443:
tstellar Oct 19, 2018
b2504ea
Merging r343428:
tstellar Oct 19, 2018
888225e
Merging r343373:
tstellar Oct 19, 2018
eb0722e
Merging r342461:
tstellar Oct 22, 2018
4c946b7
Merging r344325:
tstellar Oct 26, 2018
5ab8235
Merging r344454, r344455, r344645:
tstellar Nov 2, 2018
2e8411d
Merging r342354:
tstellar Nov 2, 2018
d0abf8b
Bump version to 7.0.1
tstellar Nov 2, 2018
b386e8b
Port Memoro to LLVM 7.0
ttreyer Nov 7, 2018
076c3f5
removing unneeded code from memoro instrumentation pass, other commen…
Dec 12, 2018
65dac8b
removing tool options in memoro instrumentation, it was a relic and w…
Dec 13, 2018
9720d28
Formatting
ttreyer Jan 6, 2019
35c5877
Merge branch 'memoro' into memoro_80
ttreyer Jan 6, 2019
4113dff
Cleanup the merge
ttreyer Jan 6, 2019
ca9d68c
Fix memoro to skip alloca-referencing loads/stores
jameslarus Aug 16, 2019
bc3f246
Properly handle global variables and unknown refs.
jameslarus Aug 16, 2019
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merging r338902:
------------------------------------------------------------------------
r338902 | jgalenson | 2018-08-03 19:12:23 +0200 (Fri, 03 Aug 2018) | 5 lines

Fix crash in bounds checking.

In r337830 I added SCEV checks to enable us to insert fewer bounds checks.  Unfortunately, this sometimes crashes when multiple bounds checks are added due to SCEV caching issues.  This patch splits the bounds checking pass into two phases, one that computes all the conditions (using SCEV checks) and the other that adds the new instructions.

Differential Revision: https://reviews.llvm.org/D49946
------------------------------------------------------------------------


git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_70@339239 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
zmodem committed Aug 8, 2018
commit f208a0a1daa9526563817e0f8da6b303b82b8e1d
82 changes: 43 additions & 39 deletions lib/Transforms/Instrumentation/BoundsChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,17 @@ STATISTIC(ChecksUnable, "Bounds checks unable to add");

using BuilderTy = IRBuilder<TargetFolder>;

/// Adds run-time bounds checks to memory accessing instructions.
/// Gets the conditions under which memory accessing instructions will overflow.
///
/// \p Ptr is the pointer that will be read/written, and \p 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.
///
/// \p GetTrapBB is a callable that returns the trap BB to use on failure.
///
/// Returns true if any change was made to the IR, false otherwise.
template <typename GetTrapBBT>
static bool instrumentMemAccess(Value *Ptr, Value *InstVal,
const DataLayout &DL, TargetLibraryInfo &TLI,
ObjectSizeOffsetEvaluator &ObjSizeEval,
BuilderTy &IRB, GetTrapBBT GetTrapBB,
ScalarEvolution &SE) {
/// Returns the condition under which the access will overflow.
static Value *getBoundsCheckCond(Value *Ptr, Value *InstVal,
const DataLayout &DL, TargetLibraryInfo &TLI,
ObjectSizeOffsetEvaluator &ObjSizeEval,
BuilderTy &IRB, ScalarEvolution &SE) {
uint64_t NeededSize = DL.getTypeStoreSize(InstVal->getType());
LLVM_DEBUG(dbgs() << "Instrument " << *Ptr << " for " << Twine(NeededSize)
<< " bytes\n");
Expand All @@ -70,7 +66,7 @@ static bool instrumentMemAccess(Value *Ptr, Value *InstVal,

if (!ObjSizeEval.bothKnown(SizeOffset)) {
++ChecksUnable;
return false;
return nullptr;
}

Value *Size = SizeOffset.first;
Expand Down Expand Up @@ -107,13 +103,23 @@ static bool instrumentMemAccess(Value *Ptr, Value *InstVal,
Or = IRB.CreateOr(Cmp1, Or);
}

return Or;
}

/// Adds run-time bounds checks to memory accessing instructions.
///
/// \p Or is the condition that should guard the trap.
///
/// \p GetTrapBB is a callable that returns the trap BB to use on failure.
template <typename GetTrapBBT>
static void insertBoundsCheck(Value *Or, BuilderTy IRB, GetTrapBBT GetTrapBB) {
// check if the comparison is always false
ConstantInt *C = dyn_cast_or_null<ConstantInt>(Or);
if (C) {
++ChecksSkipped;
// If non-zero, nothing to do.
if (!C->getZExtValue())
return true;
return;
}
++ChecksAdded;

Expand All @@ -127,12 +133,11 @@ static bool instrumentMemAccess(Value *Ptr, Value *InstVal,
// FIXME: We should really handle this differently to bypass the splitting
// the block.
BranchInst::Create(GetTrapBB(IRB), OldBB);
return true;
return;
}

// Create the conditional branch.
BranchInst::Create(GetTrapBB(IRB), Cont, Or, OldBB);
return true;
}

static bool addBoundsChecking(Function &F, TargetLibraryInfo &TLI,
Expand All @@ -143,11 +148,25 @@ static bool addBoundsChecking(Function &F, TargetLibraryInfo &TLI,

// check HANDLE_MEMORY_INST in include/llvm/Instruction.def for memory
// touching instructions
std::vector<Instruction *> WorkList;
SmallVector<std::pair<Instruction *, Value *>, 4> TrapInfo;
for (Instruction &I : instructions(F)) {
if (isa<LoadInst>(I) || isa<StoreInst>(I) || isa<AtomicCmpXchgInst>(I) ||
isa<AtomicRMWInst>(I))
WorkList.push_back(&I);
Value *Or = nullptr;
BuilderTy IRB(I.getParent(), BasicBlock::iterator(&I), TargetFolder(DL));
if (LoadInst *LI = dyn_cast<LoadInst>(&I)) {
Or = getBoundsCheckCond(LI->getPointerOperand(), LI, DL, TLI,
ObjSizeEval, IRB, SE);
} else if (StoreInst *SI = dyn_cast<StoreInst>(&I)) {
Or = getBoundsCheckCond(SI->getPointerOperand(), SI->getValueOperand(),
DL, TLI, ObjSizeEval, IRB, SE);
} else if (AtomicCmpXchgInst *AI = dyn_cast<AtomicCmpXchgInst>(&I)) {
Or = getBoundsCheckCond(AI->getPointerOperand(), AI->getCompareOperand(),
DL, TLI, ObjSizeEval, IRB, SE);
} else if (AtomicRMWInst *AI = dyn_cast<AtomicRMWInst>(&I)) {
Or = getBoundsCheckCond(AI->getPointerOperand(), AI->getValOperand(), DL,
TLI, ObjSizeEval, IRB, SE);
}
if (Or)
TrapInfo.push_back(std::make_pair(&I, Or));
}

// Create a trapping basic block on demand using a callback. Depending on
Expand Down Expand Up @@ -176,29 +195,14 @@ static bool addBoundsChecking(Function &F, TargetLibraryInfo &TLI,
return TrapBB;
};

bool MadeChange = false;
for (Instruction *Inst : WorkList) {
// Add the checks.
for (const auto &Entry : TrapInfo) {
Instruction *Inst = Entry.first;
BuilderTy IRB(Inst->getParent(), BasicBlock::iterator(Inst), TargetFolder(DL));
if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
MadeChange |= instrumentMemAccess(LI->getPointerOperand(), LI, DL, TLI,
ObjSizeEval, IRB, GetTrapBB, SE);
} else if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
MadeChange |=
instrumentMemAccess(SI->getPointerOperand(), SI->getValueOperand(),
DL, TLI, ObjSizeEval, IRB, GetTrapBB, SE);
} else if (AtomicCmpXchgInst *AI = dyn_cast<AtomicCmpXchgInst>(Inst)) {
MadeChange |=
instrumentMemAccess(AI->getPointerOperand(), AI->getCompareOperand(),
DL, TLI, ObjSizeEval, IRB, GetTrapBB, SE);
} else if (AtomicRMWInst *AI = dyn_cast<AtomicRMWInst>(Inst)) {
MadeChange |=
instrumentMemAccess(AI->getPointerOperand(), AI->getValOperand(), DL,
TLI, ObjSizeEval, IRB, GetTrapBB, SE);
} else {
llvm_unreachable("unknown Instruction type");
}
insertBoundsCheck(Entry.second, IRB, GetTrapBB);
}
return MadeChange;

return !TrapInfo.empty();
}

PreservedAnalyses BoundsCheckingPass::run(Function &F, FunctionAnalysisManager &AM) {
Expand Down
65 changes: 65 additions & 0 deletions test/Instrumentation/BoundsChecking/many-traps-2.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
; RUN: opt < %s -bounds-checking -S | FileCheck %s
@array = internal global [1819 x i16] zeroinitializer, section ".bss,bss"
@offsets = external dso_local global [10 x i16]

; CHECK-LABEL: @test
define dso_local void @test() {
bb1:
br label %bb19

bb20:
%_tmp819 = load i16, i16* null
; CHECK: br {{.*}} %trap
%_tmp820 = sub nsw i16 9, %_tmp819
%_tmp821 = sext i16 %_tmp820 to i64
%_tmp822 = getelementptr [10 x i16], [10 x i16]* @offsets, i16 0, i64 %_tmp821
%_tmp823 = load i16, i16* %_tmp822
br label %bb33

bb34:
%_tmp907 = zext i16 %i__7.107.0 to i64
%_tmp908 = getelementptr [1819 x i16], [1819 x i16]* @array, i16 0, i64 %_tmp907
store i16 0, i16* %_tmp908
; CHECK: br {{.*}} %trap
%_tmp910 = add i16 %i__7.107.0, 1
br label %bb33

bb33:
%i__7.107.0 = phi i16 [ undef, %bb20 ], [ %_tmp910, %bb34 ]
%_tmp913 = add i16 %_tmp823, 191
%_tmp914 = icmp ult i16 %i__7.107.0, %_tmp913
br i1 %_tmp914, label %bb34, label %bb19

bb19:
%_tmp976 = icmp slt i16 0, 10
br i1 %_tmp976, label %bb20, label %bb39

bb39:
ret void
}

@e = dso_local local_unnamed_addr global [1 x i16] zeroinitializer, align 1

; CHECK-LABEL: @test2
define dso_local void @test2() local_unnamed_addr {
entry:
br label %while.cond1.preheader

while.cond1.preheader:
%0 = phi i16 [ undef, %entry ], [ %inc, %while.end ]
%1 = load i16, i16* undef, align 1
; CHECK: br {{.*}} %trap
br label %while.end

while.end:
%inc = add nsw i16 %0, 1
%arrayidx = getelementptr inbounds [1 x i16], [1 x i16]* @e, i16 0, i16
%0
%2 = load i16, i16* %arrayidx, align 1
; CHECK: or i1
; CHECK-NEXT: br {{.*}} %trap
br i1 false, label %while.end6, label %while.cond1.preheader

while.end6:
ret void
}