[clang-tidy] Fixup bugprone-loop-variable-copied-then-modified triggers in Blink. [chromium/src : main]

0 views
Skip to first unread message

Daniel Cheng (Gerrit)

unread,
Sep 19, 2025, 2:05:22 PMSep 19
to Julia Hansbrough, Daniel Cheng, Alexis Menard, chromium...@chromium.org, Olga Gerchikov, Kentaro Hara, (Julie)Jeongeun Kim, Kevin Babbitt, Raphael Kubo da Costa, abigailbk...@google.com, blink-rev...@chromium.org, blink-revie...@chromium.org, blink-revie...@chromium.org, blink-rev...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, dtseng...@chromium.org, francisjp...@google.com, josiah...@chromium.org, kinuko...@chromium.org, kyungjunle...@google.com, loading-rev...@chromium.org, lucasrada...@google.com, nektar...@chromium.org, yuzo+...@chromium.org
Attention needed from Julia Hansbrough

Daniel Cheng added 2 comments

File third_party/blink/renderer/core/html/parser/html_construction_site.cc
Line 158, Patchset 1 (Latest): for (const auto& ch : chars) {
Daniel Cheng . unresolved

I feel like the heuristic needs some tuning... this is definitely an example where `ch` was not mutated. Do you know if this is being classified as "unknown, possibly mtuated" or "definitely mutated"?

There are a couple other instances, but I consider those more harmless, e.g. the Rect change above in `visible_units.cc`. But I think people will (reasonably) complain about something like this.

Then again, maybe most instances of this pattern don't trigger the warning? It'd be nice to figure out what's different here though.

File third_party/blink/renderer/platform/wtf/text/string_impl.cc
Line 1519, Patchset 1 (Latest): for (wtf_size_t i = 0; const auto& ac : chars) {
Daniel Cheng . unresolved

Similarly here... this looks like an instance where it's not actually being mutated.

Open in Gerrit

Related details

Attention is currently required from:
  • Julia Hansbrough
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I469fdf929ae91759e416a6b0a3529d0551f1425a
Gerrit-Change-Number: 6967624
Gerrit-PatchSet: 1
Gerrit-Owner: Julia Hansbrough <flowe...@google.com>
Gerrit-Reviewer: Daniel Cheng <dch...@chromium.org>
Gerrit-CC: (Julie)Jeongeun Kim <je_jul...@chromium.org>
Gerrit-CC: Akihiro Ota <akihi...@chromium.org>
Gerrit-CC: Alexis Menard <alexis...@intel.com>
Gerrit-CC: Kentaro Hara <har...@chromium.org>
Gerrit-CC: Kevin Babbitt <kbab...@microsoft.com>
Gerrit-CC: Nektarios Paisios <nek...@chromium.org>
Gerrit-CC: Olga Gerchikov <gerc...@microsoft.com>
Gerrit-CC: Raphael Kubo da Costa <ku...@igalia.com>
Gerrit-Attention: Julia Hansbrough <flowe...@google.com>
Gerrit-Comment-Date: Fri, 19 Sep 2025 18:05:11 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Julia Hansbrough (Gerrit)

unread,
Sep 23, 2025, 7:16:46 PM (12 days ago) Sep 23
to Daniel Cheng, Alexis Menard, chromium...@chromium.org, Olga Gerchikov, Kentaro Hara, (Julie)Jeongeun Kim, Kevin Babbitt, Raphael Kubo da Costa, abigailbk...@google.com, blink-rev...@chromium.org, blink-revie...@chromium.org, blink-revie...@chromium.org, blink-rev...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, dtseng...@chromium.org, francisjp...@google.com, josiah...@chromium.org, kinuko...@chromium.org, kyungjunle...@google.com, loading-rev...@chromium.org, lucasrada...@google.com, nektar...@chromium.org, yuzo+...@chromium.org
Attention needed from Daniel Cheng

Julia Hansbrough added 1 comment

File third_party/blink/renderer/core/html/parser/html_construction_site.cc
Line 158, Patchset 1 (Latest): for (const auto& ch : chars) {
Daniel Cheng . unresolved

I feel like the heuristic needs some tuning... this is definitely an example where `ch` was not mutated. Do you know if this is being classified as "unknown, possibly mtuated" or "definitely mutated"?

There are a couple other instances, but I consider those more harmless, e.g. the Rect change above in `visible_units.cc`. But I think people will (reasonably) complain about something like this.

Then again, maybe most instances of this pattern don't trigger the warning? It'd be nice to figure out what's different here though.

Julia Hansbrough

Yeah, so: the heuristic definitely tends toward marking *anything* it analyzes as a *potential* mutation as suspect (it's how LLVM's ExprMutationAnalyzer works). In the majority of cases the reason it marks things as such is fairly straightforward (if the variable is passed as an argument to some function, it's not able to introspect that function and assumes a mutation has occurred; likewise if some function is called on the object itself).

In this case, the analyzer is bothered by that `IsHTMLSpecialWhitespace` function—it *could* me modifying that value and so it flags it.

The hope is to reset Chromium to a "clean slate" with a one-time fixup—so that this alert doesn't trigger on anything in the codebase. Then, going forward, we can make a call on whether the check is overall too low-signal to be worth it, or, if it's worth it enough to update the style guide to "prefer const ref" (which would mute the alert even in cases where there isn't technically any bug) plus enable it as a regular clang-tidy check.

Let me know if that makes sense / sounds like an okay plan?

Open in Gerrit

Related details

Attention is currently required from:
  • Daniel Cheng
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I469fdf929ae91759e416a6b0a3529d0551f1425a
Gerrit-Change-Number: 6967624
Gerrit-PatchSet: 1
Gerrit-Owner: Julia Hansbrough <flowe...@google.com>
Gerrit-Reviewer: Daniel Cheng <dch...@chromium.org>
Gerrit-CC: (Julie)Jeongeun Kim <je_jul...@chromium.org>
Gerrit-CC: Akihiro Ota <akihi...@chromium.org>
Gerrit-CC: Alexis Menard <alexis...@intel.com>
Gerrit-CC: Kentaro Hara <har...@chromium.org>
Gerrit-CC: Kevin Babbitt <kbab...@microsoft.com>
Gerrit-CC: Nektarios Paisios <nek...@chromium.org>
Gerrit-CC: Olga Gerchikov <gerc...@microsoft.com>
Gerrit-CC: Raphael Kubo da Costa <ku...@igalia.com>
Gerrit-Attention: Daniel Cheng <dch...@chromium.org>
Gerrit-Comment-Date: Tue, 23 Sep 2025 23:16:36 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Daniel Cheng <dch...@chromium.org>
satisfied_requirement
unsatisfied_requirement
open
diffy

Julia Hansbrough (Gerrit)

unread,
Sep 25, 2025, 5:27:22 AM (11 days ago) Sep 25
to Daniel Cheng, Alexis Menard, chromium...@chromium.org, Olga Gerchikov, Kentaro Hara, (Julie)Jeongeun Kim, Kevin Babbitt, Raphael Kubo da Costa, abigailbk...@google.com, blink-rev...@chromium.org, blink-revie...@chromium.org, blink-revie...@chromium.org, blink-rev...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, dtseng...@chromium.org, francisjp...@google.com, josiah...@chromium.org, kinuko...@chromium.org, kyungjunle...@google.com, loading-rev...@chromium.org, lucasrada...@google.com, nektar...@chromium.org, yuzo+...@chromium.org
Attention needed from Daniel Cheng

Julia Hansbrough added 1 comment

File third_party/blink/renderer/core/html/parser/html_construction_site.cc
Line 158, Patchset 1 (Latest): for (const auto& ch : chars) {
Daniel Cheng . unresolved

I feel like the heuristic needs some tuning... this is definitely an example where `ch` was not mutated. Do you know if this is being classified as "unknown, possibly mtuated" or "definitely mutated"?

There are a couple other instances, but I consider those more harmless, e.g. the Rect change above in `visible_units.cc`. But I think people will (reasonably) complain about something like this.

Then again, maybe most instances of this pattern don't trigger the warning? It'd be nice to figure out what's different here though.

Julia Hansbrough

Yeah, so: the heuristic definitely tends toward marking *anything* it analyzes as a *potential* mutation as suspect (it's how LLVM's ExprMutationAnalyzer works). In the majority of cases the reason it marks things as such is fairly straightforward (if the variable is passed as an argument to some function, it's not able to introspect that function and assumes a mutation has occurred; likewise if some function is called on the object itself).

In this case, the analyzer is bothered by that `IsHTMLSpecialWhitespace` function—it *could* me modifying that value and so it flags it.

The hope is to reset Chromium to a "clean slate" with a one-time fixup—so that this alert doesn't trigger on anything in the codebase. Then, going forward, we can make a call on whether the check is overall too low-signal to be worth it, or, if it's worth it enough to update the style guide to "prefer const ref" (which would mute the alert even in cases where there isn't technically any bug) plus enable it as a regular clang-tidy check.

Let me know if that makes sense / sounds like an okay plan?

Gerrit-Comment-Date: Thu, 25 Sep 2025 09:27:12 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Julia Hansbrough <flowe...@google.com>
Comment-In-Reply-To: Daniel Cheng <dch...@chromium.org>
satisfied_requirement
unsatisfied_requirement
open
diffy

Julia Hansbrough (Gerrit)

unread,
Sep 25, 2025, 5:27:28 AM (11 days ago) Sep 25
to Daniel Cheng, Alexis Menard, chromium...@chromium.org, Olga Gerchikov, Kentaro Hara, (Julie)Jeongeun Kim, Kevin Babbitt, Raphael Kubo da Costa, abigailbk...@google.com, blink-rev...@chromium.org, blink-revie...@chromium.org, blink-revie...@chromium.org, blink-rev...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, dtseng...@chromium.org, francisjp...@google.com, josiah...@chromium.org, kinuko...@chromium.org, kyungjunle...@google.com, loading-rev...@chromium.org, lucasrada...@google.com, nektar...@chromium.org, yuzo+...@chromium.org

Julia Hansbrough abandoned this change

Related details

Attention set is empty
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: abandon
satisfied_requirement
unsatisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages