From 354e4c03919165f9bd9e9e46de5f6e1f94148f42 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Wed, 20 Jul 2016 10:07:10 -0700 Subject: [PATCH] fail when clang -### returns nothing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Since clang -### can silently return nothing when passed bogus arguments (eg, trying to compile a non-existent file), run the original command in that case in case it's a genuine error. This prevents puzzling behaviours such as `infer -- clang -c bogus_file.c` succeeding with 0 files analyzed. Reviewed By: martinoluca Differential Revision: D3592924 fbshipit-source-id: 5d8bc81 --- .../hijack_and_normalize_clang_command.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/infer/lib/clang_wrappers/hijack_and_normalize_clang_command.sh b/infer/lib/clang_wrappers/hijack_and_normalize_clang_command.sh index 6d26511ec..c94ebc51e 100755 --- a/infer/lib/clang_wrappers/hijack_and_normalize_clang_command.sh +++ b/infer/lib/clang_wrappers/hijack_and_normalize_clang_command.sh @@ -54,7 +54,17 @@ else sed -e 's#^\(^clang: error:.*$\)#echo "\1"; exit 1#g' | \ # add trailing ; to each line sed -e 's/$/;/g') - eval $CC_COMMAND + if [ -n "$CC_COMMAND" ]; then + eval $CC_COMMAND + else + # No command to execute after -###, this is fishy, let's execute the original command + # instead. + # + # In particular, this can happen when the user tries to run `infer -- clang -c + # file_that_does_not_exist.c`. In this case, this will fail with the appropriate error + # message from clang instead of silently analyzing 0 files. + "$CLANG_COMPILER$XX" "$@" + fi STATUS=$? fi