RE: r325175 - [Debug] Annotate compiler generated range-for loop variables.
From: Galina Kistanova [mailto:gkistan...@gmail.com] > Sent: Thursday, February 15, 2018 9:33 AM > To: Davis, Matthew > Cc: cfe-commits > Subject: Re: r325175 - [Debug] Annotate compiler generated range-for loop > variables. > > Hello Matt, > > This commit broke tests on one of our builders: > http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/7920 > . . . > Failing Tests (1): > Clang :: CodeGenCXX/debug-info-range-for-var-names.cpp > > Please have a look? > > Thanks > > Galina Thanks Galina, I will look. -Matt ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r325175 - [Debug] Annotate compiler generated range-for loop variables.
Hello Matt, This commit broke tests on one of our builders: http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/7920 . . . Failing Tests (1): Clang :: CodeGenCXX/debug-info-range-for-var-names.cpp Please have a look? Thanks Galina On Wed, Feb 14, 2018 at 1:22 PM, Matt Davis via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Author: mattd > Date: Wed Feb 14 13:22:11 2018 > New Revision: 325175 > > URL: http://llvm.org/viewvc/llvm-project?rev=325175&view=rev > Log: > [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 > > Added: > cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp > Modified: > cfe/trunk/include/clang/Sema/Scope.h > cfe/trunk/lib/Sema/SemaStmt.cpp > cfe/trunk/test/CodeGenCXX/debug-info-scope.cpp > cfe/trunk/test/CodeGenCXX/vla.cpp > > Modified: cfe/trunk/include/clang/Sema/Scope.h > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/ > clang/Sema/Scope.h?rev=325175&r1=325174&r2=325175&view=diff > > == > --- cfe/trunk/include/clang/Sema/Scope.h (original) > +++ cfe/trunk/include/clang/Sema/Scope.h Wed Feb 14 13:22:11 2018 > @@ -259,6 +259,9 @@ public: >Scope *getTemplateParamParent() { return TemplateParamParent; } >const Scope *getTemplateParamParent() const { return > TemplateParamParent; } > > + /// Returns the depth of this scope. The translation-unit has scope > depth 0. > + unsigned getDepth() const { return Depth; } > + >/// Returns the number of function prototype scopes in this scope >/// chain. >unsigned getFunctionPrototypeDepth() const { > > Modified: cfe/trunk/lib/Sema/SemaStmt.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/ > SemaStmt.cpp?rev=325175&r1=325174&r2=325175&view=diff > > == > --- cfe/trunk/lib/Sema/SemaStmt.cpp (original) > +++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Feb 14 13:22:11 2018 > @@ -2025,7 +2025,7 @@ void NoteForRangeBeginEndFunction(Sema & > > /// 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(Sc >} > >// 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(SourceLocatio >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; > > Added: cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ > CodeGenCXX/debug-info-range-for-var-names.cpp?rev=325175&view=auto > > == > --- cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp (added) > +++ cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp Wed Feb > 14 13:22:11 2018 > @@ -0,0 +1,36
r325175 - [Debug] Annotate compiler generated range-for loop variables.
Author: mattd Date: Wed Feb 14 13:22:11 2018 New Revision: 325175 URL: http://llvm.org/viewvc/llvm-project?rev=325175&view=rev Log: [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 Added: cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp Modified: cfe/trunk/include/clang/Sema/Scope.h cfe/trunk/lib/Sema/SemaStmt.cpp cfe/trunk/test/CodeGenCXX/debug-info-scope.cpp cfe/trunk/test/CodeGenCXX/vla.cpp Modified: cfe/trunk/include/clang/Sema/Scope.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Scope.h?rev=325175&r1=325174&r2=325175&view=diff == --- cfe/trunk/include/clang/Sema/Scope.h (original) +++ cfe/trunk/include/clang/Sema/Scope.h Wed Feb 14 13:22:11 2018 @@ -259,6 +259,9 @@ public: Scope *getTemplateParamParent() { return TemplateParamParent; } const Scope *getTemplateParamParent() const { return TemplateParamParent; } + /// Returns the depth of this scope. The translation-unit has scope depth 0. + unsigned getDepth() const { return Depth; } + /// Returns the number of function prototype scopes in this scope /// chain. unsigned getFunctionPrototypeDepth() const { Modified: cfe/trunk/lib/Sema/SemaStmt.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=325175&r1=325174&r2=325175&view=diff == --- cfe/trunk/lib/Sema/SemaStmt.cpp (original) +++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Feb 14 13:22:11 2018 @@ -2025,7 +2025,7 @@ void NoteForRangeBeginEndFunction(Sema & /// 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(Sc } // 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(SourceLocatio 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; Added: cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp?rev=325175&view=auto == --- cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp (added) +++ cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp Wed Feb 14 13:22:11 2018 @@ -0,0 +1,36 @@ +// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s + +struct vec { + using itr = int*; + itr begin() { return nullptr; } + itr end() { return nullptr; } +}; + +void test() { + vec as, bs, cs; + + for (auto a : as) +for (auto b : bs) + for (auto c : cs) { + } +} + +// CHECK: define void @_Z4testv() +// CHECK: call void @llvm.dbg.declare(metadata %struct.vec** {{.*}}, metadata ![[RANGE1:[0-9]+]] +// CHECK: call void @llvm.dbg.declare(metadata i32** {{.*}}, metadata ![[BEGIN1:[0-9]+]] +// CHECK: call void @llvm.dbg