From 6d4537695f8753556362c6c5521360ca9b596ab2 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Wed, 1 Jan 2020 21:59:29 +0100 Subject: [PATCH] Revert "Only pass implicit -MQ to preprocessor if needed" MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This reverts commit 19c3729d30640fc2c78242cb46136e619fdbd802 and also removes the incorrect and superfluous condition that the fix fixes. The reason for reverting is that the change introduced a nasty bug: the dependency file will get an incorrect object file location if 1) build directory != source directory and 2) -MF is not specified explictly by the user. Details: The dependency file is created by the preprocessor pass which does not have access to the final output file name, so the preprocessor uses the default object location derived from the source file location instead. Note that this partly reverts a compatibility improvement for EDG-based compilers (see issue #460). It should be possible to pass the dependency arguments to the compiler instead of the preprocessor to make -MD/-MMD without -MQ work, but that’s too risky to be done as a bug fix. Fixes #499. --- src/ccache.c | 5 ++--- unittest/test_argument_processing.c | 32 +---------------------------- 2 files changed, 3 insertions(+), 34 deletions(-) diff --git a/src/ccache.c b/src/ccache.c index 03aa97a96..9978d3874 100644 --- a/src/ccache.c +++ b/src/ccache.c @@ -1,7 +1,7 @@ // ccache -- a fast C/C++ compiler cache // // Copyright (C) 2002-2007 Andrew Tridgell -// Copyright (C) 2009-2019 Joel Rosdahl +// Copyright (C) 2009-2020 Joel Rosdahl // // This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the Free @@ -3548,8 +3548,7 @@ cc_process_args(struct args *args, } if (!dependency_target_specified - && !dependency_implicit_target_specified - && !str_eq(get_extension(output_obj), ".o")) { + && !dependency_implicit_target_specified) { args_add(dep_args, "-MQ"); args_add(dep_args, output_obj); } diff --git a/unittest/test_argument_processing.c b/unittest/test_argument_processing.c index 3a2d0ed37..c0504bee1 100644 --- a/unittest/test_argument_processing.c +++ b/unittest/test_argument_processing.c @@ -1,4 +1,4 @@ -// Copyright (C) 2010-2019 Joel Rosdahl +// Copyright (C) 2010-2020 Joel Rosdahl // // This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the Free @@ -173,36 +173,6 @@ TEST(dependency_flags_that_take_an_argument_should_not_require_space_delimiter) args_free(orig); } -TEST(MQ_flag_should_not_be_added_for_standard_obj_extension) -{ - struct args *orig = args_init_from_string("cc -c -MD foo.c -o foo.o"); - struct args *exp_cpp = args_init_from_string("cc -MD -MF foo.d"); - struct args *exp_cc = args_init_from_string("cc -c"); - struct args *act_cpp = NULL, *act_cc = NULL; - create_file("foo.c", ""); - - CHECK(cc_process_args(orig, &act_cpp, NULL, &act_cc)); - CHECK_ARGS_EQ_FREE12(exp_cpp, act_cpp); - CHECK_ARGS_EQ_FREE12(exp_cc, act_cc); - - args_free(orig); -} - -TEST(MQ_flag_should_be_added_for_non_standard_obj_extension) -{ - struct args *orig = args_init_from_string("cc -c -MD foo.c -o foo.obj"); - struct args *exp_cpp = args_init_from_string("cc -MD -MF foo.d -MQ foo.obj"); - struct args *exp_cc = args_init_from_string("cc -c"); - struct args *act_cpp = NULL, *act_cc = NULL; - create_file("foo.c", ""); - - CHECK(cc_process_args(orig, &act_cpp, NULL, &act_cc)); - CHECK_ARGS_EQ_FREE12(exp_cpp, act_cpp); - CHECK_ARGS_EQ_FREE12(exp_cc, act_cc); - - args_free(orig); -} - TEST(equal_sign_after_MF_should_be_removed) { struct args *orig = args_init_from_string("cc -c -MF=path foo.c -o foo.o"); -- 2.47.3