[C++] Don't ignore header files passed in --changed-files-index

Summary:
Whenever header file is in changed-files-index, it should be captured and analyzed on demand.
It was already being captured, but ondemand analysis wasn't triggered for code in header file. This diff does it.
Use hacky header->source mapping to go from header to source (cluster) and then analyze everything in that cluster (inlucing code coming from header)

Reviewed By: jberdine

Differential Revision: D4265495

fbshipit-source-id: 61606f4
master
Andrzej Kotulski 8 years ago committed by Facebook Github Bot
parent bd0f0cc7fc
commit 0479720c91

@ -158,7 +158,14 @@ let changed_source_files_set =
Option.map_default read_file None Config.changed_files_index |>
Option.map (
IList.fold_left
(fun changed_files line -> SourceFileSet.add (create_source_file line) changed_files)
(fun changed_files line ->
let source_file = create_source_file line in
let changed_files' = SourceFileSet.add source_file changed_files in
(* Add source corresponding to changed header if it exists *)
match source_file_of_header source_file with
| Some src -> SourceFileSet.add src changed_files'
| None -> changed_files'
)
SourceFileSet.empty
)

@ -126,7 +126,9 @@ val source_file_is_under_project_root : source_file -> bool
file exists. returns None otherwise *)
val source_file_of_header : source_file -> source_file option
(** Set of files read from --changed-files-index file, None if option not specified *)
(** Set of files read from --changed-files-index file, None if option not specified
NOTE: it may include extra source_files if --changed-files-index contains paths to
header files *)
val changed_source_files_set : SourceFileSet.t option
(** {2 Source Dirs} *)

@ -25,13 +25,7 @@ let should_capture_file_from_index () =
Process.print_error_and_exit "Error reading the changed files index %s.\n%!" index
| None -> function _ -> true)
| Some files_set ->
function source_file ->
DB.SourceFileSet.mem source_file files_set ||
(* as fallback try to capture corresponding source file for headers *)
Option.map_default
(fun src -> DB.SourceFileSet.mem src files_set)
false
(DB.source_file_of_header source_file)
function source_file -> DB.SourceFileSet.mem source_file files_set
(** The buck targets are assumed to start with //, aliases are not supported. *)
let check_args_for_targets args =

@ -12,7 +12,7 @@ CMAKE_BUILD_DIR = $(CMAKE_DIR)/_build
ANALYZER = infer
CLEAN_EXTRA = $(CMAKE_BUILD_DIR)
INFER_OPTIONS = --report-custom-error --developer-mode --project-root $(CMAKE_DIR)
INFER_OPTIONS = --cxx --report-custom-error --developer-mode --project-root $(CMAKE_DIR)
SOURCES = $(CMAKE_DIR)/hello.cpp
OBJECTS = $(CMAKE_BUILD_DIR)/compile_commands.json
INFERPRINT_OPTIONS = --issues-tests

@ -1,5 +1,7 @@
hello.cpp, test0, 2, NULL_DEREFERENCE, [start of procedure test0()]
hello.cpp, test1, 2, NULL_DEREFERENCE, [start of procedure test1(),start of procedure deref1()]
lib3.h, test, 1, NULL_DEREFERENCE, [start of procedure test(),start of procedure deref3()]
hello.cpp, test0, 2, NULL_DEREFERENCE, [start of procedure test0()]
hello.cpp, test1, 2, NULL_DEREFERENCE, [start of procedure test1(),start of procedure deref1()]
hello.cpp, test2, 2, NULL_DEREFERENCE, [start of procedure test2(),start of procedure deref2()]
lib3.h, test, 1, NULL_DEREFERENCE, [start of procedure test(),start of procedure deref3()]

@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.1)
set(CMAKE_CXX_STANDARD 11)
project (HELLO)
add_library (Hello hello.cpp lib1.cpp lib2.cpp)
add_library (Hello hello.cpp lib1.cpp lib2.cpp lib3.cpp)

@ -0,0 +1,12 @@
/*
* Copyright (c) 2016 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include "lib3.h"
int deref3(int* p) { return *p; }

@ -0,0 +1,14 @@
/*
* Copyright (c) 2016 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
int deref3(int* p);
int test() {
return deref3(nullptr);
}
Loading…
Cancel
Save