aboutsummaryrefslogtreecommitdiff
path: root/gcc/gcc.c
diff options
context:
space:
mode:
authorAlexandre Oliva <oliva@adacore.com>2020-07-24 15:38:38 -0300
committerAlexandre Oliva <oliva@gnu.org>2020-07-24 16:13:39 -0300
commitc1b9cb1a83b0d6485d9922ecef097d250a22d830 (patch)
treeb71070491f66be51eaaa51f81480f5cd61dc1114 /gcc/gcc.c
parent5fa1767aa45e1a927e832ccc09e959d4c8a9548c (diff)
downloadgcc-c1b9cb1a83b0d6485d9922ecef097d250a22d830.zip
gcc-c1b9cb1a83b0d6485d9922ecef097d250a22d830.tar.gz
gcc-c1b9cb1a83b0d6485d9922ecef097d250a22d830.tar.bz2
[PR96230] some -dumpbase-ext fixes
The initial bug report was that compiling (-c) with -dumpbase "" -dumpbase-ext .<ext> crashes the driver. The verification of -dumpbase-ext against -dumpbase doesn't cover the case in which -dumpbase activates backward-compatibility mode. I added a test for that, and for -dumpbase-ext without -dumpbase, trying to make it work in a sensible way, as if applied to the default -dumpbase for each file. It turned out that this made for too much complexity in dealing with suffixes derived from input filenames, so I gave that up and returned to discarding -dumpbase-ext as documented, ending up with a change identical to that in the original bug report. I also thought I caught an off-by-one error in the initial verification, that caused dumpbase_ext to be discarded if it was identical to the specified dumpbase, but that turned out to be intentional as well, so I put in comments and a test to reflect it. Finally, an earlier version of the newly-added tests used "$var.ext" in an expected output list, which showed me the handling of string expansion was incorrect. Reworked the expr into an eval to make that work, and, absent any reliance on post-eval adjustments to so-expanded output names, I arranged for the adjustments to be skipped after eval. Co-Authored-By: "Zhanghaijian (A)" <z.zhanghaijian@huawei.com> for gcc/ChangeLog PR driver/96230 * gcc.c (process_command): Adjust and document conditions to reset dumpbase_ext. for gcc/testsuite/ChangeLog PR driver/96230 * gcc.misc-tests/outputs.exp: Add tests with -dumpbase-ext, with identical -dumpbase, with -dumpbase "", and without any -dumpbase. (outest): Fix "" expansion in expected outputs, skip adjustments.
Diffstat (limited to 'gcc/gcc.c')
-rw-r--r--gcc/gcc.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/gcc/gcc.c b/gcc/gcc.c
index c0eb3c1..10bc988 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -4907,6 +4907,9 @@ process_command (unsigned int decoded_options_count,
int lendb = strlen (dumpbase);
int lendbx = strlen (dumpbase_ext);
+ /* -dumpbase-ext must be a suffix proper; discard it if it
+ matches all of -dumpbase, as that would make for an empty
+ basename. */
if (lendbx >= lendb
|| strcmp (dumpbase + lendb - lendbx, dumpbase_ext) != 0)
{
@@ -5083,10 +5086,18 @@ process_command (unsigned int decoded_options_count,
/* Check that dumpbase_ext, if still present, still matches the end
of dumpbase, if present, and drop it otherwise. We only retained
it above when dumpbase was absent to maybe use it to drop the
- extension from output_name before combining it with dumpdir. */
+ extension from output_name before combining it with dumpdir. We
+ won't deal with -dumpbase-ext when -dumpbase is not explicitly
+ given, even if just to activate backward-compatible dumpbase:
+ dropping it on the floor is correct, expected and documented
+ behavior. Attempting to deal with a -dumpbase-ext that might
+ match the end of some input filename, or of the combination of
+ the output basename with the suffix of the input filename,
+ possible with an intermediate .gk extension for -fcompare-debug,
+ is just calling for trouble. */
if (dumpbase_ext)
{
- if (!dumpbase)
+ if (!dumpbase || !*dumpbase)
{
free (dumpbase_ext);
dumpbase_ext = NULL;