Fixes shared libs build after D67422.
Differential Revision: https://reviews.llvm.org/D92432
--- /dev/null
+//===- CrossTUAnalysisHelper.h - Abstraction layer for CTU ------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_CLANG_ANALYSIS_CROSS_TU_HELPER_H
+#define LLVM_CLANG_ANALYSIS_CROSS_TU_HELPER_H
+
+#include "llvm/ADT/Optional.h"
+#include "clang/Basic/SourceManager.h"
+
+namespace clang {
+
+class ASTUnit;
+
+/// This class is an abstract interface acting as a bridge between
+/// an analysis that requires lookups across translation units (a user
+/// of that interface) and the facility that implements such lookups
+/// (an implementation of that interface). This is useful to break direct
+/// link-time dependencies between the (possibly shared) libraries in which
+/// the user and the implementation live.
+class CrossTUAnalysisHelper {
+public:
+ /// Determine the original source location in the original TU for an
+ /// imported source location.
+ /// \p ToLoc Source location in the imported-to AST.
+ /// \return Source location in the imported-from AST and the corresponding
+ /// ASTUnit object (the AST was loaded from a file using an internal ASTUnit
+ /// object that is returned here).
+ /// If any error happens (ToLoc is a non-imported source location) empty is
+ /// returned.
+ virtual llvm::Optional<std::pair<SourceLocation /*FromLoc*/, ASTUnit *>>
+ getImportedFromSourceLocation(SourceLocation ToLoc) const = 0;
+
+ virtual ~CrossTUAnalysisHelper() {}
+};
+} // namespace clang
+
+#endif // LLVM_CLANG_ANALYSIS_CROSS_TU_HELPER_H
class AnalyzerOptions;
class Preprocessor;
-namespace cross_tu {
-class CrossTranslationUnitContext;
-}
+class CrossTUAnalysisHelper;
namespace ento {
#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN) \
void CREATEFN(PathDiagnosticConsumerOptions Diagopts, \
PathDiagnosticConsumers &C, const std::string &Prefix, \
- const Preprocessor &PP, \
- const cross_tu::CrossTranslationUnitContext &CTU);
+ const Preprocessor &PP, const CrossTUAnalysisHelper &CTU);
#include "clang/Analysis/PathDiagnosticConsumers.def"
} // end 'ento' namespace
#ifndef LLVM_CLANG_CROSSTU_CROSSTRANSLATIONUNIT_H
#define LLVM_CLANG_CROSSTU_CROSSTRANSLATIONUNIT_H
+#include "clang/Analysis/CrossTUAnalysisHelper.h"
#include "clang/AST/ASTImporterSharedState.h"
#include "clang/Basic/LLVM.h"
#include "llvm/ADT/DenseMap.h"
/// the locations of the AST files for each definition.
///
/// Note that this class also implements caching.
-class CrossTranslationUnitContext {
+class CrossTranslationUnitContext : public CrossTUAnalysisHelper {
public:
CrossTranslationUnitContext(CompilerInstance &CI);
- ~CrossTranslationUnitContext();
+ ~CrossTranslationUnitContext() override;
/// This function loads a function or variable definition from an
/// external AST file and merges it into the original AST.
/// If any error happens (ToLoc is a non-imported source location) empty is
/// returned.
llvm::Optional<std::pair<SourceLocation /*FromLoc*/, ASTUnit *>>
- getImportedFromSourceLocation(const clang::SourceLocation &ToLoc) const;
+ getImportedFromSourceLocation(SourceLocation ToLoc) const override;
private:
using ImportedFileIDMap =
using namespace clang;
using namespace ento;
+namespace clang {
+class CrossTUAnalysisHelper;
+}
+
//===----------------------------------------------------------------------===//
// Boilerplate.
//===----------------------------------------------------------------------===//
void ento::createHTMLDiagnosticConsumer(
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
const std::string &OutputDir, const Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU) {
+ const CrossTUAnalysisHelper &CTU) {
// FIXME: HTML is currently our default output type, but if the output
// directory isn't specified, it acts like if it was in the minimal text
void ento::createHTMLSingleFileDiagnosticConsumer(
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
const std::string &OutputDir, const Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU) {
+ const CrossTUAnalysisHelper &CTU) {
createTextMinimalPathDiagnosticConsumer(DiagOpts, C, OutputDir, PP, CTU);
// TODO: Emit an error here.
using namespace clang;
using namespace ento;
+namespace clang {
+class CrossTUAnalysisHelper;
+}
+
void ento::createPlistHTMLDiagnosticConsumer(
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
const std::string &Prefix, const Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU) {
+ const CrossTUAnalysisHelper &CTU) {
createHTMLDiagnosticConsumer(
DiagOpts, C, std::string(llvm::sys::path::parent_path(Prefix)), PP, CTU);
createPlistMultiFileDiagnosticConsumer(DiagOpts, C, Prefix, PP, CTU);
//
//===----------------------------------------------------------------------===//
+#include "clang/Analysis/CrossTUAnalysisHelper.h"
#include "clang/Analysis/IssueHash.h"
#include "clang/Analysis/PathDiagnostic.h"
#include "clang/Analysis/PathDiagnosticConsumers.h"
#include "clang/Basic/PlistSupport.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/Version.h"
-#include "clang/CrossTU/CrossTranslationUnit.h"
#include "clang/Frontend/ASTUnit.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/TokenConcatenation.h"
PathDiagnosticConsumerOptions DiagOpts;
const std::string OutputFile;
const Preprocessor &PP;
- const cross_tu::CrossTranslationUnitContext &CTU;
+ const CrossTUAnalysisHelper &CTU;
const bool SupportsCrossFileDiagnostics;
void printBugPath(llvm::raw_ostream &o, const FIDMap &FM,
public:
PlistPathDiagnosticConsumer(PathDiagnosticConsumerOptions DiagOpts,
const std::string &OutputFile, const Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU,
+ const CrossTUAnalysisHelper &CTU,
bool supportsMultipleFiles);
~PlistPathDiagnosticConsumer() override {}
class PlistPrinter {
const FIDMap& FM;
const Preprocessor &PP;
- const cross_tu::CrossTranslationUnitContext &CTU;
+ const CrossTUAnalysisHelper &CTU;
llvm::SmallVector<const PathDiagnosticMacroPiece *, 0> MacroPieces;
public:
PlistPrinter(const FIDMap& FM,
const Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU)
+ const CrossTUAnalysisHelper &CTU)
: FM(FM), PP(PP), CTU(CTU) {
}
static ExpansionInfo
getExpandedMacro(SourceLocation MacroLoc, const Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU);
+ const CrossTUAnalysisHelper &CTU);
//===----------------------------------------------------------------------===//
// Methods of PlistPrinter.
PlistPathDiagnosticConsumer::PlistPathDiagnosticConsumer(
PathDiagnosticConsumerOptions DiagOpts, const std::string &output,
- const Preprocessor &PP, const cross_tu::CrossTranslationUnitContext &CTU,
+ const Preprocessor &PP, const CrossTUAnalysisHelper &CTU,
bool supportsMultipleFiles)
: DiagOpts(std::move(DiagOpts)), OutputFile(output), PP(PP), CTU(CTU),
SupportsCrossFileDiagnostics(supportsMultipleFiles) {
void ento::createPlistDiagnosticConsumer(
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
const std::string &OutputFile, const Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU) {
+ const CrossTUAnalysisHelper &CTU) {
// TODO: Emit an error here.
if (OutputFile.empty())
void ento::createPlistMultiFileDiagnosticConsumer(
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
const std::string &OutputFile, const Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU) {
+ const CrossTUAnalysisHelper &CTU) {
// TODO: Emit an error here.
if (OutputFile.empty())
static ExpansionInfo
getExpandedMacro(SourceLocation MacroLoc, const Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU) {
+ const CrossTUAnalysisHelper &CTU) {
const Preprocessor *PPToUse = &PP;
if (auto LocAndUnit = CTU.getImportedFromSourceLocation(MacroLoc)) {
using namespace clang;
using namespace ento;
+namespace clang {
+class CrossTUAnalysisHelper;
+}
+
namespace {
class SarifPathDiagnosticConsumer : public PathDiagnosticConsumer {
std::string OutputFile;
void ento::createSarifDiagnosticConsumer(
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
const std::string &Output, const Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU) {
+ const CrossTUAnalysisHelper &CTU) {
// TODO: Emit an error here.
if (Output.empty())
#include "clang/Analysis/PathDiagnosticConsumers.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/Version.h"
-#include "clang/CrossTU/CrossTranslationUnit.h"
#include "clang/Frontend/ASTUnit.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Rewrite/Core/Rewriter.h"
using namespace ento;
using namespace tooling;
+namespace clang {
+class CrossTUAnalysisHelper;
+}
+
namespace {
-/// Emitsd minimal diagnostics (report message + notes) for the 'none' output
+/// Emits minimal diagnostics (report message + notes) for the 'none' output
/// type to the standard error, or to to compliment many others. Emits detailed
/// diagnostics in textual format for the 'text' output type.
class TextPathDiagnosticConsumer : public PathDiagnosticConsumer {
void ento::createTextPathDiagnosticConsumer(
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
const std::string &Prefix, const clang::Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU) {
+ const CrossTUAnalysisHelper &CTU) {
C.emplace_back(new TextPathDiagnosticConsumer(
std::move(DiagOpts), PP.getDiagnostics(), PP.getLangOpts(),
/*ShouldDisplayPathNotes=*/true));
void ento::createTextMinimalPathDiagnosticConsumer(
PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
const std::string &Prefix, const clang::Preprocessor &PP,
- const cross_tu::CrossTranslationUnitContext &CTU) {
+ const CrossTUAnalysisHelper &CTU) {
C.emplace_back(new TextPathDiagnosticConsumer(
std::move(DiagOpts), PP.getDiagnostics(), PP.getLangOpts(),
/*ShouldDisplayPathNotes=*/false));
llvm::Optional<std::pair<SourceLocation, ASTUnit *>>
CrossTranslationUnitContext::getImportedFromSourceLocation(
- const clang::SourceLocation &ToLoc) const {
+ SourceLocation ToLoc) const {
const SourceManager &SM = Context.getSourceManager();
auto DecToLoc = SM.getDecomposedLoc(ToLoc);