Debian Codegraph @

gcc/testsuite/gcc.misc-tests/options.exp

raw
1 # Copyright (C) 2005-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 # Run the LANGUAGE compiler with GCC_OPTIONS and inspect the compiler,
18 # assembler and linker output (from gcc -v) to make sure that they
19 # match the patterns COMPILER_PATTERN, AS_PATTERN and LD_PATTERN,
20 # respectively.
21
22 load_lib gcc-defs.exp
23
24 # These tests don't run runtest_file_p consistently if it
25 # doesn't return the same values, so disable parallelization
26 # of this *.exp file. The first parallel runtest to reach
27 # this will run all the tests serially.
28 if ![gcc_parallel_test_run_p options] {
29 return
30 }
31 gcc_parallel_test_enable 0
32
33 proc check_for_all_options {language gcc_options compiler_pattern as_pattern ld_pattern} {
34 set filename test-[pid]
35 set fd [open $filename.c w]
36 puts $fd "int main (void) \{ return 0; \}"
37 close $fd
38 remote_download host $filename.c
39
40 set test "compiler driver $gcc_options option(s)"
41 set gcc_options "\{additional_flags=$gcc_options -v\}"
42
43 switch "$language" {
44 "c" { set compiler cc1 }
45 default { error "unknown language" }
46 }
47 set gcc_output [gcc_target_compile $filename.c $filename.x executable $gcc_options]
48 remote_file build delete $filename.c $filename.x $filename.gcno
49 set dumpfiles [glob -nocomplain $filename.c.*]
50 foreach dumpfile $dumpfiles {
51 remote_file build delete $dumpfile
52 }
53
54 if {![regexp -- "/${compiler}(\\.exe)? \[^\r\n\]*-quiet.*$compiler_pattern" $gcc_output]} {
55 fail "$test (compiler options)"
56 return
57 }
58 if {![regexp -- " *as(\\.exe)? .*$as_pattern" $gcc_output]} {
59 fail "$test (assembler options)"
60 return
61 }
62 # Match /collect2, /ld, or *-ld.
63 if {![regexp -- "(/collect2|\[-/\]ld)(\\.exe)? .*$ld_pattern" $gcc_output]} {
64 fail "$test (linker options)"
65 return
66 }
67 pass $test
68 }
69
70 if { [check_profiling_available "-fprofile-arcs"] } {
71 check_for_all_options c {--coverage} {-fprofile-arcs -ftest-coverage} {} {-lgcov}
72 }
73
74 proc get_dump_flags {} {
75 set res [list]
76
77 global srcdir
78 set file "$srcdir/../dumpfile.cc"
79
80 set a [open $file]
81 set lines [split [read $a] "\n"]
82 close $a
83
84 set domatch 0
85 foreach line $lines {
86 if { [regexp "dump_options.* =" $line] } {
87 set domatch 1
88 } elseif { [regexp "^\};" $line] } {
89 set domatch 0
90 }
91 if { $domatch } {
92 if { [regexp "\"(.*)\"" $line match submatch] } {
93 lappend res $submatch
94 }
95 }
96 }
97
98 return $res
99 }
100
101 foreach flag [get_dump_flags] {
102 check_for_all_options c -fdump-tree-all-$flag {} {} {}
103 check_for_all_options c -fdump-ipa-all-$flag {} {} {}
104 check_for_all_options c -fdump-rtl-all-$flag {} {} {}
105 check_for_all_options c -fdump-lang-all-$flag {} {} {}
106 }
107
108 gcc_parallel_test_enable 1