From 2d087b71426303417de43fa9c933937e6533bd23 Mon Sep 17 00:00:00 2001 From: Andrzej Kotulski Date: Wed, 15 Jul 2015 15:54:27 -0100 Subject: [PATCH] [C Frontend] Get support for map pointer -> decl from fcp Summary: This adds support for having lookup from pointer to decl in C frontend NOTE: with this diff atdgen 1.6 or later is required. To upgrade atdgen, please run `opam install atdgen.1.6.0` --- .gitignore | 4 ++++ INSTALL.md | 4 ++-- dependencies/clang-plugin/clang-plugin-version.config | 2 +- infer/src/Makefile | 8 ++++++-- infer/src/clang/cFrontend_config.ml | 2 ++ infer/src/clang/cFrontend_config.mli | 2 ++ infer/src/clang/cMain.ml | 2 +- opam | 2 +- 8 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index f3f8bd64a..593d53f25 100644 --- a/.gitignore +++ b/.gitignore @@ -88,5 +88,9 @@ infer/models/out/ /infer/src/clang/clang_ast_proj.mli /infer/src/clang/clang_ast_t.ml /infer/src/clang/clang_ast_t.mli +/infer/src/clang/clang_ast_v.ml +/infer/src/clang/clang_ast_v.mli +/infer/src/clang/clang_ast_cache.ml +/infer/src/clang/clang_ast_main.ml /infer/annotations/annotations.jar diff --git a/INSTALL.md b/INSTALL.md index d03a49295..5fb8348d1 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -49,7 +49,7 @@ Install the OCaml dependencies: ```bash opam init --comp=4.01.0 # (answer 'y' to the question) eval `opam config env` -opam install sawja.1.5 atdgen.1.5.0 javalib.2.3a extlib.1.5.4 +opam install sawja.1.5 atdgen.1.6.0 javalib.2.3a extlib.1.5.4 ``` If you do not require support for the C/Objective-C analysis in Infer, @@ -93,7 +93,7 @@ wget https://github.com/ocaml/opam/releases/download/1.2.2/opam-1.2.2-x86_64-Lin chmod +x opam ./opam init --comp=4.01.0 #(then say 'y' to the final question) eval `./opam config env` -./opam install sawja.1.5 atdgen.1.5.0 javalib.2.3a extlib.1.5.4 #(then say 'y' to the question) +./opam install sawja.1.5 atdgen.1.6.0 javalib.2.3a extlib.1.5.4 #(then say 'y' to the question) ``` If you do not require support for the C/Objective-C analysis in Infer, diff --git a/dependencies/clang-plugin/clang-plugin-version.config b/dependencies/clang-plugin/clang-plugin-version.config index 0837442d2..57ece473e 100644 --- a/dependencies/clang-plugin/clang-plugin-version.config +++ b/dependencies/clang-plugin/clang-plugin-version.config @@ -1 +1 @@ -332177951f9004e44adb554b0ab31be4710c7d7e +c4197d9f677a129304711a82c1f2e0fda4952314 diff --git a/infer/src/Makefile b/infer/src/Makefile index 987052954..7bd8b6c38 100644 --- a/infer/src/Makefile +++ b/infer/src/Makefile @@ -12,7 +12,7 @@ OCAML_INCLUDE_DIR = $(shell ocamlc -where) #### ATDGEN declarations #### -ATDGEN_SUFFIXES = _t.ml _t.mli _j.ml _j.mli +ATDGEN_SUFFIXES = _t.ml _t.mli _j.ml _j.mli _v.ml _v.mli ATDGEN_INCLUDE_DIR = $(shell ocamlfind query atdgen) BINIOU_INCLUDE_DIR = $(shell ocamlfind query biniou) @@ -99,6 +99,7 @@ CLANG_ATDGEN_STUBS = $(addprefix $(CLANG_SOURCES)/$(CLANG_AST_BASE_NAME), $(ATDG INFER_CLANG_AST_PROJ = $(addprefix $(CLANG_SOURCES)/, clang_ast_proj.ml clang_ast_proj.mli) FCP_CLANG_AST_PROJ = $(addprefix $(CLANG_OCAML_BUILD)/, clang_ast_proj.ml clang_ast_proj.mli) +FCP_CLANG_AST_CACHE = $(addprefix $(CLANG_OCAML_ROOT)/, clang_ast_cache.ml clang_ast_main.ml) #### LLVM declarations #### @@ -149,13 +150,16 @@ $(INFERPRINT_ATDGEN_STUBS): $(INFERPRINT_ATDGEN_STUB_ATD) atdgen -t $(INFERPRINT_ATDGEN_STUB_ATD) -o $(INFERPRINT_ATDGEN_STUB_BASE) atdgen -j $(INFERPRINT_ATDGEN_STUB_ATD) -o $(INFERPRINT_ATDGEN_STUB_BASE) -$(CLANG_ATDGEN_STUBS) $(INFER_CLANG_AST_PROJ): $(CLANG_ATDGEN_STUB_ATD) $(CLANG_PLUGIN_BINARIES) $(FCP_CLANG_AST_PROJ) +$(CLANG_ATDGEN_STUBS) $(INFER_CLANG_AST_PROJ): $(CLANG_ATDGEN_STUB_ATD) $(CLANG_PLUGIN_BINARIES) $(FCP_CLANG_AST_PROJ) $(FCP_CLANG_AST_CACHE) # rebuild the artifacts of the AST files whenever they're upated in FCP # also copy the ast_proj files whenever they are updated atdgen -rec -t $(CLANG_ATDGEN_STUB_ATD) -o $(CLANG_ATDGEN_STUB_BASE) atdgen -rec -j $(CLANG_ATDGEN_STUB_ATD) -o $(CLANG_ATDGEN_STUB_BASE) + atdgen -rec -v $(CLANG_ATDGEN_STUB_ATD) -o $(CLANG_ATDGEN_STUB_BASE) $(COPY) $(CLANG_OCAML_BUILD)/clang_ast_proj.ml $(CLANG_SOURCES) $(COPY) $(CLANG_OCAML_BUILD)/clang_ast_proj.mli $(CLANG_SOURCES) + $(COPY) $(CLANG_OCAML_ROOT)/clang_ast_cache.ml $(CLANG_SOURCES) + $(COPY) $(CLANG_OCAML_ROOT)/clang_ast_main.ml $(CLANG_SOURCES) init: sanitize version $(BUILDDIR) diff --git a/infer/src/clang/cFrontend_config.ml b/infer/src/clang/cFrontend_config.ml index 1997ee2e5..8a6d693ed 100644 --- a/infer/src/clang/cFrontend_config.ml +++ b/infer/src/clang/cFrontend_config.ml @@ -39,6 +39,8 @@ let ast_file : string option ref = ref None let json = ref "" +let pointer_decl_index = ref Clang_ast_cache.PointerMap.empty + let debug_mode = ref false let stats_mode = ref false diff --git a/infer/src/clang/cFrontend_config.mli b/infer/src/clang/cFrontend_config.mli index 8004e74af..63a8e38fd 100644 --- a/infer/src/clang/cFrontend_config.mli +++ b/infer/src/clang/cFrontend_config.mli @@ -37,6 +37,8 @@ val testing_mode : bool ref val json : string ref +val pointer_decl_index : Clang_ast_t.decl Clang_ast_cache.PointerMap.t ref + val objc_object : string val id_cl : string diff --git a/infer/src/clang/cMain.ml b/infer/src/clang/cMain.ml index 0c5a006f4..1b79ce771 100644 --- a/infer/src/clang/cMain.ml +++ b/infer/src/clang/cMain.ml @@ -104,7 +104,7 @@ let do_run source_path ast_path = Printing.log_out "Original AST@.%a@." CAstProcessor.pp_ast_decl ast_decl; Printing.log_out "AST with explicit locations:@.%a@." CAstProcessor.pp_ast_decl ast_decl'; - + CFrontend_config.pointer_decl_index := Clang_ast_main.index_decl_pointers ast_decl'; CFrontend_config.json := ast_filename; CLocation.check_source_file source_path; let source_file = CLocation.source_file_from_path source_path in diff --git a/opam b/opam index 88425061e..5d007a612 100644 --- a/opam +++ b/opam @@ -13,7 +13,7 @@ remove: [] depends: [ "ocamlfind" {build} "sawja" {>="1.5"} - "atdgen" {>="1.5"} + "atdgen" {>="1.6"} "javalib" {>="2.3"} "extlib" {>="1.5.4"} ]