summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSylvestre Ledru <sylvestre@debian.org>2020-11-15 12:47:07 +0100
committerSylvestre Ledru <sylvestre@debian.org>2020-11-15 12:47:07 +0100
commit14476161d1826adf6009bf4bc5787ce26137a299 (patch)
tree10290a94704671e7a3134645a7f1720d13c7c044
parent37f4dcb095819ec17ca18b0c58f29e04acb398a0 (diff)
backport some fixes
-rw-r--r--debian/patches/GlobalSourceManager.patch210
-rw-r--r--debian/patches/PrintableStmt.patch54
-rw-r--r--debian/patches/series3
-rw-r--r--debian/patches/stringref.patch146
4 files changed, 413 insertions, 0 deletions
diff --git a/debian/patches/GlobalSourceManager.patch b/debian/patches/GlobalSourceManager.patch
new file mode 100644
index 0000000..9f40f13
--- /dev/null
+++ b/debian/patches/GlobalSourceManager.patch
@@ -0,0 +1,210 @@
+From fbffd6e3be4c409109b06f858368bcee1ea2f99d Mon Sep 17 00:00:00 2001
+From: Kim Grasman <kim.grasman@gmail.com>
+Date: Tue, 22 Sep 2020 19:28:24 +0200
+Subject: [PATCH] Remove source manager from ASTNode constructor
+
+ASTNode was consistently instantiated using GlobalSourceManager(). The
+passed-in source manager was only used in ASTNode::GetLocation().
+
+Use GlobalSourceManager() there directly instead to keep the constructor
+interface simpler.
+
+No functional change.
+---
+ iwyu.cc | 20 ++++++++++----------
+ iwyu_ast_util.cc | 9 ++++-----
+ iwyu_ast_util.h | 42 ++++++++++++++++++------------------------
+ 3 files changed, 32 insertions(+), 39 deletions(-)
+
+diff --git a/iwyu.cc b/iwyu.cc
+index 8f934273..931d57b6 100644
+--- a/iwyu.cc
++++ b/iwyu.cc
+@@ -322,7 +322,7 @@ class BaseAstVisitor : public RecursiveASTVisitor<Derived> {
+ bool TraverseDecl(Decl* decl) {
+ if (current_ast_node_ && current_ast_node_->StackContainsContent(decl))
+ return true; // avoid recursion
+- ASTNode node(decl, *GlobalSourceManager());
++ ASTNode node(decl);
+ CurrentASTNodeUpdater canu(&current_ast_node_, &node);
+ return Base::TraverseDecl(decl);
+ }
+@@ -330,7 +330,7 @@ class BaseAstVisitor : public RecursiveASTVisitor<Derived> {
+ bool TraverseStmt(Stmt* stmt) {
+ if (current_ast_node_ && current_ast_node_->StackContainsContent(stmt))
+ return true; // avoid recursion
+- ASTNode node(stmt, *GlobalSourceManager());
++ ASTNode node(stmt);
+ CurrentASTNodeUpdater canu(&current_ast_node_, &node);
+ return Base::TraverseStmt(stmt);
+ }
+@@ -341,7 +341,7 @@ class BaseAstVisitor : public RecursiveASTVisitor<Derived> {
+ const Type* type = qualtype.getTypePtr();
+ if (current_ast_node_ && current_ast_node_->StackContainsContent(type))
+ return true; // avoid recursion
+- ASTNode node(type, *GlobalSourceManager());
++ ASTNode node(type);
+ CurrentASTNodeUpdater canu(&current_ast_node_, &node);
+ return Base::TraverseType(qualtype);
+ }
+@@ -365,7 +365,7 @@ class BaseAstVisitor : public RecursiveASTVisitor<Derived> {
+ }
+ if (current_ast_node_ && current_ast_node_->StackContainsContent(&typeloc))
+ return true; // avoid recursion
+- ASTNode node(&typeloc, *GlobalSourceManager());
++ ASTNode node(&typeloc);
+ CurrentASTNodeUpdater canu(&current_ast_node_, &node);
+ return Base::TraverseTypeLoc(typeloc);
+ }
+@@ -373,7 +373,7 @@ class BaseAstVisitor : public RecursiveASTVisitor<Derived> {
+ bool TraverseNestedNameSpecifier(NestedNameSpecifier* nns) {
+ if (nns == nullptr)
+ return true;
+- ASTNode node(nns, *GlobalSourceManager());
++ ASTNode node(nns);
+ CurrentASTNodeUpdater canu(&current_ast_node_, &node);
+ if (!this->getDerived().VisitNestedNameSpecifier(nns))
+ return false;
+@@ -383,7 +383,7 @@ class BaseAstVisitor : public RecursiveASTVisitor<Derived> {
+ bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc nns_loc) {
+ if (!nns_loc) // using NNSLoc::operator bool()
+ return true;
+- ASTNode node(&nns_loc, *GlobalSourceManager());
++ ASTNode node(&nns_loc);
+ CurrentASTNodeUpdater canu(&current_ast_node_, &node);
+ // TODO(csilvers): have VisitNestedNameSpecifierLoc instead.
+ if (!this->getDerived().VisitNestedNameSpecifier(
+@@ -393,7 +393,7 @@ class BaseAstVisitor : public RecursiveASTVisitor<Derived> {
+ }
+
+ bool TraverseTemplateName(TemplateName template_name) {
+- ASTNode node(&template_name, *GlobalSourceManager());
++ ASTNode node(&template_name);
+ CurrentASTNodeUpdater canu(&current_ast_node_, &node);
+ if (!this->getDerived().VisitTemplateName(template_name))
+ return false;
+@@ -401,7 +401,7 @@ class BaseAstVisitor : public RecursiveASTVisitor<Derived> {
+ }
+
+ bool TraverseTemplateArgument(const TemplateArgument& arg) {
+- ASTNode node(&arg, *GlobalSourceManager());
++ ASTNode node(&arg);
+ CurrentASTNodeUpdater canu(&current_ast_node_, &node);
+ if (!this->getDerived().VisitTemplateArgument(arg))
+ return false;
+@@ -409,7 +409,7 @@ class BaseAstVisitor : public RecursiveASTVisitor<Derived> {
+ }
+
+ bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc& argloc) {
+- ASTNode node(&argloc, *GlobalSourceManager());
++ ASTNode node(&argloc);
+ CurrentASTNodeUpdater canu(&current_ast_node_, &node);
+ if (!this->getDerived().VisitTemplateArgumentLoc(argloc))
+ return false;
+@@ -3967,7 +3967,7 @@ class IwyuAstConsumer
+ if (const TemplateSpecializationType* arg_tmpl = DynCastFrom(arg_type)) {
+ // Special case: We are instantiating the type in the context of an
+ // expression. Need to push the type to the AST stack explicitly.
+- ASTNode node(arg_tmpl, *GlobalSourceManager());
++ ASTNode node(arg_tmpl);
+ node.SetParent(current_ast_node());
+
+ instantiated_template_visitor_.ScanInstantiatedType(
+diff --git a/iwyu_ast_util.cc b/iwyu_ast_util.cc
+index b19a11fb..1d37a175 100644
+--- a/iwyu_ast_util.cc
++++ b/iwyu_ast_util.cc
+@@ -186,13 +186,12 @@ SourceLocation ASTNode::GetLocation() const {
+ // locations are in a different file, then we're uncertain of our
+ // own location. Return an invalid location.
+ if (retval.isValid()) {
+- FullSourceLoc full_loc(retval, source_manager_);
++ clang::SourceManager& sm = *GlobalSourceManager();
++ FullSourceLoc full_loc(retval, sm);
+ const FileEntry* spelling_file =
+- source_manager_.getFileEntryForID(
+- source_manager_.getFileID(full_loc.getSpellingLoc()));
++ sm.getFileEntryForID(sm.getFileID(full_loc.getSpellingLoc()));
+ const FileEntry* instantiation_file =
+- source_manager_.getFileEntryForID(
+- source_manager_.getFileID(full_loc.getExpansionLoc()));
++ sm.getFileEntryForID(sm.getFileID(full_loc.getExpansionLoc()));
+ if (spelling_file != instantiation_file)
+ return SourceLocation();
+ }
+diff --git a/iwyu_ast_util.h b/iwyu_ast_util.h
+index a66a1d4b..18ddf2d3 100644
+--- a/iwyu_ast_util.h
++++ b/iwyu_ast_util.h
+@@ -40,7 +40,6 @@ class ClassTemplateDecl;
+ class Expr;
+ class FunctionDecl;
+ class NamedDecl;
+-class SourceManager;
+ class TagDecl;
+ class TemplateDecl;
+ class TemplateName;
+@@ -72,37 +71,33 @@ class ASTNode {
+ public:
+ // In each case, the caller owns the object, and must guarantee it
+ // lives for at least as long as the ASTNode object does.
+- ASTNode(const clang::Decl* decl, const clang::SourceManager& sm)
++ ASTNode(const clang::Decl* decl)
+ : kind_(kDeclKind), as_decl_(decl),
+- parent_(nullptr), in_fwd_decl_context_(false), source_manager_(sm) { }
+- ASTNode(const clang::Stmt* stmt, const clang::SourceManager& sm)
++ parent_(nullptr), in_fwd_decl_context_(false) { }
++ ASTNode(const clang::Stmt* stmt)
+ : kind_(kStmtKind), as_stmt_(stmt),
+- parent_(nullptr), in_fwd_decl_context_(false), source_manager_(sm) { }
+- ASTNode(const clang::Type* type, const clang::SourceManager& sm)
++ parent_(nullptr), in_fwd_decl_context_(false) { }
++ ASTNode(const clang::Type* type)
+ : kind_(kTypeKind), as_type_(type),
+- parent_(nullptr), in_fwd_decl_context_(false), source_manager_(sm) { }
+- ASTNode(const clang::TypeLoc* typeloc, const clang::SourceManager& sm)
++ parent_(nullptr), in_fwd_decl_context_(false) { }
++ ASTNode(const clang::TypeLoc* typeloc)
+ : kind_(kTypelocKind), as_typeloc_(typeloc),
+- parent_(nullptr), in_fwd_decl_context_(false), source_manager_(sm) { }
+- ASTNode(const clang::NestedNameSpecifier* nns, const clang::SourceManager& sm)
++ parent_(nullptr), in_fwd_decl_context_(false) { }
++ ASTNode(const clang::NestedNameSpecifier* nns)
+ : kind_(kNNSKind), as_nns_(nns),
+- parent_(nullptr), in_fwd_decl_context_(false), source_manager_(sm) { }
+- ASTNode(const clang::NestedNameSpecifierLoc* nnsloc,
+- const clang::SourceManager& sm)
++ parent_(nullptr), in_fwd_decl_context_(false) { }
++ ASTNode(const clang::NestedNameSpecifierLoc* nnsloc)
+ : kind_(kNNSLocKind), as_nnsloc_(nnsloc),
+- parent_(nullptr), in_fwd_decl_context_(false), source_manager_(sm) { }
+- ASTNode(const clang::TemplateName* template_name,
+- const clang::SourceManager& sm)
++ parent_(nullptr), in_fwd_decl_context_(false) { }
++ ASTNode(const clang::TemplateName* template_name)
+ : kind_(kTemplateNameKind), as_template_name_(template_name),
+- parent_(nullptr), in_fwd_decl_context_(false), source_manager_(sm) { }
+- ASTNode(const clang::TemplateArgument* template_arg,
+- const clang::SourceManager& sm)
++ parent_(nullptr), in_fwd_decl_context_(false) { }
++ ASTNode(const clang::TemplateArgument* template_arg)
+ : kind_(kTemplateArgumentKind), as_template_arg_(template_arg),
+- parent_(nullptr), in_fwd_decl_context_(false), source_manager_(sm) { }
+- ASTNode(const clang::TemplateArgumentLoc* template_argloc,
+- const clang::SourceManager& sm)
++ parent_(nullptr), in_fwd_decl_context_(false) { }
++ ASTNode(const clang::TemplateArgumentLoc* template_argloc)
+ : kind_(kTemplateArgumentLocKind), as_template_argloc_(template_argloc),
+- parent_(nullptr), in_fwd_decl_context_(false), source_manager_(sm) { }
++ parent_(nullptr), in_fwd_decl_context_(false) { }
+
+ // A 'forward-declare' context means some parent of us can be
+ // forward-declared, which means we can be too. e.g. in
+@@ -327,7 +322,6 @@ class ASTNode {
+ };
+ const ASTNode* parent_;
+ bool in_fwd_decl_context_;
+- const clang::SourceManager& source_manager_;
+ };
+
+ // --- Helper classes for ASTNode.
diff --git a/debian/patches/PrintableStmt.patch b/debian/patches/PrintableStmt.patch
new file mode 100644
index 0000000..663a883
--- /dev/null
+++ b/debian/patches/PrintableStmt.patch
@@ -0,0 +1,54 @@
+From 30549c6931972456d1e09ff5dbeecd258a8df72b Mon Sep 17 00:00:00 2001
+From: Kim Grasman <kim.grasman@gmail.com>
+Date: Thu, 9 Jul 2020 18:47:56 +0200
+Subject: [PATCH] Implement Stmt printing with ASTDumper
+
+The Clang API changed in commit 473fbc90d1fbf17e so that Stmt::dump
+takes an ASTContext instead of a SourceManager.
+
+Rather than wire a global ASTContext, reimplement PrintableStmt and
+PrintStmt to duplicate the most trivial implementations not requiring
+ASTContext.
+
+No functional change.
+---
+ iwyu_ast_util.cc | 8 ++++++--
+ 1 file changed, 6 insertions(+), 2 deletions(-)
+
+diff --git a/iwyu_ast_util.cc b/iwyu_ast_util.cc
+index d3d4dd1f..b19a11fb 100644
+--- a/iwyu_ast_util.cc
++++ b/iwyu_ast_util.cc
+@@ -25,6 +25,7 @@
+ #include "llvm/Support/Casting.h"
+ #include "llvm/Support/raw_ostream.h"
+ #include "clang/AST/ASTContext.h"
++#include "clang/AST/ASTDumper.h"
+ #include "clang/AST/CanonicalType.h"
+ #include "clang/AST/Decl.h"
+ #include "clang/AST/DeclBase.h"
+@@ -46,6 +47,7 @@ namespace clang {
+ class FileEntry;
+ } // namespace clang
+
++using clang::ASTDumper;
+ using clang::BlockPointerType;
+ using clang::CXXConstructExpr;
+ using clang::CXXConstructorDecl;
+@@ -450,12 +452,14 @@ string PrintableDecl(const Decl* decl, bool terse/*=true*/) {
+ string PrintableStmt(const Stmt* stmt) {
+ std::string buffer;
+ raw_string_ostream ostream(buffer);
+- stmt->dump(ostream, *GlobalSourceManager());
++ ASTDumper dumper(ostream, /*ShowColors=*/false);
++ dumper.Visit(stmt);
+ return ostream.str();
+ }
+
+ void PrintStmt(const Stmt* stmt) {
+- stmt->dump(*GlobalSourceManager()); // This prints to errs().
++ ASTDumper dumper(llvm::errs(), /*ShowColors=*/false);
++ dumper.Visit(stmt);
+ }
+
+ string PrintableType(const Type* type) {
diff --git a/debian/patches/series b/debian/patches/series
index a9c0526..06a6a12 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,2 +1,5 @@
#struct.patch
python3.diff
+stringref.patch
+GlobalSourceManager.patch
+PrintableStmt.patch
diff --git a/debian/patches/stringref.patch b/debian/patches/stringref.patch
new file mode 100644
index 0000000..171dca2
--- /dev/null
+++ b/debian/patches/stringref.patch
@@ -0,0 +1,146 @@
+From 53487d209729d5781007dc0fd6076dc585cb3727 Mon Sep 17 00:00:00 2001
+From: Andrea Bocci <andrea.bocci@cern.ch>
+Date: Fri, 28 Feb 2020 17:45:03 +0100
+Subject: [PATCH] Add explicit conversion from llvm::StringRef to std::string
+
+llvm/llvm-project@777180a makes the llvm::StringRef conversion operator
+to std::string explicit.
+These changes add a call to the str() method to perform the conversion.
+
+Signed-off-by: Andrea Bocci <andrea.bocci@cern.ch>
+---
+ iwyu_driver.cc | 2 +-
+ iwyu_globals.cc | 4 ++--
+ iwyu_lexer_utils.cc | 2 +-
+ iwyu_location_util.h | 2 +-
+ iwyu_output.cc | 2 +-
+ iwyu_path_util.cc | 6 +++---
+ iwyu_preprocessor.cc | 4 ++--
+ 7 files changed, 11 insertions(+), 11 deletions(-)
+
+diff --git a/iwyu_driver.cc b/iwyu_driver.cc
+index bd163144..42fea35b 100644
+--- a/iwyu_driver.cc
++++ b/iwyu_driver.cc
+@@ -79,7 +79,7 @@ std::string GetExecutablePath(const char *Argv0) {
+ }
+
+ const char *SaveStringInSet(std::set<std::string> &SavedStrings, StringRef S) {
+- return SavedStrings.insert(S).first->c_str();
++ return SavedStrings.insert(S.str()).first->c_str();
+ }
+
+ void ExpandArgsFromBuf(const char *Arg,
+diff --git a/iwyu_globals.cc b/iwyu_globals.cc
+index 0f58b4dc..26998966 100644
+--- a/iwyu_globals.cc
++++ b/iwyu_globals.cc
+@@ -293,7 +293,7 @@ static vector<HeaderSearchPath> ComputeHeaderSearchPaths(
+ for (auto it = header_search->system_dir_begin();
+ it != header_search->system_dir_end(); ++it) {
+ if (const DirectoryEntry* entry = it->getDir()) {
+- const string path = NormalizeDirPath(MakeAbsolutePath(entry->getName()));
++ const string path = NormalizeDirPath(MakeAbsolutePath(entry->getName().str()));
+ search_path_map[path] = HeaderSearchPath::kSystemPath;
+ }
+ }
+@@ -303,7 +303,7 @@ static vector<HeaderSearchPath> ComputeHeaderSearchPaths(
+ // search_dir_begin()/end() includes both system and user paths.
+ // If it's a system path, it's already in the map, so everything
+ // new is a user path. The insert only 'takes' for new entries.
+- const string path = NormalizeDirPath(MakeAbsolutePath(entry->getName()));
++ const string path = NormalizeDirPath(MakeAbsolutePath(entry->getName().str()));
+ search_path_map.insert(make_pair(path, HeaderSearchPath::kUserPath));
+ }
+ }
+diff --git a/iwyu_lexer_utils.cc b/iwyu_lexer_utils.cc
+index fcea2d28..648c9da8 100644
+--- a/iwyu_lexer_utils.cc
++++ b/iwyu_lexer_utils.cc
+@@ -70,7 +70,7 @@ SourceLocation GetLocationAfter(
+ string GetIncludeNameAsWritten(
+ SourceLocation include_loc,
+ const CharacterDataGetterInterface& data_getter) {
+- const string data = GetSourceTextUntilEndOfLine(include_loc, data_getter);
++ const string data = GetSourceTextUntilEndOfLine(include_loc, data_getter).str();
+ if (data.empty())
+ return data;
+ string::size_type endpos = string::npos;
+diff --git a/iwyu_location_util.h b/iwyu_location_util.h
+index 3892a424..6f8cf81c 100644
+--- a/iwyu_location_util.h
++++ b/iwyu_location_util.h
+@@ -89,7 +89,7 @@ bool IsInScratchSpace(clang::SourceLocation loc);
+
+ inline string GetFilePath(const clang::FileEntry* file) {
+ return (IsBuiltinFile(file) ? "<built-in>" :
+- NormalizeFilePath(file->getName()));
++ NormalizeFilePath(file->getName().str()));
+ }
+
+ //------------------------------------------------------------
+diff --git a/iwyu_output.cc b/iwyu_output.cc
+index ca145710..8666c26c 100644
+--- a/iwyu_output.cc
++++ b/iwyu_output.cc
+@@ -168,7 +168,7 @@ string GetKindName(const clang::TagDecl* tag_decl) {
+ if (const FakeNamedDecl* fake = FakeNamedDeclIfItIsOne(named_decl)) {
+ return fake->kind_name();
+ }
+- return tag_decl->getKindName();
++ return tag_decl->getKindName().str();
+ }
+
+ string GetQualifiedNameAsString(const clang::NamedDecl* named_decl) {
+diff --git a/iwyu_path_util.cc b/iwyu_path_util.cc
+index ab4fc800..9987ea47 100644
+--- a/iwyu_path_util.cc
++++ b/iwyu_path_util.cc
+@@ -134,7 +134,7 @@ string NormalizeFilePath(const string& path) {
+ std::replace(normalized.begin(), normalized.end(), '\\', '/');
+ #endif
+
+- return normalized.str();
++ return normalized.str().str();
+ }
+
+ string NormalizeDirPath(const string& path) {
+@@ -154,14 +154,14 @@ string MakeAbsolutePath(const string& path) {
+ std::error_code error = llvm::sys::fs::make_absolute(absolute_path);
+ CHECK_(!error);
+
+- return absolute_path.str();
++ return absolute_path.str().str();
+ }
+
+ string MakeAbsolutePath(const string& base_path, const string& relative_path) {
+ llvm::SmallString<128> absolute_path(base_path);
+ llvm::sys::path::append(absolute_path, relative_path);
+
+- return absolute_path.str();
++ return absolute_path.str().str();
+ }
+
+ string GetParentPath(const string& path) {
+diff --git a/iwyu_preprocessor.cc b/iwyu_preprocessor.cc
+index 58e78595..88b93144 100644
+--- a/iwyu_preprocessor.cc
++++ b/iwyu_preprocessor.cc
+@@ -313,7 +313,7 @@ void IwyuPreprocessorInfo::ProcessHeadernameDirectivesInFile(
+ break;
+ }
+ const string filename = GetSourceTextUntilEndOfLine(current_loc,
+- DefaultDataGetter());
++ DefaultDataGetter()).str();
+ // Use "" or <> based on where the file lives.
+ string quoted_private_include;
+ if (IsSystemIncludeFile(GetFilePath(current_loc)))
+@@ -332,7 +332,7 @@ void IwyuPreprocessorInfo::ProcessHeadernameDirectivesInFile(
+ }
+
+ string after_text = GetSourceTextUntilEndOfLine(current_loc,
+- DefaultDataGetter());
++ DefaultDataGetter()).str();
+ const string::size_type close_brace_pos = after_text.find('}');
+ if (close_brace_pos == string::npos) {
+ Warn(current_loc, "@headername directive missing a closing brace");