[PATCH] D42813: [Debug] Annotate compiler generated range-for loop variables.

David Blaikie via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 5 10:12:24 PST 2018


dblaikie added a comment.

Seems plausible - maybe walking the scopes to count the range-for loops would produce a better number, but would be slower. :/ Dunno.



================
Comment at: lib/Sema/SemaStmt.cpp:2346
+    // Assume the variables are nested in the inner scope (loop body).
+    const auto DepthStr = std::to_string(S->getDepth() >> 1);
     VarDecl *BeginVar = BuildForRangeVarDecl(*this, ColonLoc, AutoType,
----------------
Why shifted right/divided by two? (I'd probably write this as "/ 2" rather thane ">> 1" if this is what's)

I guess this is because a range-for introduces two (actually 3, I think) scopes?

But what about if there are other random scopes that could be present? Does that adversely affect anything here?


https://reviews.llvm.org/D42813





More information about the cfe-commits mailing list