Compare commits

...

10 commits

Author SHA1 Message Date
Jakub Jelinek
ebdf92b606 testsuite: Fix up ipa/pr119530.c testcase [PR119318]
I'm seeing
+FAIL: gcc.dg/ipa/pr119530.c execution test
on i686-linux.  The problem is that when long is just 32-bit and
so is unsigned, the testcase then behaves differently and should abort.
Fixed by making the argument long long instead.
While at it, just in case I've changed type of d variable to signed char
as well just in case there is -funsigned-char 8-bit int target or something
similar.

2025-04-14  Jakub Jelinek  <jakub@redhat.com>

	PR ipa/119318
	* gcc.dg/ipa/pr119530.c (d): Change type from char to signed char.
	(e): Change argument type from long to long long.
2025-04-14 19:35:20 +02:00
Jakub Jelinek
f96a54350a expmed: Always use QImode for init_expmed set_zero_cost [PR119785]
This is a regression on some targets introduced I believe by r6-2055
which added mode argument to set_src_cost.

The problem here is that in the first iteration, mode is always QImode
and we get as -Os zero cost set_src_cost (const0_rtx, QImode, false).
But then we use the mode variable for iterating over int, partial int
and vector int modes, so for the second iteration we call set_src_cost
with mode which is at that time (machine_mode) (MAX_MODE_VECTOR_INT + 1).

In the x86 case that happens to be V2HFmode and we don't crash (and
compute the same 0 cost as we would for QImode).
But e.g. in the SPARC case (machine_mode) (MAX_MODE_VECTOR_INT + 1) is
MAX_MACHINE_MODE and that does all kinds of weird things especially
when doing ubsan bootstrap.

Fixed by always using QImode.

2025-04-14  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/119785
	* expmed.cc (init_expmed): Always pass QImode rather than mode to
	set_src_cost passed to set_zero_cost.
2025-04-14 19:34:22 +02:00
Jakub Jelinek
e0b57c75e6 cobol: Fix -fmax-errors option [PR119776]
There seems to be inconsistency in the -fmax-errors option
naming.  It is a generic option in common.opt (so applies
to all languages) but with the = character in it.
The gcobol.1 man page in one spot documents the generic
option (in the syntax, -fmax-errors=nerror) but in another
spot without the = character.

In common.opt it is
fmax-errors=
Common Joined RejectNegative UInteger Var(flag_max_errors)
-fmax-errors=<number>   Maximum number of errors to report.

I hope the cobol addition is just a mistake, having -fmax-errors variant
without = character when Joined Separate would allow to specify
-fmax-errors 10 with the same meaning as -fmax-errors=10
but also -fmax-errors10 with the same meaning which is just weird.
Also, there is no UInteger and RejectNegative on it, so one can
also specific -fno-max-errors42 or -fmax-errors blah.

So, unless the spelling without = is intentional, here is a patch
to just remove it, the common option already should have arranged
for flag_max_errors to be set to the right number.

Or if it is intentional, I guess we'd need to at least add
RejectNegative UInteger (plus using atoi is generally undesirable
anywhere in the compiler because it does no error checking).
And the man page would need to be updated to specify both forms.

2025-04-14  Jakub Jelinek  <jakub@redhat.com>

	PR cobol/119776
	* lang.opt (fmax-errors): Remove.
	* lang.opt.urls: Regenerate.
	* cobol1.cc (cobol_langhook_handle_option) <case OPT_fmax_errors>:
	Remove.
	* gcobol.1: Document -fmax-errors=nerror rather than
	-fmax-errors nerror.
2025-04-14 19:33:11 +02:00
Jakub Jelinek
d0b41f3d6d cobol: Fix up COBOL -include [PR119777]
I was looking through options.cc diff between GCC 14 and 15, looking for
entries with added CL_Cobol where at least one other language is present
and was present before too.  Besides the -fsyntax-only changes this is
the only other one I found, COBOL adds Var(cobol_include) to something
which didn't have a Var at all before and IMHO it is actively harmful.
Because one can specify multiple -include file1 -include file2 options,
both in C/C++ etc. and in COBOL as well (as documented in the man
page).  A Var can track just one entry.  cobol_langhook_handle_option
should use arg instead.

