[PATCH] D36688: [clang-diff] Fix matching for unnamed NamedDecs

Johannes Altmanninger via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 14 09:05:17 PDT 2017


johannes created this revision.
Herald added a subscriber: klimek.

This makes Node::getIdentifier return a valid value for special
NamedDecl nodes that do not have a name, such as ctors, dtors
and unnamed classes / namespaces.


https://reviews.llvm.org/D36688

Files:
  lib/Tooling/ASTDiff/ASTDiff.cpp
  test/Tooling/clang-diff-heuristics.cpp


Index: test/Tooling/clang-diff-heuristics.cpp
===================================================================
--- test/Tooling/clang-diff-heuristics.cpp
+++ test/Tooling/clang-diff-heuristics.cpp
@@ -10,6 +10,8 @@
 
 void f2(int) {;}
 
+class C3 { C3(); };
+
 #else
 
 // same parents, same value
@@ -22,4 +24,8 @@
 // CHECK: Match CompoundStmt
 void f2() {}
 
+// same parents, same identifier
+// CHECK: Match CXXConstructorDecl: :C3(void ())(9) to CXXConstructorDecl: :C3(void (int))(6)
+class C3 { C3(int); };
+
 #endif
Index: lib/Tooling/ASTDiff/ASTDiff.cpp
===================================================================
--- lib/Tooling/ASTDiff/ASTDiff.cpp
+++ lib/Tooling/ASTDiff/ASTDiff.cpp
@@ -384,8 +384,7 @@
   // Strip the qualifier, if Val refers to somthing in the current scope.
   // But leave one leading ':' in place, so that we know that this is a
   // relative path.
-  if (!ContextPrefix.empty() &&
-      StringRef(Val).startswith(ContextPrefix))
+  if (!ContextPrefix.empty() && StringRef(Val).startswith(ContextPrefix))
     Val = Val.substr(ContextPrefix.size() + 1);
   return Val;
 }
@@ -715,14 +714,18 @@
   if (auto *ND = ASTNode.get<NamedDecl>()) {
     if (ND->getDeclName().isIdentifier())
       return ND->getQualifiedNameAsString();
+    else
+      return std::string();
   }
   return llvm::None;
 }
 
 llvm::Optional<StringRef> Node::getIdentifier() const {
   if (auto *ND = ASTNode.get<NamedDecl>()) {
     if (ND->getDeclName().isIdentifier())
       return ND->getName();
+    else
+      return StringRef();
   }
   return llvm::None;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36688.110993.patch
Type: text/x-patch
Size: 1590 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170814/47cc89b8/attachment-0001.bin>


More information about the cfe-commits mailing list