gcc-dg.exp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  1. # Copyright (C) 1997-2015 Free Software Foundation, Inc.
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 3 of the License, or
  5. # (at your option) any later version.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with GCC; see the file COPYING3. If not see
  14. # <http://www.gnu.org/licenses/>.
  15. load_lib dg.exp
  16. load_lib file-format.exp
  17. load_lib target-supports.exp
  18. load_lib target-supports-dg.exp
  19. load_lib scanasm.exp
  20. load_lib scanrtl.exp
  21. load_lib scantree.exp
  22. load_lib scanipa.exp
  23. load_lib timeout.exp
  24. load_lib timeout-dg.exp
  25. load_lib prune.exp
  26. load_lib libgloss.exp
  27. load_lib target-libpath.exp
  28. load_lib torture-options.exp
  29. load_lib fortran-modules.exp
  30. # We set LC_ALL and LANG to C so that we get the same error messages as expected.
  31. setenv LC_ALL C
  32. setenv LANG C
  33. # Many hosts now default to a non-ASCII C locale, however, so
  34. # they can set a charset encoding here if they need.
  35. if { [ishost "*-*-cygwin*"] } {
  36. setenv LC_ALL C.ASCII
  37. setenv LANG C.ASCII
  38. }
  39. global GCC_UNDER_TEST
  40. if ![info exists GCC_UNDER_TEST] {
  41. set GCC_UNDER_TEST "[find_gcc]"
  42. }
  43. if [info exists TORTURE_OPTIONS] {
  44. set DG_TORTURE_OPTIONS $TORTURE_OPTIONS
  45. } else {
  46. # It is theoretically beneficial to group all of the O2/O3 options together,
  47. # as in many cases the compiler will generate identical executables for
  48. # all of them--and the c-torture testsuite will skip testing identical
  49. # executables multiple times.
  50. # Also note that -finline-functions is explicitly included in one of the
  51. # items below, even though -O3 is also specified, because some ports may
  52. # choose to disable inlining functions by default, even when optimizing.
  53. set DG_TORTURE_OPTIONS [list \
  54. { -O0 } \
  55. { -O1 } \
  56. { -O2 } \
  57. { -O3 -fomit-frame-pointer } \
  58. { -O3 -fomit-frame-pointer -funroll-loops } \
  59. { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
  60. { -O3 -g } \
  61. { -Os } ]
  62. }
  63. if [info exists ADDITIONAL_TORTURE_OPTIONS] {
  64. set DG_TORTURE_OPTIONS \
  65. [concat $DG_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
  66. }
  67. global orig_environment_saved
  68. # This file may be sourced, so don't override environment settings
  69. # that have been previously setup.
  70. if { $orig_environment_saved == 0 } {
  71. append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
  72. set_ld_library_path_env_vars
  73. }
  74. # Some torture-options cause intermediate code output, unusable for
  75. # testing using e.g. scan-assembler. In this variable are the options
  76. # how to force it, when needed.
  77. global gcc_force_conventional_output
  78. set gcc_force_conventional_output ""
  79. set LTO_TORTURE_OPTIONS ""
  80. if [check_effective_target_lto] {
  81. # When having plugin test both slim and fat LTO and plugin/nonplugin
  82. # path.
  83. if [check_linker_plugin_available] {
  84. set LTO_TORTURE_OPTIONS [list \
  85. { -O2 -flto -fno-use-linker-plugin -flto-partition=none } \
  86. { -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects }
  87. ]
  88. set gcc_force_conventional_output "-ffat-lto-objects"
  89. } else {
  90. set LTO_TORTURE_OPTIONS [list \
  91. { -O2 -flto -flto-partition=none } \
  92. { -O2 -flto }
  93. ]
  94. }
  95. }
  96. # Define gcc callbacks for dg.exp.
  97. proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
  98. # Set up the compiler flags, based on what we're going to do.
  99. set options [list]
  100. # Tests should be able to use "dg-do repo". However, the dg test
  101. # driver checks the argument to dg-do against a list of acceptable
  102. # options, and "repo" is not among them. Therefore, we resort to
  103. # this ugly approach.
  104. if [string match "*-frepo*" $extra_tool_flags] then {
  105. set do_what "repo"
  106. }
  107. switch $do_what {
  108. "preprocess" {
  109. set compile_type "preprocess"
  110. set output_file "[file rootname [file tail $prog]].i"
  111. }
  112. "compile" {
  113. set compile_type "assembly"
  114. set output_file "[file rootname [file tail $prog]].s"
  115. }
  116. "assemble" {
  117. set compile_type "object"
  118. set output_file "[file rootname [file tail $prog]].o"
  119. }
  120. "precompile" {
  121. set compile_type "precompiled_header"
  122. set output_file "[file tail $prog].gch"
  123. }
  124. "link" {
  125. set compile_type "executable"
  126. set output_file "[file rootname [file tail $prog]].exe"
  127. # The following line is needed for targets like the i960 where
  128. # the default output file is b.out. Sigh.
  129. }
  130. "repo" {
  131. set compile_type "object"
  132. set output_file "[file rootname [file tail $prog]].o"
  133. }
  134. "run" {
  135. set compile_type "executable"
  136. # FIXME: "./" is to cope with "." not being in $PATH.
  137. # Should this be handled elsewhere?
  138. # YES.
  139. set output_file "./[file rootname [file tail $prog]].exe"
  140. # This is the only place where we care if an executable was
  141. # created or not. If it was, dg.exp will try to run it.
  142. catch { remote_file build delete $output_file }
  143. }
  144. default {
  145. perror "$do_what: not a valid dg-do keyword"
  146. return ""
  147. }
  148. }
  149. # Let { dg-final { action } } force options as returned by an
  150. # optional proc ${action}_required_options.
  151. upvar 2 dg-final-code finalcode
  152. foreach x [split $finalcode "\n"] {
  153. set finalcmd [lindex $x 0]
  154. if { [info procs ${finalcmd}_required_options] != "" } {
  155. set req [${finalcmd}_required_options]
  156. if { $req != "" } {
  157. lappend extra_tool_flags $req
  158. }
  159. }
  160. }
  161. if { $extra_tool_flags != "" } {
  162. lappend options "additional_flags=$extra_tool_flags"
  163. }
  164. verbose "$target_compile $prog $output_file $compile_type $options" 4
  165. set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options]
  166. # Look for an internal compiler error, which sometimes masks the fact
  167. # that we didn't get an expected error message. XFAIL an ICE via
  168. # dg-xfail-if and use { dg-prune-output ".*internal compiler error.*" }
  169. # to avoid a second failure for excess errors.
  170. if [string match "*internal compiler error*" $comp_output] {
  171. upvar 2 name name
  172. fail "$name (internal compiler error)"
  173. }
  174. if { $do_what == "repo" } {
  175. set object_file "$output_file"
  176. set output_file "[file rootname [file tail $prog]].exe"
  177. set comp_output \
  178. [ concat $comp_output \
  179. [$target_compile "$object_file" "$output_file" \
  180. "executable" $options] ]
  181. }
  182. return [list $comp_output $output_file]
  183. }
  184. proc gcc-dg-test { prog do_what extra_tool_flags } {
  185. return [gcc-dg-test-1 gcc_target_compile $prog $do_what $extra_tool_flags]
  186. }
  187. proc gcc-dg-prune { system text } {
  188. global additional_prunes
  189. # Extra prune rules that will apply to tests defined in a .exp file.
  190. # Always remember to clear it in .exp file after executed all tests.
  191. global dg_runtest_extra_prunes
  192. set text [prune_gcc_output $text]
  193. foreach p "$additional_prunes $dg_runtest_extra_prunes" {
  194. if { [string length $p] > 0 } {
  195. # Following regexp matches a complete line containing $p.
  196. regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
  197. }
  198. }
  199. # If we see "region xxx is full" then the testcase is too big for ram.
  200. # This is tricky to deal with in a large testsuite like c-torture so
  201. # deal with it here. Just mark the testcase as unsupported.
  202. if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
  203. # The format here is important. See dg.exp.
  204. return "::unsupported::memory full"
  205. }
  206. if { [regexp "(^|\n)\[^\n\]*: relocation truncated to fit" $text]
  207. && [check_effective_target_tiny] } {
  208. return "::unsupported::memory full"
  209. }
  210. # Likewise, if we see ".text exceeds local store range" or
  211. # similar.
  212. if {[string match "spu-*" $system] && \
  213. [string match "*exceeds local store*" $text]} {
  214. # The format here is important. See dg.exp.
  215. return "::unsupported::memory full"
  216. }
  217. return $text
  218. }
  219. # Replace ${tool}_load with a wrapper to provide for an expected nonzero
  220. # exit status. Multiple languages include this file so this handles them
  221. # all, not just gcc.
  222. if { [info procs ${tool}_load] != [list] \
  223. && [info procs saved_${tool}_load] == [list] } {
  224. rename ${tool}_load saved_${tool}_load
  225. proc ${tool}_load { program args } {
  226. global tool
  227. global shouldfail
  228. global set_target_env_var
  229. set saved_target_env_var [list]
  230. if { [info exists set_target_env_var] \
  231. && [llength $set_target_env_var] != 0 } {
  232. if { [is_remote target] } {
  233. return [list "unsupported" ""]
  234. }
  235. set-target-env-var
  236. }
  237. set result [eval [list saved_${tool}_load $program] $args]
  238. if { [info exists set_target_env_var] \
  239. && [llength $set_target_env_var] != 0 } {
  240. restore-target-env-var
  241. }
  242. if { $shouldfail != 0 } {
  243. switch [lindex $result 0] {
  244. "pass" { set status "fail" }
  245. "fail" { set status "pass" }
  246. }
  247. set result [list $status [lindex $result 1]]
  248. }
  249. set result [list [lindex $result 0] [prune_file_path [lindex $result 1]]]
  250. return $result
  251. }
  252. }
  253. proc dg-set-target-env-var { args } {
  254. global set_target_env_var
  255. if { [llength $args] != 3 } {
  256. error "dg-set-target-env-var: need two arguments"
  257. return
  258. }
  259. lappend set_target_env_var [list [lindex $args 1] [lindex $args 2]]
  260. }
  261. proc set-target-env-var { } {
  262. global set_target_env_var
  263. upvar 1 saved_target_env_var saved_target_env_var
  264. foreach env_var $set_target_env_var {
  265. set var [lindex $env_var 0]
  266. set value [lindex $env_var 1]
  267. if [info exists ::env($var)] {
  268. lappend saved_target_env_var [list $var 1 $::env($var)]
  269. } else {
  270. lappend saved_target_env_var [list $var 0]
  271. }
  272. setenv $var $value
  273. }
  274. }
  275. proc restore-target-env-var { } {
  276. upvar 1 saved_target_env_var saved_target_env_var
  277. for { set env_vari [llength $saved_target_env_var] } {
  278. [incr env_vari -1] >= 0 } {} {
  279. set env_var [lindex $saved_target_env_var $env_vari]
  280. set var [lindex $env_var 0]
  281. if [lindex $env_var 1] {
  282. setenv $var [lindex $env_var 2]
  283. } else {
  284. unsetenv $var
  285. }
  286. }
  287. }
  288. # Utility routines.
  289. #
  290. # search_for -- looks for a string match in a file
  291. #
  292. proc search_for { file pattern } {
  293. set fd [open $file r]
  294. while { [gets $fd cur_line]>=0 } {
  295. if [string match "*$pattern*" $cur_line] then {
  296. close $fd
  297. return 1
  298. }
  299. }
  300. close $fd
  301. return 0
  302. }
  303. # Modified dg-runtest that can cycle through a list of optimization options
  304. # as c-torture does.
  305. proc gcc-dg-runtest { testcases flags default-extra-flags } {
  306. global runtests
  307. # Some callers set torture options themselves; don't override those.
  308. set existing_torture_options [torture-options-exist]
  309. if { $existing_torture_options == 0 } {
  310. global DG_TORTURE_OPTIONS LTO_TORTURE_OPTIONS
  311. torture-init
  312. set-torture-options $DG_TORTURE_OPTIONS [list {}] $LTO_TORTURE_OPTIONS
  313. }
  314. dump-torture-options
  315. foreach test $testcases {
  316. global torture_with_loops torture_without_loops
  317. # If we're only testing specific files and this isn't one of
  318. # them, skip it.
  319. if ![runtest_file_p $runtests $test] {
  320. continue
  321. }
  322. # Look for a loop within the source code - if we don't find one,
  323. # don't pass -funroll[-all]-loops.
  324. if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
  325. set option_list $torture_with_loops
  326. } else {
  327. set option_list $torture_without_loops
  328. }
  329. set nshort [file tail [file dirname $test]]/[file tail $test]
  330. foreach flags_t $option_list {
  331. verbose "Testing $nshort, $flags $flags_t" 1
  332. dg-test $test "$flags $flags_t" ${default-extra-flags}
  333. }
  334. }
  335. if { $existing_torture_options == 0 } {
  336. torture-finish
  337. }
  338. }
  339. proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
  340. global srcdir subdir
  341. if ![info exists DEBUG_TORTURE_OPTIONS] {
  342. set DEBUG_TORTURE_OPTIONS ""
  343. foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
  344. set comp_output [$target_compile \
  345. "$srcdir/$subdir/$trivial" "trivial.S" assembly \
  346. "additional_flags=$type"]
  347. if { ! [string match "*: target system does not support the * debug format*" \
  348. $comp_output] } {
  349. remove-build-file "trivial.S"
  350. foreach level {1 "" 3} {
  351. if { ($type == "-gdwarf-2") && ($level != "") } {
  352. lappend DEBUG_TORTURE_OPTIONS [list "${type}" "-g${level}"]
  353. foreach opt $opt_opts {
  354. lappend DEBUG_TORTURE_OPTIONS \
  355. [list "${type}" "-g${level}" "$opt" ]
  356. }
  357. } else {
  358. lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
  359. foreach opt $opt_opts {
  360. lappend DEBUG_TORTURE_OPTIONS \
  361. [list "${type}${level}" "$opt" ]
  362. }
  363. }
  364. }
  365. }
  366. }
  367. }
  368. verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
  369. global runtests
  370. foreach test $testcases {
  371. # If we're only testing specific files and this isn't one of
  372. # them, skip it.
  373. if ![runtest_file_p $runtests $test] {
  374. continue
  375. }
  376. set nshort [file tail [file dirname $test]]/[file tail $test]
  377. foreach flags $DEBUG_TORTURE_OPTIONS {
  378. set doit 1
  379. # These tests check for information which may be deliberately
  380. # suppressed at -g1.
  381. if { ([string match {*/debug-[126].c} "$nshort"] \
  382. || [string match {*/enum-1.c} "$nshort"] \
  383. || [string match {*/enum-[12].C} "$nshort"]) \
  384. && ([string match "*1" [lindex "$flags" 0] ]
  385. || [lindex "$flags" 1] == "-g1") } {
  386. set doit 0
  387. }
  388. # High optimization can remove the variable whose existence is tested.
  389. # Dwarf debugging with commentary (-dA) preserves the symbol name in the
  390. # assembler output, but stabs debugging does not.
  391. # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
  392. if { [string match {*/debug-[12].c} "$nshort"] \
  393. && [string match "*O*" "$flags"] \
  394. && ( [string match "*coff*" "$flags"] \
  395. || [string match "*stabs*" "$flags"] ) } {
  396. set doit 0
  397. }
  398. if { $doit } {
  399. verbose -log "Testing $nshort, $flags" 1
  400. dg-test $test $flags ""
  401. }
  402. }
  403. }
  404. }
  405. # Prune any messages matching ARGS[1] (a regexp) from test output.
  406. proc dg-prune-output { args } {
  407. global additional_prunes
  408. if { [llength $args] != 2 } {
  409. error "[lindex $args 1]: need one argument"
  410. return
  411. }
  412. lappend additional_prunes [lindex $args 1]
  413. }
  414. # Remove files matching the pattern from the build machine.
  415. proc remove-build-file { pat } {
  416. verbose "remove-build-file `$pat'" 2
  417. set file_list "[glob -nocomplain $pat]"
  418. verbose "remove-build-file `$file_list'" 2
  419. foreach output_file $file_list {
  420. if [is_remote host] {
  421. # Ensure the host knows the file is gone by deleting there
  422. # first.
  423. remote_file host delete $output_file
  424. }
  425. remote_file build delete $output_file
  426. }
  427. }
  428. # Remove runtime-generated profile file for the current test.
  429. proc cleanup-profile-file { } {
  430. remove-build-file "mon.out"
  431. remove-build-file "gmon.out"
  432. }
  433. # Remove compiler-generated coverage files for the current test.
  434. proc cleanup-coverage-files { } {
  435. global additional_sources_used
  436. set testcase [testname-for-summary]
  437. # The name might include a list of options; extract the file name.
  438. set testcase [lindex $testcase 0]
  439. remove-build-file "[file rootname [file tail $testcase]].gc??"
  440. # Clean up coverage files for additional source files.
  441. if [info exists additional_sources_used] {
  442. foreach srcfile $additional_sources_used {
  443. remove-build-file "[file rootname [file tail $srcfile]].gc??"
  444. }
  445. }
  446. }
  447. # Remove compiler-generated files from -repo for the current test.
  448. proc cleanup-repo-files { } {
  449. global additional_sources_used
  450. set testcase [testname-for-summary]
  451. # The name might include a list of options; extract the file name.
  452. set testcase [lindex $testcase 0]
  453. remove-build-file "[file rootname [file tail $testcase]].o"
  454. remove-build-file "[file rootname [file tail $testcase]].rpo"
  455. # Clean up files for additional source files.
  456. if [info exists additional_sources_used] {
  457. foreach srcfile $additional_sources_used {
  458. remove-build-file "[file rootname [file tail $srcfile]].o"
  459. remove-build-file "[file rootname [file tail $srcfile]].rpo"
  460. }
  461. }
  462. }
  463. # Remove compiler-generated RTL dump files for the current test.
  464. #
  465. # SUFFIX is the filename suffix pattern.
  466. proc cleanup-rtl-dump { suffix } {
  467. cleanup-dump "\[0-9\]\[0-9\]\[0-9\]r.$suffix"
  468. }
  469. # Remove a specific tree dump file for the current test.
  470. #
  471. # SUFFIX is the tree dump file suffix pattern.
  472. proc cleanup-tree-dump { suffix } {
  473. cleanup-dump "\[0-9\]\[0-9\]\[0-9\]t.$suffix"
  474. }
  475. # Remove a specific ipa dump file for the current test.
  476. #
  477. # SUFFIX is the ipa dump file suffix pattern.
  478. proc cleanup-ipa-dump { suffix } {
  479. cleanup-dump "\[0-9\]\[0-9\]\[0-9\]i.$suffix"
  480. }
  481. # Remove a final insns dump file for the current test.
  482. proc cleanup-final-insns-dump { } {
  483. set testcase [testname-for-summary]
  484. # The name might include a list of options; extract the file name.
  485. set testcase [lindex $testcase 0]
  486. remove-build-file "[file rootname [file tail $testcase]].s.gkd"
  487. # Clean up files for additional source files.
  488. if [info exists additional_sources_used] {
  489. foreach srcfile $additional_sources_used {
  490. remove-build-file "[file rootname [file tail $srcfile]].s.gkd"
  491. }
  492. }
  493. }
  494. # Remove a stack usage file for the current test.
  495. proc cleanup-stack-usage { } {
  496. set testcase [testname-for-summary]
  497. # The name might include a list of options; extract the file name.
  498. set testcase [lindex $testcase 0]
  499. remove-build-file "[file rootname [file tail $testcase]].su"
  500. # Clean up files for additional source files.
  501. if [info exists additional_sources_used] {
  502. foreach srcfile $additional_sources_used {
  503. remove-build-file "[file rootname [file tail $srcfile]].su"
  504. }
  505. }
  506. }
  507. # Remove an Ada spec file for the current test.
  508. proc cleanup-ada-spec { } {
  509. global additional_sources_used
  510. set testcase [testname-for-summary]
  511. remove-build-file "[get_ada_spec_filename $testcase]"
  512. # Clean up files for additional source files.
  513. if [info exists additional_sources_used] {
  514. foreach srcfile $additional_sources_used {
  515. remove-build-file "[get_ada_spec_filename $srcfile]"
  516. }
  517. }
  518. }
  519. # Remove all dump files with the provided suffix.
  520. proc cleanup-dump { suffix } {
  521. global additional_sources_used
  522. set testcase [testname-for-summary]
  523. # The name might include a list of options; extract the file name.
  524. set src [file tail [lindex $testcase 0]]
  525. remove-build-file "[file tail $src].$suffix"
  526. remove-build-file "[file rootname [file tail $src]].exe.$suffix"
  527. remove-build-file "[file rootname [file tail $src]].exe.ltrans\[0-9\]*.$suffix"
  528. # -fcompare-debug dumps
  529. remove-build-file "[file tail $src].gk.$suffix"
  530. # Clean up dump files for additional source files.
  531. if [info exists additional_sources_used] {
  532. foreach srcfile $additional_sources_used {
  533. remove-build-file "[file tail $srcfile].$suffix"
  534. remove-build-file "[file rootname [file tail $srcfile]].exe.$suffix"
  535. remove-build-file "[file rootname [file tail $srcfile]].exe.ltrans\[0-9\]*.$suffix"
  536. # -fcompare-debug dumps
  537. remove-build-file "[file tail $srcfile].gk.$suffix"
  538. }
  539. }
  540. }
  541. # Remove files kept by --save-temps for the current test.
  542. #
  543. # Currently this is only .i, .ii, .s and .o files, but more can be added
  544. # if there are tests generating them.
  545. # ARGS is a list of suffixes to NOT delete.
  546. proc cleanup-saved-temps { args } {
  547. global additional_sources_used
  548. set suffixes {}
  549. # add the to-be-kept suffixes
  550. foreach suffix {".mii" ".ii" ".i" ".s" ".o" ".gkd" ".res" ".ltrans.out"} {
  551. if {[lsearch $args $suffix] < 0} {
  552. lappend suffixes $suffix
  553. }
  554. }
  555. set testcase [testname-for-summary]
  556. # The name might include a list of options; extract the file name.
  557. set testcase [lindex $testcase 0]
  558. foreach suffix $suffixes {
  559. remove-build-file "[file rootname [file tail $testcase]]$suffix"
  560. remove-build-file "[file rootname [file tail $testcase]].exe$suffix"
  561. remove-build-file "[file rootname [file tail $testcase]].exe.ltrans\[0-9\]*$suffix"
  562. # -fcompare-debug dumps
  563. remove-build-file "[file rootname [file tail $testcase]].gk$suffix"
  564. }
  565. # Clean up saved temp files for additional source files.
  566. if [info exists additional_sources_used] {
  567. foreach srcfile $additional_sources_used {
  568. foreach suffix $suffixes {
  569. remove-build-file "[file rootname [file tail $srcfile]]$suffix"
  570. remove-build-file "[file rootname [file tail $srcfile]].exe$suffix"
  571. remove-build-file "[file rootname [file tail $srcfile]].exe.ltrans\[0-9\]*$suffix"
  572. # -fcompare-debug dumps
  573. remove-build-file "[file rootname [file tail $srcfile]].gk$suffix"
  574. }
  575. }
  576. }
  577. }
  578. # Scan Fortran modules for a given regexp.
  579. #
  580. # Argument 0 is the module name
  581. # Argument 1 is the regexp to match
  582. proc scan-module { args } {
  583. set modfilename [string tolower [lindex $args 0]].mod
  584. set fd [open [list | gzip -dc $modfilename] r]
  585. set text [read $fd]
  586. close $fd
  587. set testcase [testname-for-summary]
  588. if [regexp -- [lindex $args 1] $text] {
  589. pass "$testcase scan-module [lindex $args 1]"
  590. } else {
  591. fail "$testcase scan-module [lindex $args 1]"
  592. }
  593. }
  594. # Scan Fortran modules for absence of a given regexp.
  595. #
  596. # Argument 0 is the module name
  597. # Argument 1 is the regexp to match
  598. proc scan-module-absence { args } {
  599. set modfilename [string tolower [lindex $args 0]].mod
  600. set fd [open [list | gzip -dc $modfilename] r]
  601. set text [read $fd]
  602. close $fd
  603. set testcase [testname-for-summary]
  604. if [regexp -- [lindex $args 1] $text] {
  605. fail "$testcase scan-module [lindex $args 1]"
  606. } else {
  607. pass "$testcase scan-module [lindex $args 1]"
  608. }
  609. }
  610. # Verify that the compiler output file exists, invoked via dg-final.
  611. proc output-exists { args } {
  612. # Process an optional target or xfail list.
  613. if { [llength $args] >= 1 } {
  614. switch [dg-process-target [lindex $args 0]] {
  615. "S" { }
  616. "N" { return }
  617. "F" { setup_xfail "*-*-*" }
  618. "P" { }
  619. }
  620. }
  621. set testcase [testname-for-summary]
  622. # Access variable from gcc-dg-test-1.
  623. upvar 2 output_file output_file
  624. if [file exists $output_file] {
  625. pass "$testcase output-exists $output_file"
  626. } else {
  627. fail "$testcase output-exists $output_file"
  628. }
  629. }
  630. # Verify that the compiler output file does not exist, invoked via dg-final.
  631. proc output-exists-not { args } {
  632. # Process an optional target or xfail list.
  633. if { [llength $args] >= 1 } {
  634. switch [dg-process-target [lindex $args 0]] {
  635. "S" { }
  636. "N" { return }
  637. "F" { setup_xfail "*-*-*" }
  638. "P" { }
  639. }
  640. }
  641. set testcase [testname-for-summary]
  642. # Access variable from gcc-dg-test-1.
  643. upvar 2 output_file output_file
  644. if [file exists $output_file] {
  645. fail "$testcase output-exists-not $output_file"
  646. } else {
  647. pass "$testcase output-exists-not $output_file"
  648. }
  649. }
  650. # We need to make sure that additional_* are cleared out after every
  651. # test. It is not enough to clear them out *before* the next test run
  652. # because gcc-target-compile gets run directly from some .exp files
  653. # (outside of any test). (Those uses should eventually be eliminated.)
  654. # Because the DG framework doesn't provide a hook that is run at the
  655. # end of a test, we must replace dg-test with a wrapper.
  656. if { [info procs saved-dg-test] == [list] } {
  657. rename dg-test saved-dg-test
  658. proc dg-test { args } {
  659. global additional_files
  660. global additional_sources
  661. global additional_prunes
  662. global errorInfo
  663. global compiler_conditional_xfail_data
  664. global shouldfail
  665. global testname_with_flags
  666. global set_target_env_var
  667. if { [ catch { eval saved-dg-test $args } errmsg ] } {
  668. set saved_info $errorInfo
  669. set additional_files ""
  670. set additional_sources ""
  671. set additional_sources_used ""
  672. set additional_prunes ""
  673. set shouldfail 0
  674. if [info exists compiler_conditional_xfail_data] {
  675. unset compiler_conditional_xfail_data
  676. }
  677. if [info exists testname_with_flags] {
  678. unset testname_with_flags
  679. }
  680. unset_timeout_vars
  681. error $errmsg $saved_info
  682. }
  683. set additional_files ""
  684. set additional_sources ""
  685. set additional_sources_used ""
  686. set additional_prunes ""
  687. set shouldfail 0
  688. if [info exists set_target_env_var] {
  689. unset set_target_env_var
  690. }
  691. unset_timeout_vars
  692. if [info exists compiler_conditional_xfail_data] {
  693. unset compiler_conditional_xfail_data
  694. }
  695. if [info exists testname_with_flags] {
  696. unset testname_with_flags
  697. }
  698. }
  699. }
  700. if { [info procs saved-dg-warning] == [list] \
  701. && [info exists gcc_warning_prefix] } {
  702. rename dg-warning saved-dg-warning
  703. proc dg-warning { args } {
  704. # Make this variable available here and to the saved proc.
  705. upvar dg-messages dg-messages
  706. global gcc_warning_prefix
  707. process-message saved-dg-warning "$gcc_warning_prefix" "$args"
  708. }
  709. }
  710. if { [info procs saved-dg-error] == [list] \
  711. && [info exists gcc_error_prefix] } {
  712. rename dg-error saved-dg-error
  713. proc dg-error { args } {
  714. # Make this variable available here and to the saved proc.
  715. upvar dg-messages dg-messages
  716. global gcc_error_prefix
  717. process-message saved-dg-error "$gcc_error_prefix" "$args"
  718. }
  719. # Override dg-bogus at the same time. It doesn't handle a prefix
  720. # but its expression should include a column number. Otherwise the
  721. # line number can match the column number for other messages, leading
  722. # to insanity.
  723. rename dg-bogus saved-dg-bogus
  724. proc dg-bogus { args } {
  725. upvar dg-messages dg-messages
  726. process-message saved-dg-bogus "" $args
  727. }
  728. }
  729. # Modify the regular expression saved by a DejaGnu message directive to
  730. # include a prefix and to force the expression to match a single line.
  731. # MSGPROC is the procedure to call.
  732. # MSGPREFIX is the prefix to prepend.
  733. # DGARGS is the original argument list.
  734. proc process-message { msgproc msgprefix dgargs } {
  735. upvar dg-messages dg-messages
  736. # Process the dg- directive, including adding the regular expression
  737. # to the new message entry in dg-messages.
  738. set msgcnt [llength ${dg-messages}]
  739. eval $msgproc $dgargs
  740. # If the target expression wasn't satisfied there is no new message.
  741. if { [llength ${dg-messages}] == $msgcnt } {
  742. return;
  743. }
  744. # Get the entry for the new message. Prepend the message prefix to
  745. # the regular expression and make it match a single line.
  746. set newentry [lindex ${dg-messages} end]
  747. set expmsg [lindex $newentry 2]
  748. # Handle column numbers from the specified expression (if there is
  749. # one) and set up the search expression that will be used by DejaGnu.
  750. if [regexp "^(\[0-9\]+):" $expmsg "" column] {
  751. # The expression in the directive included a column number.
  752. # Remove "COLUMN:" from the original expression and move it
  753. # to the proper place in the search expression.
  754. regsub "^\[0-9\]+:" $expmsg "" expmsg
  755. set expmsg "$column: $msgprefix\[^\n\]*$expmsg"
  756. } elseif [string match "" [lindex $newentry 0]] {
  757. # The specified line number is 0; don't expect a column number.
  758. set expmsg "$msgprefix\[^\n\]*$expmsg"
  759. } else {
  760. # There is no column number in the search expression, but we
  761. # should expect one in the message itself.
  762. set expmsg "\[0-9\]+: $msgprefix\[^\n\]*$expmsg"
  763. }
  764. set newentry [lreplace $newentry 2 2 $expmsg]
  765. set dg-messages [lreplace ${dg-messages} end end $newentry]
  766. verbose "process-message:\n${dg-messages}" 2
  767. }
  768. # Look for messages that don't have standard prefixes.
  769. proc dg-message { args } {
  770. upvar dg-messages dg-messages
  771. process-message saved-dg-warning "" $args
  772. }
  773. # Check the existence of a gdb in the path, and return true if there
  774. # is one.
  775. #
  776. # Set env(GDB_FOR_GCC_TESTING) accordingly.
  777. proc gdb-exists { args } {
  778. if ![info exists ::env(GDB_FOR_GCC_TESTING)] {
  779. global GDB
  780. if ![info exists ::env(GDB_FOR_GCC_TESTING)] {
  781. if [info exists GDB] {
  782. setenv GDB_FOR_GCC_TESTING "$GDB"
  783. } else {
  784. setenv GDB_FOR_GCC_TESTING "[transform gdb]"
  785. }
  786. }
  787. }
  788. if { [which $::env(GDB_FOR_GCC_TESTING)] != 0 } {
  789. return 1;
  790. }
  791. return 0;
  792. }
  793. set additional_prunes ""
  794. set dg_runtest_extra_prunes ""