| 1 |
# Copyright (C) 2009-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 |
# We set LC_ALL and LANG to C so that we get the same error messages as expected. |
| 18 |
setenv LC_ALL C |
| 19 |
setenv LANG C |
| 20 |
|
| 21 |
# Many hosts now default to a non-ASCII C locale, however, so |
| 22 |
# they can set a charset encoding here if they need. |
| 23 |
if { [ishost "*-*-cygwin*"] } { |
| 24 |
setenv LC_ALL C.ASCII |
| 25 |
setenv LANG C.ASCII |
| 26 |
} |
| 27 |
|
| 28 |
# Run the LANGUAGE compiler with GCC_OPTIONS and inspect the compiler |
| 29 |
# output excluding EXCLUDE lines to make sure that they match the |
| 30 |
# newline-separated patterns in COMPILER_PATTERNS but not the patterns in |
| 31 |
# COMPILER_NON_PATTERNS. In case of failure, xfail if XFAIL is nonempty. |
| 32 |
|
| 33 |
proc check_for_options_with_filter { language gcc_options exclude \ |
| 34 |
compiler_patterns \ |
| 35 |
compiler_non_patterns \ |
| 36 |
expected_failure } { |
| 37 |
set test "compiler driver $gcc_options option(s):" |
| 38 |
set gcc_options "\{additional_flags=$gcc_options\}" |
| 39 |
|
| 40 |
switch "$language" { |
| 41 |
"c" { |
| 42 |
set compiler cc1 |
| 43 |
set suffix c |
| 44 |
} |
| 45 |
"c++" { |
| 46 |
set compiler cc1plus |
| 47 |
set suffix cc |
| 48 |
} |
| 49 |
default { error "unknown language" } |
| 50 |
} |
| 51 |
|
| 52 |
set filebase test-[pid] |
| 53 |
set srcfname $filebase.$suffix |
| 54 |
set fd [open $srcfname w] |
| 55 |
puts $fd "int main (void) { return 0; }" |
| 56 |
close $fd |
| 57 |
remote_download host $srcfname |
| 58 |
|
| 59 |
set gcc_output [gcc_target_compile $srcfname $filebase.x executable $gcc_options] |
| 60 |
remote_file build delete $srcfname $filebase.x $filebase.gcno |
| 61 |
|
| 62 |
if {[regexp -- "compiler not installed on this system|cannot execute" $gcc_output]} { |
| 63 |
unsupported "$test: $language compiler not available" |
| 64 |
return |
| 65 |
} |
| 66 |
|
| 67 |
if { $exclude != "" } { |
| 68 |
set lines [split $gcc_output "\n"] |
| 69 |
set gcc_output "" |
| 70 |
foreach line $lines { |
| 71 |
if {[regexp -line -- "$exclude" $line]} { |
| 72 |
continue |
| 73 |
} |
| 74 |
if { $gcc_output == "" } { |
| 75 |
set gcc_output "$line" |
| 76 |
} else { |
| 77 |
set gcc_output "$gcc_output\n$line" |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
# Verify that COMPILER_PATTERNS appear in gcc output. |
| 83 |
foreach pattern [split $compiler_patterns "\n"] { |
| 84 |
if {$pattern != ""} { |
| 85 |
if {[regexp -line -- "$pattern" $gcc_output]} { |
| 86 |
pass "$test $pattern" |
| 87 |
} else { |
| 88 |
if {$expected_failure != ""} { |
| 89 |
xfail "$test \"$pattern\" present in output" |
| 90 |
} else { |
| 91 |
fail "$test \"$pattern\" present in output" |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
# Verify that COMPILER_NON_PATTERNS do not appear in gcc output. |
| 98 |
foreach pattern [split $compiler_non_patterns "\n"] { |
| 99 |
if {$pattern != ""} { |
| 100 |
if {![regexp -line -- "$pattern" $gcc_output result]} { |
| 101 |
pass "$test $pattern" |
| 102 |
} else { |
| 103 |
if {$expected_failure != ""} { |
| 104 |
xfail "$test \"$pattern\" absent from output" |
| 105 |
} else { |
| 106 |
# Print the unexpected line that caused the failure |
| 107 |
# to make it easier to find in the multiline output. |
| 108 |
fail "$test \"$pattern\" absent from output: \"$result\"" |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
# As check_for_options_with_filter, but without the EXCLUDE parameter. |
| 116 |
|
| 117 |
proc check_for_options { language gcc_options compiler_patterns \ |
| 118 |
compiler_non_patterns expected_failure } { |
| 119 |
check_for_options_with_filter $language $gcc_options "" $compiler_patterns \ |
| 120 |
$compiler_non_patterns $expected_failure |
| 121 |
} |