+2019-07-24 Martin Sebor <msebor@redhat.com>
+
+ PR driver/80545
+ * diagnostic.c (diagnostic_classify_diagnostic): Use lang_mask.
+ (diagnostic_report_diagnostic): Same.
+ * diagnostic.h (diagnostic_context::option_enabled): Add an argument.
+ (diagnostic_context::lang_mask): New data member.
+ * ipa-pure-const.c (suggest_attribute): Use
+ lang_hooks.option_lang_mask ().
+ * opts-common.c (option_enabled): Handle new argument.
+ (get_option_state): Pass an additional argument.
+ * opts.c (print_filtered_help): Print supported languages for
+ unsupported options. Adjust printing of current state.
+ * opts.h (option_enabled): Add argument.
+ * toplev.c (print_switch_values): Use lang_mask.
+ (general_init): Set global_dc->lang_mask.
+
2019-07-24 Iain Sandoe <iain@sandoe.co.uk>
PR bootstrap/87030
+2019-07-24 Martin Sebor <msebor@redhat.com>
+
+ PR driver/80545
+ * decl.c (finish_function): Use lang_mask.
+
2019-07-20 Jason Merrill <jason@redhat.com>
* cp-tree.h (ovl_iterator::using_p): A USING_DECL by itself was also
&& same_type_ignoring_top_level_qualifiers_p
(TREE_TYPE (valtype), TREE_TYPE (current_class_ref))
&& global_dc->option_enabled (OPT_Wreturn_type,
+ global_dc->lang_mask,
global_dc->option_state))
add_return_star_this_fixit (&richloc, fndecl);
}
#include "edit-context.h"
#include "selftest.h"
#include "selftest-diagnostic.h"
+#include "opts.h"
#ifdef HAVE_TERMIOS_H
# include <termios.h>
if (old_kind == DK_UNSPECIFIED)
{
old_kind = !context->option_enabled (option_index,
+ context->lang_mask,
context->option_state)
? DK_IGNORED : (context->warning_as_error_requested
? DK_ERROR : DK_WARNING);
/* This tests if the user provided the appropriate -Wfoo or
-Wno-foo option. */
if (! context->option_enabled (diagnostic->option_index,
+ context->lang_mask,
context->option_state))
return false;
/* Client hook to say whether the option controlling a diagnostic is
enabled. Returns nonzero if enabled, zero if disabled. */
- int (*option_enabled) (int, void *);
+ int (*option_enabled) (int, unsigned, void *);
/* Client information to pass as second argument to
option_enabled. */
int lock;
+ /* A copy of lang_hooks.option_lang_mask (). */
+ unsigned lang_mask;
+
bool inhibit_notes_p;
/* When printing source code, should the characters at carets and ranges
hash_set<tree> *warned_about,
const char * attrib_name)
{
- if (!option_enabled (option, &global_options))
+ if (!option_enabled (option, lang_hooks.option_lang_mask (), &global_options))
return warned_about;
if (TREE_THIS_VOLATILE (decl)
|| (known_finite && function_always_visible_to_compiler_p (decl)))
or -1 if it isn't a simple on-off switch. */
int
-option_enabled (int opt_idx, void *opts)
+option_enabled (int opt_idx, unsigned lang_mask, void *opts)
{
const struct cl_option *option = &(cl_options[opt_idx]);
+
+ /* A language-specific option can only be considered enabled when it's
+ valid for the current language. */
+ if (option->flags & CL_LANG_ALL && !(option->flags | lang_mask))
+ return 0;
+
struct gcc_options *optsg = (struct gcc_options *) opts;
void *flag_var = option_flag_var (opt_idx, optsg);
case CLVC_BIT_CLEAR:
case CLVC_BIT_SET:
- state->ch = option_enabled (option, opts);
+ state->ch = option_enabled (option, -1, opts);
state->data = &state->ch;
state->size = 1;
break;
#include "common/common-target.h"
#include "spellcheck.h"
#include "opt-suggestions.h"
+#include "diagnostic-color.h"
static void set_Wstrict_aliasing (struct gcc_options *opts, int onoff);
else
strcpy (new_help, "\t");
+ /* Set to print whether the option is enabled or disabled,
+ or, if it's an alias for another option, the name of
+ the aliased option. */
+ bool print_state = false;
+
if (flag_var != NULL
&& option->var_type != CLVC_DEFER)
{
- if (option->flags & CL_JOINED)
+ /* If OPTION is only available for a specific subset
+ of languages other than this one, mention them. */
+ bool avail_for_lang = true;
+ if (unsigned langset = option->flags & CL_LANG_ALL)
+ {
+ if (!(langset & lang_mask))
+ {
+ avail_for_lang = false;
+ strcat (new_help, _("[available in "));
+ for (unsigned i = 0, n = 0; (1U << i) < CL_LANG_ALL; ++i)
+ if (langset & (1U << i))
+ {
+ if (n++)
+ strcat (new_help, ", ");
+ strcat (new_help, lang_names[i]);
+ }
+ strcat (new_help, "]");
+ }
+ }
+ if (!avail_for_lang)
+ ; /* Print nothing else if the option is not available
+ in the current language. */
+ else if (option->flags & CL_JOINED)
{
if (option->var_type == CLVC_STRING)
{
"%s", arg);
}
else
- sprintf (new_help + strlen (new_help),
- "%d", * (int *) flag_var);
+ {
+ if (option->cl_host_wide_int)
+ sprintf (new_help + strlen (new_help),
+ _("%llu bytes"), (unsigned long long)
+ *(unsigned HOST_WIDE_INT *) flag_var);
+ else
+ sprintf (new_help + strlen (new_help),
+ "%i", * (int *) flag_var);
+ }
+ }
+ else
+ print_state = true;
+ }
+ else
+ /* When there is no argument, print the option state only
+ if the option takes no argument. */
+ print_state = !(option->flags & CL_JOINED);
+
+ if (print_state)
+ {
+ if (option->alias_target < N_OPTS
+ && option->alias_target != OPT_SPECIAL_deprecated
+ && option->alias_target != OPT_SPECIAL_ignore
+ && option->alias_target != OPT_SPECIAL_input_file
+ && option->alias_target != OPT_SPECIAL_program_name
+ && option->alias_target != OPT_SPECIAL_unknown)
+ {
+ const struct cl_option *target
+ = &cl_options[option->alias_target];
+ sprintf (new_help + strlen (new_help), "%s%s",
+ target->opt_text,
+ option->alias_arg ? option->alias_arg : "");
}
+ else if (option->alias_target == OPT_SPECIAL_ignore)
+ strcat (new_help, ("[ignored]"));
else
- strcat (new_help, option_enabled (i, opts)
- ? _("[enabled]") : _("[disabled]"));
+ {
+ /* Print the state for an on/off option. */
+ int ena = option_enabled (i, lang_mask, opts);
+ if (ena > 0)
+ strcat (new_help, _("[enabled]"));
+ else if (ena == 0)
+ strcat (new_help, _("[disabled]"));
+ }
}
help = new_help;
location_t loc,
diagnostic_context *dc,
void (*target_option_override_hook) (void));
-extern int option_enabled (int opt_idx, void *opts);
+extern int option_enabled (int opt_idx, unsigned lang_mask, void *opts);
+
extern bool get_option_state (struct gcc_options *, int,
struct cl_option_state *);
extern void set_option (struct gcc_options *opts,
+2019-07-24 Martin Sebor <msebor@redhat.com>
+
+ PR driver/80545
+ * gcc.misc-tests/help.exp: Add tests.
+ * lib/options.exp: Handle C++.
+
2019-07-24 Claudiu Zissulescu <claziss@synopsys.com>
* gcc.target/arc/arc.exp (check_effective_target_accregs): New
-O
} "" ""
+# Verify that a C++/Objective C++ only option is indicated as such
+# by the C compiler.
+check_for_options c "-Q --help=warnings" {
+-Wclass-memaccess[ \t]+\[available in C\+\+, ObjC\+\+\]
+} "" ""
+
+# Do the same for a C/Objective C only option and the C++ compiler.
+check_for_options c++ "-Q --help=warnings" {
+-Wabsolute-value[ \t]+\[available in C, ObjC\]
+} "" ""
+
+# Verify that an option that's an alias for another option is shown
+# with the other option as the value.
+check_for_options c "-Q --help=warnings" {
+--all-warnings[ \t]+\-Wall
+-W[ \t]+-Wextra
+-Wmissing-format-attribute[ \t]+-Wsuggest-attribute=format
+-Wno-alloc-size-larger-than[ \t]+-Walloc-size-larger-than=[1-9][0-9]+
+-Wno-vla-larger-than[ \t]+-Wvla-larger-than=[1-9][0-9]+
+} "" ""
+
+# Verify that an option that expects a byte-size argument is shown with
+# a meaningful byte-size argument as the value.
+check_for_options c "-Q --help=warnings" {
+-Walloc-size-larger-than=[ \t]+[1-9][0-9]+ bytes
+-Wlarger-than=[^\n\r]+[1-9][0-9]+ bytes
+} "" ""
+
# Ensure PR 37805 is fixed.
# Specify patterns (arguments 3 and later) that match option names
# at the beginning of the line and not when they are referenced by
compiler_patterns \
compiler_non_patterns \
expected_failure } {
- set filename test-[pid]
- set fd [open $filename.c w]
- puts $fd "int main (void) { return 0; }"
- close $fd
- remote_download host $filename.c
-
set test "compiler driver $gcc_options option(s):"
set gcc_options "\{additional_flags=$gcc_options\}"
switch "$language" {
- "c" { set compiler cc1 }
+ "c" {
+ set compiler cc1
+ set suffix c
+ }
+ "c++" {
+ set compiler cc1plus
+ set suffix cc
+ }
default { error "unknown language" }
}
- set gcc_output [gcc_target_compile $filename.c $filename.x executable $gcc_options]
- remote_file build delete $filename.c $filename.x $filename.gcno
+
+ set filebase test-[pid]
+ set srcfname $filebase.$suffix
+ set fd [open $srcfname w]
+ puts $fd "int main (void) { return 0; }"
+ close $fd
+ remote_download host $srcfname
+
+ set gcc_output [gcc_target_compile $srcfname $filebase.x executable $gcc_options]
+ remote_file build delete $srcfname $filebase.x $filebase.gcno
if { $exclude != "" } {
set lines [split $gcc_output "\n"]
pos = print_single_switch (print_fn, 0,
SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
+ unsigned lang_mask = lang_hooks.option_lang_mask ();
for (j = 0; j < cl_options_count; j++)
if (cl_options[j].cl_report
- && option_enabled (j, &global_options) > 0)
+ && option_enabled (j, lang_mask, &global_options) > 0)
pos = print_single_switch (print_fn, pos,
SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
/* Initialize the diagnostics reporting machinery, so option parsing
can give warnings and errors. */
diagnostic_initialize (global_dc, N_OPTS);
+ global_dc->lang_mask = lang_hooks.option_lang_mask ();
/* Set a default printer. Language specific initializations will
override it later. */
tree_diagnostics_defaults (global_dc);