Repository: ccache/ccache

Issue #738: ccache re-orders warning flags
Created: 2020-12-04T17:41:56Z
Question
I don't know whether this is a feature or a bug, so this is just a question at first.  I noticed this difference in behavior with and without ccache:
$ g++ -c -Werror -Wmissing-prototypes test.cpp     
cc1plus: error: command line option ‘-Wmissing-prototypes’ is valid for C/ObjC but not for C++ [-Werror]
cc1plus: all warnings being treated as errors
$ ccache -C; ccache g++ -c -Werror -Wmissing-prototypes test.cpp 
Cleared cache
cc1plus: warning: command line option ‘-Wmissing-prototypes’ is valid for C/ObjC but not for C++

Without ccache, it generates an error.  Without ccache, it generates a warning.
This is because whether g++ makes the diagnostic about -Wmissing-prototypes a warning or an error depends on whether -Wmissing-prototypes is before or after -Werror (open gcc bug about it):
$ g++ -c -Werror -Wmissing-prototypes test.cpp
cc1plus: error: command line option ‘-Wmissing-prototypes’ is valid for C/ObjC but not for C++ [-Werror]
cc1plus: all warnings being treated as errors
$ g++ -c -Wmissing-prototypes -Werror test.cpp
cc1plus: warning: command line option ‘-Wmissing-prototypes’ is valid for C/ObjC but not for C++

And I noticed that ccache reorders the warning flags:
$ ccache -C; strace -f -e trace=process ccache g++ -c -Werror -Wmissing-prototypes test.cpp
...
[pid 98526] execve("/usr/bin/g++", ["/usr/bin/g++", "-Wmissing-prototypes", "-Werror", "-E", "test.cpp"], 0x556095946cf0 /* 36 vars */) = 0
...

As you can see, even though I passed -Werror before -Wmissing-prototypes on my command line, ccache called g++ with -Werror after.  And this is why the behavior differs with and without ccache.
Is there any good explanation for why ccache reorders the warning flags here?

Duplicate issue #1397: Clang's --start-no-unused-arguments not honored, causing errors due to unused arguments
Created: 2024-02-06T12:19:05Z
How to reproduce

With Clang 14 or newer, run clang --start-no-unused-arguments -stdlib=libc++ --end-no-unused-arguments -Werror -c hello.c, note that this executes cleanly, with no printed errors or warnings.
Rerun the same command with ccache prefixed. Observe that it fails with clang: error: argument unused during compilation: '-stdlib=libc++' [-Werror,-Wunused-command-line-argument].

Actual behavior
Rerunning the failing command with CCACHE_DEBUG=1 and inspecting the log shows that ccache executed this command in order to preprocess the source:
Executing clang --start-no-unused-arguments --end-no-unused-arguments -Werror -stdlib=libc++ -c -fcolor-diagnostics -o hello.o hello.c

By reordering the command line arguments, moving -stdlib=libc++ outside of the region with --start-no-unused-arguments and --end-no-unused-arguments, clang triggers a warning about unused command line arguments, which is treated as an error here.
Expected behavior
Ideally, ccache would not reorder arguments outside of the region enclosed by --start-no-unused-arguments and --end-no-unused-arguments
Environment
Tested with the latest ccache from git as of today (February 6th 2024, git commit b5c103f), version v4.9-41-gb5c103fd.
Tested with a current git version of Clang 18.x - any version of Clang since version 14 supports this feature for ignoring specific ranges of arguments.

Closing comment (2024-02-11T11:13:42Z): Duplicate of #738