diff options
author | David Malcolm <dmalcolm@redhat.com> | 2024-11-27 19:21:15 -0500 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2024-11-27 19:21:15 -0500 |
commit | 5341eb669658c7c73d55021b10a4765bf4ce3078 (patch) | |
tree | 4fcf4200563d9bba8e033d3be34bd1fbbb1aadb2 /gcc/c | |
parent | 5336b63fe81029cfd790208fbc69a08c70b82b01 (diff) | |
download | gcc-5341eb669658c7c73d55021b10a4765bf4ce3078.zip gcc-5341eb669658c7c73d55021b10a4765bf4ce3078.tar.gz gcc-5341eb669658c7c73d55021b10a4765bf4ce3078.tar.bz2 |
c-family: offer suggestions for missing command-line options [PR82892]
Some builtin macros are only defined when certain command-line options
are provided. Update the error messages for them so that we suggest
the pertinent option ('-fopenacc' for '_OPENACC', and '-fopenmp' for
'_OPENMP')
gcc/c-family/ChangeLog:
PR c/82892
* c-common.h (get_option_for_builtin_define): New decl.
* c-cppbuiltin.cc (get_option_for_builtin_define): New.
* known-headers.cc: Include "opts.h".
(suggest_missing_option::suggest_missing_option): New.
(suggest_missing_option::~suggest_missing_option): New.
* known-headers.h (class suggest_missing_option): New.
gcc/c/ChangeLog:
PR c/82892
* c-decl.cc (lookup_name_fuzzy): Provide hints for missing
command-line options.
gcc/cp/ChangeLog:
PR c/82892
* name-lookup.cc (suggest_alternatives_for_1): Provide hints for
missing command-line options.
gcc/testsuite/ChangeLog:
PR c/82892
* c-c++-common/spellcheck-missing-option.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/c-decl.cc | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index b9c688e..1c11c21 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -4547,6 +4547,17 @@ lookup_name_fuzzy (tree name, enum lookup_name_fuzzy_kind kind, location_t loc) IDENTIFIER_POINTER (name), header_hint)); + /* Next, look for exact matches for builtin defines that would have been + defined if the user had passed a command-line option (e.g. -fopenmp + for "_OPENMP"). */ + diagnostic_option_id option_id + = get_option_for_builtin_define (IDENTIFIER_POINTER (name)); + if (option_id.m_idx > 0) + return name_hint (nullptr, + new suggest_missing_option (loc, + IDENTIFIER_POINTER (name), + option_id)); + /* Only suggest names reserved for the implementation if NAME begins with an underscore. */ bool consider_implementation_names = (IDENTIFIER_POINTER (name)[0] == '_'); |