diff --git a/infer/man/man1/infer-full.txt b/infer/man/man1/infer-full.txt index ac58f485f..7ab4debfb 100644 --- a/infer/man/man1/infer-full.txt +++ b/infer/man/man1/infer-full.txt @@ -1190,6 +1190,18 @@ INTERNAL OPTIONS --clang-blacklisted-flags-with-arg-reset Set --clang-blacklisted-flags-with-arg to the empty list. + --clang-idirafter-to-override-regex dir_OCaml_regex + Use this option in the uncommon case where the normal compilation + process overrides the location of internal compiler headers. This + option should specify regular expression with the path to those + headers so that infer can use its own clang internal headers + instead. Concretely, this will replace -idirafter with -idirafter + /path/to/infer/facebook-clang-plugins/clang/install/lib/clang//include. + + --clang-idirafter-to-override-regex-reset + Cancel the effect of --clang-idirafter-to-override-regex. + --clang-ignore-regex dir_OCaml_regex The files in this regex will be ignored in the compilation process and an empty file will be passed to clang instead. This is to be diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index 3605c0569..e0f8405f2 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -1006,6 +1006,15 @@ and clang_ignore_regex = around missing generated files." +and clang_idirafter_to_override_regex = + CLOpt.mk_string_opt ~long:"clang-idirafter-to-override-regex" ~meta:"dir_OCaml_regex" + "Use this option in the uncommon case where the normal compilation process overrides the \ + location of internal compiler headers. This option should specify regular expression with \ + the path to those headers so that infer can use its own clang internal headers instead. \ + Concretely, this will replace $(b,-idirafter ) with $(b,-idirafter \ + /path/to/infer/facebook-clang-plugins/clang/install/lib/clang//include)." + + and clang_isystem_to_override_regex = CLOpt.mk_string_opt ~long:"clang-isystem-to-override-regex" ~deprecated:["-clang-include-to-override-regex"; "-clang-include-to-override"] @@ -2755,7 +2764,9 @@ and clang_blacklisted_flags_with_arg = !clang_blacklisted_flags_with_arg and clang_ignore_regex = !clang_ignore_regex -and clang_isystem_to_override_regex = !clang_isystem_to_override_regex +and clang_idirafter_to_override_regex = Option.map ~f:Str.regexp !clang_idirafter_to_override_regex + +and clang_isystem_to_override_regex = Option.map ~f:Str.regexp !clang_isystem_to_override_regex and clang_libcxx_include_to_override_regex = !clang_libcxx_include_to_override_regex diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index e627c8ace..671ee87f0 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -288,7 +288,9 @@ val clang_frontend_action_string : string val clang_ignore_regex : string option -val clang_isystem_to_override_regex : string option +val clang_isystem_to_override_regex : Str.regexp option + +val clang_idirafter_to_override_regex : Str.regexp option val clang_libcxx_include_to_override_regex : string option diff --git a/infer/src/clang/ClangCommand.ml b/infer/src/clang/ClangCommand.ml index 1da798422..5a55403cb 100644 --- a/infer/src/clang/ClangCommand.ml +++ b/infer/src/clang/ClangCommand.ml @@ -76,8 +76,6 @@ let file_arg_cmd_sanitizer cmd = {cmd with argv= [Format.sprintf "@%s" file]} -let isystem_to_override_regex = Option.map ~f:Str.regexp Config.clang_isystem_to_override_regex - let libcxx_include_to_override_regex = Option.map ~f:Str.regexp Config.clang_libcxx_include_to_override_regex @@ -148,6 +146,12 @@ let filter_and_replace_unsupported_args ?(replace_options_arg = fun _ s -> s) ?( of clang with a different version. Also mitigate version discrepancies in clang's fatal warnings. *) let clang_cc1_cmd_sanitizer cmd = + let replace_args arg = function + | Some override_regex when Str.string_match override_regex arg 0 -> + fcp_dir ^/ "clang" ^/ "install" ^/ "lib" ^/ "clang" ^/ "8.0.0" ^/ "include" + | _ -> + arg + in (* command line options not supported by the opensource compiler or the plugins *) let replace_options_arg options arg = match (options, arg) with @@ -162,12 +166,10 @@ let clang_cc1_cmd_sanitizer cmd = | "-dependency-file" :: _, _ when Option.is_some Config.buck_compilation_database -> (* In compilation database mode, dependency files are not assumed to exist *) "/dev/null" - | "-isystem" :: _, arg -> ( - match isystem_to_override_regex with - | Some isystem_to_override_regex when Str.string_match isystem_to_override_regex arg 0 -> - fcp_dir ^/ "clang" ^/ "install" ^/ "lib" ^/ "clang" ^/ "8.0.0" ^/ "include" - | _ -> - arg ) + | "-idirafter" :: _, arg -> + replace_args arg Config.clang_idirafter_to_override_regex + | "-isystem" :: _, arg -> + replace_args arg Config.clang_isystem_to_override_regex | "-I" :: _, arg -> ( match libcxx_include_to_override_regex with | Some libcxx_include_to_override_regex