Skip to content

Commit

Permalink
[clang][AST] TextNodeDumper learned to dump NRVO candidates of return…
Browse files Browse the repository at this point in the history
… stmts

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D157687
  • Loading branch information
strimo378 committed Aug 15, 2023
1 parent 88903fa commit eda9d27
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions clang/include/clang/AST/TextNodeDumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ class TextNodeDumper
void VisitLabelStmt(const LabelStmt *Node);
void VisitGotoStmt(const GotoStmt *Node);
void VisitCaseStmt(const CaseStmt *Node);
void VisitReturnStmt(const ReturnStmt *Node);
void VisitCompoundStmt(const CompoundStmt *Node);
void VisitConstantExpr(const ConstantExpr *Node);
void VisitCallExpr(const CallExpr *Node);
Expand Down
8 changes: 8 additions & 0 deletions clang/lib/AST/TextNodeDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,14 @@ void TextNodeDumper::VisitCaseStmt(const CaseStmt *Node) {
OS << " gnu_range";
}

void clang::TextNodeDumper::VisitReturnStmt(const ReturnStmt *Node) {
if (const VarDecl *Cand = Node->getNRVOCandidate()) {
OS << " nrvo_candidate(";
dumpBareDeclRef(Cand);
OS << ")";
}
}

void TextNodeDumper::VisitConstantExpr(const ConstantExpr *Node) {
if (Node->hasAPValueResult())
AddChild("value",
Expand Down
9 changes: 7 additions & 2 deletions clang/test/AST/ast-dump-decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ class testFieldDecl {

namespace testVarDeclNRVO {
class A { };
A foo() {
A TestFuncNRVO() {
A TestVarDeclNRVO;
return TestVarDeclNRVO;
}
}
// CHECK: VarDecl{{.*}} TestVarDeclNRVO 'A':'testVarDeclNRVO::A' nrvo
// CHECK: FunctionDecl{{.*}} TestFuncNRVO 'A ()'
// CHECK-NEXT: `-CompoundStmt
// CHECK-NEXT: |-DeclStmt
// CHECK-NEXT: | `-VarDecl{{.*}} TestVarDeclNRVO 'A':'testVarDeclNRVO::A' nrvo callinit
// CHECK-NEXT: | `-CXXConstructExpr
// CHECK-NEXT: `-ReturnStmt{{.*}} nrvo_candidate(Var {{.*}} 'TestVarDeclNRVO' 'A':'testVarDeclNRVO::A')

void testParmVarDeclInit(int TestParmVarDeclInit = 0);
// CHECK: ParmVarDecl{{.*}} TestParmVarDeclInit 'int'
Expand Down

0 comments on commit eda9d27

Please sign in to comment.