summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMatt Davis <Matthew.Davis@sony.com>2018-02-14 21:22:11 +0000
committerMatt Davis <Matthew.Davis@sony.com>2018-02-14 21:22:11 +0000
commit06fcaea8ad23e9e2423d1050a80847838584ce54 (patch)
treecbedad97fcf0e9a0146016d0d483c5f021f01ea4 /lib
parent3e5efa055bf4a738d69cc8f04ea2635436a9c1e1 (diff)
downloadclang-06fcaea8ad23e9e2423d1050a80847838584ce54.tar.gz
[Debug] Annotate compiler generated range-for loop variables.
Summary: This change aims to simplify debugging by annotating the range-for loop artificial variables (range, begin, end) with the scope depth. Reviewers: rsmith, dblaikie Reviewed By: dblaikie Subscribers: dblaikie, cfe-commits Tags: #debug-info Differential Revision: https://reviews.llvm.org/D42813 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@325175 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Sema/SemaStmt.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index 93907038e0..b77018503a 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -2025,7 +2025,7 @@ void NoteForRangeBeginEndFunction(Sema &SemaRef, Expr *E,
/// 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);
@@ -2094,10 +2094,12 @@ StmtResult Sema::ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc,
}
// Build auto && __range = range-init
+ // Divide by 2, since the variables are in the inner scope (loop body).
+ const auto DepthStr = std::to_string(S->getDepth() / 2);
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 @@ Sema::BuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation CoawaitLoc,
return StmtError();
// Build auto __begin = begin-expr, __end = end-expr.
+ // Divide by 2, since the variables are in the inner scope (loop body).
+ const auto DepthStr = std::to_string(S->getDepth() / 2);
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;