]> granicus.if.org Git - clang/commitdiff
[analyzer][CrossTU][NFC] Generalize to external definitions instead of external functions
authorRafael Stahl <r.stahl@tum.de>
Thu, 10 Jan 2019 17:44:04 +0000 (17:44 +0000)
committerRafael Stahl <r.stahl@tum.de>
Thu, 10 Jan 2019 17:44:04 +0000 (17:44 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@350852 91177308-0d34-0410-b5e6-96231b3b80d8

24 files changed:
include/clang/Basic/DiagnosticCrossTUKinds.td
include/clang/CrossTU/CrossTranslationUnit.h
include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
lib/CrossTU/CrossTranslationUnit.cpp
test/Analysis/Inputs/ctu-other.c.externalDefMap.txt [moved from test/Analysis/Inputs/ctu-other.c.externalFnMap.txt with 100% similarity]
test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt [moved from test/Analysis/Inputs/ctu-other.cpp.externalFnMap.txt with 100% similarity]
test/Analysis/analyzer-config.c
test/Analysis/ctu-different-triples.cpp
test/Analysis/ctu-main.c
test/Analysis/ctu-main.cpp
test/Analysis/ctu-unknown-parts-in-triples.cpp
test/Analysis/func-mapping-test.cpp
test/CMakeLists.txt
test/lit.cfg.py
tools/CMakeLists.txt
tools/clang-extdef-mapping/CMakeLists.txt [moved from tools/clang-func-mapping/CMakeLists.txt with 58% similarity]
tools/clang-extdef-mapping/ClangExtDefMapGen.cpp [moved from tools/clang-func-mapping/ClangFnMapGen.cpp with 83% similarity]
tools/scan-build-py/README.md
tools/scan-build-py/libscanbuild/__init__.py
tools/scan-build-py/libscanbuild/analyze.py
tools/scan-build-py/libscanbuild/arguments.py
tools/scan-build-py/libscanbuild/clang.py
tools/scan-build-py/tests/unit/test_analyze.py
tools/scan-build-py/tests/unit/test_clang.py

index 9c432457df83e3b8bcfea1bfcb53069234e487b5..89e261c84bc62c4070a5d14eb72b736c3195ea7c 100644 (file)
@@ -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">;
 
index 9b36fe653b2e24914c02d09798672e81fe005a8d..52e3ae27490f68f68023d58a8398cdd1b5321c39 100644 (file)
@@ -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 {
index 8e5d8d3ad37781d6bf3cfc0c5c5c2509de3437a6..3cd54df7b179901c9b51970410824fa59d5ab3f4 100644 (file)
@@ -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",
@@ -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",
index 915b5246c9e0b7b1f24d006d1b9947ebc9774273..7c97beb498a57dbad1a7a6b3aa7aca33aaf5bbd2 100644 (file)
@@ -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);
@@ -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:
index ed13a85b59fab66b3c5d508291b09fba2ce2a3fb..50b5c2dcf65f30c58ea493f1849b460887983ba9 100644 (file)
@@ -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
index 314bada0c20dd7f206bbcfa0305b747692ec002d..dbfa82fb483d90111b81851db25b8df47fb0c1b5 100644 (file)
@@ -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 \
index 239d51ab4935f1d3f18357c8e200847814a5a77a..114d694020a1ff8a9b5b2671e20889c1e8801aac 100644 (file)
@@ -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 \
index 44c0c07603d7c231e735d3cb33082b34f09ad21f..35d1f52ad0446fd7a7c27a8d12705858a54f47d9 100644 (file)
@@ -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 \
index a632cfbb32e884115a999032ef7a99d7ff278d1f..5e643c164dd7dbca3fb280c8f141fe0b059dfb3f 100644 (file)
@@ -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 \
index 37e653882b7bf912b0755f3bb7219bf152cad077..a5d7cfb449c75edd008f95126404036a428ff778 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_func_map %s -- | FileCheck %s
+// RUN: %clang_extdef_map %s -- | FileCheck %s
 
 int f(int) {
   return 0;
index 2836aefada98165fb2e1c10579d9e96418ab0edf..7d9dc429a41b034e7b881128b7bb91b0df0e6818 100644 (file)
@@ -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()
 
index e61b4bb104840e99951a127e53ccc71c1f9cea7a..ace0b81081d36cdfc52ee2626279749b57af321c 100644 (file)
@@ -63,8 +63,8 @@ tool_dirs = [config.clang_tools_dir, config.llvm_tools_dir]
 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:
index 9f76d36dba0e34eff062a58b0c51fa8ce630e29b..43dfffe1492e7c83896df18f1f902b78c9ae9708 100644 (file)
@@ -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()
similarity index 58%
rename from tools/clang-func-mapping/CMakeLists.txt
rename to tools/clang-extdef-mapping/CMakeLists.txt
index 3544009a45d8bf620f16ca77abfdaf61d527bb0c..6c81689a831adb5b25578c2c435621faea0749e1 100644 (file)
@@ -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
@@ -17,5 +17,5 @@ target_link_libraries(clang-func-mapping
   clangTooling
   )
 
-install(TARGETS clang-func-mapping
+install(TARGETS clang-extdef-mapping
   RUNTIME DESTINATION bin)
similarity index 83%
rename from tools/clang-func-mapping/ClangFnMapGen.cpp
rename to tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
index 635bb0296c5c5a120e1027e8680525be65adba7e..7885f3901897c68c78eb3dbb2c5373bd1ee0e716 100644 (file)
@@ -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);
   }
@@ -54,7 +54,7 @@ private:
   std::string CurrentFileName;
 };
 
