public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug pch/57242] New: gcc ignores precompiled headers unless the .gch and TU's are compiled with certain combinations of -g flag
@ 2013-05-10 16:50 scottbaldwin at gmail dot com
  2013-05-10 16:55 ` [Bug pch/57242] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: scottbaldwin at gmail dot com @ 2013-05-10 16:50 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57242

            Bug ID: 57242
           Summary: gcc ignores precompiled headers unless the .gch and
                    TU's are compiled with certain combinations of -g flag
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: pch
          Assignee: unassigned at gcc dot gnu.org
          Reporter: scottbaldwin at gmail dot com

In GCC 4.7.2 and 4.8.x, precompiled headers (PCH) .gch file is ignored unless a
certain combination of '-gN' debug options are used.
To demonstrate, consider the following g++ commands to generate PCH
(my_pch.hpp.gch) and compile a TU (foo.cpp) using the PCH cache:

g++ $(PCH_DEBUG_FLAGS) -std=c++11 -m64 -Wall -Werror -Wno-unused
-Wno-unused-variable -I./dbg-mt -I. -I. ./dbg-mt/my_pch.hpp -o
./dbg-mt/my_pch.hpp.gch
g++ $(CPP_DEBUG_FLAGS) -std=c++11 -m64 -Wall -Werror -Wno-unused
-Wno-unused-variable -I./dbg-mt -I. -I. -c foo.cpp -o dbg-mt/foo.o

The only difference between these two commands (other than the input file) is
the $(PCH_DEBUG_FLAGS) vs $(CPP_DEBUG_FLAGS).

However, in order for the precompiled headers (.gch file) to be used when
compiling the source files (e.g., foo.cpp), both of the following conditions
must be met:
  1) The '-g' or '-g2' or '-g3' flag must be used when building the precompiled
headers (.gch file).
  2) The '-g3' flag (and no less) must be used when compiling each TU (.c/.cpp
file), and

In other words:
  PCH_DEBUG_FLAGS = -g3 or -g2 or -g (specifying no 'g' at all will cause PCH
cache to be ignored)
  CPP_DEBUG_FLAGS = -g3 (specifying -g2 or -g or no 'g' at all will cause PCH
cache to be ignored)

I put a #warning in the my_pch.hpp file to be sure of when PCH were being
ignored (though, the long delay also made it quite obvious).

This bug is present in all 3 versions of gcc I tested (4.7.2, 4.8.0,
4.8.1_20130427).


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug pch/57242] gcc ignores precompiled headers unless the .gch and TU's are compiled with certain combinations of -g flag
  2013-05-10 16:50 [Bug pch/57242] New: gcc ignores precompiled headers unless the .gch and TU's are compiled with certain combinations of -g flag scottbaldwin at gmail dot com
@ 2013-05-10 16:55 ` pinskia at gcc dot gnu.org
  2013-05-10 16:56 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-05-10 16:55 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57242

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is by design as -g changes the information produced by the front-end and
maybe even predefines too.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug pch/57242] gcc ignores precompiled headers unless the .gch and TU's are compiled with certain combinations of -g flag
  2013-05-10 16:50 [Bug pch/57242] New: gcc ignores precompiled headers unless the .gch and TU's are compiled with certain combinations of -g flag scottbaldwin at gmail dot com
  2013-05-10 16:55 ` [Bug pch/57242] " pinskia at gcc dot gnu.org
@ 2013-05-10 16:56 ` pinskia at gcc dot gnu.org
  2013-05-10 17:15 ` scottbaldwin at gmail dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-05-10 16:56 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57242

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to etherice from comment #0)
> I put a #warning in the my_pch.hpp file to be sure of when PCH were being
> ignored (though, the long delay also made it quite obvious).

You can use -Winvalid-pch for that instead.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug pch/57242] gcc ignores precompiled headers unless the .gch and TU's are compiled with certain combinations of -g flag
  2013-05-10 16:50 [Bug pch/57242] New: gcc ignores precompiled headers unless the .gch and TU's are compiled with certain combinations of -g flag scottbaldwin at gmail dot com
  2013-05-10 16:55 ` [Bug pch/57242] " pinskia at gcc dot gnu.org
  2013-05-10 16:56 ` pinskia at gcc dot gnu.org
@ 2013-05-10 17:15 ` scottbaldwin at gmail dot com
  2013-05-10 18:33 ` [Bug pch/57242] precompiled headers ignored " scottbaldwin at gmail dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: scottbaldwin at gmail dot com @ 2013-05-10 17:15 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57242

--- Comment #3 from etherice <scottbaldwin at gmail dot com> ---
(In reply to Andrew Pinski from comment #1)
> This is by design as -g changes the information produced by the front-end
> and maybe even predefines too.

I think you may have read the report too quickly :)

When building the .gch file, and then subsequently building the translation
unit that uses the .gch ... even if you do not specify a -gN at all, or specify
the SAME -gN (unless both are -g3), the .gch will be ignored when compiling the
TU. For example, using -g2 for both (.gch and TU) will cause pch to be ignored.
Or using no -g flag at all for both (.gch and TU) will cause pch to be ignored.
You MUST specify a -g flag (either -g -g2 or -g3) when building the .gch, and
you must specify EXACTLY -g3 when building the TU. I hope that clarifies it.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug pch/57242] precompiled headers ignored unless the .gch and TU's are compiled with certain combinations of -g flag
  2013-05-10 16:50 [Bug pch/57242] New: gcc ignores precompiled headers unless the .gch and TU's are compiled with certain combinations of -g flag scottbaldwin at gmail dot com
                   ` (2 preceding siblings ...)
  2013-05-10 17:15 ` scottbaldwin at gmail dot com
@ 2013-05-10 18:33 ` scottbaldwin at gmail dot com
  2013-05-13  8:53 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: scottbaldwin at gmail dot com @ 2013-05-10 18:33 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57242

