[gcc r15-4712] RISC-V:Bugfix for vlmul_ext and vlmul_trunc with NULL return value[pr117286]
https://gcc.gnu.org/g:75caa17f5cb4e414919baff0435300b549a76eca commit r15-4712-g75caa17f5cb4e414919baff0435300b549a76eca Author: xuli Date: Mon Oct 28 04:41:09 2024 + RISC-V:Bugfix for vlmul_ext and vlmul_trunc with NULL return value[pr117286] This patch fixes following ICE: test.c: In function 'func': test.c:37:24: internal compiler error: Segmentation fault 37 | vfloat16mf2_t vc = __riscv_vlmul_trunc_v_f16m1_f16mf2(vb); |^~ The root cause is that vlmul_trunc has a null return value. gimple_call <__riscv_vlmul_trunc_v_f16m1_f16mf2, NULL, vb_13> ^^^ Passed the rv64gcv_zvfh regression test. Singed-off-by: Li Xu PR target/117286 gcc/ChangeLog: * config/riscv/riscv-vector-builtins-bases.cc: Do not expand NULL return. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/base/pr117286.c: New test. Diff: --- gcc/config/riscv/riscv-vector-builtins-bases.cc| 4 gcc/testsuite/gcc.target/riscv/rvv/base/pr117286.c | 16 2 files changed, 20 insertions(+) diff --git a/gcc/config/riscv/riscv-vector-builtins-bases.cc b/gcc/config/riscv/riscv-vector-builtins-bases.cc index fcc1bf934532..b8c337f4e77a 100644 --- a/gcc/config/riscv/riscv-vector-builtins-bases.cc +++ b/gcc/config/riscv/riscv-vector-builtins-bases.cc @@ -1753,6 +1753,8 @@ public: rtx expand (function_expander &e) const override { +if (!e.target) + return NULL_RTX; tree arg = CALL_EXPR_ARG (e.exp, 0); rtx src = expand_normal (arg); emit_move_insn (gen_lowpart (e.vector_mode (), e.target), src); @@ -1767,6 +1769,8 @@ public: rtx expand (function_expander &e) const override { +if (!e.target) + return NULL_RTX; rtx src = expand_normal (CALL_EXPR_ARG (e.exp, 0)); emit_move_insn (e.target, gen_lowpart (GET_MODE (e.target), src)); return e.target; diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr117286.c b/gcc/testsuite/gcc.target/riscv/rvv/base/pr117286.c new file mode 100644 index ..dabb8ae0751d --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pr117286.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv_zvfh -mabi=lp64d -O1" } */ + +#include +_Float16 a[10]; +void func(){ + int placeholder0 = 10; + _Float16* ptr_a = a; + for (size_t vl; placeholder0 > 0; placeholder0 -= vl){ +vl = __riscv_vsetvl_e16m1(placeholder0); +vfloat16mf2_t va = __riscv_vle16_v_f16mf2(ptr_a, vl); +vfloat16m1_t vb = __riscv_vlmul_ext_v_f16mf2_f16m1(va); +vfloat16mf2_t vc = __riscv_vlmul_trunc_v_f16m1_f16mf2(vb); +ptr_a += vl; + } +}
[gcc r15-4703] testsuite: Fix up gcc.dg/vec-perm-lower.c test
https://gcc.gnu.org/g:e2ce2a4661103bc40ff3cf5fdcbf92c1243dd637 commit r15-4703-ge2ce2a4661103bc40ff3cf5fdcbf92c1243dd637 Author: Jakub Jelinek Date: Sun Oct 27 16:41:28 2024 +0100 testsuite: Fix up gcc.dg/vec-perm-lower.c test On Tue, Oct 15, 2024 at 12:45:35PM +, Tamar Christina wrote: > I'll write a gimple one and commit with this then. The new test FAILs on i686-linux, with the usual FAIL: gcc.dg/vec-perm-lower.c (test for excess errors) Excess errors: .../gcc/testsuite/gcc.dg/vec-perm-lower.c:9:1: warning: SSE vector return without SSE enabled changes the ABI [-Wpsabi] .../gcc/testsuite/gcc.dg/vec-perm-lower.c:8:1: warning: MMX vector argument without MMX enabled changes the ABI [-Wpsabi] The following patch fixes that. Tested on x86_64-linux with make check-gcc RUNTESTFLAGS='--target_board=unix/\{-m32,-m32/-mno-sse/-mno-mmx,-m64\} dg.exp=vec-perm-lower.c' which previously FAILed, now PASSes, ok for trunk? 2024-10-27 Jakub Jelinek * gcc.dg/vec-perm-lower.c: Add -Wno-psabi to dg-options. Diff: --- gcc/testsuite/gcc.dg/vec-perm-lower.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.dg/vec-perm-lower.c b/gcc/testsuite/gcc.dg/vec-perm-lower.c index da738fbeed80..4b5dda58f006 100644 --- a/gcc/testsuite/gcc.dg/vec-perm-lower.c +++ b/gcc/testsuite/gcc.dg/vec-perm-lower.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-fgimple -O2" } */ +/* { dg-options "-fgimple -O2 -Wno-psabi" } */ typedef char v8qi __attribute__ ((vector_size (8))); typedef char v16qi __attribute__ ((vector_size (16)));
[gcc r15-4711] gcc.target/i386/pr53533-[13].c: Adjust assembly scan
https://gcc.gnu.org/g:f1823d8037e355cd755087e695051d190ffe755e commit r15-4711-gf1823d8037e355cd755087e695051d190ffe755e Author: H.J. Lu Date: Sat Oct 12 05:53:49 2024 +0800 gcc.target/i386/pr53533-[13].c: Adjust assembly scan Before 1089d083117 Simplify (B * v + C) * D -> BD* v + CD when B,C,D are all INTEGER_CST. the loop was .L2: movl(%rdi,%rdx), %eax addl$12345, %eax imull $-1564285888, %eax, %eax leal-333519936(%rax), %eax movl%eax, (%rsi,%rdx) addq$4, %rdx cmpq$1024, %rdx jne .L2 There were 1 addl and 1 leal. 1 addq was to update the loop counter. The optimized loop is .L2: imull $-1564285888, (%rdi,%rax), %edx subl$1269844480, %edx movl%edx, (%rsi,%rax) addq$4, %rax cmpq$1024, %rax jne .L2 1 addl is changed to subl and leal is removed. Adjust assembly scan to check for 1 subl and 1 addl/addq as well as lea removal. * gcc.target/i386/pr53533-1.c: Adjust assembly scan. * gcc.target/i386/pr53533-3.c: Likewise. Signed-off-by: H.J. Lu Diff: --- gcc/testsuite/gcc.target/i386/pr53533-1.c | 4 +++- gcc/testsuite/gcc.target/i386/pr53533-3.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/gcc.target/i386/pr53533-1.c b/gcc/testsuite/gcc.target/i386/pr53533-1.c index 095de6653665..11d12015145b 100644 --- a/gcc/testsuite/gcc.target/i386/pr53533-1.c +++ b/gcc/testsuite/gcc.target/i386/pr53533-1.c @@ -1,7 +1,9 @@ /* { dg-do compile } */ /* { dg-options "-O1" } */ /* { dg-final { scan-assembler-times "imull\[ \t\]" "1" } } */ -/* { dg-final { scan-assembler-times "(?:addl|subl)\[ \t\]" "1" { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-times "subl\[ \t\]" "1" } } */ +/* { dg-final { scan-assembler-times "add(?:l|q)\[ \t\]" "1" } } */ +/* { dg-final { scan-assembler-not "leal" } } */ void __attribute__((noipa)) diff --git a/gcc/testsuite/gcc.target/i386/pr53533-3.c b/gcc/testsuite/gcc.target/i386/pr53533-3.c index 3b260d134e91..347fa828eb76 100644 --- a/gcc/testsuite/gcc.target/i386/pr53533-3.c +++ b/gcc/testsuite/gcc.target/i386/pr53533-3.c @@ -1,7 +1,9 @@ /* { dg-do compile } */ /* { dg-options "-O1 -fwrapv" } */ /* { dg-final { scan-assembler-times "imull\[ \t\]" "1" } } */ -/* { dg-final { scan-assembler-times "(?:addl|subl)\[ \t\]" "1" { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-times "subl\[ \t\]" "1" } } */ +/* { dg-final { scan-assembler-times "add(?:l|q)\[ \t\]" "1" } } */ +/* { dg-final { scan-assembler-not "leal" } } */ void __attribute__((noipa))
[gcc r15-4705] genmatch: Add selftests to genmatch for diag_vfprintf
https://gcc.gnu.org/g:c246c4bcb353e8dc30e7e4d45dd27d982a21eab4 commit r15-4705-gc246c4bcb353e8dc30e7e4d45dd27d982a21eab4 Author: Jakub Jelinek Date: Sun Oct 27 16:44:35 2024 +0100 genmatch: Add selftests to genmatch for diag_vfprintf The following patch adds selftests to genmatch to verify the new printing routine there. So that I can rely on HAVE_DECL_FMEMOPEN (host test), the tests are done solely in stage2+ where we link the host libcpp etc. to genmatch. The tests have been adjusted from pretty-print.cc (test_pp_format), and I've added to that function two new tests because I've noticed nothing was testing the %M$.*N$s etc. format specifiers. 2024-10-27 Jakub Jelinek * configure.ac (gcc_AC_CHECK_DECLS): Add fmemopen. * configure: Regenerate. * config.in: Regenerate. * Makefile.in (build/genmatch.o): Add -DGENMATCH_SELFTESTS to BUILD_CPPFLAGS for stage2+ genmatch. * genmatch.cc (test_diag_vfprintf, genmatch_diag_selftests): New functions. (main): Call genmatch_diag_selftests. * pretty-print.cc (test_pp_format): Add two tests, one for %M$.*N$s and one for %M$.Ns. Diff: --- gcc/Makefile.in | 1 + gcc/config.in | 7 +++ gcc/configure | 2 +- gcc/configure.ac| 2 +- gcc/genmatch.cc | 134 gcc/pretty-print.cc | 8 6 files changed, 152 insertions(+), 2 deletions(-) diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 059cf2e8f79f..1be4ea02992c 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -3143,6 +3143,7 @@ else BUILD_CPPLIB = $(CPPLIB) $(LIBIBERTY) build/genmatch$(build_exeext): BUILD_LIBDEPS += $(LIBINTL_DEP) $(LIBICONV_DEP) build/genmatch$(build_exeext): BUILD_LIBS += $(LIBINTL) $(LIBICONV) +build/genmatch.o: BUILD_CPPFLAGS += -DGENMATCH_SELFTESTS endif build/genmatch$(build_exeext) : $(BUILD_CPPLIB) \ diff --git a/gcc/config.in b/gcc/config.in index 7fcabbe5061d..3fc4666d60b5 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -1018,6 +1018,13 @@ #endif +/* Define to 1 if we found a declaration for 'fmemopen', otherwise define to + 0. */ +#ifndef USED_FOR_TARGET +#undef HAVE_DECL_FMEMOPEN +#endif + + /* Define to 1 if we found a declaration for 'fprintf_unlocked', otherwise define to 0. */ #ifndef USED_FOR_TARGET diff --git a/gcc/configure b/gcc/configure index 5acc42c1e4d9..47c58036530f 100755 --- a/gcc/configure +++ b/gcc/configure @@ -12084,7 +12084,7 @@ for ac_func in getenv atol atoll asprintf sbrk abort atof getcwd getwd \ madvise stpcpy strnlen strsignal strverscmp \ strtol strtoul strtoll strtoull setenv unsetenv \ errno snprintf vsnprintf vasprintf malloc realloc calloc \ - free getopt clock getpagesize ffs clearerr_unlocked feof_unlocked ferror_unlocked fflush_unlocked fgetc_unlocked fgets_unlocked fileno_unlocked fprintf_unlocked fputc_unlocked fputs_unlocked fread_unlocked fwrite_unlocked getchar_unlocked getc_unlocked putchar_unlocked putc_unlocked + free getopt clock getpagesize ffs fmemopen clearerr_unlocked feof_unlocked ferror_unlocked fflush_unlocked fgetc_unlocked fgets_unlocked fileno_unlocked fprintf_unlocked fputc_unlocked fputs_unlocked fread_unlocked fwrite_unlocked getchar_unlocked getc_unlocked putchar_unlocked putc_unlocked do ac_tr_decl=`$as_echo "HAVE_DECL_$ac_func" | $as_tr_cpp` { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $ac_func is declared" >&5 diff --git a/gcc/configure.ac b/gcc/configure.ac index 23f4884eff9e..dc8346a7b823 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -1629,7 +1629,7 @@ gcc_AC_CHECK_DECLS(getenv atol atoll asprintf sbrk abort atof getcwd getwd \ madvise stpcpy strnlen strsignal strverscmp \ strtol strtoul strtoll strtoull setenv unsetenv \ errno snprintf vsnprintf vasprintf malloc realloc calloc \ - free getopt clock getpagesize ffs gcc_UNLOCKED_FUNCS, , ,[ + free getopt clock getpagesize ffs fmemopen gcc_UNLOCKED_FUNCS, , ,[ #include "ansidecl.h" #include "system.h"]) diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index 1acd9216b3b0..170bf6162b5d 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -585,6 +585,138 @@ diag_vfprintf (FILE *f, int err_no, const char *msg, va_list *ap) fprintf (f, "%s", q); } +#if defined(GENMATCH_SELFTESTS) && defined(HAVE_DECL_FMEMOPEN) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wsuggest-attribute=format" + +static void +test_diag_vfprintf (const char *expected, const char *msg, ...) +{ + char buf[256]; + va_list ap; + FILE *f = fmemopen (buf, 256, "w"); + gcc_assert (f != NULL); + va_start (ap, msg); + diag_vfprintf (f, 0, msg, &ap); + va_end (ap); + fclose (f); + gcc_assert (strcmp (buf, expected) == 0); +} + +#pragma GCC diagnostic pop + +static void +genmatch_d
[gcc r15-4704] c-family: -Wleading-whitespace= argument spelling
https://gcc.gnu.org/g:ad7d5cd65ee35e95b067a14ed882f7beaa94bdf0 commit r15-4704-gad7d5cd65ee35e95b067a14ed882f7beaa94bdf0 Author: Jakub Jelinek Date: Sun Oct 27 16:42:53 2024 +0100 c-family: -Wleading-whitespace= argument spelling On Thu, Oct 24, 2024 at 03:33:25PM -0400, Eric Gallager wrote: > On Thu, Oct 24, 2024 at 4:17 AM Jakub Jelinek wrote: > > I've tried to build stage3 with > > -Wleading-whitespace=blanks -Wtrailing-whitespace=blank -Wno-error=leading-whitespace=blanks -Wno-error=trailing-whitespace=blank > > So wait, it's "blanks" (plural) when it's leading, but "blank" > (singular) when it's trailing? That inconsistency bothers me... I've mentioned it already in https://gcc.gnu.org/pipermail/gcc-patches/2024-October/664664.html Citing that here: Not sure about the kinds for the option, given -Wleading-whitespace= uses plural and this option singular and -Wleading-whitespace= spaces means literally just ' ' characters, while space in -Wtrailing-whitespace= was ' ', '\t', '\v' and '\f'; so category; perhaps just use any and blanks? Other preferences? Here is a patch to do the blank->blanks and space->any changes. 2024-10-27 Jakub Jelinek gcc/ * doc/invoke.texi (Wtrailing-whitespace=): Change blank argument to blanks and space argument to any. gcc/c-family/ * c.opt (warn_trailing_whitespace_kind): Change blank to blanks and space to any. gcc/testsuite/ * c-c++-common/cpp/Wtrailing-whitespace-2.c: Use -Wtrailing-whitespace=blanks rather than -Wtrailing-whitespace=blank. * c-c++-common/cpp/Wtrailing-whitespace-3.c: Use -Wtrailing-whitespace=any rather than -Wtrailing-whitespace=space. * c-c++-common/cpp/Wtrailing-whitespace-7.c: Use -Wtrailing-whitespace=blanks rather than -Wtrailing-whitespace=blank. * c-c++-common/cpp/Wtrailing-whitespace-8.c: Use -Wtrailing-whitespace=any rather than -Wtrailing-whitespace=space. Diff: --- gcc/c-family/c.opt | 8 gcc/doc/invoke.texi | 4 ++-- gcc/testsuite/c-c++-common/cpp/Wtrailing-whitespace-2.c | 2 +- gcc/testsuite/c-c++-common/cpp/Wtrailing-whitespace-3.c | 2 +- gcc/testsuite/c-c++-common/cpp/Wtrailing-whitespace-7.c | 2 +- gcc/testsuite/c-c++-common/cpp/Wtrailing-whitespace-8.c | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index af79e4f726b7..3fd331cda829 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -1492,18 +1492,18 @@ EnumValue Enum(warn_trailing_whitespace_kind) String(none) Value(0) EnumValue -Enum(warn_trailing_whitespace_kind) String(blank) Value(1) +Enum(warn_trailing_whitespace_kind) String(blanks) Value(1) EnumValue -Enum(warn_trailing_whitespace_kind) String(space) Value(2) +Enum(warn_trailing_whitespace_kind) String(any) Value(2) Wtrailing-whitespace= C ObjC C++ ObjC++ CPP(cpp_warn_trailing_whitespace) CppReason(CPP_W_TRAILING_WHITESPACE) Enum(warn_trailing_whitespace_kind) Joined RejectNegative Var(warn_trailing_whitespace) Init(0) Warning Warn about trailing whitespace on lines except when in raw string literals. Wtrailing-whitespace -C ObjC C++ ObjC++ Alias(Wtrailing-whitespace=,blank,none) Warning -Warn about trailing whitespace on lines except when in raw string literals. Equivalent to Wtrailing-whitespace=blank when enabled or Wtrailing-whitespace=none when disabled. +C ObjC C++ ObjC++ Alias(Wtrailing-whitespace=,blanks,none) Warning +Warn about trailing whitespace on lines except when in raw string literals. Equivalent to Wtrailing-whitespace=blanks when enabled or Wtrailing-whitespace=none when disabled. Wtrigraphs C ObjC C++ ObjC++ CPP(warn_trigraphs) CppReason(CPP_W_TRIGRAPHS) Var(cpp_warn_trigraphs) Init(2) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 6f946421462a..ae52cc68c511 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -8784,8 +8784,8 @@ This warning is enabled by @option{-Wall}. Warn about trailing whitespace at the end of lines, including inside of comments, but excluding trailing whitespace in raw string literals. @code{-Wtrailing-whitespace} is equivalent to -@code{-Wtrailing-whitespace=blank} and warns just about trailing space and -horizontal tab characters. @code{-Wtrailing-whitespace=space} warns about +@code{-Wtrailing-whitespace=blanks} and warns just about trailing space and +horizontal tab characters. @code{-Wtrailing-whitespace=any} warns about those or trailing form feed or vertical tab characters. @code{-Wno-trailing-whitespace} or @code{-Wtrailing-whitespace=none} disables the warning, which is the default. diff --git a/gcc/testsuite/c-c++-common/cpp/Wtraili
[gcc r15-4706] xtensa: Define TARGET_DIFFERENT_ADDR_DISPLACEMENT_P target hook
https://gcc.gnu.org/g:211459e12147e9ed42c0a0947b1b95b551e03ef3 commit r15-4706-g211459e12147e9ed42c0a0947b1b95b551e03ef3 Author: Takayuki 'January June' Suwa Date: Wed Oct 23 11:31:15 2024 +0900 xtensa: Define TARGET_DIFFERENT_ADDR_DISPLACEMENT_P target hook In commit bc5a9dab55d13f888a3cdd150c8cf5c2244f35e0 ("gcc: xtensa: reorder movsi_internal patterns for better code generation during LRA"), the instruction order in "movsi_internal" MD definition was changed to make LRA use load/store instructions with larger memory address displacements, but as a side effect, it now uses the larger displacements (ie., the larger instructions) even outside of reload operations. The underlying problem is that LRA assumes by default that there is only one maximal legitimate displacement for the same address structure, meaning that it has no choice but to use the first load/store instruction it finds. To fix this, define TARGET_DIFFERENT_ADDR_DISPLACEMENT_P hook to always return true. gcc/ChangeLog: * config/xtensa/xtensa.cc (TARGET_DIFFERENT_ADDR_DISPLACEMENT_P): Add new target hook to always return true. * config/xtensa/xtensa.md (movsi_internal): Revert the previous changes. Diff: --- gcc/config/xtensa/xtensa.cc | 3 +++ gcc/config/xtensa/xtensa.md | 12 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc index 43b1332d42b3..d2793822641c 100644 --- a/gcc/config/xtensa/xtensa.cc +++ b/gcc/config/xtensa/xtensa.cc @@ -363,6 +363,9 @@ static rtx xtensa_delegitimize_address (rtx); #undef TARGET_MAX_ANCHOR_OFFSET #define TARGET_MAX_ANCHOR_OFFSET 1020 +#undef TARGET_DIFFERENT_ADDR_DISPLACEMENT_P +#define TARGET_DIFFERENT_ADDR_DISPLACEMENT_P hook_bool_void_true + struct gcc_target targetm = TARGET_INITIALIZER; diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md index f19e1fd16b54..2c08c7d6bf10 100644 --- a/gcc/config/xtensa/xtensa.md +++ b/gcc/config/xtensa/xtensa.md @@ -1279,15 +1279,13 @@ }) (define_insn "movsi_internal" - [(set (match_operand:SI 0 "nonimmed_operand" "=D,D,D,a,U,D,R,R,a,q,a,a,W,a,*a,*A") - (match_operand:SI 1 "move_operand" "M,D,d,U,r,R,D,d,r,r,I,Y,i,T,*A,*r"))] + [(set (match_operand:SI 0 "nonimmed_operand" "=D,D,D,D,R,R,a,q,a,a,W,a,a,U,*a,*A") + (match_operand:SI 1 "move_operand" "M,D,d,R,D,d,r,r,I,Y,i,T,U,r,*A,*r"))] "xtensa_valid_move (SImode, operands)" "@ movi.n\t%0, %x1 mov.n\t%0, %1 mov.n\t%0, %1 - %v1l32i\t%0, %1 - %v0s32i\t%1, %0 %v1l32i.n\t%0, %1 %v0s32i.n\t%1, %0 %v0s32i.n\t%1, %0 @@ -1297,11 +1295,13 @@ movi\t%0, %1 const16\t%0, %t1\;const16\t%0, %b1 %v1l32r\t%0, %1 + %v1l32i\t%0, %1 + %v0s32i\t%1, %0 rsr\t%0, ACCLO wsr\t%1, ACCLO" - [(set_attr "type" "move,move,move,load,store,load,store,store,move,move,move,move,move,load,rsr,wsr") + [(set_attr "type" "move,move,move,load,store,store,move,move,move,move,move,load,load,store,rsr,wsr") (set_attr "mode""SI") - (set_attr "length" "2,2,2,3,3,2,2,2,3,3,3,3,6,3,3,3")]) + (set_attr "length" "2,2,2,2,2,2,3,3,3,3,6,3,3,3,3,3")]) (define_split [(set (match_operand:SHI 0 "register_operand")
[gcc r15-4707] arm: Support -mfdpic for more targets
https://gcc.gnu.org/g:8e6cc1e7cdbb431a0950e491ed2830213f3ad81b commit r15-4707-g8e6cc1e7cdbb431a0950e491ed2830213f3ad81b Author: Fangrui Song Date: Sun Oct 27 12:37:21 2024 -0700 arm: Support -mfdpic for more targets Targets that are not arm*-*-uclinuxfdpiceabi can use -S -mfdpic, but -c -mfdpic does not pass --fdpic to gas. This is an unnecessary restriction. Just define the ASM_SPEC in bpabi.h. Additionally, use armelf[b]_linux_fdpiceabi emulations for -mfdpic in linux-eabi.h. This will allow a future musl fdpic port to use the desired BFD emulation. gcc/ChangeLog: * config/arm/bpabi.h (TARGET_FDPIC_ASM_SPEC): Transform -mfdpic. * config/arm/linux-eabi.h (TARGET_FDPIC_LINKER_EMULATION): Define. (SUBTARGET_EXTRA_LINK_SPEC): Use TARGET_FDPIC_LINKER_EMULATION if -mfdpic. Diff: --- gcc/config/arm/bpabi.h | 2 +- gcc/config/arm/linux-eabi.h | 5 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/gcc/config/arm/bpabi.h b/gcc/config/arm/bpabi.h index 2e418fa91350..fd4b65a28afe 100644 --- a/gcc/config/arm/bpabi.h +++ b/gcc/config/arm/bpabi.h @@ -55,7 +55,7 @@ #define TARGET_FIX_V4BX_SPEC " %{mcpu=arm8|mcpu=arm810|mcpu=strongarm*"\ "|march=armv4|mcpu=fa526|mcpu=fa626:--fix-v4bx}" -#define TARGET_FDPIC_ASM_SPEC "" +#define TARGET_FDPIC_ASM_SPEC "%{mfdpic: --fdpic}" #define BE8_LINK_SPEC \ "%{!r:%{!mbe32:%:be8_linkopt(%{mlittle-endian:little}" \ diff --git a/gcc/config/arm/linux-eabi.h b/gcc/config/arm/linux-eabi.h index 50b753df9bcd..b12e4ff82cc3 100644 --- a/gcc/config/arm/linux-eabi.h +++ b/gcc/config/arm/linux-eabi.h @@ -46,12 +46,15 @@ #undef TARGET_LINKER_EMULATION #if TARGET_BIG_ENDIAN_DEFAULT #define TARGET_LINKER_EMULATION "armelfb_linux_eabi" +#define TARGET_FDPIC_LINKER_EMULATION "armelfb_linux_fdpiceabi" #else #define TARGET_LINKER_EMULATION "armelf_linux_eabi" +#define TARGET_FDPIC_LINKER_EMULATION "armelf_linux_fdpiceabi" #endif #undef SUBTARGET_EXTRA_LINK_SPEC -#define SUBTARGET_EXTRA_LINK_SPEC " -m " TARGET_LINKER_EMULATION +#define SUBTARGET_EXTRA_LINK_SPEC " -m %{mfdpic: " \ + TARGET_FDPIC_LINKER_EMULATION ";:" TARGET_LINKER_EMULATION "}" /* GNU/Linux on ARM currently supports three dynamic linkers: - ld-linux.so.2 - for the legacy ABI
[gcc r15-4708] libstdc++: Fix std::vector::emplace to forward parameter
https://gcc.gnu.org/g:f1c844be5202f4be446f165d9a7625eb7ec4c5b4 commit r15-4708-gf1c844be5202f4be446f165d9a7625eb7ec4c5b4 Author: Jonathan Wakely Date: Sat Oct 26 21:24:58 2024 +0100 libstdc++: Fix std::vector::emplace to forward parameter If the parameter is not lvalue-convertible to bool then the current code will fail to compile. The parameter should be forwarded to restore the original value category. libstdc++-v3/ChangeLog: * include/bits/stl_bvector.h (emplace_back, emplace): Forward parameter pack to preserve value category. * testsuite/23_containers/vector/bool/emplace_rvalue.cc: New test. Diff: --- libstdc++-v3/include/bits/stl_bvector.h| 4 ++-- .../23_containers/vector/bool/emplace_rvalue.cc| 24 ++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index 42261ac5915f..70f69b5b5b55 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -1343,7 +1343,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER #endif emplace_back(_Args&&... __args) { - push_back(bool(__args...)); + push_back(bool(std::forward<_Args>(__args)...)); #if __cplusplus > 201402L return back(); #endif @@ -1353,7 +1353,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _GLIBCXX20_CONSTEXPR iterator emplace(const_iterator __pos, _Args&&... __args) - { return insert(__pos, bool(__args...)); } + { return insert(__pos, bool(std::forward<_Args>(__args)...)); } #endif protected: diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/emplace_rvalue.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/emplace_rvalue.cc new file mode 100644 index ..5dea2426d602 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/emplace_rvalue.cc @@ -0,0 +1,24 @@ +// { dg-do compile { target c++11 } } + +#include + +struct S +{ + explicit operator bool() &&; +}; + +void +test_emplace_back() +{ + S s; + std::vector v; + v.emplace_back(std::move(s)); +} + +void +test_emplace() +{ + S s; + std::vector v; + v.emplace(v.begin(), std::move(s)); +}
[gcc r15-4709] libstdc++: Add P1206R7 from_range members to std::vector [PR111055]
https://gcc.gnu.org/g:b281e13ecad12d07209924a7282c53be3a1c3774 commit r15-4709-gb281e13ecad12d07209924a7282c53be3a1c3774 Author: Jonathan Wakely Date: Tue Oct 8 21:15:18 2024 +0100 libstdc++: Add P1206R7 from_range members to std::vector [PR111055] This is another piece of P1206R7, adding new members to std::vector and std::vector. The __uninitialized_copy_a extension needs to be enhanced to support passing non-common ranges (i.e. a sentinel that is a different type from the iterator) and move-only input iterators. libstdc++-v3/ChangeLog: PR libstdc++/111055 * include/bits/ranges_base.h (__container_compatible_range): New concept. * include/bits/stl_bvector.h (vector(from_range, R&&, const Alloc&)) (assign_range, insert_range, append_range): Define. * include/bits/stl_uninitialized.h (__do_uninit_copy): Support non-common ranges. (__uninitialized_copy_a): Likewise. * include/bits/stl_vector.h (_Vector_base::_M_append_range_to): New function. (_Vector_base::_M_append_range): Likewise. (vector(from_range, R&&, const Alloc&), assign_range): Define. (append_range): Define. (insert_range): Declare. * include/debug/vector (vector(from_range, R&&, const Alloc&)) (assign_range, insert_range, append_range): Define. * include/bits/vector.tcc (insert_range): Define. * testsuite/util/testsuite_iterators.h (input_iterator_wrapper_rval): New class template. * testsuite/23_containers/vector/bool/cons/from_range.cc: New test. * testsuite/23_containers/vector/bool/modifiers/assign/assign_range.cc: New test. * testsuite/23_containers/vector/bool/modifiers/insert/append_range.cc: New test. * testsuite/23_containers/vector/bool/modifiers/insert/insert_range.cc: New test. * testsuite/23_containers/vector/cons/from_range.cc: New test. * testsuite/23_containers/vector/modifiers/append_range.cc: New test. * testsuite/23_containers/vector/modifiers/assign/assign_range.cc: New test. * testsuite/23_containers/vector/modifiers/insert/insert_range.cc: New test. Reviewed-by: Patrick Palka Diff: --- libstdc++-v3/include/bits/ranges_base.h| 10 ++ libstdc++-v3/include/bits/stl_bvector.h| 120 +++ libstdc++-v3/include/bits/stl_uninitialized.h | 37 - libstdc++-v3/include/bits/stl_vector.h | 166 + libstdc++-v3/include/bits/vector.tcc | 123 +++ libstdc++-v3/include/debug/vector | 70 + .../23_containers/vector/bool/cons/from_range.cc | 91 +++ .../vector/bool/modifiers/assign/assign_range.cc | 106 + .../vector/bool/modifiers/insert/append_range.cc | 93 .../vector/bool/modifiers/insert/insert_range.cc | 104 + .../23_containers/vector/cons/from_range.cc| 108 ++ .../23_containers/vector/modifiers/append_range.cc | 97 .../vector/modifiers/assign/assign_range.cc| 121 +++ .../vector/modifiers/insert/insert_range.cc| 108 ++ libstdc++-v3/testsuite/util/testsuite_iterators.h | 20 +++ 15 files changed, 1366 insertions(+), 8 deletions(-) diff --git a/libstdc++-v3/include/bits/ranges_base.h b/libstdc++-v3/include/bits/ranges_base.h index cb2eba1f841a..a2c743ff56bc 100644 --- a/libstdc++-v3/include/bits/ranges_base.h +++ b/libstdc++-v3/include/bits/ranges_base.h @@ -1079,6 +1079,16 @@ namespace ranges #if __glibcxx_ranges_to_container // C++ >= 23 struct from_range_t { explicit from_range_t() = default; }; inline constexpr from_range_t from_range{}; + +/// @cond undocumented +namespace __detail +{ + template +concept __container_compatible_range + = ranges::input_range<_Rg> + && convertible_to, _Tp>; +} +/// @endcond #endif _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index 70f69b5b5b55..39d19e7954d6 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -892,6 +892,31 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER } #endif +#if __glibcxx_ranges_to_container // C++ >= 23 + /** + * @brief Construct a vector from a range. + * @since C++23 + */ + template<__detail::__container_compatible_range _Rg> + constexpr + vector(from_range_t, _Rg&& __rg, const _Alloc& __a = _Alloc()) + : _Base(__a) + { + if constexpr (ranges::forward_range<_Rg> || ranges::sized_range<_Rg>) + { + _M_initialize(size_type(ranges::dist
[gcc r15-4701] testsuite: Sanitize pacbti test cases for Cortex-M
https://gcc.gnu.org/g:6ad29a858bac7cf9e765925cf5f6945e20f085be commit r15-4701-g6ad29a858bac7cf9e765925cf5f6945e20f085be Author: Torbjörn SVENSSON Date: Tue Sep 3 11:23:57 2024 +0200 testsuite: Sanitize pacbti test cases for Cortex-M Some of the test cases were scanning for "bti", but it would, incorrectly, match the ".arch_extenssion pacbti". gcc/testsuite/ChangeLog: * gcc.target/arm/bti-1.c: Check for asm instructions starting with a tab. * gcc.target/arm/bti-2.c: Likewise. * gcc.target/arm/pac-1.c: Likewise. * gcc.target/arm/pac-2.c: Likewise. * gcc.target/arm/pac-3.c: Likewise. * gcc.target/arm/pac-4.c: Likewise. * gcc.target/arm/pac-6.c: Likewise. * gcc.target/arm/pac-7.c: Likewise. * gcc.target/arm/pac-8.c: Likewise. * gcc.target/arm/pac-9.c: Likewise. * gcc.target/arm/pac-10.c: Likewise. * gcc.target/arm/pac-11.c: Likewise. * gcc.target/arm/pac-15.c: Likewise. * gcc.target/arm/pac-sibcall.c: Likewise. Signed-off-by: Torbjörn SVENSSON Co-authored-by: Yvan ROUX Diff: --- gcc/testsuite/gcc.target/arm/bti-1.c | 2 +- gcc/testsuite/gcc.target/arm/bti-2.c | 2 +- gcc/testsuite/gcc.target/arm/pac-1.c | 4 ++-- gcc/testsuite/gcc.target/arm/pac-10.c | 4 ++-- gcc/testsuite/gcc.target/arm/pac-11.c | 4 ++-- gcc/testsuite/gcc.target/arm/pac-15.c | 2 +- gcc/testsuite/gcc.target/arm/pac-2.c | 4 ++-- gcc/testsuite/gcc.target/arm/pac-3.c | 4 ++-- gcc/testsuite/gcc.target/arm/pac-4.c | 2 +- gcc/testsuite/gcc.target/arm/pac-6.c | 6 +++--- gcc/testsuite/gcc.target/arm/pac-7.c | 4 ++-- gcc/testsuite/gcc.target/arm/pac-8.c | 4 ++-- gcc/testsuite/gcc.target/arm/pac-9.c | 4 ++-- gcc/testsuite/gcc.target/arm/pac-sibcall.c | 2 +- 14 files changed, 24 insertions(+), 24 deletions(-) diff --git a/gcc/testsuite/gcc.target/arm/bti-1.c b/gcc/testsuite/gcc.target/arm/bti-1.c index a34bb0842b63..8403fc876ee2 100644 --- a/gcc/testsuite/gcc.target/arm/bti-1.c +++ b/gcc/testsuite/gcc.target/arm/bti-1.c @@ -10,4 +10,4 @@ main (void) return 0; } -/* { dg-final { scan-assembler "bti" } } */ +/* { dg-final { scan-assembler "\tbti" } } */ diff --git a/gcc/testsuite/gcc.target/arm/bti-2.c b/gcc/testsuite/gcc.target/arm/bti-2.c index e5bc4d5543a8..5af2b0dcc3c7 100644 --- a/gcc/testsuite/gcc.target/arm/bti-2.c +++ b/gcc/testsuite/gcc.target/arm/bti-2.c @@ -56,4 +56,4 @@ lab2: return 2; } -/* { dg-final { scan-assembler-times "bti" 15 } } */ +/* { dg-final { scan-assembler-times "\tbti" 14 } } */ diff --git a/gcc/testsuite/gcc.target/arm/pac-1.c b/gcc/testsuite/gcc.target/arm/pac-1.c index 9b26f62b65f7..e0eea0858e03 100644 --- a/gcc/testsuite/gcc.target/arm/pac-1.c +++ b/gcc/testsuite/gcc.target/arm/pac-1.c @@ -6,6 +6,6 @@ #include "pac.h" -/* { dg-final { scan-assembler-times "pac\tip, lr, sp" 2 } } */ -/* { dg-final { scan-assembler-times "aut\tip, lr, sp" 2 } } */ +/* { dg-final { scan-assembler-times "\tpac\tip, lr, sp" 2 } } */ +/* { dg-final { scan-assembler-times "\taut\tip, lr, sp" 2 } } */ /* { dg-final { scan-assembler-not "\tbti" } } */ diff --git a/gcc/testsuite/gcc.target/arm/pac-10.c b/gcc/testsuite/gcc.target/arm/pac-10.c index a794195e8f6e..6da8434aeaf0 100644 --- a/gcc/testsuite/gcc.target/arm/pac-10.c +++ b/gcc/testsuite/gcc.target/arm/pac-10.c @@ -5,6 +5,6 @@ #include "pac.h" -/* { dg-final { scan-assembler "pac\tip, lr, sp" } } */ -/* { dg-final { scan-assembler "aut\tip, lr, sp" } } */ +/* { dg-final { scan-assembler "\tpac\tip, lr, sp" } } */ +/* { dg-final { scan-assembler "\taut\tip, lr, sp" } } */ /* { dg-final { scan-assembler-not "\tbti" } } */ diff --git a/gcc/testsuite/gcc.target/arm/pac-11.c b/gcc/testsuite/gcc.target/arm/pac-11.c index 37ffc93b41b3..0bb727c2c800 100644 --- a/gcc/testsuite/gcc.target/arm/pac-11.c +++ b/gcc/testsuite/gcc.target/arm/pac-11.c @@ -5,6 +5,6 @@ #include "pac.h" -/* { dg-final { scan-assembler-times "pacbti\tip, lr, sp" 2 } } */ -/* { dg-final { scan-assembler-times "aut\tip, lr, sp" 2 } } */ +/* { dg-final { scan-assembler-times "\tpacbti\tip, lr, sp" 2 } } */ +/* { dg-final { scan-assembler-times "\taut\tip, lr, sp" 2 } } */ /* { dg-final { scan-assembler-not "\tbti" } } */ diff --git a/gcc/testsuite/gcc.target/arm/pac-15.c b/gcc/testsuite/gcc.target/arm/pac-15.c index e10549029556..979941492d3b 100644 --- a/gcc/testsuite/gcc.target/arm/pac-15.c +++ b/gcc/testsuite/gcc.target/arm/pac-15.c @@ -24,7 +24,7 @@ int main (void) } /* { dg-final { scan-assembler-times "\.pacspval" 1 } } */ -/* { dg-final { scan-assembler-times "pac ip, lr, sp" 3 } } */ +/* { dg-final { scan-assembler-times "\tpac\tip, lr, sp" 3 } } */ /* { dg-final { scan-assembler-times "\.cfi_register 143, 12" 3 } } */ /* { dg-final { scan-assembler-times "\.save {r
[gcc r14-10843] testsuite: Sanitize pacbti test cases for Cortex-M
https://gcc.gnu.org/g:ec9bd14144a9e536e450b9fb98f26dab40ee75d8 commit r14-10843-gec9bd14144a9e536e450b9fb98f26dab40ee75d8 Author: Torbjörn SVENSSON Date: Tue Sep 3 11:23:57 2024 +0200 testsuite: Sanitize pacbti test cases for Cortex-M Some of the test cases were scanning for "bti", but it would, incorrectly, match the ".arch_extenssion pacbti". gcc/testsuite/ChangeLog: * gcc.target/arm/bti-1.c: Check for asm instructions starting with a tab. * gcc.target/arm/bti-2.c: Likewise. * gcc.target/arm/pac-1.c: Likewise. * gcc.target/arm/pac-2.c: Likewise. * gcc.target/arm/pac-3.c: Likewise. * gcc.target/arm/pac-4.c: Likewise. * gcc.target/arm/pac-6.c: Likewise. * gcc.target/arm/pac-7.c: Likewise. * gcc.target/arm/pac-8.c: Likewise. * gcc.target/arm/pac-9.c: Likewise. * gcc.target/arm/pac-10.c: Likewise. * gcc.target/arm/pac-11.c: Likewise. * gcc.target/arm/pac-15.c: Likewise. * gcc.target/arm/pac-sibcall.c: Likewise. Signed-off-by: Torbjörn SVENSSON Co-authored-by: Yvan ROUX (cherry picked from commit 6ad29a858bac7cf9e765925cf5f6945e20f085be) Diff: --- gcc/testsuite/gcc.target/arm/bti-1.c | 2 +- gcc/testsuite/gcc.target/arm/bti-2.c | 2 +- gcc/testsuite/gcc.target/arm/pac-1.c | 4 ++-- gcc/testsuite/gcc.target/arm/pac-10.c | 4 ++-- gcc/testsuite/gcc.target/arm/pac-11.c | 4 ++-- gcc/testsuite/gcc.target/arm/pac-15.c | 2 +- gcc/testsuite/gcc.target/arm/pac-2.c | 4 ++-- gcc/testsuite/gcc.target/arm/pac-3.c | 4 ++-- gcc/testsuite/gcc.target/arm/pac-4.c | 2 +- gcc/testsuite/gcc.target/arm/pac-6.c | 6 +++--- gcc/testsuite/gcc.target/arm/pac-7.c | 4 ++-- gcc/testsuite/gcc.target/arm/pac-8.c | 4 ++-- gcc/testsuite/gcc.target/arm/pac-9.c | 4 ++-- gcc/testsuite/gcc.target/arm/pac-sibcall.c | 2 +- 14 files changed, 24 insertions(+), 24 deletions(-) diff --git a/gcc/testsuite/gcc.target/arm/bti-1.c b/gcc/testsuite/gcc.target/arm/bti-1.c index 79dd8010d2da..54a733d9f20a 100644 --- a/gcc/testsuite/gcc.target/arm/bti-1.c +++ b/gcc/testsuite/gcc.target/arm/bti-1.c @@ -9,4 +9,4 @@ main (void) return 0; } -/* { dg-final { scan-assembler "bti" } } */ +/* { dg-final { scan-assembler "\tbti" } } */ diff --git a/gcc/testsuite/gcc.target/arm/bti-2.c b/gcc/testsuite/gcc.target/arm/bti-2.c index 33910563849a..645ad3694241 100644 --- a/gcc/testsuite/gcc.target/arm/bti-2.c +++ b/gcc/testsuite/gcc.target/arm/bti-2.c @@ -55,4 +55,4 @@ lab2: return 2; } -/* { dg-final { scan-assembler-times "bti" 15 } } */ +/* { dg-final { scan-assembler-times "\tbti" 14 } } */ diff --git a/gcc/testsuite/gcc.target/arm/pac-1.c b/gcc/testsuite/gcc.target/arm/pac-1.c index 9b26f62b65f7..e0eea0858e03 100644 --- a/gcc/testsuite/gcc.target/arm/pac-1.c +++ b/gcc/testsuite/gcc.target/arm/pac-1.c @@ -6,6 +6,6 @@ #include "pac.h" -/* { dg-final { scan-assembler-times "pac\tip, lr, sp" 2 } } */ -/* { dg-final { scan-assembler-times "aut\tip, lr, sp" 2 } } */ +/* { dg-final { scan-assembler-times "\tpac\tip, lr, sp" 2 } } */ +/* { dg-final { scan-assembler-times "\taut\tip, lr, sp" 2 } } */ /* { dg-final { scan-assembler-not "\tbti" } } */ diff --git a/gcc/testsuite/gcc.target/arm/pac-10.c b/gcc/testsuite/gcc.target/arm/pac-10.c index a794195e8f6e..6da8434aeaf0 100644 --- a/gcc/testsuite/gcc.target/arm/pac-10.c +++ b/gcc/testsuite/gcc.target/arm/pac-10.c @@ -5,6 +5,6 @@ #include "pac.h" -/* { dg-final { scan-assembler "pac\tip, lr, sp" } } */ -/* { dg-final { scan-assembler "aut\tip, lr, sp" } } */ +/* { dg-final { scan-assembler "\tpac\tip, lr, sp" } } */ +/* { dg-final { scan-assembler "\taut\tip, lr, sp" } } */ /* { dg-final { scan-assembler-not "\tbti" } } */ diff --git a/gcc/testsuite/gcc.target/arm/pac-11.c b/gcc/testsuite/gcc.target/arm/pac-11.c index 37ffc93b41b3..0bb727c2c800 100644 --- a/gcc/testsuite/gcc.target/arm/pac-11.c +++ b/gcc/testsuite/gcc.target/arm/pac-11.c @@ -5,6 +5,6 @@ #include "pac.h" -/* { dg-final { scan-assembler-times "pacbti\tip, lr, sp" 2 } } */ -/* { dg-final { scan-assembler-times "aut\tip, lr, sp" 2 } } */ +/* { dg-final { scan-assembler-times "\tpacbti\tip, lr, sp" 2 } } */ +/* { dg-final { scan-assembler-times "\taut\tip, lr, sp" 2 } } */ /* { dg-final { scan-assembler-not "\tbti" } } */ diff --git a/gcc/testsuite/gcc.target/arm/pac-15.c b/gcc/testsuite/gcc.target/arm/pac-15.c index e10549029556..979941492d3b 100644 --- a/gcc/testsuite/gcc.target/arm/pac-15.c +++ b/gcc/testsuite/gcc.target/arm/pac-15.c @@ -24,7 +24,7 @@ int main (void) } /* { dg-final { scan-assembler-times "\.pacspval" 1 } } */ -/* { dg-final { scan-assembler-times "pac ip, lr, sp" 3 } } */ +/* { dg-final { scan-assembler-times "\tpac\tip, lr, sp" 3 } } */ /* { dg-final { scan-assembler-times "\.cfi_reg
[gcc r15-4702] Fortran: Fix regressions with intent(out) class[PR115070, PR115348].
https://gcc.gnu.org/g:ed8ca972f8857869d2bb4a416994bb896eb1c34e commit r15-4702-ged8ca972f8857869d2bb4a416994bb896eb1c34e Author: Paul Thomas Date: Sun Oct 27 12:40:42 2024 + Fortran: Fix regressions with intent(out) class[PR115070, PR115348]. 2024-10-27 Paul Thomas gcc/fortran PR fortran/115070 PR fortran/115348 * trans-expr.cc (gfc_trans_class_init_assign): If all the components of the default initializer are null for a scalar, build an empty statement to prevent prior declarations from disappearing. gcc/testsuite/ PR fortran/115070 * gfortran.dg/pr115070.f90: New test. PR fortran/115348 * gfortran.dg/pr115348.f90: New test. Diff: --- gcc/fortran/trans-expr.cc | 29 gcc/testsuite/gfortran.dg/pr115070.f90 | 28 +++ gcc/testsuite/gfortran.dg/pr115348.f90 | 35 ++ 3 files changed, 80 insertions(+), 12 deletions(-) diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 663d762df88d..ff8cde93ef4f 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -1791,10 +1791,12 @@ gfc_trans_class_init_assign (gfc_code *code) { stmtblock_t block; tree tmp; + bool cmp_flag = true; gfc_se dst,src,memsz; gfc_expr *lhs, *rhs, *sz; gfc_component *cmp; gfc_symbol *sym; + gfc_ref *ref; gfc_start_block (&block); @@ -1812,24 +1814,25 @@ gfc_trans_class_init_assign (gfc_code *code) rhs->rank = 0; /* Check def_init for initializers. If this is an INTENT(OUT) dummy with all - default initializer components NULL, return NULL_TREE and use the passed - value as required by F2018(8.5.10). */ + default initializer components NULL, use the passed value even though + F2018(8.5.10) asserts that it should considered to be undefined. This is + needed for consistency with other brands. */ sym = code->expr1->expr_type == EXPR_VARIABLE ? code->expr1->symtree->n.sym : NULL; if (code->op != EXEC_ALLOCATE && sym && sym->attr.dummy && sym->attr.intent == INTENT_OUT) { - if (!lhs->ref && lhs->symtree->n.sym->attr.dummy) + ref = rhs->ref; + while (ref && ref->next) + ref = ref->next; + cmp = ref->u.c.component->ts.u.derived->components; + for (; cmp; cmp = cmp->next) { - cmp = rhs->ref->next->u.c.component->ts.u.derived->components; - for (; cmp; cmp = cmp->next) - { - if (cmp->initializer) - break; - else if (!cmp->next) - return NULL_TREE; - } + if (cmp->initializer) + break; + else if (!cmp->next) + cmp_flag = false; } } @@ -1843,7 +1846,7 @@ gfc_trans_class_init_assign (gfc_code *code) gfc_add_full_array_ref (lhs, tmparr); tmp = gfc_trans_class_array_init_assign (rhs, lhs, code->expr1); } - else + else if (cmp_flag) { /* Scalar initialization needs the _data component. */ gfc_add_data_component (lhs); @@ -1873,6 +1876,8 @@ gfc_trans_class_init_assign (gfc_code *code) tmp, build_empty_stmt (input_location)); } } + else +tmp = build_empty_stmt (input_location); if (code->expr1->symtree->n.sym->attr.dummy && (code->expr1->symtree->n.sym->attr.optional diff --git a/gcc/testsuite/gfortran.dg/pr115070.f90 b/gcc/testsuite/gfortran.dg/pr115070.f90 new file mode 100644 index ..9378f770e2c6 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr115070.f90 @@ -0,0 +1,28 @@ +! { dg-do compile } +! +! Test the fix for PR115070 +! +! Contributed by Sebastien Bardeau +! +module my_mod + type my_type +integer :: a + contains +final :: myfinal + end type my_type +contains + subroutine my_sub(obs) +use ieee_arithmetic +class(my_type), intent(out) :: obs + end subroutine my_sub + subroutine myfinal (arg) +type (my_type) :: arg +print *, arg%a + end +end module my_mod + + use my_mod + type (my_type) :: z + z%a = 42 + call my_sub (z) +end diff --git a/gcc/testsuite/gfortran.dg/pr115348.f90 b/gcc/testsuite/gfortran.dg/pr115348.f90 new file mode 100644 index ..bc644b2f1c0c --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr115348.f90 @@ -0,0 +1,35 @@ +! { dg-do compile } +! { dg-options "-fcheck=recursion" } +! +! Test the fix for pr115348. +! +! Contributed by Maxime van den Bossche +! +module mymodule +implicit none + +type mytype +integer :: mynumber +contains +procedure :: myroutine +end type mytype + +contains + +subroutine myroutine(self) +class(mytype), intent(out) :: self + +self%mynumber = 1 +end subroutine myroutine +end module mymodule + + +