-void MapFunctionNamesConsumer::handleDecl(const Decl *D) {
+void MapExtDefNamesConsumer::handleDecl(const Decl *D) {
   if (!D)
     return;
 
@@ -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());
   }
 };
 
@@ -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());
 }
index 720bde1cf3b1500c67baff4795700ad973ad8437..01e3454bed4445355a5404ac7cd1d905e55c7493 100644 (file)
@@ -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`.
index e7b74879167e501dd77539ba5d1cdff6cc2a8bf1..903207c6be090ffed0a6814aade9c39ee5b6c34d 100644 (file)
@@ -20,7 +20,7 @@ ENVIRONMENT_KEY = 'INTERCEPT_BUILD'
 Execution = collections.namedtuple('Execution', ['pid', 'cwd', 'cmd'])
 
 CtuConfig = collections.namedtuple('CtuConfig', ['collect', 'analyze', 'dir',
-                                                 'func_map_cmd'])
+                                                 'extdef_map_cmd'])
 
 
 def duplicate_check(method):
index ec2ffbb275b918572321f92e7cfb53a267c0aad8..ab8ea62f46fe89a867517787ea93aca3b4794a4f 100644 (file)
@@ -42,8 +42,8 @@ __all__ = ['scan_build', 'analyze_build', 'analyze_compiler_wrapper']
 COMPILER_WRAPPER_CC = 'analyze-cc'
 COMPILER_WRAPPER_CXX = 'analyze-c++'
 
-CTU_FUNCTION_MAP_FILENAME = 'externalFnMap.txt'
-CTU_TEMP_FNMAP_FOLDER = 'tmpExternalFnMaps'
+CTU_EXTDEF_MAP_FILENAME = 'externalDefMap.txt'
+CTU_TEMP_DEFMAP_FOLDER = 'tmpExternalDefMaps'
 
 
 @command_entry_point
@@ -117,9 +117,9 @@ def get_ctu_config_from_args(args):
         CtuConfig(collect=args.ctu_phases.collect,
                   analyze=args.ctu_phases.analyze,
                   dir=args.ctu_dir,
-                  func_map_cmd=args.func_map_cmd)
+                  extdef_map_cmd=args.extdef_map_cmd)
         if hasattr(args, 'ctu_phases') and hasattr(args.ctu_phases, 'dir')
-        else CtuConfig(collect=False, analyze=False, dir='', func_map_cmd=''))
+        else CtuConfig(collect=False, analyze=False, dir='', extdef_map_cmd=''))
 
 
 def get_ctu_config_from_json(ctu_conf_json):
@@ -130,23 +130,24 @@ def get_ctu_config_from_json(ctu_conf_json):
     return CtuConfig(collect=ctu_config[0],
                      analyze=ctu_config[1],
                      dir=ctu_config[2],
-                     func_map_cmd=ctu_config[3])
+                     extdef_map_cmd=ctu_config[3])
 
 
-def create_global_ctu_function_map(func_map_lines):
-    """ Takes iterator of individual function maps and creates a global map
-    keeping only unique names. We leave conflicting names out of CTU.
+def create_global_ctu_extdef_map(extdef_map_lines):
+    """ Takes iterator of individual external definition maps and creates a
+    global map keeping only unique names. We leave conflicting names out of
+    CTU.
 
-    :param func_map_lines: Contains the id of a function (mangled name) and
+    :param extdef_map_lines: Contains the id of a definition (mangled name) and
     the originating source (the corresponding AST file) name.
-    :type func_map_lines: Iterator of str.
+    :type extdef_map_lines: Iterator of str.
     :returns: Mangled name - AST file pairs.
     :rtype: List of (str, str) tuples.
     """
 
     mangled_to_asts = defaultdict(set)
 
-    for line in func_map_lines:
+    for line in extdef_map_lines:
         mangled_name, ast_file = line.strip().split(' ', 1)
         mangled_to_asts[mangled_name].add(ast_file)
 
@@ -159,20 +160,20 @@ def create_global_ctu_function_map(func_map_lines):
     return mangled_ast_pairs
 
 
-def merge_ctu_func_maps(ctudir):
-    """ Merge individual function maps into a global one.
+def merge_ctu_extdef_maps(ctudir):
+    """ Merge individual external definition maps into a global one.
 
     As the collect phase runs parallel on multiple threads, all compilation
-    units are separately mapped into a temporary file in CTU_TEMP_FNMAP_FOLDER.
-    These function maps contain the mangled names of functions and the source
-    (AST generated from the source) which had them.
+    units are separately mapped into a temporary file in CTU_TEMP_DEFMAP_FOLDER.
+    These definition maps contain the mangled names and the source
+    (AST generated from the source) which had their definition.
     These files should be merged at the end into a global map file:
-    CTU_FUNCTION_MAP_FILENAME."""
+    CTU_EXTDEF_MAP_FILENAME."""
 
-    def generate_func_map_lines(fnmap_dir):
+    def generate_extdef_map_lines(extdefmap_dir):
         """ Iterate over all lines of input files in a determined order. """
 
-        files = glob.glob(os.path.join(fnmap_dir, '*'))
+        files = glob.glob(os.path.join(extdefmap_dir, '*'))
         files.sort()
         for filename in files:
             with open(filename, 'r') as in_file:
@@ -180,11 +181,11 @@ def merge_ctu_func_maps(ctudir):
                     yield line
 
     def write_global_map(arch, mangled_ast_pairs):
-        """ Write (mangled function name, ast file) pairs into final file. """
+        """ Write (mangled name, ast file) pairs into final file. """
 
-        extern_fns_map_file = os.path.join(ctudir, arch,
-                                           CTU_FUNCTION_MAP_FILENAME)
-        with open(extern_fns_map_file, 'w') as out_file:
+        extern_defs_map_file = os.path.join(ctudir, arch,
+                                           CTU_EXTDEF_MAP_FILENAME)
+        with open(extern_defs_map_file, 'w') as out_file:
             for mangled_name, ast_file in mangled_ast_pairs:
                 out_file.write('%s %s\n' % (mangled_name, ast_file))
 
@@ -192,15 +193,15 @@ def merge_ctu_func_maps(ctudir):
     for triple_path in triple_arches:
         if os.path.isdir(triple_path):
             triple_arch = os.path.basename(triple_path)
-            fnmap_dir = os.path.join(ctudir, triple_arch,
-                                     CTU_TEMP_FNMAP_FOLDER)
+            extdefmap_dir = os.path.join(ctudir, triple_arch,
+                                     CTU_TEMP_DEFMAP_FOLDER)
 
-            func_map_lines = generate_func_map_lines(fnmap_dir)
-            mangled_ast_pairs = create_global_ctu_function_map(func_map_lines)
+            extdef_map_lines = generate_extdef_map_lines(extdefmap_dir)
+            mangled_ast_pairs = create_global_ctu_extdef_map(extdef_map_lines)
             write_global_map(triple_arch, mangled_ast_pairs)
 
             # Remove all temporary files
-            shutil.rmtree(fnmap_dir, ignore_errors=True)
+            shutil.rmtree(extdefmap_dir, ignore_errors=True)
 
 
 def run_analyzer_parallel(args):
@@ -251,21 +252,21 @@ def govern_analyzer_runs(args):
     # left so multiple analyze runs can use the same data gathered by a single
     # collection run.
     if ctu_config.collect and ctu_config.analyze:
-        # CTU strings are coming from args.ctu_dir and func_map_cmd,
+        # CTU strings are coming from args.ctu_dir and extdef_map_cmd,
         # so we can leave it empty
         args.ctu_phases = CtuConfig(collect=True, analyze=False,
-                                    dir='', func_map_cmd='')
+                                    dir='', extdef_map_cmd='')
         run_analyzer_parallel(args)
-        merge_ctu_func_maps(ctu_config.dir)
+        merge_ctu_extdef_maps(ctu_config.dir)
         args.ctu_phases = CtuConfig(collect=False, analyze=True,
-                                    dir='', func_map_cmd='')
+                                    dir='', extdef_map_cmd='')
         run_analyzer_parallel(args)
         shutil.rmtree(ctu_config.dir, ignore_errors=True)
     else:
         # Single runs (collect or analyze) are launched from here.
         run_analyzer_parallel(args)
         if ctu_config.collect:
-            merge_ctu_func_maps(ctu_config.dir)
+            merge_ctu_extdef_maps(ctu_config.dir)
 
 
 def setup_environment(args):
@@ -544,20 +545,20 @@ def run_analyzer(opts, continuation=report_failure):
         return result
 
 
-def func_map_list_src_to_ast(func_src_list):
-    """ Turns textual function map list with source files into a
-    function map list with ast files. """
+def extdef_map_list_src_to_ast(extdef_src_list):
+    """ Turns textual external definition map list with source files into an
+    external definition map list with ast files. """
 
-    func_ast_list = []
-    for fn_src_txt in func_src_list:
-        mangled_name, path = fn_src_txt.split(" ", 1)
+    extdef_ast_list = []
+    for extdef_src_txt in extdef_src_list:
+        mangled_name, path = extdef_src_txt.split(" ", 1)
         # Normalize path on windows as well
         path = os.path.splitdrive(path)[1]
         # Make relative path out of absolute
         path = path[1:] if path[0] == os.sep else path
         ast_path = os.path.join("ast", path + ".ast")
-        func_ast_list.append(mangled_name + " " + ast_path)
-    return func_ast_list
+        extdef_ast_list.append(mangled_name + " " + ast_path)
+    return extdef_ast_list
 
 
 @require(['clang', 'directory', 'flags', 'direct_args', 'file', 'ctu'])
@@ -588,37 +589,38 @@ def ctu_collect_phase(opts):
         logging.debug("Generating AST using '%s'", ast_command)
         run_command(ast_command, cwd=opts['directory'])
 
-    def map_functions(triple_arch):
-        """ Generate function map file for the current source. """
+    def map_extdefs(triple_arch):
+        """ Generate external definition map file for the current source. """
 
         args = opts['direct_args'] + opts['flags']
-        funcmap_command = [opts['ctu'].func_map_cmd]
-        funcmap_command.append(opts['file'])
-        funcmap_command.append('--')
-        funcmap_command.extend(args)
-        logging.debug("Generating function map using '%s'", funcmap_command)
-        func_src_list = run_command(funcmap_command, cwd=opts['directory'])
-        func_ast_list = func_map_list_src_to_ast(func_src_list)
-        extern_fns_map_folder = os.path.join(opts['ctu'].dir, triple_arch,
-                                             CTU_TEMP_FNMAP_FOLDER)
-        if not os.path.isdir(extern_fns_map_folder):
+        extdefmap_command = [opts['ctu'].extdef_map_cmd]
+        extdefmap_command.append(opts['file'])
+        extdefmap_command.append('--')
+        extdefmap_command.extend(args)
+        logging.debug("Generating external definition map using '%s'",
+                      extdefmap_command)
+        extdef_src_list = run_command(extdefmap_command, cwd=opts['directory'])
+        extdef_ast_list = extdef_map_list_src_to_ast(extdef_src_list)
+        extern_defs_map_folder = os.path.join(opts['ctu'].dir, triple_arch,
+                                             CTU_TEMP_DEFMAP_FOLDER)
+        if not os.path.isdir(extern_defs_map_folder):
             try:
-                os.makedirs(extern_fns_map_folder)
+                os.makedirs(extern_defs_map_folder)
             except OSError:
                 # In case an other process already created it.
                 pass
-        if func_ast_list:
+        if extdef_ast_list:
             with tempfile.NamedTemporaryFile(mode='w',
-                                             dir=extern_fns_map_folder,
+                                             dir=extern_defs_map_folder,
                                              delete=False) as out_file:
-                out_file.write("\n".join(func_ast_list) + "\n")
+                out_file.write("\n".join(extdef_ast_list) + "\n")
 
     cwd = opts['directory']
     cmd = [opts['clang'], '--analyze'] + opts['direct_args'] + opts['flags'] \
         + [opts['file']]
     triple_arch = get_triple_arch(cmd, cwd)
     generate_ast(triple_arch)
-    map_functions(triple_arch)
+    map_extdefs(triple_arch)
 
 
 @require(['ctu'])
index eb8ea0d9fffd09f0d40dde7cecd89e5764d33595..58c56d2b6d290f6b4a710159176d0e66619e4b54 100644 (file)
@@ -135,10 +135,10 @@ def validate_args_for_analyze(parser, args, from_build_command):
         if args.ctu_phases.analyze and not args.ctu_phases.collect \
                 and not os.path.exists(args.ctu_dir):
             parser.error(message='missing CTU directory')
-        # Check CTU capability via checking clang-func-mapping
-        if not is_ctu_capable(args.func_map_cmd):
+        # Check CTU capability via checking clang-extdef-mapping
+        if not is_ctu_capable(args.extdef_map_cmd):
             parser.error(message="""This version of clang does not support CTU
-            functionality or clang-func-mapping command not found.""")
+            functionality or clang-extdef-mapping command not found.""")
 
 
 def create_intercept_parser():
@@ -366,7 +366,7 @@ def create_analyze_parser(from_build_command):
             '--ctu',
             action='store_const',
             const=CtuConfig(collect=True, analyze=True,
-                            dir='', func_map_cmd=''),
+                            dir='', extdef_map_cmd=''),
             dest='ctu_phases',
             help="""Perform cross translation unit (ctu) analysis (both collect
             and analyze phases) using default <ctu-dir> for temporary output.
@@ -382,7 +382,7 @@ def create_analyze_parser(from_build_command):
             '--ctu-collect-only',
             action='store_const',
             const=CtuConfig(collect=True, analyze=False,
-                            dir='', func_map_cmd=''),
+                            dir='', extdef_map_cmd=''),
             dest='ctu_phases',
             help="""Perform only the collect phase of ctu.
             Keep <ctu-dir> for further use.""")
@@ -390,20 +390,20 @@ def create_analyze_parser(from_build_command):
             '--ctu-analyze-only',
             action='store_const',
             const=CtuConfig(collect=False, analyze=True,
-                            dir='', func_map_cmd=''),
+                            dir='', extdef_map_cmd=''),
             dest='ctu_phases',
             help="""Perform only the analyze phase of ctu. <ctu-dir> should be
             present and will not be removed after analysis.""")
         ctu.add_argument(
-            '--use-func-map-cmd',
+            '--use-extdef-map-cmd',
             metavar='<path>',
-            dest='func_map_cmd',
-            default='clang-func-mapping',
-            help="""'%(prog)s' uses the 'clang-func-mapping' executable
-            relative to itself for generating function maps for static
-            analysis. One can override this behavior with this option by using
-            the 'clang-func-mapping' packaged with Xcode (on OS X) or from the
-            PATH.""")
+            dest='extdef_map_cmd',
+            default='clang-extdef-mapping',
+            help="""'%(prog)s' uses the 'clang-extdef-mapping' executable
+            relative to itself for generating external definition maps for
+            static analysis. One can override this behavior with this option
+            by using the 'clang-extdef-mapping' packaged with Xcode (on OS X)
+            or from the PATH.""")
     return parser
 
 
index ab422066cab128f5fc0ac57c913d058b4f3bb2c9..0cbfdb648f6a956c5035e2030bdf635827f678fd 100644 (file)
@@ -156,12 +156,12 @@ def get_checkers(clang, plugins):
     return checkers
 
 
-def is_ctu_capable(func_map_cmd):
-    """ Detects if the current (or given) clang and function mapping
+def is_ctu_capable(extdef_map_cmd):
+    """ Detects if the current (or given) clang and external definition mapping
     executables are CTU compatible. """
 
     try:
-        run_command([func_map_cmd, '-version'])
+        run_command([extdef_map_cmd, '-version'])
     except (OSError, subprocess.CalledProcessError):
         return False
     return True
index 9964a296b8ddfbd01c8a4b82564cd41bd1ad0016..768a3b691090622b7ba00980895ad98d5f8e5f1b 100644 (file)
@@ -349,14 +349,14 @@ class PrefixWithTest(unittest.TestCase):
 class MergeCtuMapTest(unittest.TestCase):
 
     def test_no_map_gives_empty(self):
-        pairs = sut.create_global_ctu_function_map([])
+        pairs = sut.create_global_ctu_extdef_map([])
         self.assertFalse(pairs)
 
     def test_multiple_maps_merged(self):
         concat_map = ['c:@F@fun1#I# ast/fun1.c.ast',
                       'c:@F@fun2#I# ast/fun2.c.ast',
                       'c:@F@fun3#I# ast/fun3.c.ast']
-        pairs = sut.create_global_ctu_function_map(concat_map)
+        pairs = sut.create_global_ctu_extdef_map(concat_map)
         self.assertTrue(('c:@F@fun1#I#', 'ast/fun1.c.ast') in pairs)
         self.assertTrue(('c:@F@fun2#I#', 'ast/fun2.c.ast') in pairs)
         self.assertTrue(('c:@F@fun3#I#', 'ast/fun3.c.ast') in pairs)
@@ -366,7 +366,7 @@ class MergeCtuMapTest(unittest.TestCase):
         concat_map = ['c:@F@fun1#I# ast/fun1.c.ast',
                       'c:@F@fun2#I# ast/fun2.c.ast',
                       'c:@F@fun1#I# ast/fun7.c.ast']
-        pairs = sut.create_global_ctu_function_map(concat_map)
+        pairs = sut.create_global_ctu_extdef_map(concat_map)
         self.assertFalse(('c:@F@fun1#I#', 'ast/fun1.c.ast') in pairs)
         self.assertFalse(('c:@F@fun1#I#', 'ast/fun7.c.ast') in pairs)
         self.assertTrue(('c:@F@fun2#I#', 'ast/fun2.c.ast') in pairs)
@@ -376,28 +376,28 @@ class MergeCtuMapTest(unittest.TestCase):
         concat_map = ['c:@F@fun1#I# ast/fun1.c.ast',
                       'c:@F@fun2#I# ast/fun2.c.ast',
                       'c:@F@fun1#I# ast/fun1.c.ast']
-        pairs = sut.create_global_ctu_function_map(concat_map)
+        pairs = sut.create_global_ctu_extdef_map(concat_map)
         self.assertTrue(('c:@F@fun1#I#', 'ast/fun1.c.ast') in pairs)
         self.assertTrue(('c:@F@fun2#I#', 'ast/fun2.c.ast') in pairs)
         self.assertEqual(2, len(pairs))
 
     def test_space_handled_in_source(self):
         concat_map = ['c:@F@fun1#I# ast/f un.c.ast']
-        pairs = sut.create_global_ctu_function_map(concat_map)
+        pairs = sut.create_global_ctu_extdef_map(concat_map)
         self.assertTrue(('c:@F@fun1#I#', 'ast/f un.c.ast') in pairs)
         self.assertEqual(1, len(pairs))
 
 
-class FuncMapSrcToAstTest(unittest.TestCase):
+class ExtdefMapSrcToAstTest(unittest.TestCase):
 
     def test_empty_gives_empty(self):
-        fun_ast_lst = sut.func_map_list_src_to_ast([])
+        fun_ast_lst = sut.extdef_map_list_src_to_ast([])
         self.assertFalse(fun_ast_lst)
 
     def test_sources_to_asts(self):
         fun_src_lst = ['c:@F@f1#I# ' + os.path.join(os.sep + 'path', 'f1.c'),
                        'c:@F@f2#I# ' + os.path.join(os.sep + 'path', 'f2.c')]
-        fun_ast_lst = sut.func_map_list_src_to_ast(fun_src_lst)
+        fun_ast_lst = sut.extdef_map_list_src_to_ast(fun_src_lst)
         self.assertTrue('c:@F@f1#I# ' +
                         os.path.join('ast', 'path', 'f1.c.ast')
                         in fun_ast_lst)
@@ -408,7 +408,7 @@ class FuncMapSrcToAstTest(unittest.TestCase):
 
     def test_spaces_handled(self):
         fun_src_lst = ['c:@F@f1#I# ' + os.path.join(os.sep + 'path', 'f 1.c')]
-        fun_ast_lst = sut.func_map_list_src_to_ast(fun_src_lst)
+        fun_ast_lst = sut.extdef_map_list_src_to_ast(fun_src_lst)
         self.assertTrue('c:@F@f1#I# ' +
                         os.path.join('ast', 'path', 'f 1.c.ast')
                         in fun_ast_lst)
index 07ac4d9fb80663879ff3cd2b6470afd8693e5e2f..7d625c6c5bc493db08d4732e5cc2e24bdd99ebe9 100644 (file)
@@ -96,7 +96,7 @@ class ClangGetCheckersTest(unittest.TestCase):
 
 class ClangIsCtuCapableTest(unittest.TestCase):
     def test_ctu_not_found(self):
-        is_ctu = sut.is_ctu_capable('not-found-clang-func-mapping')
+        is_ctu = sut.is_ctu_capable('not-found-clang-extdef-mapping')
         self.assertFalse(is_ctu)