Commit 77713fdd authored by Peter Kasting's avatar Peter Kasting Committed by V8 LUCI CQ

Fix -Wloop-analysis warnings in V8.

These indicate when a range-based for loop is using an index whose type
(value, pointer, or reference) doesn't match what the loop actually
extracts from the range.  Fix by matching the actual type better.

This shouldn't cause any behavior/performance change, just be slightly
clearer about what's actually happening when reading the code.

Bug: chromium:1223264
Change-Id: Ib8773fbbeb038609c54a52c7cd6ce5bd11fd99ba
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2983710Reviewed-by: 's avatarSantiago Aboy Solanes <solanes@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75373}
parent bd80ad89
......@@ -2003,7 +2003,7 @@ void BaselineCompiler::VisitSwitchOnSmiNoFeedback() {
int case_value_base = (*offsets.begin()).case_value;
std::unique_ptr<Label*[]> labels = std::make_unique<Label*[]>(offsets.size());
for (const interpreter::JumpTableTargetOffset& offset : offsets) {
for (interpreter::JumpTableTargetOffset offset : offsets) {
labels[offset.case_value - case_value_base] =
&EnsureLabels(offset.target_offset)->unlinked;
}
......@@ -2167,7 +2167,7 @@ void BaselineCompiler::VisitSwitchOnGeneratorState() {
std::unique_ptr<Label*[]> labels =
std::make_unique<Label*[]>(offsets.size());
for (const interpreter::JumpTableTargetOffset& offset : offsets) {
for (interpreter::JumpTableTargetOffset offset : offsets) {
labels[offset.case_value] = &EnsureLabels(offset.target_offset)->unlinked;
}
__ SmiUntag(continuation);
......
......@@ -230,7 +230,8 @@ void UpdateOutLiveness(Bytecode bytecode, BytecodeLivenessState* out_liveness,
int target_offset = iterator.GetJumpTargetOffset();
out_liveness->Union(*liveness_map.GetInLiveness(target_offset));
} else if (Bytecodes::IsSwitch(bytecode)) {
for (const auto& entry : iterator.GetJumpTableTargetOffsets()) {
for (interpreter::JumpTableTargetOffset entry :
iterator.GetJumpTableTargetOffsets()) {
out_liveness->Union(*liveness_map.GetInLiveness(entry.target_offset));
}
}
......@@ -530,7 +531,8 @@ void BytecodeAnalysis::Analyze() {
liveness_map().GetLiveness(current_offset);
bool any_changed = false;
for (const auto& entry : iterator.GetJumpTableTargetOffsets()) {
for (interpreter::JumpTableTargetOffset entry :
iterator.GetJumpTableTargetOffsets()) {
if (switch_liveness.out->UnionIsChanged(
*liveness_map().GetInLiveness(entry.target_offset))) {
any_changed = true;
......@@ -713,7 +715,7 @@ bool BytecodeAnalysis::ResumeJumpTargetsAreValid() {
// First collect all required suspend ids.
std::map<int, int> unresolved_suspend_ids;
for (const interpreter::JumpTableTargetOffset& offset :
for (interpreter::JumpTableTargetOffset offset :
iterator.GetJumpTableTargetOffsets()) {
int suspend_id = offset.case_value;
int resume_offset = offset.target_offset;
......
......@@ -3610,7 +3610,7 @@ void BytecodeGraphBuilder::BuildSwitchOnSmi(Node* condition) {
bytecode_iterator().GetJumpTableTargetOffsets();
NewSwitch(condition, offsets.size() + 1);
for (const auto& entry : offsets) {
for (interpreter::JumpTableTargetOffset entry : offsets) {
SubEnvironment sub_environment(this);
NewIfValue(entry.case_value);
MergeIntoSuccessorEnvironment(entry.target_offset);
......
......@@ -117,7 +117,7 @@ void JsonPrintFunctionSource(std::ostream& os, int source_id,
os << ", \"sourceText\": \"";
int len = shared->EndPosition() - start;
SubStringRange source(String::cast(script->source()), no_gc, start, len);
for (const auto& c : source) {
for (auto c : source) {
os << AsEscapedUC16ForJSON(c);
}
os << "\"";
......
......@@ -857,7 +857,7 @@ void PrintFunctionSource(OptimizedCompilationInfo* info, Isolate* isolate,
int len = shared->EndPosition() - start;
SubStringRange source(String::cast(script->source()), no_gc, start,
len);
for (const auto& c : source) {
for (auto c : source) {
os << AsReversiblyEscapedUC16(c);
}
}
......
......@@ -2801,7 +2801,7 @@ void SerializerForBackgroundCompilation::VisitSwitchOnSmiNoFeedback(
interpreter::BytecodeArrayIterator* iterator) {
interpreter::JumpTableTargetOffsets targets =
iterator->GetJumpTableTargetOffsets();
for (const auto& target : targets) {
for (interpreter::JumpTableTargetOffset target : targets) {
ContributeToJumpTargetEnvironment(target.target_offset);
}
}
......
......@@ -450,7 +450,7 @@ UnobservablesSet UnobservablesSet::Intersect(const UnobservablesSet& other,
if (IsEmpty() || other.IsEmpty()) return empty;
UnobservablesSet::SetT* intersection = NewSet(zone);
for (const auto& triple : set()->Zip(*other.set())) {
for (auto triple : set()->Zip(*other.set())) {
if (std::get<1>(triple) && std::get<2>(triple)) {
intersection->Set(std::get<0>(triple), kPresent);
}
......@@ -476,7 +476,7 @@ UnobservablesSet UnobservablesSet::RemoveSameOffset(StoreOffset offset,
*new_set = *set();
// Remove elements with the given offset.
for (const auto& entry : *new_set) {
for (auto entry : *new_set) {
const UnobservableStore& obs = entry.first;
if (obs.offset_ == offset) SetErase(new_set, obs);
}
......
......@@ -311,7 +311,7 @@ JumpTableTargetOffsets::iterator JumpTableTargetOffsets::end() const {
int JumpTableTargetOffsets::size() const {
int ret = 0;
// TODO(leszeks): Is there a more efficient way of doing this than iterating?
for (const auto& entry : *this) {
for (JumpTableTargetOffset entry : *this) {
USE(entry);
ret++;
}
......
......@@ -661,7 +661,8 @@ void BytecodeArray::Disassemble(std::ostream& os) {
if (interpreter::Bytecodes::IsSwitch(iterator.current_bytecode())) {
os << " {";
bool first_entry = true;
for (const auto& entry : iterator.GetJumpTableTargetOffsets()) {
for (interpreter::JumpTableTargetOffset entry :
iterator.GetJumpTableTargetOffsets()) {
if (first_entry) {
first_entry = false;
} else {
......
......@@ -791,7 +791,7 @@ TEST_F(BytecodeArrayBuilderTest, SmallSwitch) {
int switch_end =
iterator.current_offset() + iterator.current_bytecode_size();
for (const auto& entry : iterator.GetJumpTableTargetOffsets()) {
for (JumpTableTargetOffset entry : iterator.GetJumpTableTargetOffsets()) {
CHECK_EQ(entry.case_value, small_jump_table_base + i);
CHECK_EQ(entry.target_offset, switch_end + i);
......@@ -839,7 +839,7 @@ TEST_F(BytecodeArrayBuilderTest, WideSwitch) {
int switch_end =
iterator.current_offset() + iterator.current_bytecode_size();
for (const auto& entry : iterator.GetJumpTableTargetOffsets()) {
for (JumpTableTargetOffset entry : iterator.GetJumpTableTargetOffsets()) {
CHECK_EQ(entry.case_value, large_jump_table_base + i);
CHECK_EQ(entry.target_offset, switch_end + i);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment