Bug 25175 - Meaningless pre-processor lineno comments inserted
Summary: Meaningless pre-processor lineno comments inserted
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.0.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-30 02:09 UTC by John Witford
Modified: 2005-11-30 04:16 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Witford 2005-11-30 02:09:57 UTC
Create this file, x.c:
     main(){}

Then pre-process with, "cc -E -g x.c" (the -g is significant).

The output will contain a line such as:

    # 1 "/home/me/testdir//"

This seems to be at odds with all other such annotations.
Why is the current directory output?  And why the double /?
Comment 1 Andrew Pinski 2005-11-30 02:14:42 UTC
The current directory is outputted so that when compiling with -save-temps -g is no different from -g.  The double // is not really a problem at all.
Comment 2 John Witford 2005-11-30 02:18:17 UTC
(In reply to comment #1)
> The current directory is outputted so that when compiling with -save-temps -g
> is no different from -g.  The double // is not really a problem at all.
> 

That is rather unfortunate.
Because if you use the -H option then you will get different output depending on whether you use "-g" or not.  So while you might be helping the "-save-temps" case you have upset the "-H" case.

Comment 3 Andrew Pinski 2005-11-30 02:24:45 UTC
(In reply to comment #2)
> That is rather unfortunate.
> Because if you use the -H option then you will get different output depending
> on whether you use "-g" or not.  So while you might be helping the
> "-save-temps" case you have upset the "-H" case.

HUH?
earth:~>gcc -V4.0.0 -H t.c -S -save-temps -E -o t.i -g
. /usr/include/stdio.h
.. /usr/include/features.h
... /usr/include/sys/cdefs.h
... /usr/include/gnu/stubs.h
.. /home/gates/pinskia/linux/lib/gcc/i686-pc-linux-gnu/4.0.0/include/stddef.h
.. /usr/include/bits/types.h
... /usr/include/bits/wordsize.h
... /home/gates/pinskia/linux/lib/gcc/i686-pc-linux-gnu/4.0.0/include/stddef.h
... /usr/include/bits/typesizes.h
.. /usr/include/libio.h
... /usr/include/_G_config.h
.... /home/gates/pinskia/linux/lib/gcc/i686-pc-linux-gnu/4.0.0/include/stddef.h
.... /usr/include/wchar.h
..... /home/gates/pinskia/linux/lib/gcc/i686-pc-linux-gnu/4.0.0/include/stddef.h
..... /usr/include/bits/wchar.h
.... /usr/include/gconv.h
..... /usr/include/wchar.h
...... /home/gates/pinskia/linux/lib/gcc/i686-pc-linux-gnu/4.0.0/include/stddef.h
..... /home/gates/pinskia/linux/lib/gcc/i686-pc-linux-gnu/4.0.0/include/stddef.h
... /home/gates/pinskia/linux/lib/gcc/i686-pc-linux-gnu/4.0.0/include/stdarg.h
.. /usr/include/bits/stdio_lim.h
.. /usr/include/bits/sys_errlist.h


that is for the simple "#include <stdio.h> int i;" case.  Can you show where -H will give you the CWD?
Comment 4 John Witford 2005-11-30 02:55:55 UTC
>  Can you show where -H will give you the CWD?

Use my original example and add -H.
I *never* had "-save-temps" in my example so I don't understand why you are corrupting my example so.  And I *never* used a -S flag either.
Comment 5 Andrew Pinski 2005-11-30 03:06:07 UTC
(In reply to comment #4)
> >  Can you show where -H will give you the CWD?
> Use my original example and add -H.
Your orginal example does not show a difference for -H at all.
pc64:~> gcc -H t.c -g
pc64:~> gcc -H t.c 
pc64:~> 

-H shows the includes.
Comment 6 John Witford 2005-11-30 03:37:02 UTC
> Your orginal example does not show a difference for -H at all.

Does for me:

    pc:~/work/stats $ cc -E -H x.c
    # 1 "x.c"
    # 1 "<built-in>"
    # 1 "<command line>"
    # 1 "x.c"
    main(){}

and:

    pc:~/work/stats $ cc -E -H -g x.c
    # 1 "x.c"
    # 1 "/home/me/work/stats//"
    # 1 "<built-in>"
    # 1 "<command line>"
    # 1 "x.c"
    main(){}

And here is my compiler:

    pc:~/work/stats $ cc --version
    cc (GCC) 4.0.1 20050727 (Red Hat 4.0.1-5)

So there!
Comment 7 Andrew Pinski 2005-11-30 03:42:34 UTC
(In reply to comment #6)
> > Your orginal example does not show a difference for -H at all.
Wait a minute, -E outputs the preprocessed source.  -H outputs the files which are included.  

Again this is not a bug.
Comment 8 John Witford 2005-11-30 03:52:43 UTC
(In reply to comment #7)
> (In reply to comment #6)
> > > Your orginal example does not show a difference for -H at all.
> Wait a minute, -E outputs the preprocessed source.  -H outputs the files which
> are included.  
> 
> Again this is not a bug.
> 

I am sorry, but unless you also use the -E flag you get absolutely no output from the -H flag.

Are you sure you know anything about gcc?

Comment 9 Ian Lance Taylor 2005-11-30 04:06:53 UTC
This is documented behaviour.

The -g option enables the -fworking-directory option, as described in the documentation of -fworking-directory.  It is the -fworking-directory option which is printing the directory name.

If you use -E -H -g -fno-working-directory, you will not see the directory name.
Comment 10 John Witford 2005-11-30 04:16:09 UTC
>
> If you use -E -H -g -fno-working-directory, you will not see the directory
> name.

Thanks, I can use that.