| 1 |
# Copyright (C) 2003-2025 Free Software Foundation, Inc. |
| 2 |
|
| 3 |
# This program is free software; you can redistribute it and/or modify |
| 4 |
# it under the terms of the GNU General Public License as published by |
| 5 |
# the Free Software Foundation; either version 3 of the License, or |
| 6 |
# (at your option) any later version. |
| 7 |
# |
| 8 |
# This program is distributed in the hope that it will be useful, |
| 9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
# GNU General Public License for more details. |
| 12 |
# |
| 13 |
# You should have received a copy of the GNU General Public License |
| 14 |
# along with GCC; see the file COPYING3. If not see |
| 15 |
# <http://www.gnu.org/licenses/>. |
| 16 |
|
| 17 |
load_lib copy-file.exp |
| 18 |
|
| 19 |
proc pch-init { args } { |
| 20 |
global pch_unsupported_debug pch_unsupported |
| 21 |
|
| 22 |
if [info exists pch_unsupported_debug] { |
| 23 |
error "pch-init: pch_unsupported_debug is not empty as expected" |
| 24 |
} |
| 25 |
if [info exists pch_unsupported] { |
| 26 |
error "pch-init: pch_unsupported is not empty as expected" |
| 27 |
} |
| 28 |
|
| 29 |
set result [check_compile pchtest object "int i;" "-g -x c-header"] |
| 30 |
set pch_unsupported_debug \ |
| 31 |
[regexp "debug info cannot be used with pre-compiled headers" \ |
| 32 |
[lindex $result 0]] |
| 33 |
remote_file build delete [lindex $result 1] |
| 34 |
|
| 35 |
set pch_unsupported 0 |
| 36 |
if { $pch_unsupported_debug } { |
| 37 |
verbose -log "pch is unsupported with the debug info format" |
| 38 |
|
| 39 |
set result [check_compile pchtest object "int i;" "-x c-header"] |
| 40 |
set pch_unsupported \ |
| 41 |
[regexp "debug info cannot be used with pre-compiled headers" \ |
| 42 |
[lindex $result 0]] |
| 43 |
remote_file build delete [lindex $result 1] |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
proc pch-finish { args } { |
| 48 |
global pch_unsupported_debug pch_unsupported |
| 49 |
unset pch_unsupported_debug |
| 50 |
unset pch_unsupported |
| 51 |
} |
| 52 |
|
| 53 |
proc check_effective_target_pch_supported_debug { } { |
| 54 |
global pch_unsupported_debug |
| 55 |
if { $pch_unsupported_debug } { |
| 56 |
return 0 |
| 57 |
} |
| 58 |
return 1 |
| 59 |
} |
| 60 |
|
| 61 |
proc dg-flags-pch { subdir test otherflags options suffix } { |
| 62 |
global runtests dg-do-what-default |
| 63 |
global pch_unsupported_debug pch_unsupported |
| 64 |
|
| 65 |
# If we're only testing specific files and this isn't one of them, skip it. |
| 66 |
if ![runtest_file_p $runtests $test] { |
| 67 |
return |
| 68 |
} |
| 69 |
|
| 70 |
if { [istarget "powerpc-ibm-aix*"] } { |
| 71 |
set torture_execute_xfail "powerpc-ibm-aix*" |
| 72 |
return |
| 73 |
} |
| 74 |
|
| 75 |
set nshort "$subdir/[file tail $test]" |
| 76 |
set bname "[file rootname [file tail $nshort]]" |
| 77 |
|
| 78 |
catch { file_on_host delete "$bname$suffix.gch" } |
| 79 |
catch { file_on_host delete "$bname.s" } |
| 80 |
catch { file_on_host delete "$bname.s-gch" } |
| 81 |
|
| 82 |
# We don't try to use the loop-optimizing options, since they are highly |
| 83 |
# unlikely to make any difference to PCH. |
| 84 |
foreach flags $options { |
| 85 |
verbose "Testing $nshort, $otherflags $flags" 1 |
| 86 |
|
| 87 |
if { $pch_unsupported != 0 \ |
| 88 |
|| ( $pch_unsupported_debug != 0 && [regexp " -g" " $flags"] ) } { |
| 89 |
verbose -log "$nshort unsupported because debug format conflicts with PCH" |
| 90 |
unsupported "$nshort $flags" |
| 91 |
continue |
| 92 |
} |
| 93 |
|
| 94 |
# For the header files, the default is to precompile. |
| 95 |
set dg-do-what-default precompile |
| 96 |
catch { file_on_host delete "$bname$suffix" } |
| 97 |
gcc_copy_files "[file rootname $test]${suffix}s" "$bname$suffix" |
| 98 |
dg-test -keep-output "./$bname$suffix" "$otherflags $flags -c" "" |
| 99 |
|
| 100 |
# For the rest, the default is to compile to .s. |
| 101 |
set dg-do-what-default compile |
| 102 |
|
| 103 |
# Process the target selectors to see whether the remaining |
| 104 |
# part of the test should be skipped. |
| 105 |
# |
| 106 |
# ??? This doesn't currently handle flag-specific skips, |
| 107 |
# based on dg-options. |
| 108 |
set dg-do-what [list compile "" P] |
| 109 |
set dg-extra-tool-flags "" |
| 110 |
foreach op [dg-get-options "./$bname$suffix"] { |
| 111 |
switch [lindex $op 0] { |
| 112 |
dg-require-effective-target - |
| 113 |
dg-skip-if { |
| 114 |
if { [catch "$op" msg] } { |
| 115 |
perror "$bname$suffix: $msg for \"$op\"" |
| 116 |
} |
| 117 |
} |
| 118 |
} |
| 119 |
} |
| 120 |
if { [lindex ${dg-do-what} 1] == "N" } { |
| 121 |
continue |
| 122 |
} |
| 123 |
|
| 124 |
set have_errs [llength [grep $test "{\[ \t\]\+dg-error\[ \t\]\+.*\[ \t\]\+}"]] |
| 125 |
|
| 126 |
if { [ file_on_host exists "$bname$suffix.gch" ] } { |
| 127 |
# Ensure that the PCH file is used, not the original header. |
| 128 |
file_on_host delete "$bname$suffix" |
| 129 |
|
| 130 |
# The flags "-Dwith_PCH" and "-Dwithout_PCH" are to distinguish the |
| 131 |
# two compiles in test summary lines. |
| 132 |
dg-test -keep-output $test "$otherflags $flags -I. -Dwith_PCH" "" |
| 133 |
file_on_host delete "$bname$suffix.gch" |
| 134 |
if { !$have_errs } { |
| 135 |
if { [ file_on_host exists "$bname.s" ] } { |
| 136 |
remote_upload host "$bname.s" "$bname.s-gch" |
| 137 |
remote_download host "$bname.s-gch" |
| 138 |
gcc_copy_files "[file rootname $test]${suffix}s" "$bname$suffix" |
| 139 |
dg-test -keep-output $test "$otherflags $flags -I. -Dwithout_PCH" "" |
| 140 |
remote_upload host "$bname.s" |
| 141 |
set tmp [ diff "$bname.s" "$bname.s-gch" ] |
| 142 |
if { $tmp == 0 } { |
| 143 |
verbose -log "assembly file '$bname.s', '$bname.s-gch' comparison error" |
| 144 |
fail "$nshort $otherflags $flags assembly comparison" |
| 145 |
} elseif { $tmp == 1 } { |
| 146 |
pass "$nshort $otherflags $flags assembly comparison" |
| 147 |
} else { |
| 148 |
fail "$nshort $otherflags $flags assembly comparison" |
| 149 |
} |
| 150 |
file_on_host delete "$bname$suffix" |
| 151 |
file_on_host delete "$bname.s" |
| 152 |
file_on_host delete "$bname.s-gch" |
| 153 |
} else { |
| 154 |
verbose -log "assembly file '$bname.s' missing" |
| 155 |
fail "$nshort $flags assembly comparison" |
| 156 |
} |
| 157 |
} |
| 158 |
} else { |
| 159 |
verbose -log "pch file '$bname$suffix.gch' missing" |
| 160 |
fail "$nshort $flags" |
| 161 |
if { !$have_errs } { |
| 162 |
verbose -log "assembly file '$bname.s' missing" 1 |
| 163 |
fail "$nshort $flags assembly comparison" |
| 164 |
} |
| 165 |
} |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
proc dg-pch { subdir test options suffix } { |
| 170 |
return [dg-flags-pch $subdir $test "" $options $suffix] |
| 171 |
} |