On Thu, Feb 14, 2013 at 05:48:57AM -0700, Jeff Law wrote:
> I think two tests should be sufficient.  First, compile a simple
> program with -g and verify it generates dwarf2 debug records.
> Second verify that there aren't any -g<foo> options, unless <foo> is
> dwarf2.
> 
> I'm actually on PTO today/tomorrow, so I won't be able to look
> further at this until Monday.
> 
> If someone wants to run with it, my recommendation would be Steven's
> warning patch, moved to the location Jakub suggests so that users
> know stabs+PCH is going away plus a hack to the testsuite suite
> similar to what I outlined above plus something to either suppress
> creation of the pch or suppress reading the PCH in the presence of
> non-dwarf debug output.

Here is what seems to work for me.
Tested with
make check -j4 -k 
RUNTESTFLAGS='--target_board=unix\{-m32,-m32/-gstabs,-m64,-m64/-gstabs\} 
pch.exp'
on x86_64-linux, both with gcc just with this patch and also
this patch + changed PREFERRED_DEBUGGING_TYPE to DBX_DEBUG.
No FAILs at all, tests that wouldn't work because either -gstabs is forced
in the flags from target board or tests that would be compiled with -g
when stabs is the default are UNSUPPORTED.

2013-02-15  Jakub Jelinek  <ja...@redhat.com>
            Steven Bosscher  <ste...@gcc.gnu.org>

        PR pch/54117
        * c-opts.c (c_common_post_options): If debug info is enabled
        and non-dwarf*, refuse to load PCH files and when writing PCH
        file warn.

        * lib/dg-pch.exp (pch-init, pch-finish,
        check_effective_target_pch_supported_debug): New procs.
        (dg-flags-pch): If $pch_unsupported, make tests UNSUPPORTED.
        Likewise if $pch_unsupported_debug and $flags include -g.
        Skip FAILs about missing *.gch file if $pch_unsupported_debug
        and dg-require-effective-target pch_unsupported_debug.
        * g++.dg/pch/pch.exp: Call pch-init and pch-finish.
        * objc.dg/pch/pch.exp: Likewise.
        * gcc.dg/pch/pch.exp: Likewise.
        * gcc.dg/pch/valid-1.c: Add dg-require-effective-target
        pch_unsupported_debug.
        * gcc.dg/pch/valid-1.hs: Likewise.
        * gcc.dg/pch/valid-1b.c: Likewise.
        * gcc.dg/pch/valid-1b.hs: Likewise.

