make blacklisted clang flags configurable

Reviewed By: jvillard

Differential Revision: D15575785

fbshipit-source-id: 3f3885d22
master
Martin Trojer 6 years ago committed by Facebook Github Bot
parent 1e7b13bdcd
commit 90a1324ed3

@ -196,6 +196,14 @@ CLANG OPTIONS
--clang-biniou-file file --clang-biniou-file file
Specify a file containing the AST of the program, in biniou format Specify a file containing the AST of the program, in biniou format
--clang-blacklisted-flags +string
Clang flags to filter out (default:
--expt-relaxed-constexpr,-fembed-bitcode-marker,-fno-absolute-module-directory,-fno-canonical-system-headers)
--clang-blacklisted-flags-with-arg +string
Clang flags (taking args) to filter out (default:
-index-store-path,-mllvm)
--compilation-database +path --compilation-database +path
File that contain compilation commands (can be specified multiple File that contain compilation commands (can be specified multiple
times) times)

@ -172,6 +172,15 @@ OPTIONS
Specify a file containing the AST of the program, in biniou format Specify a file containing the AST of the program, in biniou format
See also infer-capture(1). See also infer-capture(1).
--clang-blacklisted-flags +string
Clang flags to filter out (default:
--expt-relaxed-constexpr,-fembed-bitcode-marker,-fno-absolute-module-directory,-fno-canonical-system-headers)
See also infer-capture(1).
--clang-blacklisted-flags-with-arg +string
Clang flags (taking args) to filter out (default:
-index-store-path,-mllvm) See also infer-capture(1).
--class-loads --class-loads
Activates: Java class loading analysis (Conversely: Activates: Java class loading analysis (Conversely:
--no-class-loads) See also infer-analyze(1). --no-class-loads) See also infer-analyze(1).
@ -1178,6 +1187,12 @@ INTERNAL OPTIONS
--clang-biniou-file-reset --clang-biniou-file-reset
Cancel the effect of --clang-biniou-file. Cancel the effect of --clang-biniou-file.
--clang-blacklisted-flags-reset
Set --clang-blacklisted-flags to the empty list.
--clang-blacklisted-flags-with-arg-reset
Set --clang-blacklisted-flags-with-arg to the empty list.
--clang-ignore-regex dir_OCaml_regex --clang-ignore-regex dir_OCaml_regex
The files in this regex will be ignored in the compilation process 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 and an empty file will be passed to clang instead. This is to be

@ -172,6 +172,15 @@ OPTIONS
Specify a file containing the AST of the program, in biniou format Specify a file containing the AST of the program, in biniou format
See also infer-capture(1). See also infer-capture(1).
--clang-blacklisted-flags +string
Clang flags to filter out (default:
--expt-relaxed-constexpr,-fembed-bitcode-marker,-fno-absolute-module-directory,-fno-canonical-system-headers)
See also infer-capture(1).
--clang-blacklisted-flags-with-arg +string
Clang flags (taking args) to filter out (default:
-index-store-path,-mllvm) See also infer-capture(1).
--class-loads --class-loads
Activates: Java class loading analysis (Conversely: Activates: Java class loading analysis (Conversely:
--no-class-loads) See also infer-analyze(1). --no-class-loads) See also infer-analyze(1).

@ -905,6 +905,24 @@ and clang_extra_flags =
"Pass values as command-line arguments to invocations of clang" "Pass values as command-line arguments to invocations of clang"
and clang_blacklisted_flags =
CLOpt.mk_string_list ~long:"clang-blacklisted-flags"
~default:
[ "--expt-relaxed-constexpr"
; "-fembed-bitcode-marker"
; "-fno-absolute-module-directory"
; "-fno-canonical-system-headers" ]
~in_help:InferCommand.[(Capture, manual_clang)]
"Clang flags to filter out"
and clang_blacklisted_flags_with_arg =
CLOpt.mk_string_list ~long:"clang-blacklisted-flags-with-arg"
~default:["-index-store-path"; "-mllvm"]
~in_help:InferCommand.[(Capture, manual_clang)]
"Clang flags (taking args) to filter out"
and clang_compilation_dbs = ref [] and clang_compilation_dbs = ref []
and clang_frontend_action = and clang_frontend_action =
@ -2658,6 +2676,10 @@ and clang_biniou_file = !clang_biniou_file
and clang_extra_flags = !clang_extra_flags and clang_extra_flags = !clang_extra_flags
and clang_blacklisted_flags = !clang_blacklisted_flags
and clang_blacklisted_flags_with_arg = !clang_blacklisted_flags_with_arg
and clang_ignore_regex = !clang_ignore_regex and clang_ignore_regex = !clang_ignore_regex
and clang_isystem_to_override_regex = !clang_isystem_to_override_regex and clang_isystem_to_override_regex = !clang_isystem_to_override_regex

@ -276,6 +276,10 @@ val clang_biniou_file : string option
val clang_extra_flags : string list val clang_extra_flags : string list
val clang_blacklisted_flags : string list
val clang_blacklisted_flags_with_arg : string list
val clang_frontend_action_string : string val clang_frontend_action_string : string
val clang_ignore_regex : string option val clang_ignore_regex : string option

