Created attachment 32324 [details] test.c - Source to trigger the bug To trigger this bug, three conditions must be met: - At least one function must be annotated with "__attribute__((optimize))". - The object file is placed in a sub-directory to where the source file is located. - The flag -fdump-rtl-expand is used. The path to the directory where the dump file is supposed to be saved is prepended the same number of times as there are functions with "attribute optimize" in the source C file. Compiler output: $ gcc -std=c99 -fdump-rtl-expand -o objs/test.o -c test.c test.c: In function ‘Optimized_1’: test.c:3:1: error: could not open dump file ‘objs/objs/objs/test.c.166r.expand’: No such file or directory Optimized_1(int arg) ^ test.c: In function ‘Optimized_2’: test.c:10:1: error: could not open dump file ‘objs/objs/objs/test.c.166r.expand’: No such file or directory Optimized_2(int arg) ^ test.c: In function ‘main’: test.c:15:5: error: could not open dump file ‘objs/objs/objs/test.c.166r.expand’: No such file or directory int main() ^ Compiler version: $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ./configure Thread model: posix gcc version 4.8.2 (GCC) System type: $ uname -a Linux jf-linux 3.4.63-2.44-desktop #1 SMP PREEMPT Wed Oct 2 11:18:32 UTC 2013 (d91a619) x86_64 x86_64 x86_64 GNU/Linux
Confirmed. GCC 4.4 works.
(In reply to Marek Polacek from comment #1) > Confirmed. GCC 4.4 works. Well, seems 4.4 puts the dump file in $PWD.
Anyway, this is because finish_options is called for every optimize attribute (handle_optimize_attribute->parse_optimize_attribute->decode_options->finish_options) + one more time for command line options and every time it adds the directory prefix. I guess we should add the directory prefix just once.
Created attachment 32348 [details] gcc49-pr60484.patch Untested fix. Alternatively, e.g. finish_options could guard it also with && loc == UNKNOWN_LOCATION (for calls other than the first one loc should be some real locus).
I've just regtested a similar patch, so it looks good.
Author: mpolacek Date: Fri Mar 14 17:58:52 2014 New Revision: 208571 URL: http://gcc.gnu.org/viewcvs?rev=208571&root=gcc&view=rev Log: PR middle-end/60484 * common.opt (dump_base_name_prefixed): New Variable. * opts.c (finish_options): Don't prepend directory to x_dump_base_name if x_dump_base_name_prefixed is already set, set it at the end. Modified: trunk/gcc/ChangeLog trunk/gcc/common.opt trunk/gcc/opts.c
Fixed.