1# Copyright (C) 2009-2019 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. 18setenv LC_ALL C 19setenv 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. 23if { [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 33proc check_for_options_with_filter { language gcc_options exclude \ 34 compiler_patterns \ 35 compiler_non_patterns \ 36 expected_failure } { 37 set filename test-[pid] 38 set fd [open $filename.c w] 39 puts $fd "int main (void) { return 0; }" 40 close $fd 41 remote_download host $filename.c 42 43 set test "compiler driver $gcc_options option(s):" 44 set gcc_options "\{additional_flags=$gcc_options\}" 45 46 switch "$language" { 47 "c" { set compiler cc1 } 48 default { error "unknown language" } 49 } 50 set gcc_output [gcc_target_compile $filename.c $filename.x executable $gcc_options] 51 remote_file build delete $filename.c $filename.x $filename.gcno 52 53 if { $exclude != "" } { 54 set lines [split $gcc_output "\n"] 55 set gcc_output "" 56 foreach line $lines { 57 if {[regexp -line -- "$exclude" $line]} { 58 continue 59 } 60 if { $gcc_output == "" } { 61 set gcc_output "$line" 62 } else { 63 set gcc_output "$gcc_output\n$line" 64 } 65 } 66 } 67 68 # Verify that COMPILER_PATTERRNS appear in gcc output. 69 foreach pattern [split $compiler_patterns "\n"] { 70 if {$pattern != ""} { 71 if {[regexp -line -- "$pattern" $gcc_output]} { 72 pass "$test $pattern" 73 } else { 74 if {$expected_failure != ""} { 75 xfail "$test \"$pattern\" present in output" 76 } else { 77 fail "$test \"$pattern\" present in output" 78 } 79 } 80 } 81 } 82 83 # Verify that COMPILER_NON_PATTERRNS do not appear in gcc output. 84 foreach pattern [split $compiler_non_patterns "\n"] { 85 if {$pattern != ""} { 86 if {![regexp -line -- "$pattern" $gcc_output result]} { 87 pass "$test $pattern" 88 } else { 89 if {$expected_failure != ""} { 90 xfail "$test \"$pattern\" absent from output" 91 } else { 92 # Print the unexpected line that caused the failure 93 # to make it easier to find in the multiline output. 94 fail "$test \"$pattern\" absent from output: \"$result\"" 95 } 96 } 97 } 98 } 99} 100 101# As check_for_options_with_filter, but without the EXCLUDE parameter. 102 103proc check_for_options { language gcc_options compiler_patterns \ 104 compiler_non_patterns expected_failure } { 105 check_for_options_with_filter $language $gcc_options "" $compiler_patterns \ 106 $compiler_non_patterns $expected_failure 107} 108