From 54fb38b7e813273b80e2fc6e6f383514bf2abbbe Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Mon, 5 Nov 2018 09:21:57 -0800 Subject: [PATCH] [clang] ensure we get the correct file path Summary: As explained in the added comment, clang started adding `-faddrsig` at the end of every `-cc1` command, which trumps our heuristic for finding the file name (thus we would write debug scripts to `-faddrsig.ast.sh`, do filename-based filtering on `-faddrsig` instead of the source path, and more...). We rely on the file name being the last argument in `-cc1` commands because so far that's always been the case, and we don't want to parse the clang command line and have to know about all the clang options... Thanks martinoluca for the trick of simply passing `-fno-addrsig`! Reviewed By: martinoluca Differential Revision: D12921987 fbshipit-source-id: 28bebe647 --- infer/src/clang/ClangWrapper.ml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/infer/src/clang/ClangWrapper.ml b/infer/src/clang/ClangWrapper.ml index cb5d8f745..5e5b86cf8 100644 --- a/infer/src/clang/ClangWrapper.ml +++ b/infer/src/clang/ClangWrapper.ml @@ -66,9 +66,17 @@ let clang_driver_action_items : ClangCommand.t -> action_item list = pass it now. Using clang instead of gcc may trigger warnings about unsupported optimization flags; - passing -Wno-ignored-optimization-argument prevents that. *) + passing -Wno-ignored-optimization-argument prevents that. + + Clang adds "-faddrsig" by default on ELF targets. This is ok in itself, but for some + reason that flag is the only one to show up *after* the source file name in the -cc1 + commands emitted by [clang -### ...]. Passing [-fno-addrsig] ensures that the source + path is always the last argument. *) ClangCommand.append_args - ["-fno-cxx-modules"; "-Qunused-arguments"; "-Wno-ignored-optimization-argument"] + [ "-fno-cxx-modules" + ; "-Qunused-arguments" + ; "-Wno-ignored-optimization-argument" + ; "-fno-addrsig" ] |> (* If -fembed-bitcode is passed, it leads to multiple cc1 commands, which try to read .bc files that don't get generated, and fail. So pass -fembed-bitcode=off to disable. *) ClangCommand.append_args ["-fembed-bitcode=off"]