Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Unified Diff: tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp

Issue 2671713005: Avoid calling getName() on declarations that don't have an associated identifier. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
diff --git a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
index 025fbdcc3d0389ad6ef5603228142beee8ec1841..c0c2ad138dbc5e05e49d5b625e28c63d102a45e4 100644
--- a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
+++ b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
@@ -135,6 +135,9 @@ class MethodBlocklist {
}
bool Contains(const clang::FunctionDecl& method) const {
+ if (!method.getDeclName().isIdentifier())
+ return false;
+
auto it = method_to_class_to_args_.find(method.getName());
if (it == method_to_class_to_args_.end())
return false;
@@ -146,6 +149,8 @@ class MethodBlocklist {
clang::dyn_cast<clang::NamedDecl>(method.getDeclContext());
if (!method_context)
return false;
+ if (!method_context->getDeclName().isIdentifier())
+ return false;
const llvm::StringMap<std::set<unsigned>>& class_to_args = it->second;
auto it2 = class_to_args.find(method_context->getName());
@@ -454,11 +459,17 @@ bool IsBlacklistedMethodName(llvm::StringRef name) {
}
bool IsBlacklistedFunction(const clang::FunctionDecl& decl) {
+ if (!decl.getDeclName().isIdentifier())
+ return false;
+
clang::StringRef name = decl.getName();
return IsBlacklistedFunctionName(name) || IsBlacklistedFreeFunctionName(name);
}
bool IsBlacklistedMethod(const clang::CXXMethodDecl& decl) {
+ if (!decl.getDeclName().isIdentifier())
+ return false;
+
clang::StringRef name = decl.getName();
if (IsBlacklistedFunctionName(name))
return true;
@@ -494,7 +505,7 @@ bool IsKnownTraitName(clang::StringRef name) {
}
AST_MATCHER(clang::VarDecl, isKnownTraitName) {
- return IsKnownTraitName(Node.getName());
+ return Node.getDeclName().isIdentifier() && IsKnownTraitName(Node.getName());
}
// Helper to convert from a camelCaseName to camel_case_name. It uses some
@@ -725,7 +736,8 @@ bool ShouldPrefixFunctionName(const std::string& old_method_name) {
}
AST_MATCHER(clang::FunctionDecl, shouldPrefixFunctionName) {
- return ShouldPrefixFunctionName(Node.getName().str());
+ return Node.getDeclName().isIdentifier() &&
+ ShouldPrefixFunctionName(Node.getName().str());
}
bool GetNameForDecl(const clang::FunctionDecl& decl,
@@ -1131,6 +1143,9 @@ class DeclRewriterBase : public RewriterBase<TargetNode> {
void run(const MatchFinder::MatchResult& result) override {
const DeclNode* decl = result.Nodes.getNodeAs<DeclNode>("decl");
+ if (!decl->getDeclName().isIdentifier())
+ return;
+
assert(decl);
llvm::StringRef old_name = decl->getName();
Łukasz Anforowicz 2017/02/02 22:51:42 In theory a few GetNameForDecl should also be prot
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698