blob: 0c770120cc93f36cf03dcdbc180df7ee3c35fb49 [file] [log] [blame]
# Copyright (C) 2009-2021 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GCC; see the file COPYING3. If not see
# <http://www.gnu.org/licenses/>.
# We set LC_ALL and LANG to C so that we get the same error messages as expected.
setenv LC_ALL C
setenv LANG C
# Many hosts now default to a non-ASCII C locale, however, so
# they can set a charset encoding here if they need.
if { [ishost "*-*-cygwin*"] } {
setenv LC_ALL C.ASCII
setenv LANG C.ASCII
}
# Run the LANGUAGE compiler with GCC_OPTIONS and inspect the compiler
# output excluding EXCLUDE lines to make sure that they match the
# newline-separated patterns in COMPILER_PATTERNS but not the patterns in
# COMPILER_NON_PATTERNS. In case of failure, xfail if XFAIL is nonempty.
proc check_for_options_with_filter { language gcc_options exclude \
compiler_patterns \
compiler_non_patterns \
expected_failure } {
set test "compiler driver $gcc_options option(s):"
set gcc_options "\{additional_flags=$gcc_options\}"
switch "$language" {
"c" {
set compiler cc1
set suffix c
}
"c++" {
set compiler cc1plus
set suffix cc
}
default { error "unknown language" }
}
set filebase test-[pid]
set srcfname $filebase.$suffix
set fd [open $srcfname w]
puts $fd "int main (void) { return 0; }"
close $fd
remote_download host $srcfname
set gcc_output [gcc_target_compile $srcfname $filebase.x executable $gcc_options]
remote_file build delete $srcfname $filebase.x $filebase.gcno
if {[regexp -- "compiler not installed on this system" $gcc_output]} {
unsupported "$test: $language compiler not available"
return
}
if { $exclude != "" } {
set lines [split $gcc_output "\n"]
set gcc_output ""
foreach line $lines {
if {[regexp -line -- "$exclude" $line]} {
continue
}
if { $gcc_output == "" } {
set gcc_output "$line"
} else {
set gcc_output "$gcc_output\n$line"
}
}
}
# Verify that COMPILER_PATTERNS appear in gcc output.
foreach pattern [split $compiler_patterns "\n"] {
if {$pattern != ""} {
if {[regexp -line -- "$pattern" $gcc_output]} {
pass "$test $pattern"
} else {
if {$expected_failure != ""} {
xfail "$test \"$pattern\" present in output"
} else {
fail "$test \"$pattern\" present in output"
}
}
}
}
# Verify that COMPILER_NON_PATTERNS do not appear in gcc output.
foreach pattern [split $compiler_non_patterns "\n"] {
if {$pattern != ""} {
if {![regexp -line -- "$pattern" $gcc_output result]} {
pass "$test $pattern"
} else {
if {$expected_failure != ""} {
xfail "$test \"$pattern\" absent from output"
} else {
# Print the unexpected line that caused the failure
# to make it easier to find in the multiline output.
fail "$test \"$pattern\" absent from output: \"$result\""
}
}
}
}
}
# As check_for_options_with_filter, but without the EXCLUDE parameter.
proc check_for_options { language gcc_options compiler_patterns \
compiler_non_patterns expected_failure } {
check_for_options_with_filter $language $gcc_options "" $compiler_patterns \
$compiler_non_patterns $expected_failure
}