[PATCH] D42813: [Debug] Annotate compiler generated range-for loop variables.
Matt Davis via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 1 13:15:39 PST 2018
mattd created this revision.
mattd added a reviewer: rsmith.
mattd edited the summary of this revision.
This change aims to simplify debugging by annotating the range-for loop artificial variables (range, begin, end) with the scope depth.
https://reviews.llvm.org/D42813
Files:
SemaStmt.cpp
Index: SemaStmt.cpp
===================================================================
--- SemaStmt.cpp
+++ SemaStmt.cpp
@@ -2025,7 +2025,7 @@
/// Build a variable declaration for a for-range statement.
VarDecl *BuildForRangeVarDecl(Sema &SemaRef, SourceLocation Loc,
- QualType Type, const char *Name) {
+ QualType Type, StringRef Name) {
DeclContext *DC = SemaRef.CurContext;
IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name);
TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc);
@@ -2093,11 +2093,13 @@
return StmtError();
}
- // Build auto && __range = range-init
+ // Build auto && __range = range-init.
+ // Assume the variables are nested in the inner scope (loop body).
+ const auto DepthStr = std::to_string(S->getDepth() >> 1);
SourceLocation RangeLoc = Range->getLocStart();
VarDecl *RangeVar = BuildForRangeVarDecl(*this, RangeLoc,
Context.getAutoRRefDeductType(),
- "__range");
+ std::string("__range") + DepthStr);
if (FinishForRangeVarDecl(*this, RangeVar, Range, RangeLoc,
diag::err_for_range_deduction_failure)) {
LoopVar->setInvalidDecl();
@@ -2340,10 +2342,12 @@
return StmtError();
// Build auto __begin = begin-expr, __end = end-expr.
+ // 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,
- "__begin");
+ std::string("__begin") + DepthStr);
VarDecl *EndVar = BuildForRangeVarDecl(*this, ColonLoc, AutoType,
- "__end");
+ std::string("__end") + DepthStr);
// Build begin-expr and end-expr and attach to __begin and __end variables.
ExprResult BeginExpr, EndExpr;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42813.132462.patch
Type: text/x-patch
Size: 2139 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180201/76f24fce/attachment.bin>
More information about the cfe-commits
mailing list