[committed][SH] Fix 101737
Hi, The attached patch should fix PR 101737. It's a rather obvious oversight. Sanity tested with 'make all-gcc'. Committed to master, gcc-13, gcc-12, gcc-11. Cheers, Oleg gcc/ChangeLog: PR target/101737 * config/sh/sh.cc (sh_is_nott_insn): Handle case where the input is not an insn, but e.g. a code label. From 4ff8ffe7331cf174668cf5c729fd68ff327ab014 Mon Sep 17 00:00:00 2001 From: Oleg Endo Date: Sun, 3 Mar 2024 14:58:58 +0900 Subject: [PATCH] SH: Fix 101737 gcc/ChangeLog: PR target/101737 * config/sh/sh.cc (sh_is_nott_insn): Handle case where the input is not an insn, but e.g. a code label. --- gcc/config/sh/sh.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gcc/config/sh/sh.cc b/gcc/config/sh/sh.cc index 2c4..ef3c2e6 100644 --- a/gcc/config/sh/sh.cc +++ b/gcc/config/sh/sh.cc @@ -11766,9 +11766,10 @@ sh_insn_operands_modified_between_p (rtx_insn* operands_insn, negates the T bit and stores the result in the T bit. */ bool sh_is_nott_insn (const rtx_insn* i) { - return i != NULL && GET_CODE (PATTERN (i)) == SET + return i != NULL_RTX && PATTERN (i) != NULL_RTX + && GET_CODE (PATTERN (i)) == SET && t_reg_operand (XEXP (PATTERN (i), 0), VOIDmode) && negt_reg_operand (XEXP (PATTERN (i), 1), VOIDmode); } -- libgit2 1.6.4
[committed] d: Fix gdc -O2 -mavx generates misaligned vmovdqa instruction [PR114171]
Hi, This patch fixes a wrong code issue in the D front-end where lowered struct comparisons would reinterpret fields with a different (usually bigger) alignment than the original. Use `build_aligned_type' to preserve the alignment when casting away for such comparisons. Bootstrapped and regression tested on x86_64-linux-gnu/-m32, committed to mainline, and backported to releases/gcc-13, releases/gcc-12, and releases/gcc-11. Regards, Iain. --- PR d/114171 gcc/d/ChangeLog: * d-codegen.cc (lower_struct_comparison): Keep alignment of original type in reinterpret cast for comparison. gcc/testsuite/ChangeLog: * gdc.dg/torture/pr114171.d: New test. --- gcc/d/d-codegen.cc | 1 + gcc/testsuite/gdc.dg/torture/pr114171.d | 29 + 2 files changed, 30 insertions(+) create mode 100644 gcc/testsuite/gdc.dg/torture/pr114171.d diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc index 5bc233928aa..43d7739f8fc 100644 --- a/gcc/d/d-codegen.cc +++ b/gcc/d/d-codegen.cc @@ -1006,6 +1006,7 @@ lower_struct_comparison (tree_code code, StructDeclaration *sd, if (tmode == NULL_TREE) tmode = make_unsigned_type (GET_MODE_BITSIZE (mode.require ())); + tmode = build_aligned_type (tmode, TYPE_ALIGN (stype)); t1ref = build_vconvert (tmode, t1ref); t2ref = build_vconvert (tmode, t2ref); diff --git a/gcc/testsuite/gdc.dg/torture/pr114171.d b/gcc/testsuite/gdc.dg/torture/pr114171.d new file mode 100644 index 000..0f9ffcab916 --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/pr114171.d @@ -0,0 +1,29 @@ +// { dg-do run } +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } +import gcc.builtins; + +struct S1 +{ +string label; +} + +struct S2 +{ +ulong pad; +S1 label; +} + +pragma(inline, false) +auto newitem() +{ +void *p = __builtin_malloc(S2.sizeof); +__builtin_memset(p, 0, S2.sizeof); +return cast(S2*) p; +} + +int main() +{ +auto bn = newitem(); +return bn.label is S1.init ? 0 : 1; +} -- 2.40.1
[committed][GCC13] d: Fix callee destructor call invalidates the live object [PR113758]
Hi, This patch backports a fix to code generation when passing objects by invisible reference that have a defined cpctor or dtor. When generating the argument, check the isCalleeDestroyingArgs hook, and force a TARGET_EXPR to be created if true, so that a reference to the live object isn't passed directly to the function that runs dtors. When instead dealing with caller running destructors, two temporaries were being generated, one explicit temporary generated by the D front-end, and another implicitly by the code generator. This has been reduced to one by setting DECL_VALUE_EXPR on the explicit temporary to bind it to the implicit slot created for the TARGET_EXPR, as that has the shorter lifetime of the two. Bootstrapped and regression tested on x86_64-linux-gnu/-m32, backported to releases/gcc-13, releases/gcc-12, and releases/gcc-11. Regards, Iain. --- PR d/113758 gcc/d/ChangeLog: * d-codegen.cc (d_build_call): Force a TARGET_EXPR when callee destorys its arguments. * decl.cc (DeclVisitor::visit (VarDeclaration *)): Set SET_DECL_VALUE_EXPR on the temporary variable to make it a placeholder for the TARGET_EXPR_SLOT. gcc/testsuite/ChangeLog: * gdc.dg/torture/pr113758.d: New test. (cherry picked from commit 3c57b1c12a8e34d50bdf6aaf44146760db6d1b33) --- gcc/d/d-codegen.cc | 15 +++ gcc/d/decl.cc | 22 -- gcc/testsuite/gdc.dg/torture/pr113758.d | 19 +++ 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gdc.dg/torture/pr113758.d diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc index 8fe659ad527..b8e4b83d2de 100644 --- a/gcc/d/d-codegen.cc +++ b/gcc/d/d-codegen.cc @@ -2213,10 +2213,17 @@ d_build_call (TypeFunction *tf, tree callable, tree object, Type *t = arg->type->toBasetype (); StructDeclaration *sd = t->baseElemOf ()->isTypeStruct ()->sym; - /* Nested structs also have ADDRESSABLE set, but if the type has -neither a copy constructor nor a destructor available, then we -need to take care of copying its value before passing it. */ - if (arg->op == EXP::structLiteral || (!sd->postblit && !sd->dtor)) + /* Need to take care of copying its value before passing the +argument in the following scenarios: +- The argument is a literal expression; a CONSTRUCTOR can't +have its address taken. +- The type has neither a copy constructor nor a destructor +available; nested structs also have ADDRESSABLE set. +- The ABI of the function expects the callee to destroy its +arguments; when the caller is handles destruction, then `targ' +has already been made into a temporary. */ + if (arg->op == EXP::structLiteral || (!sd->postblit && !sd->dtor) + || target.isCalleeDestroyingArgs (tf)) targ = force_target_expr (targ); targ = convert (build_reference_type (TREE_TYPE (targ)), diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc index 0375ede082b..2a135b516aa 100644 --- a/gcc/d/decl.cc +++ b/gcc/d/decl.cc @@ -860,10 +860,28 @@ public: /* Maybe put variable on list of things needing destruction. */ if (d->needsScopeDtor ()) { + /* Rewrite: `decl = exp' => TARGET_EXPR(decl, exp, dtor). */ vec_safe_push (d_function_chain->vars_in_scope, decl); + /* Force a TARGET_EXPR to add the corresponding cleanup. */ - exp = force_target_expr (compound_expr (exp, decl)); - TARGET_EXPR_CLEANUP (exp) = build_expr (d->edtor); + if (TREE_CODE (exp) != TARGET_EXPR) + { + if (VOID_TYPE_P (TREE_TYPE (exp))) + exp = compound_expr (exp, decl); + + exp = force_target_expr (exp); + } + + TARGET_EXPR_CLEANUP (exp) + = compound_expr (TARGET_EXPR_CLEANUP (exp), + build_expr (d->edtor)); + + /* The decl is really an alias for the TARGET_EXPR slot. */ + SET_DECL_VALUE_EXPR (decl, TARGET_EXPR_SLOT (exp)); + DECL_HAS_VALUE_EXPR_P (decl) = 1; + /* This tells the gimplifier not to emit a clobber for the decl + as its lifetime ends when the slot gets cleaned up. */ + TREE_ADDRESSABLE (decl) = 0; } add_stmt (exp); diff --git a/gcc/testsuite/gdc.dg/torture/pr113758.d b/gcc/testsuite/gdc.dg/torture/pr113758.d new file mode 100644 index 000..dc53883a8de --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/pr113758.d @@ -0,0 +1,19 @@ +// { dg-do run } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime
[committed][GCC13] d: Fix internal compiler error: in make_import, at d/imports.cc:48 [PR113125]
Hi, This patch backports an ICE triggered in the D front-end. The cause of the ICE was that TYPE_DECLs were only being generated for structs with members, not opaque structs. Bootstrapped and regression tested on x86_64-linux-gnu/-m32, backported to releases/gcc-13, releases/gcc-12, and releases/gcc-11. Regards, Iain. --- PR d/113125 gcc/d/ChangeLog: * types.cc (TypeVisitor::visit (TypeStruct *)): Generate TYPE_DECL and apply UDAs to opaque struct declarations. gcc/testsuite/ChangeLog: * gdc.dg/imports/pr113125.d: New test. * gdc.dg/pr113125.d: New test. (cherry picked from commit b0efb1c35724e3332ee5993976efb98200c1a154) --- gcc/d/types.cc | 5 + gcc/testsuite/gdc.dg/imports/pr113125.d | 2 ++ gcc/testsuite/gdc.dg/pr113125.d | 4 3 files changed, 11 insertions(+) create mode 100644 gcc/testsuite/gdc.dg/imports/pr113125.d create mode 100644 gcc/testsuite/gdc.dg/pr113125.d diff --git a/gcc/d/types.cc b/gcc/d/types.cc index f19779fec7d..05050f9edd0 100644 --- a/gcc/d/types.cc +++ b/gcc/d/types.cc @@ -1230,6 +1230,11 @@ public: apply_user_attributes (t->sym, t->ctype); finish_aggregate_type (structsize, alignsize, t->ctype); } +else + { + build_type_decl (t->ctype, t->sym); + apply_user_attributes (t->sym, t->ctype); + } /* For structs with a user defined postblit, copy constructor, or a destructor, also set TREE_ADDRESSABLE on the type and all variants. diff --git a/gcc/testsuite/gdc.dg/imports/pr113125.d b/gcc/testsuite/gdc.dg/imports/pr113125.d new file mode 100644 index 000..761e613b055 --- /dev/null +++ b/gcc/testsuite/gdc.dg/imports/pr113125.d @@ -0,0 +1,2 @@ +module imports.pr113125; +struct S113125; diff --git a/gcc/testsuite/gdc.dg/pr113125.d b/gcc/testsuite/gdc.dg/pr113125.d new file mode 100644 index 000..cb7300baa1a --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr113125.d @@ -0,0 +1,4 @@ +// { dg-do compile } +// { dg-options "-I $srcdir/gdc.dg" } +module pr113125; +import imports.pr113125: S113125; -- 2.40.1
libbacktrace patch committed: Link test programs with -no-install
Some of the libbacktrace tests link a program and then modify the debug info in some way. When configured with --enable-shared the linking, using libtool, generates a shell script. That causes the tests to fail because they can't modify the debug info of a shell script. This patch, originally by Jan Tojnar, pass the -no-install flag to libtool to avoid generating a shell script. Bootstrapped and ran libbacktrace tests on x86_64-pc-linux-gnu. Committed to mainline. Ian * Makefile.am (libbacktrace_testing_ldflags): Define. (*_LDFLAGS): Add $(libbacktrace_testing_ldflags) for test programs. * Makefile.in: Regenerate 9b0d218544cd1b12bf63792c70052d2970acc69b diff --git a/libbacktrace/Makefile.am b/libbacktrace/Makefile.am index 750ed80ed05..5677ecd8865 100644 --- a/libbacktrace/Makefile.am +++ b/libbacktrace/Makefile.am @@ -106,6 +106,10 @@ check_DATA = # Flags to use when compiling test programs. libbacktrace_TEST_CFLAGS = $(EXTRA_FLAGS) $(WARN_FLAGS) -g +# Flags to use when linking test programs. +# This avoids generating a shell script when configured with --enable-shared. +libbacktrace_testing_ldflags = -no-install + if USE_DSYMUTIL %.dSYM: % @@ -170,54 +174,63 @@ xcoff_%.c: xcoff.c test_elf_32_SOURCES = test_format.c testlib.c test_elf_32_CFLAGS = $(libbacktrace_TEST_CFLAGS) +test_elf_32_LDFLAGS = $(libbacktrace_testing_ldflags) test_elf_32_LDADD = libbacktrace_noformat.la elf_32.lo BUILDTESTS += test_elf_32 test_elf_64_SOURCES = test_format.c testlib.c test_elf_64_CFLAGS = $(libbacktrace_TEST_CFLAGS) +test_elf_64_LDFLAGS = $(libbacktrace_testing_ldflags) test_elf_64_LDADD = libbacktrace_noformat.la elf_64.lo BUILDTESTS += test_elf_64 test_macho_SOURCES = test_format.c testlib.c test_macho_CFLAGS = $(libbacktrace_TEST_CFLAGS) +test_macho_LDFLAGS = $(libbacktrace_testing_ldflags) test_macho_LDADD = libbacktrace_noformat.la macho.lo BUILDTESTS += test_macho test_xcoff_32_SOURCES = test_format.c testlib.c test_xcoff_32_CFLAGS = $(libbacktrace_TEST_CFLAGS) +test_xcoff_32_LDFLAGS = $(libbacktrace_testing_ldflags) test_xcoff_32_LDADD = libbacktrace_noformat.la xcoff_32.lo BUILDTESTS += test_xcoff_32 test_xcoff_64_SOURCES = test_format.c testlib.c test_xcoff_64_CFLAGS = $(libbacktrace_TEST_CFLAGS) +test_xcoff_64_LDFLAGS = $(libbacktrace_testing_ldflags) test_xcoff_64_LDADD = libbacktrace_noformat.la xcoff_64.lo BUILDTESTS += test_xcoff_64 test_pecoff_SOURCES = test_format.c testlib.c test_pecoff_CFLAGS = $(libbacktrace_TEST_CFLAGS) +test_pecoff_LDFLAGS = $(libbacktrace_testing_ldflags) test_pecoff_LDADD = libbacktrace_noformat.la pecoff.lo BUILDTESTS += test_pecoff test_unknown_SOURCES = test_format.c testlib.c test_unknown_CFLAGS = $(libbacktrace_TEST_CFLAGS) +test_unknown_LDFLAGS = $(libbacktrace_testing_ldflags) test_unknown_LDADD = libbacktrace_noformat.la unknown.lo BUILDTESTS += test_unknown unittest_SOURCES = unittest.c testlib.c unittest_CFLAGS = $(libbacktrace_TEST_CFLAGS) +unittest_LDFLAGS = $(libbacktrace_testing_ldflags) unittest_LDADD = libbacktrace.la BUILDTESTS += unittest unittest_alloc_SOURCES = $(unittest_SOURCES) unittest_alloc_CFLAGS = $(libbacktrace_TEST_CFLAGS) +unittest_alloc_LDFLAGS = $(libbacktrace_testing_ldflags) unittest_alloc_LDADD = libbacktrace_alloc.la BUILDTESTS += unittest_alloc @@ -253,7 +266,7 @@ if HAVE_OBJCOPY_DEBUGLINK b2test_SOURCES = $(btest_SOURCES) b2test_CFLAGS = $(libbacktrace_TEST_CFLAGS) -b2test_LDFLAGS = -Wl,--build-id +b2test_LDFLAGS = -Wl,--build-id $(libbacktrace_testing_ldflags) b2test_LDADD = libbacktrace_elf_for_test.la check_PROGRAMS += b2test @@ -263,7 +276,7 @@ if HAVE_DWZ b3test_SOURCES = $(btest_SOURCES) b3test_CFLAGS = $(libbacktrace_TEST_CFLAGS) -b3test_LDFLAGS = -Wl,--build-id +b3test_LDFLAGS = -Wl,--build-id $(libbacktrace_testing_ldflags) b3test_LDADD = libbacktrace_elf_for_test.la check_PROGRAMS += b3test @@ -277,6 +290,7 @@ endif HAVE_ELF btest_SOURCES = btest.c testlib.c btest_CFLAGS = $(libbacktrace_TEST_CFLAGS) -O +btest_LDFLAGS = $(libbacktrace_testing_ldflags) btest_LDADD = libbacktrace.la BUILDTESTS += btest @@ -289,6 +303,7 @@ if HAVE_ELF btest_lto_SOURCES = btest.c testlib.c btest_lto_CFLAGS = $(libbacktrace_TEST_CFLAGS) -O -flto +btest_lto_LDFLAGS = $(libbacktrace_testing_ldflags) btest_lto_LDADD = libbacktrace.la BUILDTESTS += btest_lto @@ -297,6 +312,7 @@ endif HAVE_ELF btest_alloc_SOURCES = $(btest_SOURCES) btest_alloc_CFLAGS = $(libbacktrace_TEST_CFLAGS) +btest_alloc_LDFLAGS = $(libbacktrace_testing_ldflags) btest_alloc_LDADD = libbacktrace_alloc.la BUILDTESTS += btest_alloc @@ -331,6 +347,7 @@ endif HAVE_DWZ stest_SOURCES = stest.c stest_CFLAGS = $(libbacktrace_TEST_CFLAGS) +stest_LDFLAGS = $(libbacktrace_testing_ldflags) stest_LDADD = libbacktrace.la BUILDTESTS += stest @@ -341,6 +358,7 @@ endif USE_DSYMUTIL stest_alloc_SOURCES = $(stest_SOURCES) stest_alloc_CFLAGS = $(libbacktrace_TEST_CFLAGS)
libbacktrace patch committed: Skip all LZMA block header padding bytes
This patch to libbacktrace corrects the LZMA block header parsing to skip all the padding bytes, verifying that they are zero. This fixes https://github.com/ianlancetaylor/libbacktrace/issues/118. Bootstrapped and ran libbacktrace tests on x86_64-pc-linux-gnu. I was able to verify that the problem occurred when setting the environment variable XZ_OPT="--threads=2", and that this patch fixes the bug. Committed to mainline. Ian * elf.c (elf_uncompress_lzma_block): Skip all header padding bytes and verify that they are zero. 23f9fbed3c97ed70d2615d7d3fa7c249cc862553 diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c index f4527e2477d..7841c86cd9c 100644 --- a/libbacktrace/elf.c +++ b/libbacktrace/elf.c @@ -5568,6 +5568,7 @@ elf_uncompress_lzma_block (const unsigned char *compressed, uint64_t header_compressed_size; uint64_t header_uncompressed_size; unsigned char lzma2_properties; + size_t crc_offset; uint32_t computed_crc; uint32_t stream_crc; size_t uncompressed_offset; @@ -5671,19 +5672,20 @@ elf_uncompress_lzma_block (const unsigned char *compressed, /* The properties describe the dictionary size, but we don't care what that is. */ - /* Block header padding. */ - if (unlikely (off + 4 > compressed_size)) + /* Skip to just before CRC, verifying zero bytes in between. */ + crc_offset = block_header_offset + block_header_size - 4; + if (unlikely (crc_offset + 4 > compressed_size)) { elf_uncompress_failed (); return 0; } - - off = (off + 3) &~ (size_t) 3; - - if (unlikely (off + 4 > compressed_size)) + for (; off < crc_offset; off++) { - elf_uncompress_failed (); - return 0; + if (compressed[off] != 0) + { + elf_uncompress_failed (); + return 0; + } } /* Block header CRC. */
Re: [PATCH 01/11] gcc/doc/extend.texi: Sort built-in traits alphabetically
Hi Dr. Brown, Sorry for forgetting to CC you. Could you please review my patch series when you get a chance? This patch series adds documentation only for built-ins I implemented. To minimize git conflicts, I will add documentation updates to my existing patches after this patch series gets merged. After that, I will try to add documentation to missing built-ins that I did not implement. Thank you! Sincerely, Ken Matsui On Fri, Mar 1, 2024 at 4:23 PM Ken Matsui wrote: > > This patch sorts built-in traits alphabetically for better codebase > consistency and easier future integration of changes. > > gcc/ChangeLog: > > * doc/extend.texi (Type Traits): Sort built-in traits > alphabetically. > > Signed-off-by: Ken Matsui > --- > gcc/doc/extend.texi | 62 ++--- > 1 file changed, 31 insertions(+), 31 deletions(-) > > diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi > index f679c81acf2..b13f9d6f934 100644 > --- a/gcc/doc/extend.texi > +++ b/gcc/doc/extend.texi > @@ -29499,15 +29499,6 @@ Requires: @var{type} shall be a complete type, > (possibly cv-qualified) > @code{void}, or an array of unknown bound. > @enddefbuiltin > > -@defbuiltin{bool __has_nothrow_copy (@var{type})} > -If @code{__has_trivial_copy (type)} is @code{true} then the trait is > -@code{true}, else if @var{type} is a cv-qualified class or union type > -with copy constructors that are known not to throw an exception then > -the trait is @code{true}, else it is @code{false}. > -Requires: @var{type} shall be a complete type, (possibly cv-qualified) > -@code{void}, or an array of unknown bound. > -@enddefbuiltin > - > @defbuiltin{bool __has_nothrow_constructor (@var{type})} > If @code{__has_trivial_constructor (type)} is @code{true} then the trait > is @code{true}, else if @var{type} is a cv class or union type (or array > @@ -29517,6 +29508,15 @@ Requires: @var{type} shall be a complete type, > (possibly cv-qualified) > @code{void}, or an array of unknown bound. > @enddefbuiltin > > +@defbuiltin{bool __has_nothrow_copy (@var{type})} > +If @code{__has_trivial_copy (type)} is @code{true} then the trait is > +@code{true}, else if @var{type} is a cv-qualified class or union type > +with copy constructors that are known not to throw an exception then > +the trait is @code{true}, else it is @code{false}. > +Requires: @var{type} shall be a complete type, (possibly cv-qualified) > +@code{void}, or an array of unknown bound. > +@enddefbuiltin > + > @defbuiltin{bool __has_trivial_assign (@var{type})} > If @var{type} is @code{const}- qualified or is a reference type then > the trait is @code{false}. Otherwise if @code{__is_trivial (type)} is > @@ -29527,15 +29527,6 @@ Requires: @var{type} shall be a complete type, > (possibly cv-qualified) > @code{void}, or an array of unknown bound. > @enddefbuiltin > > -@defbuiltin{bool __has_trivial_copy (@var{type})} > -If @code{__is_trivial (type)} is @code{true} or @var{type} is a reference > -type then the trait is @code{true}, else if @var{type} is a cv class > -or union type with a trivial copy constructor ([class.copy]) then the trait > -is @code{true}, else it is @code{false}. Requires: @var{type} shall be > -a complete type, (possibly cv-qualified) @code{void}, or an array of unknown > -bound. > -@enddefbuiltin > - > @defbuiltin{bool __has_trivial_constructor (@var{type})} > If @code{__is_trivial (type)} is @code{true} then the trait is @code{true}, > else if @var{type} is a cv-qualified class or union type (or array thereof) > @@ -29545,6 +29536,15 @@ Requires: @var{type} shall be a complete type, > (possibly cv-qualified) > @code{void}, or an array of unknown bound. > @enddefbuiltin > > +@defbuiltin{bool __has_trivial_copy (@var{type})} > +If @code{__is_trivial (type)} is @code{true} or @var{type} is a reference > +type then the trait is @code{true}, else if @var{type} is a cv class > +or union type with a trivial copy constructor ([class.copy]) then the trait > +is @code{true}, else it is @code{false}. Requires: @var{type} shall be > +a complete type, (possibly cv-qualified) @code{void}, or an array of unknown > +bound. > +@enddefbuiltin > + > @defbuiltin{bool __has_trivial_destructor (@var{type})} > If @code{__is_trivial (type)} is @code{true} or @var{type} is a reference > type > then the trait is @code{true}, else if @var{type} is a cv class or union > @@ -29560,6 +29560,13 @@ If @var{type} is a class type with a virtual > destructor > Requires: If @var{type} is a non-union class type, it shall be a complete > type. > @enddefbuiltin > > +@defbuiltin{bool __integer_pack (@var{length})} > +When used as the pattern of a pack expansion within a template > +definition, expands to a template argument pack containing integers > +from @code{0} to @code{@var{length}-1}. This is provided for > +efficient implementation of @code{std::make_integer_sequence}. > +@enddefbuiltin > + > @defbuiltin{bool __is_abstract
Re: [PATCH] c-c++-common/Wrestrict.c: fix some typos and enable for LLP64
On 2/15/24 14:08, Jonathan Yong wrote: Attached patch OK? Copy/pasted for review convenience. Ping.
[PATCH v2] gcc, libcpp: Add warning switch for "#pragma once in main file" [PR89808]
This patch adds a warning switch for "#pragma once in main file". The warning option name is Wpragma-once-outside-header, which is the same as Clang. PR preprocessor/89808 gcc/c-family/ChangeLog: * c-opts.cc (c_common_handle_option): Handle OPT_Wpragma_once_outside_header. * c.opt (Wpragma_once_outside_header): Define new option. gcc/ChangeLog: * doc/invoke.texi (Warning Options): Document -Wno-pragma-once-outside-header. libcpp/ChangeLog: * include/cpplib.h (struct cpp_options): Define cpp_warn_pragma_once_outside_header. * directives.cc (do_pragma_once): Use cpp_warn_pragma_once_outside_header. * init.cc (cpp_create_reader): Handle cpp_warn_pragma_once_outside_header. gcc/testsuite/ChangeLog: * g++.dg/Wpragma-once-outside-header.C: New test. * g++.dg/warn/Wno-pragma-once-outside-header.C: New test. * g++.dg/warn/Wpragma-once-outside-header.C: New test. Signed-off-by: Ken Matsui --- gcc/c-family/c-opts.cc | 9 + gcc/c-family/c.opt | 4 gcc/doc/invoke.texi| 10 -- gcc/testsuite/g++.dg/Wpragma-once-outside-header.C | 5 + .../g++.dg/warn/Wno-pragma-once-outside-header.C | 5 + .../g++.dg/warn/Wpragma-once-outside-header.C | 5 + libcpp/directives.cc | 8 ++-- libcpp/include/cpplib.h| 4 libcpp/init.cc | 1 + 9 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/Wpragma-once-outside-header.C create mode 100644 gcc/testsuite/g++.dg/warn/Wno-pragma-once-outside-header.C create mode 100644 gcc/testsuite/g++.dg/warn/Wpragma-once-outside-header.C diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index be3058dca63..4edd8c6c515 100644 --- a/gcc/c-family/c-opts.cc +++ b/gcc/c-family/c-opts.cc @@ -430,6 +430,15 @@ c_common_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value, cpp_opts->warn_num_sign_change = value; break; +case OPT_Wpragma_once_outside_header: + if (value == 0) + cpp_opts->cpp_warn_pragma_once_outside_header = 0; + else if (kind == DK_ERROR) + cpp_opts->cpp_warn_pragma_once_outside_header = 2; + else + cpp_opts->cpp_warn_pragma_once_outside_header = 1; + break; + case OPT_Wunknown_pragmas: /* Set to greater than 1, so that even unknown pragmas in system headers will be warned about. */ diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index b7a4a1a68e3..6841a5a5e81 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -1180,6 +1180,10 @@ Wpragmas C ObjC C++ ObjC++ Var(warn_pragmas) Init(1) Warning Warn about misuses of pragmas. +Wpragma-once-outside-header +C ObjC C++ ObjC++ Var(warn_pragma_once_outside_header) Init(1) Warning +Warn about #pragma once outside of a header. + Wprio-ctor-dtor C ObjC C++ ObjC++ Var(warn_prio_ctor_dtor) Init(1) Warning Warn if constructor or destructors with priorities from 0 to 100 are used. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index bdf05be387d..eeb8954bcdf 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -391,8 +391,8 @@ Objective-C and Objective-C++ Dialects}. -Wpacked -Wno-packed-bitfield-compat -Wpacked-not-aligned -Wpadded -Wparentheses -Wno-pedantic-ms-format -Wpointer-arith -Wno-pointer-compare -Wno-pointer-to-int-cast --Wno-pragmas -Wno-prio-ctor-dtor -Wredundant-decls --Wrestrict -Wno-return-local-addr -Wreturn-type +-Wno-pragmas -Wno-pragma-once-outside-header -Wno-prio-ctor-dtor +-Wredundant-decls -Wrestrict -Wno-return-local-addr -Wreturn-type -Wno-scalar-storage-order -Wsequence-point -Wshadow -Wshadow=global -Wshadow=local -Wshadow=compatible-local -Wno-shadow-ivar @@ -7955,6 +7955,12 @@ Do not warn about misuses of pragmas, such as incorrect parameters, invalid syntax, or conflicts between pragmas. See also @option{-Wunknown-pragmas}. +@opindex Wno-pragma-once-outside-header +@opindex Wpragma-once-outside-header +@item -Wno-pragma-once-outside-header +Do not warn when @code{#pragma once} is used in a file that is not a header +file, such as a main file. + @opindex Wno-prio-ctor-dtor @opindex Wprio-ctor-dtor @item -Wno-prio-ctor-dtor diff --git a/gcc/testsuite/g++.dg/Wpragma-once-outside-header.C b/gcc/testsuite/g++.dg/Wpragma-once-outside-header.C new file mode 100644 index 000..678bd4e7626 --- /dev/null +++ b/gcc/testsuite/g++.dg/Wpragma-once-outside-header.C @@ -0,0 +1,5 @@ +/* { dg-do assemble } */ +/* { dg-options "-Werror=pragma-once-outside-header" } */ + +#pragma once // { dg-error "#pragma once in main file" } +int main() {} diff --git a/gcc/testsuite/g++.dg/warn/Wno-pragma-once-outside-header.C
[patch,avr,applied] Avoid magic numbers for register numbers.
There are some places where avr.cc uses magic numbers like 17 that are actually register numbers. This patch defines constants like REG_17 and uses them instead of the magic numbers when a register number is meant. Johann -- AVR: Use REG_ constants instead of magic numbers . There are some places where avr.cc uses magic numbers like 17 that are actually register numbers. This patch defines constants like REG_17 and uses them instead of the magic numbers when a register number is meant. gcc/ * config/avr/avr.md (REG_0, ... REG_36): New define_constants. * config/avr/avr.cc: Use them instead of magic numbers when it means a register number. diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc index e312ddfbff4..5c71c7f8c0d 100644 --- a/gcc/config/avr/avr.cc +++ b/gcc/config/avr/avr.cc @@ -171,10 +171,10 @@ static bool avr_rtx_costs (rtx, machine_mode, int, int, int *, bool); /* Allocate registers from r25 to r8 for parameters for function calls. */ -#define FIRST_CUM_REG 26 +#define FIRST_CUM_REG REG_26 /* Last call saved register */ -#define LAST_CALLEE_SAVED_REG (AVR_TINY ? 19 : 17) +#define LAST_CALLEE_SAVED_REG (AVR_TINY ? REG_19 : REG_17) /* Implicit target register of LPM instruction (R0) */ extern GTY(()) rtx lpm_reg_rtx; @@ -197,8 +197,8 @@ extern GTY(()) rtx cc_reg_rtx; rtx cc_reg_rtx; /* RTXs for all general purpose registers as QImode */ -extern GTY(()) rtx all_regs_rtx[32]; -rtx all_regs_rtx[32]; +extern GTY(()) rtx all_regs_rtx[REG_32]; +rtx all_regs_rtx[REG_32]; /* SREG, the processor status */ extern GTY(()) rtx sreg_rtx; @@ -542,7 +542,7 @@ avr_casei_sequence_check_operands (rtx *xop) if (AVR_HAVE_EIJMP_EICALL // The last clobber op of the tablejump. - && xop[8] == all_regs_rtx[24]) + && xop[8] == all_regs_rtx[REG_24]) { // $6 is: (subreg:SI ($5) 0) sub_5 = xop[6]; @@ -1171,7 +1171,7 @@ avr_init_machine_status (void) void avr_init_expanders (void) { - for (int regno = 0; regno < 32; regno ++) + for (int regno = REG_0; regno < REG_32; regno ++) all_regs_rtx[regno] = gen_rtx_REG (QImode, regno); lpm_reg_rtx = all_regs_rtx[LPM_REGNO]; @@ -1549,7 +1549,7 @@ avr_regs_to_save (HARD_REG_SET *set) || cfun->machine->is_OS_main) return 0; - for (int reg = 0; reg < 32; reg++) + for (int reg = REG_0; reg < REG_32; reg++) { /* Do not push/pop __tmp_reg__, __zero_reg__, as well as any global register variables. */ @@ -2300,9 +2300,9 @@ avr_pass_fuse_add::execute (function *func) FOR_EACH_BB_FN (bb, func) { - Ldi_Insn prev_ldi_insns[32]; - Add_Insn prev_add_insns[32]; - Mem_Insn prev_mem_insns[32]; + Ldi_Insn prev_ldi_insns[REG_32]; + Add_Insn prev_add_insns[REG_32]; + Mem_Insn prev_mem_insns[REG_32]; rtx_insn *insn, *curr; avr_dump ("\n;; basic block %d\n\n", bb->index); @@ -2484,7 +2484,7 @@ avr_incoming_return_addr_rtx (void) static int avr_hregs_split_reg (HARD_REG_SET *set) { - for (int regno = 0; regno < 32; regno++) + for (int regno = REG_0; regno < REG_32; regno++) if (TEST_HARD_REG_BIT (*set, regno)) { // Don't remove a register from *SET which might indicate that @@ -2620,9 +2620,9 @@ avr_prologue_setup_frame (HOST_WIDE_INT size, HARD_REG_SET set) first_reg = (LAST_CALLEE_SAVED_REG + 1) - (live_seq - 2); - for (reg = 29, offset = -live_seq + 1; + for (reg = REG_29, offset = -live_seq + 1; reg >= first_reg; - reg = (reg == 28 ? LAST_CALLEE_SAVED_REG : reg - 1), ++offset) + reg = (reg == REG_28 ? LAST_CALLEE_SAVED_REG : reg - 1), ++offset) { rtx m, r; @@ -2636,7 +2636,7 @@ avr_prologue_setup_frame (HOST_WIDE_INT size, HARD_REG_SET set) } else /* !minimize */ { - for (int reg = 0; reg < 32; ++reg) + for (int reg = REG_0; reg < REG_32; ++reg) if (TEST_HARD_REG_BIT (set, reg)) emit_push_byte (reg, true); @@ -3795,7 +3795,7 @@ avr_print_operand (FILE *file, rtx x, int code) { if (x == zero_reg_rtx) fprintf (file, "__zero_reg__"); - else if (code == 'r' && REGNO (x) < 32) + else if (code == 'r' && REGNO (x) < REG_32) fprintf (file, "%d", (int) REGNO (x)); else fprintf (file, "%s", reg_names[REGNO (x) + abcd]); @@ -4136,7 +4136,9 @@ avr_asm_final_postscan_insn (FILE *stream, rtx_insn *insn, rtx *, int) int avr_function_arg_regno_p (int r) { - return AVR_TINY ? IN_RANGE (r, 20, 25) : IN_RANGE (r, 8, 25); + return AVR_TINY +? IN_RANGE (r, REG_20, REG_25) +: IN_RANGE (r, REG_8, REG_25); } @@ -4148,7 +4150,7 @@ void avr_init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype, rtx libname, tree fndecl ATTRIBUTE_UNUSED) { - cum->nregs = AVR_TINY ? 6 : 18; + cum->nregs = 1 + AVR_TINY ? REG_25 - REG_20 : REG_25 - REG_8; cum->regno = FIRST_CUM_REG; cum->has_stack_args = 0; if (!libname && stdarg_p (fntype)) @@ -4216,7 +4218,7 @@ avr_function_arg_advance
[patch,avr,applied] Take into account -mtiny-stack in frame pointer adjustments
Applied this addendum to avr PR114100: When the frame pointer is adjusted and -mtiny-stack is set, then it is enough to adjust the low part of the frame pointer. Johann -- AVR: target/114100 - Factor in -mtiny-stack in frame pointer adjustments gcc/ PR target/114100 * config/avr/avr.cc (avr_out_plus_1) [-mtiny-stack]: Only adjust the low part of the frame pointer with 8-bit stack pointer. diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc index 94ef7c591a9..d39d6707c97 100644 --- a/gcc/config/avr/avr.cc +++ b/gcc/config/avr/avr.cc @@ -8983,14 +8983,17 @@ avr_out_plus_1 (rtx *xop, int *plen, enum rtx_code code, int *pcc, && frame_pointer_needed && REGNO (xop[0]) == FRAME_POINTER_REGNUM) { - rtx xval16 = simplify_gen_subreg (HImode, xval, imode, i); - if (xval16 == const1_rtx || xval16 == constm1_rtx) + if (AVR_HAVE_8BIT_SP) + { + avr_asm_len ("subi %A0,%n2", xop, plen, 1); + return; + } + else if (xop[2] == const1_rtx || xop[2] == constm1_rtx) { - avr_asm_len ((code == PLUS) == (xval16 == const1_rtx) + avr_asm_len (xop[2] == const1_rtx ? "ld __tmp_reg__,%a0+" : "ld __tmp_reg__,-%a0", xop, plen, 1); - i++; - continue; + return; } }