@ -15,14 +15,6 @@ type t =
; quoting_style: ClangQuotes.style ; quoting_style: ClangQuotes.style
; is_driver: bool } ; is_driver: bool }
(** bad for every clang invocation *)
let clang_blacklisted_flags =
[ "--expt-relaxed-constexpr"
; "-fembed-bitcode-marker"
; "-fno-absolute-module-directory"
; "-fno-canonical-system-headers" ]
let fcp_dir = let fcp_dir =
Config.bin_dir ^/ Filename.parent_dir_name ^/ Filename.parent_dir_name Config.bin_dir ^/ Filename.parent_dir_name ^/ Filename.parent_dir_name
^/ "facebook-clang-plugins" ^/ "facebook-clang-plugins"
@ -92,8 +84,8 @@ let libcxx_include_to_override_regex =
(** Filter arguments from [args], looking into argfiles too. [replace_options_arg prev arg] returns (** Filter arguments from [args], looking into argfiles too. [replace_options_arg prev arg] returns
[arg'], where [arg'] is the new version of [arg] given the preceding arguments (in reverse order) [prev]. *) [arg'], where [arg'] is the new version of [arg] given the preceding arguments (in reverse order) [prev]. *)
let filter_and_replace_unsupported_args ?(replace_options_arg = fun _ s -> s) let filter_and_replace_unsupported_args ?(replace_options_arg = fun _ s -> s) ?(post_args = [])
?(blacklisted_flags = []) ?(blacklisted_flags_with_arg = []) ?(post_args = []) args = args =
(* [prev] is the previously seen argument, [res_rev] is the reversed result, [changed] is true if (* [prev] is the previously seen argument, [res_rev] is the reversed result, [changed] is true if
some change has been performed *) some change has been performed *)
let rec aux in_argfiles (prev_is_blacklisted_with_arg, res_rev, changed) args = let rec aux in_argfiles (prev_is_blacklisted_with_arg, res_rev, changed) args =
@ -130,9 +122,9 @@ let filter_and_replace_unsupported_args ?(replace_options_arg = fun _ s -> s)
L.external_warning "Error reading argument file '%s': %s@\n" at_argfile L.external_warning "Error reading argument file '%s': %s@\n" at_argfile
(Exn.to_string e) ; (Exn.to_string e) ;
aux in_argfiles' (false, at_argfile :: res_rev, changed) tl ) aux in_argfiles' (false, at_argfile :: res_rev, changed) tl )
| flag :: tl when List.mem ~equal:String.equal blacklisted_flags flag -> | flag :: tl when List.mem ~equal:String.equal Config.clang_blacklisted_flags flag ->
aux in_argfiles (false, res_rev, true) tl aux in_argfiles (false, res_rev, true) tl
| flag :: tl when List.mem ~equal:String.equal blacklisted_flags_with_arg flag -> | flag :: tl when List.mem ~equal:String.equal Config.clang_blacklisted_flags_with_arg flag ->
(* remove the flag and its arg separately in case we are at the end of an argfile *) (* remove the flag and its arg separately in case we are at the end of an argfile *)
aux in_argfiles (true, res_rev, true) tl aux in_argfiles (true, res_rev, true) tl
| arg :: tl -> | arg :: tl ->
@ -150,7 +142,6 @@ let filter_and_replace_unsupported_args ?(replace_options_arg = fun _ s -> s)
fatal warnings. *) fatal warnings. *)
let clang_cc1_cmd_sanitizer cmd = let clang_cc1_cmd_sanitizer cmd =
(* command line options not supported by the opensource compiler or the plugins *) (* command line options not supported by the opensource compiler or the plugins *)
let blacklisted_flags_with_arg = ["-mllvm"] in
let replace_options_arg options arg = let replace_options_arg options arg =
match (options, arg) with match (options, arg) with
| [], _ -> | [], _ ->
@ -194,19 +185,15 @@ let clang_cc1_cmd_sanitizer cmd =
argv_cons "-Wno-everything" argv_cons "-Wno-everything"
in in
let clang_arguments = let clang_arguments =
filter_and_replace_unsupported_args ~blacklisted_flags:clang_blacklisted_flags filter_and_replace_unsupported_args ~replace_options_arg ~post_args:(List.rev post_args_rev)
~blacklisted_flags_with_arg ~replace_options_arg ~post_args:(List.rev post_args_rev) cmd.argv cmd.argv
in in
file_arg_cmd_sanitizer {cmd with argv= clang_arguments} file_arg_cmd_sanitizer {cmd with argv= clang_arguments}
let mk ~is_driver quoting_style ~prog ~args = let mk ~is_driver quoting_style ~prog ~args =
(* Some arguments break the compiler so they need to be removed even before the normalization step *) (* Some arguments break the compiler so they need to be removed even before the normalization step *)
let blacklisted_flags_with_arg = ["-index-store-path"] in let sanitized_args = filter_and_replace_unsupported_args args in
let sanitized_args =
filter_and_replace_unsupported_args ~blacklisted_flags:clang_blacklisted_flags
~blacklisted_flags_with_arg args
in
let sanitized_args = let sanitized_args =
if is_driver then sanitized_args @ List.rev Config.clang_extra_flags else sanitized_args if is_driver then sanitized_args @ List.rev Config.clang_extra_flags else sanitized_args
in in

Loading…
Cancel
Save