Bug 60484 - [4.7/4.8/4.9 Regression] -fdump-rtl-expand and attribute optimize gives incorrect dump file path
Summary: [4.7/4.8/4.9 Regression] -fdump-rtl-expand and attribute optimize gives incor...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.8.2
: P2 normal
Target Milestone: 4.7.4
Assignee: Marek Polacek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-10 12:51 UTC by secondary.mail7865220
Modified: 2014-03-14 18:04 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-03-14 00:00:00


Attachments
test.c - Source to trigger the bug (128 bytes, text/plain)
2014-03-10 12:51 UTC, secondary.mail7865220
Details
gcc49-pr60484.patch (692 bytes, patch)
2014-03-14 15:42 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description secondary.mail7865220 2014-03-10 12:51:20 UTC
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
Comment 1 Marek Polacek 2014-03-14 12:24:35 UTC
Confirmed.  GCC 4.4 works.
Comment 2 Marek Polacek 2014-03-14 13:03:49 UTC
(In reply to Marek Polacek from comment #1)
> Confirmed.  GCC 4.4 works.

Well, seems 4.4 puts the dump file in $PWD.
Comment 3 Marek Polacek 2014-03-14 14:08:11 UTC
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.
Comment 4 Jakub Jelinek 2014-03-14 15:42:42 UTC
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).
Comment 5 Marek Polacek 2014-03-14 15:55:33 UTC
I've just regtested a similar patch, so it looks good.
Comment 6 Marek Polacek 2014-03-14 17:59:24 UTC
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
Comment 7 Marek Polacek 2014-03-14 18:04:39 UTC
Fixed.