Reviewers: Benedikt Meurer,
Message:
PTAL
Description:
Fix undefined behavior in InstructionSequence::GetInstructionBlock.
Some implementations of std::lower_bound require weak-strict ordering.
The comparison operator must be assymetric, which doesn't hold for
less_equals.
BUG=
Please review this at https://codereview.chromium.org/1232613002/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+6, -3 lines):
M src/compiler/instruction.cc
Index: src/compiler/instruction.cc
diff --git a/src/compiler/instruction.cc b/src/compiler/instruction.cc
index
83b45b39ddec69baaac0d80e37c58654c5b49933..9aebb9a17a5389d2f7c0fbb3f45715c2c137a8cf
100644
--- a/src/compiler/instruction.cc
+++ b/src/compiler/instruction.cc
@@ -566,9 +566,12 @@ InstructionBlock*
InstructionSequence::GetInstructionBlock(
int instruction_index) const {
DCHECK(instruction_blocks_->size() == block_starts_.size());
auto begin = block_starts_.begin();
- auto end = std::lower_bound(begin, block_starts_.end(),
instruction_index,
- std::less_equal<int>());
- size_t index = std::distance(begin, end) - 1;
+ auto end = std::lower_bound(begin, block_starts_.end(),
instruction_index);
+ // Post condition of std::lower_bound:
+ DCHECK(end == block_starts_.end() || *end >= instruction_index);
+ if (end == block_starts_.end() || *end > instruction_index) --end;
+ DCHECK(*end <= instruction_index);
+ size_t index = std::distance(begin, end);
auto block = instruction_blocks_->at(index);
DCHECK(block->code_start() <= instruction_index &&
instruction_index < block->code_end());
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.