2025-04-14  Jakub Jelinek  <jakub@redhat.com>

	PR cobol/119777
	* lang.opt (include): Remove Var(cobol_include).
	* cobol1.cc (cobol_langhook_handle_option) <case OPT_include>: Use
	arg instead of cobol_include.
2025-04-14 19:32:43 +02:00
Jakub Jelinek
e96cb35ceb cobol: Drop -fsyntax-only from COBOL lang.opt [PR119777]
The comment is incorrect, fsyntax-only is not documented in c.opt,
but in common.opt:
fsyntax-only
Common Var(flag_syntax_only)
Check for syntax errors, then stop.
and as such it applies to all languages, so adding CL_Cobol to
the CL_COMMON is both unnecessary and because of RejectNegative which
contradicts the generic option very harmful, because it makes
-fno-syntax-only invalid for all languages.

Fixed by just dropping it.

2025-04-14  Jakub Jelinek  <jakub@redhat.com>

	PR cobol/119777
	* lang.opt (fsyntax-only): Remove.
	* lang.opt.urls: Regenerate.
2025-04-14 19:32:06 +02:00
Jakub Jelinek
2e3c91786a pretty-print, expand: Print [must tail call] for CALL_EXPRs and fix up maybe_complain_about_tail_call [PR119718]
Andrew P. mentioned earlier he'd like to see in the dump files a note
whether it was a failed must tail call or not.
We already print that on the tailc/musttail pass side, because
print_gimple_stmt prints [must tail call] after the musttail calls.
The first hunk below does it for GENERIC CALL_EXPRs too (which is needed
for the expand diagnostics).  That isn't enough though, because the
error on it was done first and then CALL_EXPR_MUST_TAIL_CALL flag was
cleared, so the dump didn't have it anymore.  I've reordered the
dump printing with error, so that it works properly.

2025-04-14  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/119718
	* tree-pretty-print.cc (dump_generic_node) <case CALL_EXPR>: Dump
	also CALL_EXPR_MUST_TAIL_CALL flag.
	* calls.cc (maybe_complain_about_tail_call): Emit error about
	CALL_EXPR_MUST_TAIL_CALL only after emitting dump message, not before
	it.
2025-04-14 19:31:23 +02:00
Arthur Cohen
901d94e8b4 gccrs: lang-items: Add ManuallyDrop<T>
gcc/rust/ChangeLog:

	* util/rust-lang-item.h: Add new manually_drop lang item.
	* util/rust-lang-item.cc: Likewise.
2025-04-14 18:23:56 +02:00
Arthur Cohen
73d72498f9 gccrs: attributes: Handle external tool annotations like rustfmt::
gcc/rust/ChangeLog:

	* util/rust-attribute-values.h: Add RUSTFMT value.
	* util/rust-attributes.cc: Define the attribute.
	* util/rust-attributes.h (enum CompilerPass): Add EXTERNAL variant.
	* expand/rust-macro-builtins.cc: Fix formatting.
2025-04-14 18:23:56 +02:00
Arthur Cohen
9ed95c0697 gccrs: nr2.0: Only insert derive macros if they exist
This causes an assertion failure when compiling core with nr2.0, but should
probably be improved. I'm not sure how this code enables built-in derive
macros to be resolved so this is a temporary fix.

gcc/rust/ChangeLog:

	* resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes): Remove assertion.
2025-04-14 18:23:56 +02:00
Arthur Cohen
34c516efbb gccrs: attributes: Add missing attributes used in core
gcc/rust/ChangeLog:

	* util/rust-attribute-values.h: Add missing attributes.
	* util/rust-attributes.cc: Likewise.
	* util/rust-attributes.h (enum CompilerPass): Mention adding something for const
	functions.
2025-04-14 18:23:56 +02:00
15 changed files with 72 additions and 37 deletions

View file

