summaryrefslogtreecommitdiff
path: root/lib/profile/InstrProfilingValue.c
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2016-05-25 21:27:02 +0000
committerXinliang David Li <davidxl@google.com>2016-05-25 21:27:02 +0000
commitf234154a8706fc1f8a88c728e7ea9825a21bcfc8 (patch)
tree63fd7ce579a60801d8b29954c0a7f65cea864206 /lib/profile/InstrProfilingValue.c
parente46c1085798c224058942cd5aa7577fdfb8f43da (diff)
[profile] Add early checking to bypass node pointer update
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@270766 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/profile/InstrProfilingValue.c')
-rw-r--r--lib/profile/InstrProfilingValue.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/profile/InstrProfilingValue.c b/lib/profile/InstrProfilingValue.c
index 08f91b35f..63b5e6fca 100644
--- a/lib/profile/InstrProfilingValue.c
+++ b/lib/profile/InstrProfilingValue.c
@@ -103,16 +103,21 @@ static ValueProfNode *allocateOneNode(__llvm_profile_data *Data, uint32_t Index,
if (!hasStaticCounters)
return (ValueProfNode *)calloc(1, sizeof(ValueProfNode));
- Node = COMPILER_RT_PTR_FETCH_ADD(ValueProfNode, CurrentVNode, 1);
- if (Node >= EndVNode) {
+ /* Early check to avoid value wrapping around. */
+ if (CurrentVNode >= EndVNode) {
if (OutOfNodesWarnings++ < MAX_VP_WARNS) {
PROF_WARN("Unable to track new values: %s. "
- " Consider using option -mllvm -vp-counters-per-site=<n> to allocate more"
+ " Consider using option -mllvm -vp-counters-per-site=<n> to "
+ "allocate more"
" value profile counters at compile time. \n",
"Running out of static counters");
}
return 0;
}
+ Node = COMPILER_RT_PTR_FETCH_ADD(ValueProfNode, CurrentVNode, 1);
+ if (Node >= EndVNode)
+ return 0;
+
return Node;
}