[clang] eda9d27 - [clang][AST] TextNodeDumper learned to dump NRVO candidates of return stmts
Timo Stripf via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 15 09:25:42 PDT 2023
Author: Timo Stripf
Date: 2023-08-15T16:24:15Z
New Revision: eda9d27a91e6f3bf6d7c65a300be729c410e93a7
URL: https://github.com/llvm/llvm-project/commit/eda9d27a91e6f3bf6d7c65a300be729c410e93a7
DIFF: https://github.com/llvm/llvm-project/commit/eda9d27a91e6f3bf6d7c65a300be729c410e93a7.diff
LOG: [clang][AST] TextNodeDumper learned to dump NRVO candidates of return stmts
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D157687
Added:
Modified:
clang/include/clang/AST/TextNodeDumper.h
clang/lib/AST/TextNodeDumper.cpp
clang/test/AST/ast-dump-decl.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/TextNodeDumper.h b/clang/include/clang/AST/TextNodeDumper.h
index 771dab01c2ba04..7a188668cab0f4 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -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);
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index a562e6d8140115..8b0ed593db623a 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -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",
diff --git a/clang/test/AST/ast-dump-decl.cpp b/clang/test/AST/ast-dump-decl.cpp
index e822b5fa44c55f..5cea68be0c8280 100644
--- a/clang/test/AST/ast-dump-decl.cpp
+++ b/clang/test/AST/ast-dump-decl.cpp
@@ -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'
More information about the cfe-commits
mailing list