forked from ldc-developers/ldc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboundscheck.d
29 lines (22 loc) · 1.16 KB
/
boundscheck.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Test instrumentation of autogenerated boundschecking calls
// Boundschecks are inserted for (a) array indexing and (b) array slicing.
// Boundschecks should not be instrumented.
// The fail branch of a boundscheck goes to a basicblock that terminates in
// 'unreachable'. This means that LLVM will already assign minimum probability
// to the fail branch and maximum probability to the pass branch. See the
// documentation of UR_TAKEN_WEIGHT and UR_NONTAKEN_WEIGHT in file
// "llvm/Analysis/BranchProbabilityInfo.cpp".
// Adding instrumentation to boundschecks would only add runtime overhead at
// zero benefit.
// The tests here check for the absence of the instrumentation of boundschecks.
// RUN: %ldc -c -output-ll -fprofile-instr-generate -of=%t.ll %s && FileCheck %s --check-prefix=PROFGEN < %t.ll
// PROFGEN: @[[MAIN:__(llvm_profile_counters|profc)__Dmain]] ={{.*}} global [1 x i64] zeroinitializer
// PROFGEN-LABEL: @_Dmain(
// PROFGEN: store {{.*}} @[[MAIN]], i{{32|64}} 0, i{{32|64}} 0
@safe:
void main() {
int[] array = [1,2,3];
// PROFGEN-NOT: store {{.*}} @[[MAIN]]
auto one = array[2]; // (a) array indexing
auto two = array[1..2]; // (b) array slicing
}