--- Comment #4 from etherice <scottbaldwin at gmail dot com> ---
(In reply to Andrew Pinski from comment #1)
> This is by design as -g changes the information produced by the front-end
> and maybe even predefines too.

I created a simpler test to demonstrate the bug. Two files:

----------
pch.hpp
----------
#ifndef __PCH_HPP__
#define __PCH_HPP__
  #pragma message "[ not using pre-compiled headers ]"
  #include <iostream>
#endif

----------
test.cpp
----------
#include <pch.hpp>
int main() {
    std::cout << "hello world" << std::endl;
    return 0;
}

----------

If you run commands [1] and [2] below, you will notice that pch is ignored.

[1]  g++ -I.     pch.hpp  -o pch.hpp.gch
[2]  g++ -I. -c test.cpp  -o test.o
[3]  g++ -I. -c test.cpp  -o test.o -include pch.hpp

However, if you add -g3 to commands [1] and [2], then pch will be used in
command [2]. More specifically, you must use a combination of the -g flags I
described in the report for pch to be utilized.

One more note: Using the -include option (even though it's unnecessary in this
case) makes the -g3 flags no longer needed. To confirm this, execute commands
[1] and [3] and observe that pch is no longer ignored, even without the -g3
flags.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug pch/57242] precompiled headers ignored unless the .gch and TU's are compiled with certain combinations of -g flag
  2013-05-10 16:50 [Bug pch/57242] New: gcc ignores precompiled headers unless the .gch and TU's are compiled with certain combinations of -g flag scottbaldwin at gmail dot com
                   ` (3 preceding siblings ...)
  2013-05-10 18:33 ` [Bug pch/57242] precompiled headers ignored " scottbaldwin at gmail dot com
