| 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 |
# This file contains a set of test that check that gcc options are |
| 18 |
# documented in --help, and that the various --help* options work. |
| 19 |
|
| 20 |
load_lib options.exp |
| 21 |
load_lib gcc-defs.exp |
| 22 |
|
| 23 |
# These tests don't run runtest_file_p consistently if it |
| 24 |
# doesn't return the same values, so disable parallelization |
| 25 |
# of this *.exp file. The first parallel runtest to reach |
| 26 |
# this will run all the tests serially. |
| 27 |
if ![gcc_parallel_test_run_p help] { |
| 28 |
return |
| 29 |
} |
| 30 |
gcc_parallel_test_enable 0 |
| 31 |
|
| 32 |
# GCC breaks up --help output into lines at most $COLUMNS characters |
| 33 |
# wide (or 80 when COLUMNS is not defined), set the COLUMNS environment |
| 34 |
# variable to a value large enough to prevent this (and restore it when |
| 35 |
# done). |
| 36 |
global env |
| 37 |
|
| 38 |
if [ info exists env(COLUMNS) ] { |
| 39 |
set prev_columns $env(COLUMNS) |
| 40 |
} |
| 41 |
|
| 42 |
set env(COLUMNS) 1024 |
| 43 |
|
| 44 |
# Document --version. Ideally, there should be no undocumented switches |
| 45 |
# in --help. |
| 46 |
check_for_options c "--help" "--version" "This option lacks documentation" "" |
| 47 |
|
| 48 |
# Output from different subprocesses should not be intermingled |
| 49 |
# (we check for some patterns that could be seen with a missing |
| 50 |
# fflush in gcc.c). |
| 51 |
check_for_options c "-v --help" "" { |
| 52 |
[^\n]The following options |
| 53 |
-Wconversion[^\n]*lacks documentation |
| 54 |
" -g " |
| 55 |
} "" |
| 56 |
|
| 57 |
# There are still undocumented switches in -v --help. |
| 58 |
check_for_options c "-v --help" "" "This option lacks documentation" "xfail" |
| 59 |
|
| 60 |
# Check whether multiline conversion in optc-gen is broken. |
| 61 |
check_for_options c "-v --help" "" {are likely to\n -std} "" |
| 62 |
|
| 63 |
# Try various --help= classes and qualifiers. |
| 64 |
check_for_options c "--help=optimizers" "-O" " -g " "" |
| 65 |
check_for_options c "--help=params" "maximum number of" "-Wunsafe-loop-optimizations" "" |
| 66 |
check_for_options_with_filter c "--help=params" \ |
| 67 |
"^The following options control parameters:$" "" {[^.]$} "" |
| 68 |
check_for_options c "--help=C" "-ansi" "-gnatO" "" |
| 69 |
check_for_options c {--help=C++} {-std=c\+\+} "-gnatO" "" |
| 70 |
check_for_options c "--help=common" "-dumpbase" "-gnatO" "" |
| 71 |
check_for_options c "--help=undocumented" "This option lacks documentation" "" "" |
| 72 |
|
| 73 |
# Undocumented flags are not yet consistently marked as such. |
| 74 |
check_for_options c "--help=^undocumented" "-Wall" "This option lacks documentation" "xfail" |
| 75 |
|
| 76 |
# Try some --help=* examples from the manual. |
| 77 |
check_for_options c "--help=target,undocumented" "" "" "" |
| 78 |
check_for_options c "--help=target,optimizers" "" "" "" |
| 79 |
check_for_options c "--help=warnings,^joined,^undocumented" "" "" "" |
| 80 |
check_for_options c "-Q -O2 --help=optimizers" { |
| 81 |
-O |
| 82 |
-ftree-loop-vectorize[^\n]*enabled |
| 83 |
} " -g " "" |
| 84 |
check_for_options c "-Q -O3 --help=optimizers" { |
| 85 |
-O |
| 86 |
-ftree-loop-vectorize[^\n]*enabled |
| 87 |
} " -g " "" |
| 88 |
# Try repeated --help=. |
| 89 |
check_for_options c "--help=params --help=optimizers" { |
| 90 |
maximum number of |
| 91 |
-O |
| 92 |
} "" "" |
| 93 |
|
| 94 |
# Verify that a C++/Objective C++ only option is indicated as such |
| 95 |
# by the C compiler. |
| 96 |
check_for_options c "-Q --help=warnings" { |
| 97 |
-Wclass-memaccess[ \t]+\[available in C\+\+, ObjC\+\+\] |
| 98 |
} "" "" |
| 99 |
|
| 100 |
# Do the same for a C/Objective C only option and the C++ compiler. |
| 101 |
check_for_options c++ "-Q --help=warnings" { |
| 102 |
-Wabsolute-value[ \t]+\[available in C, ObjC\] |
| 103 |
} "" "" |
| 104 |
|
| 105 |
# Verify that an option that's an alias for another option is shown |
| 106 |
# with the other option as the value. |
| 107 |
check_for_options c "-Q --help=warnings" { |
| 108 |
--all-warnings[ \t]+\-Wall |
| 109 |
-W[ \t]+-Wextra |
| 110 |
-Wmissing-format-attribute[ \t]+-Wsuggest-attribute=format |
| 111 |
-Wno-alloc-size-larger-than[ \t]+-Walloc-size-larger-than=[1-9][0-9]+ |
| 112 |
-Wno-vla-larger-than[ \t]+-Wvla-larger-than=[1-9][0-9]+ |
| 113 |
} "" "" |
| 114 |
|
| 115 |
# Verify that an option that expects a byte-size argument is shown with |
| 116 |
# a meaningful byte-size argument as the value. |
| 117 |
check_for_options c "-Q --help=warnings" { |
| 118 |
-Walloc-size-larger-than=<bytes>[ \t]+[1-9][0-9]+ bytes |
| 119 |
-Wlarger-than=[^\n\r]+[1-9][0-9]+ bytes |
| 120 |
} "" "" |
| 121 |
|
| 122 |
# Ensure PR 37805 is fixed. |
| 123 |
# Specify patterns (arguments 3 and later) that match option names |
| 124 |
# at the beginning of the line and not when they are referenced by |
| 125 |
# some other options later on. |
| 126 |
check_for_options c "--help=joined" \ |
| 127 |
"^ +-Wformat=" "^ +-fstrict-prototype" "" |
| 128 |
check_for_options c "--help=separate" \ |
| 129 |
"^ +-MF" "^ +-fstrict-prototype" "" |
| 130 |
check_for_options c "--help=warnings,joined" \ |
| 131 |
"^ +-Wformat=" "^ +-Wtrigraphs" "" |
| 132 |
check_for_options c "--help=warnings,^joined" \ |
| 133 |
"^ +-Wtrigraphs" "^ +-Wformat=" "" |
| 134 |
check_for_options c "--help=joined,separate" \ |
| 135 |
"^ +-I" "" "" |
| 136 |
check_for_options c "--help=joined,^separate" \ |
| 137 |
"^ +--help=" "" "" |
| 138 |
check_for_options c "--help=joined,undocumented" "" "" "" |
| 139 |
|
| 140 |
# Check to make sure the description for every option is a complete |
| 141 |
# sentence ending in a period. This matters not just for consistency |
| 142 |
# but also because other sentences may be appended to it by the help |
| 143 |
# subsystem. Do this one help class at a time to make it easier to |
| 144 |
# find the source a failure. |
| 145 |
|
| 146 |
foreach cls { "ada" "c" "c++" "d" "fortran" "go" \ |
| 147 |
"common" "optimizers" "param" "target" "warnings" } { |
| 148 |
check_for_options c "--help=$cls" "" "^ +-.*\[^:.\]$" "" |
| 149 |
} |
| 150 |
|
| 151 |
# Listing only excludes gives empty results. |
| 152 |
check_for_options c "--help=^joined,^separate" "" "" "" |
| 153 |
|
| 154 |
check_for_options c "--help=hardened" "The following options are enabled by -fhardened" "" "" |
| 155 |
|
| 156 |
if [ info exists prev_columns ] { |
| 157 |
# Reset the enviroment variable to its oriuginal value. |
| 158 |
set env(COLUMNS) $prev_columns |
| 159 |
} else { |
| 160 |
# Remove the variable from the environment if it didn't exist |
| 161 |
# to begin with to avoid affecting subsequent tests. |
| 162 |
array unset env COLUMNS |
| 163 |
} |
| 164 |
|
| 165 |
gcc_parallel_test_enable 1 |