--- gcc/c-family/c-opts.c.jj    2013-02-14 14:45:01.000000000 +0100
+++ gcc/c-family/c-opts.c       2013-02-15 12:44:48.936535118 +0100
@@ -945,6 +945,16 @@ c_common_post_options (const char **pfil
         because the default address space slot then can't be used
         for the output PCH file.  */
       if (pch_file)
+       {
+         c_common_no_more_pch ();
+         /* Only -g0 and -gdwarf* are supported with PCH, for other
+            debug formats we warn here and refuse to load any PCH files.  */
+         if (write_symbols != NO_DEBUG && write_symbols != DWARF2_DEBUG)
+           warning (OPT_Wdeprecated,
+                    "the \"%s\" debug format cannot be used with "
+                    "pre-compiled headers", debug_type_names[write_symbols]);
+       }
+      else if (write_symbols != NO_DEBUG && write_symbols != DWARF2_DEBUG)
        c_common_no_more_pch ();
 
       /* Yuk.  WTF is this?  I do know ObjC relies on it somewhere.  */
--- gcc/testsuite/lib/dg-pch.exp.jj     2013-01-11 09:02:39.000000000 +0100
+++ gcc/testsuite/lib/dg-pch.exp        2013-02-15 15:45:53.747855529 +0100
@@ -16,8 +16,49 @@
 
 load_lib copy-file.exp
 
+proc pch-init { args } {
+    global pch_unsupported_debug pch_unsupported
+
+    if [info exists pch_unsupported_debug] {
+       error "pch-init: pch_unsupported_debug is not empty as expected"
+    }
+    if [info exists pch_unsupported] {
+       error "pch-init: pch_unsupported is not empty as expected"
+    }
+
+    set result [check_compile pchtest object "int i;" "-g -x c-header"]
+    set pch_unsupported_debug \
+       [regexp "debug format cannot be used with pre-compiled headers" \
+               [lindex $result 0]]
+
+    set pch_unsupported 0
+    if { $pch_unsupported_debug } {
+       verbose -log "pch is unsupported with the debug info format"
+
+       set result [check_compile pchtest object "int i;" "-x c-header"]
+           set pch_unsupported \
+               [regexp "debug format cannot be used with pre-compiled headers" 
\
+                       [lindex $result 0]]
+    }
+}
+
+proc pch-finish { args } {
+    global pch_unsupported_debug pch_unsupported
+    unset pch_unsupported_debug
+    unset pch_unsupported
+}
+
+proc check_effective_target_pch_supported_debug { } {
+    global pch_unsupported_debug
+    if { $pch_unsupported_debug } {
+       return 0
+    }
+    return 1
+}
+
 proc dg-flags-pch { subdir test otherflags options suffix } {
     global runtests dg-do-what-default
+    global pch_unsupported_debug pch_unsupported
 
     # If we're only testing specific files and this isn't one of them, skip it.
     if ![runtest_file_p $runtests $test] {
@@ -35,6 +76,13 @@ proc dg-flags-pch { subdir test otherfla
     foreach flags $options {
        verbose "Testing $nshort, $otherflags $flags" 1
 
+       if { $pch_unsupported != 0 \
+            || ( $pch_unsupported_debug != 0 && [regexp " -g" " $flags"] ) } {
+           verbose -log "$nshort unsupported because debug format conflicts 
with PCH"
+           unsupported "$nshort $flags"
+           continue
+       }
+
        # For the header files, the default is to precompile.
        set dg-do-what-default precompile
        catch { file_on_host delete "$bname$suffix" }
@@ -78,7 +126,8 @@ proc dg-flags-pch { subdir test otherfla
                    fail "$nshort $flags assembly comparison"
                }
            }
-       } else {
+       } elseif { $pch_unsupported_debug == 0 \
+                  || [llength [grep $test "{\[ 
\t\]\+dg-require-effective-target\[ \t\]\+pch_supported_debug\[ \t\]\+.*\[ 
\t\]\+}"]] > 0 } {
            verbose -log "pch file '$bname$suffix.gch' missing"
            fail "$nshort $flags"
            if { !$have_errs } {
--- gcc/testsuite/g++.dg/pch/pch.exp.jj 2013-01-11 09:02:44.000000000 +0100
+++ gcc/testsuite/g++.dg/pch/pch.exp    2013-02-15 14:53:03.517106464 +0100
@@ -23,6 +23,7 @@ load_lib dg-pch.exp
 
 # Initialize `dg'.
 dg-init
+pch-init
 
 set old_dg_do_what_default "${dg-do-what-default}"
 
@@ -36,4 +37,5 @@ foreach test [lsort [glob -nocomplain $s
 set dg-do-what-default "$old_dg_do_what_default"
 
 # All done.
+pch-finish
 dg-finish
--- gcc/testsuite/objc.dg/pch/pch.exp.jj        2013-01-11 09:02:44.000000000 
+0100
+++ gcc/testsuite/objc.dg/pch/pch.exp   2013-02-15 14:53:30.063951051 +0100
@@ -24,8 +24,8 @@ load_lib torture-options.exp
 
 # Initialize `dg'.
 dg-init
-
 torture-init
+pch-init
 
 set-torture-options $DG_TORTURE_OPTIONS
 
@@ -59,5 +59,6 @@ if [istarget "*-*-darwin*" ] {
 set dg-do-what-default "$old_dg_do_what_default"
 
 # All done.
+pch-finish
 torture-finish
 dg-finish
--- gcc/testsuite/gcc.dg/pch/pch.exp.jj 2013-01-11 09:02:42.000000000 +0100
+++ gcc/testsuite/gcc.dg/pch/pch.exp    2013-02-15 14:11:27.053896809 +0100
@@ -26,6 +26,7 @@ load_lib torture-options.exp
 dg-init
 torture-init
 set-torture-options $DG_TORTURE_OPTIONS
+pch-init
 
 set old_dg_do_what_default "${dg-do-what-default}"
 
@@ -59,5 +60,6 @@ file delete $testh
 set dg-do-what-default "$old_dg_do_what_default"
 
 # All done.
+pch-finish
 torture-finish
 dg-finish
--- gcc/testsuite/gcc.dg/pch/valid-1.c.jj       2009-06-08 11:53:48.000000000 
+0200
+++ gcc/testsuite/gcc.dg/pch/valid-1.c  2013-02-15 15:19:44.124833259 +0100
@@ -1,3 +1,4 @@
+/* { dg-require-effective-target pch_supported_debug } */
 /* { dg-options "-I. -Winvalid-pch -g" } */
 
 #include "valid-1.h"/* { dg-warning "created with -gnone, but used with -g" } 
*/
--- gcc/testsuite/gcc.dg/pch/valid-1.hs.jj      2008-09-05 12:54:26.000000000 
+0200
+++ gcc/testsuite/gcc.dg/pch/valid-1.hs 2013-02-15 15:19:50.686794340 +0100
@@ -1,3 +1,4 @@
+/* { dg-require-effective-target pch_supported_debug } */
 /* { dg-options "-I. -Winvalid-pch -g0" } */
 
 extern int x;
--- gcc/testsuite/gcc.dg/pch/valid-1b.c.jj      2008-09-05 12:54:26.000000000 
+0200
+++ gcc/testsuite/gcc.dg/pch/valid-1b.c 2013-02-15 15:19:55.935763631 +0100
@@ -1,3 +1,4 @@
+/* { dg-require-effective-target pch_supported_debug } */
 /* { dg-options "-I. -Winvalid-pch -g0" } */
 
 #include "valid-1b.h"
--- gcc/testsuite/gcc.dg/pch/valid-1b.hs.jj     2008-09-05 12:54:26.000000000 
+0200
+++ gcc/testsuite/gcc.dg/pch/valid-1b.hs        2013-02-15 15:20:02.214727794 
+0100
@@ -1,3 +1,4 @@
+/* { dg-require-effective-target pch_supported_debug } */
 /* { dg-options "-I. -Winvalid-pch -g" } */
 
 extern int x;


        Jakub

Reply via email to