@ 2013-05-13  8:53 ` rguenth at gcc dot gnu.org
  2013-05-13 16:55 ` scottbaldwin at gmail dot com
  2013-11-10  8:03 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-05-13  8:53 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57242

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2013-05-13
     Ever confirmed|0                           |1

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to etherice from comment #4)
> (In reply to Andrew Pinski from comment #1)
> > This is by design as -g changes the information produced by the front-end
> > and maybe even predefines too.
> 
> I created a simpler test to demonstrate the bug. Two files:
> 
> ----------
> pch.hpp
> ----------
> #ifndef __PCH_HPP__
> #define __PCH_HPP__
>   #pragma message "[ not using pre-compiled headers ]"
>   #include <iostream>
> #endif
> 
> ----------
> test.cpp
> ----------
> #include <pch.hpp>
> int main() {
> 	std::cout << "hello world" << std::endl;
> 	return 0;
> }
> 
> ----------
> 
> If you run commands [1] and [2] below, you will notice that pch is ignored.
> 
> [1]  g++ -I.     pch.hpp  -o pch.hpp.gch
> [2]  g++ -I. -c test.cpp  -o test.o
> [3]  g++ -I. -c test.cpp  -o test.o -include pch.hpp

How?  I see

rguenther@murzim:/tmp> g++-4.7 -I.     pch.hpp  -o pch.hpp.gch
pch.hpp:3:19: note: #pragma message: [ not using pre-compiled headers ]
rguenther@murzim:/tmp> g++-4.7 -I. -c test.cpp  -o test.o  
rguenther@murzim:/tmp> g++-4.7 -I. -c test.cpp  -o test.o -include pch.hpp

rguenther@murzim:/tmp> g++-4.8 -I.     pch.hpp  -o pch.hpp.gch
pch.hpp:3:19: note: #pragma message: [ not using pre-compiled headers ]
   #pragma message "[ not using pre-compiled headers ]"
                   ^
rguenther@murzim:/tmp> g++-4.8 -I. -c test.cpp  -o test.o 
rguenther@murzim:/tmp> g++-4.8 -I. -c test.cpp  -o test.o -include pch.hpp

the issue is probably that there are pre-installed precompiled headers
for libstdc++ which use certain flags.  Maybe in your case this confuses
things?  (disclaimer: I always install gcc built with --disable-libstdcxx-pch)
Try removing them.
>From gcc-bugs-return-422130-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon May 13 09:01:07 2013
Return-Path: <gcc-bugs-return-422130-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 5897 invoked by alias); 13 May 2013 09:01:07 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 5609 invoked by uid 48); 13 May 2013 09:01:01 -0000
From: "izamyatin at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/57124] 254.gap@spec2000 got miscompare after r198413
Date: Mon, 13 May 2013 09:01:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: tree-optimization
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: izamyatin at gmail dot com
X-Bugzilla-Status: ASSIGNED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: law at redhat dot com
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-57124-4-RkHDreyqkB@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-57124-4@http.gcc.gnu.org/bugzilla/>
References: <bug-57124-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-05/txt/msg00803.txt.bz2
Content-length: 169

http://gcc.gnu.org/bugzilla/show_bug.cgi?idW124

--- Comment #5 from Igor Zamyatin <izamyatin at gmail dot com> ---
Indeed, -fwrapv helps to run 254.gap successfully


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug pch/57242] precompiled headers ignored unless the .gch and TU's are compiled with certain combinations of -g flag
  2013-05-10 16:50 [Bug pch/57242] New: gcc ignores precompiled headers unless the .gch and TU's are compiled with certain combinations of -g flag scottbaldwin at gmail dot com
                   ` (4 preceding siblings ...)
  2013-05-13  8:53 ` rguenth at gcc dot gnu.org
@ 2013-05-13 16:55 ` scottbaldwin at gmail dot com
  2013-11-10  8:03 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: scottbaldwin at gmail dot com @ 2013-05-13 16:55 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57242

--- Comment #6 from etherice <scottbaldwin at gmail dot com> ---
(In reply to Richard Biener from comment #5)
> (In reply to etherice from comment #4)
> > (In reply to Andrew Pinski from comment #1)
> > > This is by design as -g changes the information produced by the front-end
> > > and maybe even predefines too.
> > 
> > I created a simpler test to demonstrate the bug. Two files:
> > 
> > ----------
> > pch.hpp
> > ----------
> > #ifndef __PCH_HPP__
> > #define __PCH_HPP__
> >   #pragma message "[ not using pre-compiled headers ]"
> >   #include <iostream>
> > #endif
> > 
> > ----------
> > test.cpp
> > ----------
> > #include <pch.hpp>
> > int main() {
> > 	std::cout << "hello world" << std::endl;
> > 	return 0;
> > }
> > 
> > ----------
> > 
> > If you run commands [1] and [2] below, you will notice that pch is ignored.
> > 
> > [1]  g++ -I.     pch.hpp  -o pch.hpp.gch
> > [2]  g++ -I. -c test.cpp  -o test.o
> > [3]  g++ -I. -c test.cpp  -o test.o -include pch.hpp
> 
> How?  I see
> 
> rguenther@murzim:/tmp> g++-4.7 -I.     pch.hpp  -o pch.hpp.gch
> pch.hpp:3:19: note: #pragma message: [ not using pre-compiled headers ]
> rguenther@murzim:/tmp> g++-4.7 -I. -c test.cpp  -o test.o  
> rguenther@murzim:/tmp> g++-4.7 -I. -c test.cpp  -o test.o -include pch.hpp
> 
> rguenther@murzim:/tmp> g++-4.8 -I.     pch.hpp  -o pch.hpp.gch
> pch.hpp:3:19: note: #pragma message: [ not using pre-compiled headers ]
>    #pragma message "[ not using pre-compiled headers ]"
>                    ^
> rguenther@murzim:/tmp> g++-4.8 -I. -c test.cpp  -o test.o 
> rguenther@murzim:/tmp> g++-4.8 -I. -c test.cpp  -o test.o -include pch.hpp
> 
> the issue is probably that there are pre-installed precompiled headers
> for libstdc++ which use certain flags.  Maybe in your case this confuses
> things?  (disclaimer: I always install gcc built with
> --disable-libstdcxx-pch)
> Try removing them.

I did a clean rebuild of 4.8 with --disable-libstdcxx-pch and results were the
same, pch ignored, but... after triple-checking some things I realized ccache
was still being used.

Once ccache was disabled, the issue went away and gcc-pch worked as expected.
So this appears to be a bug with ccache, not gcc.

Fortunately, the workaround is simple (using '-g3' or the '-include' option).
>From gcc-bugs-return-422169-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon May 13 17:13:25 2013
Return-Path: <gcc-bugs-return-422169-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 26646 invoked by alias); 13 May 2013 17:13:25 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 26520 invoked by uid 48); 13 May 2013 17:13:22 -0000
From: "paolo.carlini at oracle dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/31952] parameters may be redeclared in a function try-block
Date: Mon, 13 May 2013 17:13:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 4.1.1
X-Bugzilla-Keywords: accepts-invalid, diagnostic
X-Bugzilla-Severity: normal
X-Bugzilla-Who: paolo.carlini at oracle dot com
X-Bugzilla-Status: ASSIGNED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: paolo.carlini at oracle dot com
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status assigned_to
Message-ID: <bug-31952-4-zZMZWHQLjm@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-31952-4@http.gcc.gnu.org/bugzilla/>
References: <bug-31952-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-05/txt/msg00842.txt.bz2
Content-length: 468

http://gcc.gnu.org/bugzilla/show_bug.cgi?id1952

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |paolo.carlini at oracle dot com

--- Comment #8 from Paolo Carlini <paolo.carlini at oracle dot com> ---
On it.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug pch/57242] precompiled headers ignored unless the .gch and TU's are compiled with certain combinations of -g flag
  2013-05-10 16:50 [Bug pch/57242] New: gcc ignores precompiled headers unless the .gch and TU's are compiled with certain combinations of -g flag scottbaldwin at gmail dot com
                   ` (5 preceding siblings ...)
  2013-05-13 16:55 ` scottbaldwin at gmail dot com
@ 2013-11-10  8:03 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-11-10  8:03 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57242

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|---                         |INVALID

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Not a bug, ccache getting in the way.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-11-10  8:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-10 16:50 [Bug pch/57242] New: gcc ignores precompiled headers unless the .gch and TU's are compiled with certain combinations of -g flag scottbaldwin at gmail dot com
2013-05-10 16:55 ` [Bug pch/57242] " pinskia at gcc dot gnu.org
2013-05-10 16:56 ` pinskia at gcc dot gnu.org
2013-05-10 17:15 ` scottbaldwin at gmail dot com
2013-05-10 18:33 ` [Bug pch/57242] precompiled headers ignored " scottbaldwin at gmail dot com
2013-05-13  8:53 ` rguenth at gcc dot gnu.org
2013-05-13 16:55 ` scottbaldwin at gmail dot com
2013-11-10  8:03 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).