From c10126d0fdd58829879ddd4633f64d887d3e45e3 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Thu, 12 Jan 2017 12:01:47 -0800 Subject: [PATCH] [DB] return resolved path when path cannot be made relative Summary: This makes it more obvious why infer would force a path to be absolute since we base that decision on the resolved path. For instance: ``` $ mkdir foo $ cd foo $ ln -s ../examples goo $ infer -- clang -c goo/hello.c [...] /home/jul/infer/examples/hello.c:14: error: NULL_DEREFERENCE ``` We see that the path is outside of the current directory clearly, whereas before infer would report on "goo/hello.c". Reviewed By: akotulski Differential Revision: D4409579 fbshipit-source-id: 7172005 --- infer/src/base/SourceFile.ml | 2 +- infer/tests/build_systems/cmake/Makefile | 4 ++-- infer/tests/build_systems/cmake/issues.exp | 2 +- infer/tests/build_systems/codetoanalyze/cmake/hello.c | 2 +- infer/tests/build_systems/genrule/Makefile | 3 ++- infer/tests/build_systems/genrule/issues.exp | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/infer/src/base/SourceFile.ml b/infer/src/base/SourceFile.ml index b05c6fdf3..b42c83666 100644 --- a/infer/src/base/SourceFile.ml +++ b/infer/src/base/SourceFile.ml @@ -47,7 +47,7 @@ let from_abs_path fname = | None -> ( match Utils.filename_to_relative ~root:models_dir_real fname_real with | Some path -> RelativeInferModel path - | None -> Absolute fname (* fname is absolute already *) + | None -> Absolute fname_real (* fname_real is absolute already *) ) let curr_encoding = `Enc_crc diff --git a/infer/tests/build_systems/cmake/Makefile b/infer/tests/build_systems/cmake/Makefile index bc9c18ae9..5cd797978 100644 --- a/infer/tests/build_systems/cmake/Makefile +++ b/infer/tests/build_systems/cmake/Makefile @@ -13,7 +13,7 @@ CMAKE_ANALYZE_DIR = $(CMAKE_DIR)/_build_infer ANALYZER = infer CLEAN_EXTRA = $(CMAKE_BUILD_DIR) $(CMAKE_ANALYZE_DIR) -INFER_OPTIONS = --project-root $(CMAKE_DIR) +INFER_OPTIONS = --project-root $(TESTS_DIR) SOURCES = $(CMAKE_DIR)/hello.c OBJECTS = $(CMAKE_BUILD_DIR)/CMakeFiles/Hello.dir/hello.c.o INFERPRINT_OPTIONS = --issues-tests @@ -39,4 +39,4 @@ infer-out/report.json: $(SOURCES) $(CMAKE_DIR)/CMakeLists.txt $(CLANG_DEPS) $(call silent_on_success,\ $(INFER_BIN) -a $(ANALYZER) $(INFER_OPTIONS) -- $(MAKE) -C $(CMAKE_ANALYZE_DIR)) # cmake makes all paths absolute - @sed -i -e 's#$(abspath $(CMAKE_DIR))/##g' $@ + @sed -i -e 's#$(abspath $(TESTS_DIR))/##g' $@ diff --git a/infer/tests/build_systems/cmake/issues.exp b/infer/tests/build_systems/cmake/issues.exp index d03e4fd25..11cfe57f5 100644 --- a/infer/tests/build_systems/cmake/issues.exp +++ b/infer/tests/build_systems/cmake/issues.exp @@ -1 +1 @@ -hello.c, test, 2, NULL_DEREFERENCE, [start of procedure test()] +build_systems/codetoanalyze/hello.c, test, 2, NULL_DEREFERENCE, [start of procedure test()] diff --git a/infer/tests/build_systems/codetoanalyze/cmake/hello.c b/infer/tests/build_systems/codetoanalyze/cmake/hello.c index b336897bc..7132d19cf 120000 --- a/infer/tests/build_systems/codetoanalyze/cmake/hello.c +++ b/infer/tests/build_systems/codetoanalyze/cmake/hello.c @@ -1 +1 @@ -../../../../../examples/hello.c \ No newline at end of file +../hello.c \ No newline at end of file diff --git a/infer/tests/build_systems/genrule/Makefile b/infer/tests/build_systems/genrule/Makefile index d322eb043..31a0aa852 100644 --- a/infer/tests/build_systems/genrule/Makefile +++ b/infer/tests/build_systems/genrule/Makefile @@ -30,6 +30,7 @@ genrule: $(ROOT_DIR)/buck-out/genruletest/gen/infer/tests/build_systems/genrule/ $(ROOT_DIR)/buck-out/genruletest/gen/infer/tests/build_systems/genrule/module2/module2_infer/infer_out/report.json: \ $(JAVA_DEPS) $(JAVA_SOURCE_FILES) cd $(ROOT_DIR) && \ + $(REMOVE_DIR) buck-out && \ $(call silent_on_success,\ INFER_BIN="$(INFER_BIN)" NO_BUCKD=1 GENERATE_INFER_GENRULES=1 \ buck build --config project.buck_out=buck-out/genruletest --no-cache //infer/tests/build_systems/genrule/module2:module2_infer) @@ -38,4 +39,4 @@ $(ROOT_DIR)/buck-out/genruletest/gen/infer/tests/build_systems/genrule/module2/m infer-out/report.json: $(ROOT_DIR)/buck-out/genruletest/gen/infer/tests/build_systems/genrule/module2/module2_infer/infer_out/report.json $(MKDIR_P) infer-out # the report contains absolute paths - @sed -e 's#$(abspath $(ROOT_DIR))/##g' $< > $@ + @sed -e 's#$(abspath $(TESTS_DIR))/##g' $< > $@ diff --git a/infer/tests/build_systems/genrule/issues.exp b/infer/tests/build_systems/genrule/issues.exp index 78d9615dd..eacad8493 100644 --- a/infer/tests/build_systems/genrule/issues.exp +++ b/infer/tests/build_systems/genrule/issues.exp @@ -1 +1 @@ -buck-out/genruletest/gen/infer/tests/build_systems/genrule/module2/module2_infer__srcs/Class2.java, void Class2.localNPE2(), 2, NULL_DEREFERENCE, [start of procedure localNPE2()] +build_systems/genrule/module2/Class2.java, void Class2.localNPE2(), 2, NULL_DEREFERENCE, [start of procedure localNPE2()]