[clang capture] Don't attach plugin when clang is invoked in preprocessor mode

Summary:
There is no point in attaching plugin to `clang -E` calls since they don't produce any AST.
Same applies to `-M`, `-MM`, etc. (but not `-MD` nor `-MMD`).

Reviewed By: jvillard

Differential Revision: D4681618

fbshipit-source-id: 7a76add
master
Andrzej Kotulski 8 years ago committed by Facebook Github Bot
parent 6c1339d044
commit 6c67c850d5

1
.gitignore vendored

@ -31,6 +31,7 @@ duplicates.txt
/infer/tests/build_systems/codetoanalyze/path with spaces/ /infer/tests/build_systems/codetoanalyze/path with spaces/
/infer/tests/build_systems/clang_compilation_db_escaped/compile_commands.json /infer/tests/build_systems/clang_compilation_db_escaped/compile_commands.json
/infer/tests/build_systems/clang_compilation_db_relpath/compile_commands.json /infer/tests/build_systems/clang_compilation_db_relpath/compile_commands.json
/infer/tests/build_systems/clang_with_MD_flag/hello.d
/infer/tests/build_systems/codetoanalyze/xcodebuild/simple_app/app_built /infer/tests/build_systems/codetoanalyze/xcodebuild/simple_app/app_built
/infer/tests/build_systems/codetoanalyze/xcodebuild/simple_app/build/ /infer/tests/build_systems/codetoanalyze/xcodebuild/simple_app/build/
infer/tests/build_systems/differential_*/**/*.class infer/tests/build_systems/differential_*/**/*.class

@ -21,6 +21,9 @@ BUILD_SYSTEMS_TESTS += \
clang_multiple_files \ clang_multiple_files \
clang_translation \ clang_translation \
clang_unknown_ext \ clang_unknown_ext \
clang_with_E_flag \
clang_with_M_flag \
clang_with_MD_flag \
delete_results_dir \ delete_results_dir \
differential_resolve_infer_eradicate_conflict \ differential_resolve_infer_eradicate_conflict \
differential_skip_anonymous_class_renamings \ differential_skip_anonymous_class_renamings \

@ -53,16 +53,19 @@ let value_of_option {orig_argv} => value_of_argv_option orig_argv;
let has_flag {orig_argv} flag => List.exists f::(String.equal flag) orig_argv; let has_flag {orig_argv} flag => List.exists f::(String.equal flag) orig_argv;
let can_attach_ast_exporter cmd => let can_attach_ast_exporter cmd => {
has_flag cmd "-cc1" && ( let is_supported_language cmd =>
switch (value_of_option cmd "-x") { switch (value_of_option cmd "-x") {
| None => | None =>
Logging.stderr "malformed -cc1 command has no \"-x\" flag!"; Logging.stderr "malformed -cc1 command has no \"-x\" flag!";
false false
| Some lang when String.is_prefix prefix::"assembler" lang => false | Some lang when String.is_prefix prefix::"assembler" lang => false
| Some _ => true | Some _ => true
} };
); /* -Eonly is -cc1 flag that gets produced by 'clang -M -### ...' */
let is_preprocessor_only cmd => has_flag cmd "-E" || has_flag cmd "-Eonly";
has_flag cmd "-cc1" && is_supported_language cmd && not (is_preprocessor_only cmd)
};
let argv_cons a b => [a, ...b]; let argv_cons a b => [a, ...b];

@ -0,0 +1,17 @@
# Copyright (c) 2017 - 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.
TESTS_DIR = ../..
ANALYZER = infer
CLANG_OPTIONS = -E -c
INFER_OPTIONS = --report-custom-error --developer-mode --project-root ../codetoanalyze --no-failures-allowed
INFERPRINT_OPTIONS = --issues-tests
SOURCES = ../codetoanalyze/hello.c
include $(TESTS_DIR)/clang.make

@ -0,0 +1,17 @@
# Copyright (c) 2017 - 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.
TESTS_DIR = ../..
ANALYZER = infer
CLANG_OPTIONS = -MD -c
INFER_OPTIONS = --report-custom-error --developer-mode --project-root ../codetoanalyze --no-failures-allowed
INFERPRINT_OPTIONS = --issues-tests
SOURCES = ../codetoanalyze/hello.c
include $(TESTS_DIR)/clang.make

@ -0,0 +1 @@
hello.c, test, 2, NULL_DEREFERENCE, [start of procedure test()]

@ -0,0 +1,17 @@
# Copyright (c) 2017 - 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.
TESTS_DIR = ../..
ANALYZER = infer
CLANG_OPTIONS = -M -c
INFER_OPTIONS = --report-custom-error --developer-mode --project-root ../codetoanalyze --no-failures-allowed
INFERPRINT_OPTIONS = --issues-tests
SOURCES = ../codetoanalyze/hello.c
include $(TESTS_DIR)/clang.make
Loading…
Cancel
Save