https://llvm.org/bugs/show_bug.cgi?id=29145
Bug ID: 29145 Summary: ParmVarDecl corresponding to unnamed parameter incorrectly has a name Product: clang Version: trunk Hardware: PC OS: Linux Status: NEW Severity: normal Priority: P Component: -New Bugs Assignee: unassignedclangb...@nondot.org Reporter: luka...@chromium.org CC: llvm-bugs@lists.llvm.org Classification: Unclassified clang version 4.0.0 (trunk 277962) Expected behavior: 1. The ParmVarDecl corresponding to void f(int); declaration on line 5 should have 1) no identifier 2) no name 2. I can safely generate replacements of text inside parm.getLocation() (e.g. rename "dataSize" to "data_size"). Actual behavior: 1. There are 2 ParmVarDecls on line 5. One of these ParmVarDecls has a non-empty name and identifier. 2. Generating replacements based on parm.getLocation() would butcher the source code. 3. Output of the repro program below: Name = '' Identifier = '0x0' <-- looking good so far... Line = 'input.cc:5:19' --------------------------------- Name = 'dataSize' <-- THIS IS THE BUG Identifier = '0x3a05f98' Line = 'input.cc:5:19' --------------------------------- Name = '' Identifier = '0x0' Line = 'input.cc:3:13' <- please ignore ParmVarDecls from other lines --------------------------------- Name = 'dataSize' Identifier = '0x3a05f98' Line = 'input.cc:9:28' <- please ignore ParmVarDecls from other lines Repro: #include <memory> #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/ASTMatchers/ASTMatchers.h" #include "clang/ASTMatchers/ASTMatchersMacros.h" #include "clang/Basic/CharInfo.h" #include "clang/Frontend/FrontendActions.h" #include "clang/Tooling/CommonOptionsParser.h" #include "clang/Tooling/Refactoring.h" #include "clang/Tooling/Tooling.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/TargetSelect.h" using namespace clang::ast_matchers; class ReproMatchCallback : public MatchFinder::MatchCallback { public: void run(const MatchFinder::MatchResult& result) override { const clang::ParmVarDecl* parm = result.Nodes.getNodeAs<clang::ParmVarDecl>("decl"); if (!parm) return; llvm::outs() << "---------------------------------\n"; llvm::outs() << "Name = '" << parm->getName() << "'\n"; llvm::outs() << "Identifier = '" << parm->getIdentifier() << "'\n"; llvm::outs() << "Line = '" << parm->getLocation().printToString(result.Context->getSourceManager()) << "'\n"; } }; int main(int argc, const char* argv[]) { llvm::InitializeNativeTarget(); llvm::InitializeNativeTargetAsmParser(); llvm::cl::OptionCategory category("Repro."); clang::tooling::CommonOptionsParser options(argc, argv, category); clang::tooling::ClangTool tool(options.getCompilations(), options.getSourcePathList()); const char* code = R"code( // line 1 template <typename T> // line 2 class Class { // line 3 public: // line 4 void f(int); // <- NO NAME! // line 5 }; // line 6 // line 7 template <typename T> // line 8 void Class<T>::f(int dataSize){}; // line 9 // line 10 void foo() { // line 11 Class<char>().f(123); // line 12 }; // line 13 )code"; auto matcher = id("decl", parmVarDecl()); MatchFinder match_finder; ReproMatchCallback match_callback; match_finder.addMatcher(matcher, &match_callback); std::unique_ptr<clang::tooling::FrontendActionFactory> factory = clang::tooling::newFrontendActionFactory(&match_finder); clang::tooling::runToolOnCode(factory->create(), code); return 0; } -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs