Skip to content

Commit

Permalink
[analyzer][CrossTU][NFC] Generalize to external definitions instead o…
Browse files Browse the repository at this point in the history
…f external functions

Summary: This is just changing naming and documentation to be general about external definitions that can be imported for cross translation unit analysis. There is at least a plan to add VarDecls: D46421

Reviewers: NoQ, xazax.hun, martong, a.sidorin, george.karpenkov, serge-sans-paille

Reviewed By: xazax.hun, martong

Subscribers: mgorny, whisperity, baloghadamsoftware, szepet, rnkovacs, mikhail.ramalho, Szelethus, donat.nagy, dkrupp, cfe-commits

Differential Revision: https://reviews.llvm.org/D56441

llvm-svn: 350852
  • Loading branch information
Rafael Stahl committed Jan 10, 2019
1 parent b8819dc commit 8c48705
Show file tree
Hide file tree
Showing 24 changed files with 126 additions and 124 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticCrossTUKinds.td
Expand Up @@ -12,7 +12,7 @@ let Component = "CrossTU" in {
def err_ctu_error_opening : Error<
"error opening '%0': required by the CrossTU functionality">;

def err_fnmap_parsing : Error<
def err_extdefmap_parsing : Error<
"error parsing index file: '%0' line: %1 'UniqueID filename' format "
"expected">;

Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/CrossTU/CrossTranslationUnit.h
Expand Up @@ -90,11 +90,11 @@ std::string createCrossTUIndexString(const llvm::StringMap<std::string> &Index);
/// This class is used for tools that requires cross translation
/// unit capability.
///
/// This class can load function definitions from external AST files.
/// This class can load definitions from external AST files.
/// The loaded definition will be merged back to the original AST using the
/// AST Importer.
/// In order to use this class, an index file is required that describes
/// the locations of the AST files for each function definition.
/// the locations of the AST files for each definition.
///
/// Note that this class also implements caching.
class CrossTranslationUnitContext {
Expand Down
6 changes: 3 additions & 3 deletions clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
Expand Up @@ -275,7 +275,7 @@ ANALYZER_OPTION(
ANALYZER_OPTION(
bool, IsNaiveCTUEnabled, "experimental-enable-naive-ctu-analysis",
"Whether naive cross translation unit analysis is enabled. This is an "
"experimental feature to inline functions from another translation units.",
"experimental feature to inline functions from other translation units.",
false)

ANALYZER_OPTION(bool, ShouldDisplayMacroExpansions, "expand-macros",
Expand Down Expand Up @@ -344,8 +344,8 @@ ANALYZER_OPTION(StringRef, CTUDir, "ctu-dir",
"The directory containing the CTU related files.", "")

ANALYZER_OPTION(StringRef, CTUIndexName, "ctu-index-name",
"the name of the file containing the CTU index of functions.",
"externalFnMap.txt")
"the name of the file containing the CTU index of definitions.",
"externalDefMap.txt")

ANALYZER_OPTION(
StringRef, ModelPath, "model-path",
Expand Down
14 changes: 7 additions & 7 deletions clang/lib/CrossTU/CrossTranslationUnit.cpp
Expand Up @@ -120,26 +120,26 @@ std::error_code IndexError::convertToErrorCode() const {

llvm::Expected<llvm::StringMap<std::string>>
parseCrossTUIndex(StringRef IndexPath, StringRef CrossTUDir) {
std::ifstream ExternalFnMapFile(IndexPath);
if (!ExternalFnMapFile)
std::ifstream ExternalMapFile(IndexPath);
if (!ExternalMapFile)
return llvm::make_error<IndexError>(index_error_code::missing_index_file,
IndexPath.str());

llvm::StringMap<std::string> Result;
std::string Line;
unsigned LineNo = 1;
while (std::getline(ExternalFnMapFile, Line)) {
while (std::getline(ExternalMapFile, Line)) {
const size_t Pos = Line.find(" ");
if (Pos > 0 && Pos != std::string::npos) {
StringRef LineRef{Line};
StringRef FunctionLookupName = LineRef.substr(0, Pos);
if (Result.count(FunctionLookupName))
StringRef LookupName = LineRef.substr(0, Pos);
if (Result.count(LookupName))
return llvm::make_error<IndexError>(
index_error_code::multiple_definitions, IndexPath.str(), LineNo);
StringRef FileName = LineRef.substr(Pos + 1);
SmallString<256> FilePath = CrossTUDir;
llvm::sys::path::append(FilePath, FileName);
Result[FunctionLookupName] = FilePath.str().str();
Result[LookupName] = FilePath.str().str();
} else
return llvm::make_error<IndexError>(
index_error_code::invalid_index_format, IndexPath.str(), LineNo);
Expand Down Expand Up @@ -250,7 +250,7 @@ void CrossTranslationUnitContext::emitCrossTUDiagnostics(const IndexError &IE) {
<< IE.getFileName();
break;
case index_error_code::invalid_index_format:
Context.getDiagnostics().Report(diag::err_fnmap_parsing)
Context.getDiagnostics().Report(diag::err_extdefmap_parsing)
<< IE.getFileName() << IE.getLineNum();
break;
case index_error_code::multiple_definitions:
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/analyzer-config.c
Expand Up @@ -20,7 +20,7 @@
// CHECK-NEXT: cfg-temporary-dtors = true
// CHECK-NEXT: crosscheck-with-z3 = false
// CHECK-NEXT: ctu-dir = ""
// CHECK-NEXT: ctu-index-name = externalFnMap.txt
// CHECK-NEXT: ctu-index-name = externalDefMap.txt
// CHECK-NEXT: display-ctu-progress = false
// CHECK-NEXT: eagerly-assume = true
// CHECK-NEXT: elide-constructors = true
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/ctu-different-triples.cpp
Expand Up @@ -2,7 +2,7 @@
// RUN: mkdir -p %t/ctudir
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu \
// RUN: -emit-pch -o %t/ctudir/ctu-other.cpp.ast %S/Inputs/ctu-other.cpp
// RUN: cp %S/Inputs/ctu-other.cpp.externalFnMap.txt %t/ctudir/externalFnMap.txt
// RUN: cp %S/Inputs/ctu-other.cpp.externalDefMap.txt %t/ctudir/externalDefMap.txt
// RUN: %clang_analyze_cc1 -triple powerpc64-montavista-linux-gnu \
// RUN: -analyzer-checker=core,debug.ExprInspection \
// RUN: -analyzer-config experimental-enable-naive-ctu-analysis=true \
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/ctu-main.c
Expand Up @@ -2,7 +2,7 @@
// RUN: mkdir -p %t/ctudir2
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu \
// RUN: -emit-pch -o %t/ctudir2/ctu-other.c.ast %S/Inputs/ctu-other.c
// RUN: cp %S/Inputs/ctu-other.c.externalFnMap.txt %t/ctudir2/externalFnMap.txt
// RUN: cp %S/Inputs/ctu-other.c.externalDefMap.txt %t/ctudir2/externalDefMap.txt
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -std=c89 -analyze \
// RUN: -analyzer-checker=core,debug.ExprInspection \
// RUN: -analyzer-config experimental-enable-naive-ctu-analysis=true \
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/ctu-main.cpp
Expand Up @@ -4,7 +4,7 @@
// RUN: -emit-pch -o %t/ctudir/ctu-other.cpp.ast %S/Inputs/ctu-other.cpp
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu \
// RUN: -emit-pch -o %t/ctudir/ctu-chain.cpp.ast %S/Inputs/ctu-chain.cpp
// RUN: cp %S/Inputs/ctu-other.cpp.externalFnMap.txt %t/ctudir/externalFnMap.txt
// RUN: cp %S/Inputs/ctu-other.cpp.externalDefMap.txt %t/ctudir/externalDefMap.txt
// RUN: %clang_analyze_cc1 -triple x86_64-pc-linux-gnu \
// RUN: -analyzer-checker=core,debug.ExprInspection \
// RUN: -analyzer-config experimental-enable-naive-ctu-analysis=true \
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/ctu-unknown-parts-in-triples.cpp
Expand Up @@ -5,7 +5,7 @@
// RUN: mkdir -p %t/ctudir
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu \
// RUN: -emit-pch -o %t/ctudir/ctu-other.cpp.ast %S/Inputs/ctu-other.cpp
// RUN: cp %S/Inputs/ctu-other.cpp.externalFnMap.txt %t/ctudir/externalFnMap.txt
// RUN: cp %S/Inputs/ctu-other.cpp.externalDefMap.txt %t/ctudir/externalDefMap.txt
// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux-gnu \
// RUN: -analyzer-checker=core,debug.ExprInspection \
// RUN: -analyzer-config experimental-enable-naive-ctu-analysis=true \
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/func-mapping-test.cpp
@@ -1,4 +1,4 @@
// RUN: %clang_func_map %s -- | FileCheck %s
// RUN: %clang_extdef_map %s -- | FileCheck %s

int f(int) {
return 0;
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CMakeLists.txt
Expand Up @@ -61,7 +61,7 @@ list(APPEND CLANG_TEST_DEPS
if(CLANG_ENABLE_STATIC_ANALYZER)
list(APPEND CLANG_TEST_DEPS
clang-check
clang-func-mapping
clang-extdef-mapping
)
endif()

Expand Down
4 changes: 2 additions & 2 deletions clang/test/lit.cfg.py
Expand Up @@ -63,8 +63,8 @@
tools = [
'c-index-test', 'clang-check', 'clang-diff', 'clang-format', 'clang-tblgen',
'opt',
ToolSubst('%clang_func_map', command=FindTool(
'clang-func-mapping'), unresolved='ignore'),
ToolSubst('%clang_extdef_map', command=FindTool(
'clang-extdef-mapping'), unresolved='ignore'),
]

if config.clang_examples:
Expand Down
2 changes: 1 addition & 1 deletion clang/tools/CMakeLists.txt
Expand Up @@ -21,7 +21,7 @@ endif()

if(CLANG_ENABLE_STATIC_ANALYZER)
add_clang_subdirectory(clang-check)
add_clang_subdirectory(clang-func-mapping)
add_clang_subdirectory(clang-extdef-mapping)
add_clang_subdirectory(scan-build)
add_clang_subdirectory(scan-view)
endif()
Expand Down
Expand Up @@ -3,11 +3,11 @@ set(LLVM_LINK_COMPONENTS
support
)

add_clang_executable(clang-func-mapping
ClangFnMapGen.cpp
add_clang_executable(clang-extdef-mapping
ClangExtDefMapGen.cpp
)

target_link_libraries(clang-func-mapping
target_link_libraries(clang-extdef-mapping
PRIVATE
clangAST
clangBasic
Expand All @@ -17,5 +17,5 @@ target_link_libraries(clang-func-mapping
clangTooling
)

install(TARGETS clang-func-mapping
install(TARGETS clang-extdef-mapping
RUNTIME DESTINATION bin)
Expand Up @@ -30,14 +30,14 @@ using namespace clang;
using namespace clang::cross_tu;
using namespace clang::tooling;

static cl::OptionCategory ClangFnMapGenCategory("clang-fnmapgen options");
static cl::OptionCategory ClangExtDefMapGenCategory("clang-extdefmapgen options");

class MapFunctionNamesConsumer : public ASTConsumer {
class MapExtDefNamesConsumer : public ASTConsumer {
public:
MapFunctionNamesConsumer(ASTContext &Context)
MapExtDefNamesConsumer(ASTContext &Context)
: SM(Context.getSourceManager()) {}

~MapFunctionNamesConsumer() {
~MapExtDefNamesConsumer() {
// Flush results to standard output.
llvm::outs() << createCrossTUIndexString(Index);
}
Expand All @@ -54,7 +54,7 @@ class MapFunctionNamesConsumer : public ASTConsumer {
std::string CurrentFileName;
};

void MapFunctionNamesConsumer::handleDecl(const Decl *D) {
void MapExtDefNamesConsumer::handleDecl(const Decl *D) {
if (!D)
return;

Expand Down Expand Up @@ -90,11 +90,11 @@ void MapFunctionNamesConsumer::handleDecl(const Decl *D) {
handleDecl(D);
}

class MapFunctionNamesAction : public ASTFrontendAction {
class MapExtDefNamesAction : public ASTFrontendAction {
protected:
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
llvm::StringRef) {
return llvm::make_unique<MapFunctionNamesConsumer>(CI.getASTContext());
return llvm::make_unique<MapExtDefNamesConsumer>(CI.getASTContext());
}
};

Expand All @@ -106,13 +106,13 @@ int main(int argc, const char **argv) {
PrettyStackTraceProgram X(argc, argv);

const char *Overview = "\nThis tool collects the USR name and location "
"of all functions definitions in the source files "
"of external definitions in the source files "
"(excluding headers).\n";
CommonOptionsParser OptionsParser(argc, argv, ClangFnMapGenCategory,
CommonOptionsParser OptionsParser(argc, argv, ClangExtDefMapGenCategory,
cl::ZeroOrMore, Overview);

ClangTool Tool(OptionsParser.getCompilations(),
OptionsParser.getSourcePathList());

return Tool.run(newFrontendActionFactory<MapFunctionNamesAction>().get());
return Tool.run(newFrontendActionFactory<MapExtDefNamesAction>().get());
}
2 changes: 1 addition & 1 deletion clang/tools/scan-build-py/README.md
Expand Up @@ -53,7 +53,7 @@ with CTU analysis enabled, execute:

$ analyze-build --ctu

For CTU analysis an additional (function-definition) collection-phase is required.
For CTU analysis an additional (external definition) collection-phase is required.
For debugging purposes, it is possible to separately execute the collection
and the analysis phase. By doing this, the intermediate files used for
the analysis are kept on the disk in `./ctu-dir`.
Expand Down
2 changes: 1 addition & 1 deletion clang/tools/scan-build-py/libscanbuild/__init__.py
Expand Up @@ -20,7 +20,7 @@
Execution = collections.namedtuple('Execution', ['pid', 'cwd', 'cmd'])

CtuConfig = collections.namedtuple('CtuConfig', ['collect', 'analyze', 'dir',
'func_map_cmd'])
'extdef_map_cmd'])


def duplicate_check(method):
Expand Down

0 comments on commit 8c48705

Please sign in to comment.