Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Unified Diff: src/compiler/instruction.cc

Issue 1232613002: [turbofan] Fix undefined behavior in InstructionSequence::GetInstructionBlock. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698