1 # Copyright (C) 2009-2023 Free Software Foundation, Inc.
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.
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.
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/>.
17 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
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*"] } {
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.
33 proc check_for_options_with_filter { language gcc_options exclude \
35 compiler_non_patterns \
37 set test "compiler driver $gcc_options option(s):"
38 set gcc_options "\{additional_flags=$gcc_options\}"
49 default { error "unknown language" }
52 set filebase test-[pid]
53 set srcfname $filebase.$suffix
54 set fd [open $srcfname w]
55 puts $fd "int main (void) { return 0; }"
57 remote_download host $srcfname
59 set gcc_output [gcc_target_compile $srcfname $filebase.x executable $gcc_options]
60 remote_file build delete $srcfname $filebase.x $filebase.gcno
62 if {[regexp -- "compiler not installed on this system" $gcc_output]} {
63 unsupported "$test: $language compiler not available"
67 if { $exclude != "" } {
68 set lines [split $gcc_output "\n"]
71 if {[regexp -line -- "$exclude" $line]} {
74 if { $gcc_output == "" } {
75 set gcc_output "$line"
77 set gcc_output "$gcc_output\n$line"
82 # Verify that COMPILER_PATTERNS appear in gcc output.
83 foreach pattern [split $compiler_patterns "\n"] {
85 if {[regexp -line -- "$pattern" $gcc_output]} {
88 if {$expected_failure != ""} {
89 xfail "$test \"$pattern\" present in output"
91 fail "$test \"$pattern\" present in output"
97 # Verify that COMPILER_NON_PATTERNS do not appear in gcc output.
98 foreach pattern [split $compiler_non_patterns "\n"] {
100 if {![regexp -line -- "$pattern" $gcc_output result]} {
101 pass "$test $pattern"
103 if {$expected_failure != ""} {
104 xfail "$test \"$pattern\" absent from output"
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\""
115 # As check_for_options_with_filter, but without the EXCLUDE parameter.
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