@ -1273,11 +1273,6 @@ void
maybe_complain_about_tail_call (tree call_expr, const char *reason)
{
gcc_assert (TREE_CODE (call_expr) == CALL_EXPR);
if (CALL_EXPR_MUST_TAIL_CALL (call_expr))
{
error_at (EXPR_LOCATION (call_expr), "cannot tail-call: %s", reason);
CALL_EXPR_MUST_TAIL_CALL (call_expr) = 0;
}
if (CALL_EXPR_TAILCALL (call_expr)
&& dump_file
&& (dump_flags & TDF_DETAILS))
@ -1286,6 +1281,11 @@ maybe_complain_about_tail_call (tree call_expr, const char *reason)
print_generic_expr (dump_file, call_expr, TDF_SLIM);
fprintf (dump_file, "\n");
}
if (CALL_EXPR_MUST_TAIL_CALL (call_expr))
{
error_at (EXPR_LOCATION (call_expr), "cannot tail-call: %s", reason);
CALL_EXPR_MUST_TAIL_CALL (call_expr) = 0;
}
}
/* Fill in ARGS_SIZE and ARGS array based on the parameters found in

View file

@ -385,10 +385,6 @@ cobol_langhook_handle_option (size_t scode,
return true;
}
case OPT_fmax_errors:
flag_max_errors = atoi(arg);
return true;
case OPT_ffixed_form:
cobol_set_indicator_column(-7);
return true;
@ -413,8 +409,8 @@ cobol_langhook_handle_option (size_t scode,
}
return true;
case OPT_include:
if( ! include_file_add(cobol_include) ) {
cbl_errx( "could not include %s", cobol_include);
if( ! include_file_add(arg) ) {
cbl_errx( "could not include %s", arg);
}
return true;

View file

@ -224,7 +224,7 @@ had appeared.
Not all exception conditions are implemented. Any that are not
produce a warning message.
.
.It Fl fmax-errors Ar nerror
.It Fl fmax-errors Ns Li = Ns Ar nerror
.Ar nerror
represents the number of error messages produced. Without this option,
.Nm

View file

@ -77,10 +77,6 @@ ffixed-form
Cobol RejectNegative
Assume that the source file is fixed form.
fsyntax-only
Cobol RejectNegative
; Documented in c.opt
ffree-form
Cobol RejectNegative
Assume that the source file is free form.
@ -93,10 +89,6 @@ finternal-ebcdic
Cobol Var(cobol_ebcdic, 1) Init(0)
-finternal-ebcdic Internal processing is in EBCDIC Code Page 1140
fmax-errors
Cobol Joined Separate
; Documented in C
fstatic-call
Cobol Var(cobol_static_call, 1) Init(1)
Enable/disable static linkage for CALL literals
@ -118,7 +110,7 @@ Cobol Joined Separate
; Documented in C
include
Cobol Joined Separate Var(cobol_include)
Cobol Joined Separate
; Documented in C
isysroot

View file

@ -13,15 +13,9 @@ UrlSuffix(gcc/Directory-Options.html#index-I) LangUrlSuffix_D(gdc/Directory-Opti
ffixed-form
LangUrlSuffix_Fortran(gfortran/Fortran-Dialect-Options.html#index-ffixed-form)
fsyntax-only
UrlSuffix(gcc/Warning-Options.html#index-fsyntax-only) LangUrlSuffix_D(gdc/Warnings.html#index-fno-syntax-only) LangUrlSuffix_Fortran(gfortran/Error-and-Warning-Options.html#index-fsyntax-only)
ffree-form
LangUrlSuffix_Fortran(gfortran/Fortran-Dialect-Options.html#index-ffree-form)
fmax-errors
UrlSuffix(gcc/Warning-Options.html#index-fmax-errors) LangUrlSuffix_D(gdc/Warnings.html#index-fmax-errors)
iprefix
UrlSuffix(gcc/Directory-Options.html#index-iprefix) LangUrlSuffix_D(gdc/Directory-Options.html#index-iprefix) LangUrlSuffix_Fortran(gfortran/Preprocessing-Options.html#index-iprefix)

View file

@ -285,7 +285,7 @@ init_expmed (void)
for (speed = 0; speed < 2; speed++)
{
crtl->maybe_hot_insn_p = speed;
set_zero_cost (speed, set_src_cost (const0_rtx, mode, speed));
set_zero_cost (speed, set_src_cost (const0_rtx, QImode, speed));
for (mode = MIN_MODE_INT; mode <= MAX_MODE_INT;
mode = (machine_mode)(mode + 1))

View file

@ -83,7 +83,6 @@ const BiMap<std::string, BuiltinMacro> MacroBuiltin::builtins = {{
{"Ord", BuiltinMacro::Ord},
{"PartialOrd", BuiltinMacro::PartialOrd},
{"Hash", BuiltinMacro::Hash},
}};
AST::MacroTranscriberFunc

View file

@ -325,10 +325,9 @@ Early::visit_attributes (std::vector<AST::Attribute> &attrs)
auto pm_def = mappings.lookup_derive_proc_macro_def (
definition->get_node_id ());
rust_assert (pm_def.has_value ());
mappings.insert_derive_proc_macro_invocation (trait,
pm_def.value ());
if (pm_def.has_value ())
mappings.insert_derive_proc_macro_invocation (trait,
pm_def.value ());
}
}
else if (Analysis::BuiltinAttributeMappings::get ()

View file

@ -40,12 +40,14 @@ public:
static constexpr auto &NO_MANGLE = "no_mangle";
static constexpr auto &REPR = "repr";
static constexpr auto &RUSTC_BUILTIN_MACRO = "rustc_builtin_macro";
static constexpr auto &RUSTC_MACRO_TRANSPARENCY = "rustc_macro_transparency";
static constexpr auto &PATH = "path";
static constexpr auto &MACRO_USE = "macro_use";
static constexpr auto &MACRO_EXPORT = "macro_export";
static constexpr auto &PROC_MACRO = "proc_macro";
static constexpr auto &PROC_MACRO_DERIVE = "proc_macro_derive";
static constexpr auto &PROC_MACRO_ATTRIBUTE = "proc_macro_attribute";
static constexpr auto &TARGET_FEATURE = "target_feature";
// From now on, these are reserved by the compiler and gated through
// #![feature(rustc_attrs)]
@ -54,11 +56,35 @@ public:
= "rustc_inherit_overflow_checks";
static constexpr auto &STABLE = "stable";
static constexpr auto &UNSTABLE = "unstable";
static constexpr auto &RUSTC_PROMOTABLE = "rustc_promotable";
static constexpr auto &RUSTC_CONST_STABLE = "rustc_const_stable";
static constexpr auto &RUSTC_CONST_UNSTABLE = "rustc_const_unstable";
static constexpr auto &RUSTC_SPECIALIZATION_TRAIT
= "rustc_specialization_trait";
static constexpr auto &RUSTC_UNSAFE_SPECIALIZATION_MARKER
= "rustc_unsafe_specialization_marker";
static constexpr auto &RUSTC_RESERVATION_IMPL = "rustc_reservation_impl";
static constexpr auto &RUSTC_PAREN_SUGAR = "rustc_paren_sugar";
static constexpr auto &RUSTC_NONNULL_OPTIMIZATION_GUARANTEED
= "rustc_nonnull_optimization_guaranteed";
static constexpr auto &RUSTC_LAYOUT_SCALAR_VALID_RANGE_START
= "rustc_layout_scalar_valid_range_start";
static constexpr auto &MAY_DANGLE = "may_dangle";
static constexpr auto &PRELUDE_IMPORT = "prelude_import";
static constexpr auto &TRACK_CALLER = "track_caller";
static constexpr auto &RUSTC_DIAGNOSTIC_ITEM = "rustc_diagnostic_item";
static constexpr auto &RUSTC_ON_UNIMPLEMENTED = "rustc_on_unimplemented";
static constexpr auto &FUNDAMENTAL = "fundamental";
static constexpr auto &NON_EXHAUSTIVE = "non_exhaustive";
static constexpr auto &RUSTFMT = "rustfmt";
};
} // namespace Values
} // namespace Rust

View file

@ -57,6 +57,7 @@ static const BuiltinAttrDefinition __definitions[]
{Attrs::NO_MANGLE, CODE_GENERATION},
{Attrs::REPR, CODE_GENERATION},
{Attrs::RUSTC_BUILTIN_MACRO, EXPANSION},
{Attrs::RUSTC_MACRO_TRANSPARENCY, EXPANSION},
{Attrs::PATH, EXPANSION},
{Attrs::MACRO_USE, NAME_RESOLUTION},
{Attrs::MACRO_EXPORT, NAME_RESOLUTION},
@ -72,11 +73,29 @@ static const BuiltinAttrDefinition __definitions[]
{Attrs::RUSTC_INHERIT_OVERFLOW_CHECKS, CODE_GENERATION},
{Attrs::STABLE, STATIC_ANALYSIS},
{Attrs::UNSTABLE, STATIC_ANALYSIS},
// assuming we keep these for static analysis
{Attrs::RUSTC_PROMOTABLE, CODE_GENERATION},
{Attrs::RUSTC_CONST_STABLE, STATIC_ANALYSIS},
{Attrs::RUSTC_CONST_UNSTABLE, STATIC_ANALYSIS},
{Attrs::PRELUDE_IMPORT, NAME_RESOLUTION},
{Attrs::TRACK_CALLER, CODE_GENERATION}};
{Attrs::TRACK_CALLER, CODE_GENERATION},
{Attrs::RUSTC_SPECIALIZATION_TRAIT, TYPE_CHECK},
{Attrs::RUSTC_UNSAFE_SPECIALIZATION_MARKER, TYPE_CHECK},
{Attrs::RUSTC_RESERVATION_IMPL, TYPE_CHECK},
{Attrs::RUSTC_PAREN_SUGAR, TYPE_CHECK},
{Attrs::RUSTC_NONNULL_OPTIMIZATION_GUARANTEED, TYPE_CHECK},
{Attrs::RUSTC_LAYOUT_SCALAR_VALID_RANGE_START, CODE_GENERATION},
{Attrs::PRELUDE_IMPORT, NAME_RESOLUTION},
{Attrs::RUSTC_DIAGNOSTIC_ITEM, STATIC_ANALYSIS},
{Attrs::RUSTC_ON_UNIMPLEMENTED, STATIC_ANALYSIS},
{Attrs::FUNDAMENTAL, TYPE_CHECK},
{Attrs::NON_EXHAUSTIVE, TYPE_CHECK},
{Attrs::RUSTFMT, EXTERNAL}};
BuiltinAttributeMappings *
BuiltinAttributeMappings::get ()

View file

@ -40,7 +40,12 @@ enum CompilerPass
HIR_LOWERING,
TYPE_CHECK,
STATIC_ANALYSIS,
CODE_GENERATION
CODE_GENERATION,
// External Rust tooling attributes, like #[rustfmt::skip]
EXTERNAL,
// Do we need to add something here for const fns?
};
struct BuiltinAttrDefinition

View file

@ -118,6 +118,7 @@ const BiMap<std::string, LangItem::Kind> Rust::LangItem::lang_items = {{
{"discriminant_kind", Kind::DISCRIMINANT_KIND},
{"discriminant_type", Kind::DISCRIMINANT_TYPE},
{"manually_drop", Kind::MANUALLY_DROP},
}};
tl::optional<LangItem::Kind>

View file

@ -150,6 +150,8 @@ public:
DISCRIMINANT_TYPE,
DISCRIMINANT_KIND,
MANUALLY_DROP,
};
static const BiMap<std::string, Kind> lang_items;

View file

@ -5,8 +5,8 @@ struct a {
int b;
};
int c;
char d;
static int e(long f) { return f < 0; }
signed char d;
static int e(long long f) { return f < 0; }
static void g(unsigned f) { c = e(~f); }
int main() {
int h;

View file

@ -3201,6 +3201,8 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags,
pp_string (pp, " [return slot optimization]");
if (CALL_EXPR_TAILCALL (node))
pp_string (pp, " [tail call]");
if (CALL_EXPR_MUST_TAIL_CALL (node))
pp_string (pp, " [must tail call]");
break;
case WITH_CLEANUP_EXPR: