[Bug c/108224] [PATCH] add srandom random initstate setstate

2022-12-26 Thread Jonny Grant



>From 6ff344979af46dbcd739dd9068d6d595547e4c27 Mon Sep 17 00:00:00 2001
From: Jonathan Grant 
Date: Sun, 25 Dec 2022 22:38:44 +
Subject: [PATCH] add srandom random initstate setstate

---
 gcc/c-family/known-headers.cc | 4 
 1 file changed, 4 insertions(+)

diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc
index 9c256173b82..ade9fa2dcc0 100644
--- a/gcc/c-family/known-headers.cc
+++ b/gcc/c-family/known-headers.cc
@@ -171,6 +171,10 @@ get_stdlib_header_for_name (const char *name, enum stdlib 
lib)
 {"getenv", {"", ""} },
 {"malloc", {"", ""} },
 {"realloc", {"", ""} },
+{"random", {"", ""} },
+{"srandom", {"", ""} },
+{"initstate", {"", ""} },
+{"setstate", {"", ""} },
 
 /*  and .  */
 {"memchr", {"", ""} },
-- 
2.37.2


Re: [PATCH] RISC-V: Add testcases for VSETVL PASS

2022-12-26 Thread Andreas Schwab
FAIL: gcc.target/riscv/rvv/vsetvl/dump-1.c   -O0  (test for excess errors)
Excess errors:
/usr/include/gnu/stubs.h:8:11: fatal error: gnu/stubs-ilp32.h: No such file or 
directory
compilation terminated.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."


Re: [Bug c/108224] [PATCH] add srandom random initstate setstate

2022-12-26 Thread Prathamesh Kulkarni via Gcc-patches
On Mon, 26 Dec 2022 at 14:25, Jonny Grant  wrote:
>
>
>
> From 6ff344979af46dbcd739dd9068d6d595547e4c27 Mon Sep 17 00:00:00 2001
> From: Jonathan Grant 
> Date: Sun, 25 Dec 2022 22:38:44 +
> Subject: [PATCH] add srandom random initstate setstate
>
> ---
>  gcc/c-family/known-headers.cc | 4 
>  1 file changed, 4 insertions(+)
>
> diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc
> index 9c256173b82..ade9fa2dcc0 100644
> --- a/gcc/c-family/known-headers.cc
> +++ b/gcc/c-family/known-headers.cc
> @@ -171,6 +171,10 @@ get_stdlib_header_for_name (const char *name, enum 
> stdlib lib)
>  {"getenv", {"", ""} },
>  {"malloc", {"", ""} },
>  {"realloc", {"", ""} },
> +{"random", {"", ""} },
> +{"srandom", {"", ""} },
> +{"initstate", {"", ""} },
> +{"setstate", {"", ""} },
>
>  /*  and .  */
>  {"memchr", {"", ""} },
Hi Jonny,
Thanks for the patch. A couple of things:
(a) Could you please add a test-case for the above symbols ? See
testsuite/gcc.dg/missing-header-fixit-4.c
for a similar example for printf.
(b) The patch is missing changelog.
I assume you've tested the patch with bootstrap+regtest ?

Thanks,
Prathamesh

> --
> 2.37.2


Re: Re: [PATCH] RISC-V: Add testcases for VSETVL PASS

2022-12-26 Thread 钟居哲
This is another issue and I have no idea. I think palmer or kito may have know 
how to solve it. 

It seems  this patch 
https://gcc.gnu.org/pipermail/gcc-patches/2022-December/609045.html 
fixed previous issue which is more important. I think it's time to merge it.




juzhe.zh...@rivai.ai
 
From: Andreas Schwab
Date: 2022-12-26 17:20
To: juzhe.zhong
CC: gcc-patches; kito.cheng; palmer
Subject: Re: [PATCH] RISC-V: Add testcases for VSETVL PASS
FAIL: gcc.target/riscv/rvv/vsetvl/dump-1.c   -O0  (test for excess errors)
Excess errors:
/usr/include/gnu/stubs.h:8:11: fatal error: gnu/stubs-ilp32.h: No such file or 
directory
compilation terminated.
 
-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
 


[PATCH modula2] PR-108142 Remove empty directories created in the build directory

2022-12-26 Thread Gaius Mulley via Gcc-patches


Hello,

Bootstrapped on amd64 GNU/Linux.  Ok for trunk?

regards,
Gaius

--- 8< ---

PR-108142 Remove empty directories created in the build directory.

This patch removes empty directories created in the build directory.
Directories are only created if required and all modula-2 build output
is created under m2.  Add m2.stageprofile and m2.stagefeedback rules.

gcc/m2/ChangeLog:

* PR m2/108142
* Make-lang.in: Change build directory to m2.
Change all rules to dynamically create subdirectories
when required.
(m2.stageprofile): New.
(m2.stagefeedback): New.
* Make-maintainer.in: Change build directory to m2.
Change all rules to dynamically create subdirectories when
required.
* config-lang.in: Remove static creation of build directories.

diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
index a8bd7fe4d19..828eaad6285 100644
--- a/gcc/m2/Make-lang.in
+++ b/gcc/m2/Make-lang.in
@@ -27,7 +27,7 @@ GM2_CROSS_NAME = `echo gm2|sed 
'$(program_transform_cross_name)'`
 
 M2_MAINTAINER = no
 
-GM2_1 = ./gm2 -B./stage1/m2 -g -fm2-g
+GM2_1 = ./gm2 -B./m2/stage1 -g -fm2-g
 
 GM2_FOR_TARGET = $(STAGE_CC_WRAPPER) ./gm2 -B./ -B$(build_tooldir)/bin/ 
-L$(objdir)/../ld $(TFLAGS)
 
@@ -61,7 +61,6 @@ m2.srcextra: m2/SYSTEM-pim.texi m2/SYSTEM-iso.texi 
m2/gm2-libs.texi m2/gm2-ebnf.
-cp -p m2/SYSTEM-iso.texi $(srcdir)/m2
-cp -p m2/gm2-libs.texi $(srcdir)/m2
-cp -p m2/gm2-ebnf.texi $(srcdir)/m2
-   find . -name '*.texi' -print
 else
 m2.srcextra:
 endif
@@ -153,7 +152,7 @@ doc/m2.info: $(TEXISRC)
else true; fi
 
 $(objdir)/m2/images/gnu.eps: $(srcdir)/m2/images/gnupng
-   test -d m2/images || mkdir -p m2/images
+   -test -d m2/images || $(mkinstalldirs) m2/images
cp $(srcdir)/m2/images/gnu.eps $@
 
 # gm2-libs.texi
@@ -163,6 +162,9 @@ m2/gm2-libs.texi: gm2-libs.texi-check; @true
 ifeq ($(HAVE_PYTHON),yes)
 gm2-libs.texi-check: m2/SYSTEM-pim.texi m2/SYSTEM-iso.texi m2/Builtins.texi \
  $(objdir)/m2/gm2-libs-coroutines/SYSTEM.def
+   test -d m2/gm2-libs-pim || $(mkinstalldirs) m2/gm2-libs-pim
+   test -d m2/gm2-libs-iso || $(mkinstalldirs) m2/gm2-libs-iso
+   test -d m2/gm2-libs || $(mkinstalldirs) m2/gm2-libs
$(PYTHON) $(srcdir)/m2/tools-src/def2doc.py -t -uLibraries 
-s$(srcdir)/m2 -b$(objdir)/m2 -o $(objdir)/m2/gm2-libs.texi
 else
 gm2-libs.texi-check:
@@ -279,59 +281,21 @@ Builtins.rst-check:  m2/gm2-libs/Builtins.def
 endif
$(STAMP) Builtins.rst-check
 
-$(objdir)/m2/gm2-compiler-boot:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libs-boot:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libiberty:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-gcc:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-compiler:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libs:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libs-iso:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libs-min:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-compiler-paranoid:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libs-paranoid:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-compiler-verify:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/boot-bin:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libs-pim:
-   test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libs-coroutines:
-   test -d $@ || mkdir $@
-
-stage1/m2:
-   -test -d $@ || mkdir -p stage1/m2
-
-stage2/m2:
-   -test -d $@ || mkdir -p stage2/m2
-
-stage3/m2:
-   -test -d $@ || mkdir -p stage3/m2
+# Stage hooks:
+# The toplevel makefile has already created stage?/m2 at this point.
 
-stage4/m2:
-   -test -d $@ || mkdir -p stage4/m2
+m2.stage1: stage1-start
+   -mv m2/*$(objext) stage1/m2
+m2.stage2: stage2-start
+   -mv m2/*$(objext) stage2/m2
+m2.stage3: stage3-start
+   -mv m2/*$(objext) stage3/m2
+m2.stage4: stage4-start
+   -mv m2/*$(objext) stage4/m2
+m2.stageprofile: stageprofile-start
+   -mv m2/*$(objext) stageprofile/m2
+m2.stagefeedback: stageprofile-start
+   -mv m2/*$(objext) stagefeedback/m2
 
 # No gm2-specific selftests
 selftest-m2:
@@ -408,7 +372,7 @@ m2.install-plugin: installdirs
 
 plugin/m2rte$(exeext).so: $(srcdir)/m2/plugin/m2rte.cc 
$(GCC_HEADER_DEPENDENCIES_FOR_M2) \
 insn-attr-common.h insn-flags.h $(generated_files)
-   test -d plugin || mkdir plugin
+   -test -d plugin || $(mkinstalldirs) plugin
$(PLUGINCC) $(PLUGINCFLAGS) -fno-rtti -I. -I$(srcdir) -I$(srcdir)/m2 
-I$(srcdir)/m2/gm2-gcc -I$(srcdir)/../include -I$(srcdir)/../libcpp/include 
-Wall $(GMPINC) -Wno-literal-suffix -fPIC -c -o plugin/m2rte.o 
$(srcdir)/m2/plugin/m2rte.cc
$(PLUGINCC) $(PLUGINCFLAGS) $(PLUGINLIBS) -fno-rtti plugin/m2rte.o 
-shared -o $@
 
@@ -428,20 +392,6 @@ m2.clean:
 m2.extraclean:
 m2.realclean:
 
-# Stage hooks:
-
-m2.stage1: stage1-start
-   -mv m2/*$(objext) stage1/m2
-
-m2.stage2: stage2-start

[PATCH] Add support for x86_64-*-gnu-* targets to build x86_64 gnumach/hurd

2022-12-26 Thread Flavio Cruz via Gcc-patches
Tested by building a toolchain and compiling gnumach for x86_64 [1].
This is the basic version without unwind support which I think is only required 
to
implement exceptions.

[1] https://github.com/flavioc/cross-hurd/blob/master/bootstrap-kernel.sh.

---
 gcc/config.gcc  |  5 -
 gcc/config/i386/gnu64.h | 40 +
 libgcc/config.host  |  8 ++-
 libgcc/config/i386/gnu-unwind.h | 10 +
 4 files changed, 61 insertions(+), 2 deletions(-)
 create mode 100644 gcc/config/i386/gnu64.h

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 95190233820..0e2b15768bf 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1955,7 +1955,7 @@ i[34567]86-*-linux* | i[34567]86-*-kfreebsd*-gnu | 
i[34567]86-*-gnu* | i[34567]8
;;
esac
;;
-x86_64-*-linux* | x86_64-*-kfreebsd*-gnu)
+x86_64-*-linux* | x86_64-*-kfreebsd*-gnu | x86_64-*-gnu*)
tm_file="${tm_file} i386/unix.h i386/att.h elfos.h gnu-user.h 
glibc-stdint.h \
 i386/x86-64.h i386/gnu-user-common.h i386/gnu-user64.h"
case ${target} in
@@ -1966,6 +1966,9 @@ x86_64-*-linux* | x86_64-*-kfreebsd*-gnu)
x86_64-*-kfreebsd*-gnu)
tm_file="${tm_file} kfreebsd-gnu.h i386/kfreebsd-gnu64.h"
;;
+   x86_64-*-gnu*)
+   tm_file="${tm_file} gnu.h i386/gnu64.h"
+   ;;
esac
tmake_file="${tmake_file} i386/t-linux64"
x86_multilibs="${with_multilib_list}"
diff --git a/gcc/config/i386/gnu64.h b/gcc/config/i386/gnu64.h
new file mode 100644
index 000..a1ecfaa1cdb
--- /dev/null
+++ b/gcc/config/i386/gnu64.h
@@ -0,0 +1,40 @@
+/* Configuration for an x86_64 running GNU with ELF as the target machine.  */
+
+/*
+Copyright (C) 2022 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC.  If not, see .
+*/
+
+#define GNU_USER_LINK_EMULATION32 "elf_i386"
+#define GNU_USER_LINK_EMULATION64 "elf_x86_64"
+#define GNU_USER_LINK_EMULATIONX32 "elf32_x86_64"
+
+#undef GNU_USER_DYNAMIC_LINKER
+#define GNU_USER_DYNAMIC_LINKER32 "/lib/ld.so.1"
+#define GNU_USER_DYNAMIC_LINKER64 "/lib/ld-x86-64.so.1"
+#define GNU_USER_DYNAMIC_LINKERX32 "/lib/ld-x32.so.1"
+
+#undef STARTFILE_SPEC
+#if defined HAVE_LD_PIE
+#define STARTFILE_SPEC \
+  "%{!shared: 
%{pg|p|profile:%{static:gcrt0.o%s;:gcrt1.o%s};pie:Scrt1.o%s;static:crt0.o%s;:crt1.o%s}}
 \
+   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}"
+#else
+#define STARTFILE_SPEC \
+  "%{!shared: 
%{pg|p|profile:%{static:gcrt0.o%s;:gcrt1.o%s};static:crt0.o%s;:crt1.o%s}} \
+   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}"
+#endif
diff --git a/libgcc/config.host b/libgcc/config.host
index eb23abe89f5..75fd1b778fe 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -751,6 +751,12 @@ x86_64-*-kfreebsd*-gnu)
tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff 
t-dfprules"
tm_file="${tm_file} i386/elf-lib.h"
;;
+x86_64-*-gnu*)
+   extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o 
crtfastmath.o"
+   tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff 
t-dfprules"
+   tm_file="${tm_file} i386/elf-lib.h"
+   md_unwind_header=i386/gnu-unwind.h
+   ;;
 i[34567]86-pc-msdosdjgpp*)
;;
 i[34567]86-*-lynxos*)
@@ -1523,7 +1529,7 @@ esac
 case ${host} in
 i[34567]86-*-linux* | x86_64-*-linux* | \
   i[34567]86-*-kfreebsd*-gnu | x86_64-*-kfreebsd*-gnu | \
-  i[34567]86-*-gnu*)
+  i[34567]86-*-gnu* | x86_64-*-gnu*)
tmake_file="${tmake_file} t-tls i386/t-linux i386/t-msabi 
t-slibgcc-libgcc"
if test "$libgcc_cv_cfi" = "yes"; then
tmake_file="${tmake_file} t-stack i386/t-stack-i386"
diff --git a/libgcc/config/i386/gnu-unwind.h b/libgcc/config/i386/gnu-unwind.h
index 25eb690e370..2cbfc40ea7e 100644
--- a/libgcc/config/i386/gnu-unwind.h
+++ b/libgcc/config/i386/gnu-unwind.h
@@ -30,6 +30,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
 
 #include 
 
+#ifdef __x86_64__
+
+/*
+ * TODO: support for 64 bits needs to be implemented.
+ */
+
+#else /* ifdef __x86_64__  */
+
 #define MD_FALLBACK_FRAME_STATE_FOR x86_gnu_fallback_frame_state
 
 static _Unwind_Reason_Code
@@ -138,4 +146,6 @@ x86_gnu_fallback_frame_state
   return _URC_NO_REASON;
 }
 
+#endif /* ifdef __x86_64__  */
+
 #endif /* ifnde

Re: [PATCH modula2] PR-108142 Remove empty directories created in the build directory

2022-12-26 Thread Iain Sandoe
Hi Gaius,

I’m finding it hard to figure out how the configuration is supposed to work for 
cross compilers (and more so for Canadian/native crosses).

Apologies if this is already answered in other review (but maybe some notes 
would help in that case).

questions in-line, thanks
Iain
 
> On 26 Dec 2022, at 14:46, Gaius Mulley via Gcc-patches 
>  wrote:
> 
> 
> Hello,
> 
> Bootstrapped on amd64 GNU/Linux.  Ok for trunk?
> 
> regards,
> Gaius
> 
> --- 8< ---
> 
> PR-108142 Remove empty directories created in the build directory.
> 
> This patch removes empty directories created in the build directory.
> Directories are only created if required and all modula-2 build output
> is created under m2.  Add m2.stageprofile and m2.stagefeedback rules.
> 
> gcc/m2/ChangeLog:
> 
>* PR m2/108142
>   * Make-lang.in: Change build directory to m2.
>Change all rules to dynamically create subdirectories
>when required.
>   (m2.stageprofile): New.
>   (m2.stagefeedback): New.
>   * Make-maintainer.in: Change build directory to m2.
>Change all rules to dynamically create subdirectories when
>required.
>   * config-lang.in: Remove static creation of build directories.
> 
> diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
> index a8bd7fe4d19..828eaad6285 100644
> --- a/gcc/m2/Make-lang.in
> +++ b/gcc/m2/Make-lang.in
> @@ -27,7 +27,7 @@ GM2_CROSS_NAME = `echo gm2|sed 
> '$(program_transform_cross_name)'`
> 
> M2_MAINTAINER = no
> 
> -GM2_1 = ./gm2 -B./stage1/m2 -g -fm2-g
> +GM2_1 = ./gm2 -B./m2/stage1 -g -fm2-g

What does “stage1” mean in the case of a cross-compiler or a —disable-bootstrap 
configure?

> GM2_FOR_TARGET = $(STAGE_CC_WRAPPER) ./gm2 -B./ -B$(build_tooldir)/bin/ 
> -L$(objdir)/../ld $(TFLAGS)
> 
> @@ -61,7 +61,6 @@ m2.srcextra: m2/SYSTEM-pim.texi m2/SYSTEM-iso.texi 
> m2/gm2-libs.texi m2/gm2-ebnf.
>   -cp -p m2/SYSTEM-iso.texi $(srcdir)/m2
>   -cp -p m2/gm2-libs.texi $(srcdir)/m2
>   -cp -p m2/gm2-ebnf.texi $(srcdir)/m2
> - find . -name '*.texi' -print
> else
> m2.srcextra:
> endif
> @@ -153,7 +152,7 @@ doc/m2.info: $(TEXISRC)
>   else true; fi
> 
> $(objdir)/m2/images/gnu.eps: $(srcdir)/m2/images/gnupng
> - test -d m2/images || mkdir -p m2/images
> + -test -d m2/images || $(mkinstalldirs) m2/images
>   cp $(srcdir)/m2/images/gnu.eps $@
> 
> # gm2-libs.texi
> @@ -163,6 +162,9 @@ m2/gm2-libs.texi: gm2-libs.texi-check; @true
> ifeq ($(HAVE_PYTHON),yes)
> gm2-libs.texi-check: m2/SYSTEM-pim.texi m2/SYSTEM-iso.texi m2/Builtins.texi \
>  $(objdir)/m2/gm2-libs-coroutines/SYSTEM.def
> + test -d m2/gm2-libs-pim || $(mkinstalldirs) m2/gm2-libs-pim
> + test -d m2/gm2-libs-iso || $(mkinstalldirs) m2/gm2-libs-iso
> + test -d m2/gm2-libs || $(mkinstalldirs) m2/gm2-libs
>   $(PYTHON) $(srcdir)/m2/tools-src/def2doc.py -t -uLibraries 
> -s$(srcdir)/m2 -b$(objdir)/m2 -o $(objdir)/m2/gm2-libs.texi
> else
> gm2-libs.texi-check:
> @@ -279,59 +281,21 @@ Builtins.rst-check:  m2/gm2-libs/Builtins.def
> endif
>   $(STAMP) Builtins.rst-check
> 
> -$(objdir)/m2/gm2-compiler-boot:
> - test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-libs-boot:
> - test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-libiberty:
> - test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-gcc:
> - test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-compiler:
> - test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-libs:
> - test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-libs-iso:
> - test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-libs-min:
> - test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-compiler-paranoid:
> - test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-libs-paranoid:
> - test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-compiler-verify:
> - test -d $@ || mkdir $@
> -
> -$(objdir)/m2/boot-bin:
> - test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-libs-pim:
> - test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-libs-coroutines:
> - test -d $@ || mkdir $@
> -
> -stage1/m2:
> - -test -d $@ || mkdir -p stage1/m2
> -
> -stage2/m2:
> - -test -d $@ || mkdir -p stage2/m2
> -
> -stage3/m2:
> - -test -d $@ || mkdir -p stage3/m2
> +# Stage hooks:
> +# The toplevel makefile has already created stage?/m2 at this point.
> 
> -stage4/m2:
> - -test -d $@ || mkdir -p stage4/m2
> +m2.stage1: stage1-start
> + -mv m2/*$(objext) stage1/m2
> +m2.stage2: stage2-start
> + -mv m2/*$(objext) stage2/m2
> +m2.stage3: stage3-start
> + -mv m2/*$(objext) stage3/m2
> +m2.stage4: stage4-start
> + -mv m2/*$(objext) stage4/m2
> +m2.stageprofile: stageprofile-start
> + -mv m2/*$(objext) stageprofile/m2
> +m2.stagefeedback: stageprofile-start
> + -mv m2/*$(objext) stagefeedback/m2
> 
> # No gm2-specific selftests
> selftest-m2:
> @@ -408,7 +372,7 @@ m2.install-plugin: installdirs
> 
> plugin/m2rte$(exeext).so: $(srcdir)/m2/plugin/m2rte.cc 
> $(GCC_HEADER_DEPENDENCIES_FOR_M2) \
> insn-attr-co

Bugzilla Bug 81649 [PATCH]: Clarify LeakSanitizer in documentation

2022-12-26 Thread Jonny Grant
My ticket, but text change proposed by Jakub Jelinek.

2022-12-26  Jonathan Grant 
* gcc/doc/invoke.texi: Clarify LeakSanitizer in documentation


>From 2d70a3728536151c4c2f78b6c5d5281ce2233d43 Mon Sep 17 00:00:00 2001
From: Jonathan Grant 
Date: Mon, 26 Dec 2022 20:46:23 +
Subject: [PATCH] Bugzilla 81649 clarify LeakSanitizer onlinedocs

Signed-off-by: Jonathan Grant 
---
 gcc/doc/invoke.texi | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index da9ad1068fb..6743204adc0 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -16668,8 +16668,8 @@ operating on invalid memory addresses with non-call 
exceptions
 @item -fsanitize=leak
 @opindex fsanitize=leak
 Enable LeakSanitizer, a memory leak detector.
-This option only matters for linking of executables and
-the executable is linked against a library that overrides @code{malloc}
+This option only matters for linking of executables.
+The executable is linked against a library that overrides @code{malloc}
 and other allocator functions.  See
 @uref{https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer} 
for more
 details.  The run-time behavior can be influenced using the
-- 
2.37.2


[PATCHJ]: Bugzilla 88860 - Clarify online manual infelicities

2022-12-26 Thread Jonny Grant


2022-12-26  Jonathan Grant 
* gcc/doc/extend.texi: Bugzilla 88860 - Clarify online manual 
infelicities


>From 8b142ad8973dc67289e197e30966490a944e4819 Mon Sep 17 00:00:00 2001
From: Jonathan Grant 
Date: Mon, 26 Dec 2022 20:58:29 +
Subject: [PATCH] Bugzilla 88860 - Clarify gcc online manual infelicities

Signed-off-by: Jonathan Grant 
---
 gcc/doc/extend.texi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index adba057c190..88fc625050b 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -9190,7 +9190,7 @@ have to optimize it to just @code{return 42 + 42;}.
 This section describes the syntax with which @code{__attribute__} may be
 used, and the constructs to which attribute specifiers bind, for the C
 language.  Some details may vary for C++ and Objective-C@.  Because of
-infelicities in the grammar for attributes, some forms described here
+limitations in the grammar for attributes, some forms described here
 may not be successfully parsed in all cases.
 
 There are some problems with the semantics of attributes in C++.  For
-- 
2.37.2


Bugzilla 88860 - Clarify gcc online manual attribute format printf example

2022-12-26 Thread Jonny Grant
2022-12-26  Jonathan Grant 
* gcc/doc/extend.texi: Bugzilla 88860 - Add attribute format printf 
example



>From 1668dc58206428ee92ff142bafb5f545dba029ae Mon Sep 17 00:00:00 2001
From: Jonathan Grant 
Date: Mon, 26 Dec 2022 21:02:35 +
Subject: [PATCH] Bugzilla 88860 - Clarify gcc online manual attribute format
 printf example

Signed-off-by: Jonathan Grant 
---
 gcc/doc/extend.texi | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 88fc625050b..9b200c6f3a0 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -9353,6 +9353,13 @@ __attribute__((noreturn)) void d0 (void),
 the @code{noreturn} attribute applies to all the functions
 declared; the @code{format} attribute only applies to @code{d1}.
 
+@noindent
+The following __attribute__ causes gcc to check run printf argument checks on 
argument '3' which is 'const char * string format' (when visible at compile 
time), against argument '4' the '...' variadic ellipsis.  In the example below, 
arguments '1' and '2' are not checked.
+
+@smallexample
+void string_format(const char * prefix, size_t line, const char * const 
format, ...) __attribute__ ((format (printf,3,4)));
+@end smallexample
+
 An attribute specifier list may appear immediately before the comma,
 @code{=} or semicolon terminating the declaration of an identifier other
 than a function definition.  Such attribute specifiers apply
-- 
2.37.2


[patch, fortran] ICE in attr_decl1, at fortran/decl.c:8691

2022-12-26 Thread Jerry DeLisle via Gcc-patches
The attached patch was provided by Steve Kargl.  After exploring for
possible other checks I settled on leaving the patch intact.

Two existing test cases updated as different but sensible error messages
resulted.

Regression tested on main line.

OK to commit?

Regards,

Jerry

Author: Steve Kargl 
Date:   Mon Dec 26 14:07:04 2022 -0800

 Modify checks to avoid referencing NULL pointer.
 Update test cases with error messages that changed as a result.

 gcc/fortran/ChangeLog:

 * decl.cc (attr_decl1): Guard against NULL pointer.
 * parse.cc (match_deferred_characteristics): Include
BT_CLASS in check for
   derived being undefined.

 gcc/testsuite/ChangeLog:

 * gfortran.dg/class_result_4.f90: Update error message check.
 * gfortran.dg/pr85779_3.f90: Update error message check.diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index e593518a77e..bac7b6568b0 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -8743,7 +8743,9 @@ attr_decl1 (void)
   /* Update symbol table.  DIMENSION attribute is set in
  gfc_set_array_spec().  For CLASS variables, this must be applied
  to the first component, or '_data' field.  */
-  if (sym->ts.type == BT_CLASS && sym->ts.u.derived->attr.is_class)
+  if (sym->ts.type == BT_CLASS
+  && sym->ts.u.derived
+  && sym->ts.u.derived->attr.is_class)
 {
   /* gfc_set_array_spec sets sym->attr not CLASS_DATA(sym)->attr.  Check
 	 for duplicate attribute here.  */
diff --git a/gcc/fortran/parse.cc b/gcc/fortran/parse.cc
index bc2b2188eea..6186c48aee2 100644
--- a/gcc/fortran/parse.cc
+++ b/gcc/fortran/parse.cc
@@ -3934,7 +3934,7 @@ match_deferred_characteristics (gfc_typespec * ts)
   m = gfc_match_prefix (ts);
   gfc_buffer_error (false);
 
-  if (ts->type == BT_DERIVED)
+  if (ts->type == BT_DERIVED || ts->type == BT_CLASS)
 {
   ts->kind = 0;
 
@@ -4215,7 +4215,7 @@ declSt:
   if (bad_characteristic)
 {
   ts = &gfc_current_block ()->result->ts;
-  if (ts->type != BT_DERIVED)
+  if (ts->type != BT_DERIVED && ts->type != BT_CLASS)
 	gfc_error ("Bad kind expression for function %qs at %L",
 		   gfc_current_block ()->name,
 		   &gfc_current_block ()->declared_at);
diff --git a/gcc/testsuite/gfortran.dg/class_result_4.f90 b/gcc/testsuite/gfortran.dg/class_result_4.f90
index 4b22a3c30ee..5497ac652ec 100644
--- a/gcc/testsuite/gfortran.dg/class_result_4.f90
+++ b/gcc/testsuite/gfortran.dg/class_result_4.f90
@@ -1,6 +1,6 @@
 ! { dg-do compile }
 ! PR fortran/78500
-class(t) function f() ! { dg-error "must be dummy, allocatable or pointer" }
+class(t) function f() ! { dg-error "is not accessible" }
f = 1  ! { dg-error "variable must not be polymorphic" }
 end
 
diff --git a/gcc/testsuite/gfortran.dg/pr85779_3.f90 b/gcc/testsuite/gfortran.dg/pr85779_3.f90
index fba1133b3ea..a81a9faf88e 100644
--- a/gcc/testsuite/gfortran.dg/pr85779_3.f90
+++ b/gcc/testsuite/gfortran.dg/pr85779_3.f90
@@ -1,6 +1,6 @@
 ! { dg-do compile }
 ! PR fortran/85779
-class(t) function f()   ! { dg-error "must be dummy, allocatable or pointer" }
+class(t) function f()   ! { dg-error "is not accessible" }
type f   ! { dg-error "already has a basic type" }
end type ! { dg-error "END FUNCTION statement" }
 end


Re: [PATCH] loading float member of parameter stored via int registers

2022-12-26 Thread Jiufu Guo via Gcc-patches
Hi,

Segher Boessenkool  writes:

> Hi!
>
> On Fri, Dec 23, 2022 at 08:36:36PM +0800, Jiufu Guo wrote:
>> It seems some limitations there. e.g. 1. "subreg:DF on DI register"
>> may not work well on pseudo,
>
> It is perfectly normal:
>   A hard register may be accessed in various modes throughout one
>   function, but each pseudo register is given a natural mode
>   and is accessed only in that mode.  When it is necessary to describe
>   an access to a pseudo register using a nonnatural mode, a @code{subreg}
>   expression is used.
>
> and:
>   @code{subreg} expressions are used to refer to a register in a machine
>   mode other than its natural one, or to refer to one register of
>   a multi-part @code{reg} that actually refers to several registers.
>
>   Each pseudo register has a natural mode.  If it is necessary to
>   operate on it in a different mode, the register must be
>   enclosed in a @code{subreg}.
>
> and we even have:
>   @item hard registers
>   It is seldom necessary to wrap hard registers in @code{subreg}s; such
>   registers would normally reduce to a single @code{reg} rtx.  This use of
>   @code{subreg}s is discouraged and may not be supported in the future.
>
Thanks so much for detailed explaination!

>> and 2. to convert high-part:DI to SF,
>> a "shift/rotate" is needed, and then we need to "emit shift insn"
>> in cse. I may need to update this patch.
>
> Hrm.  The machine insns to do this is just mtvsrd;xscvspdpn, but for
> converting the lowpart it is mtvsrws;xscvspdpn (this needs p9 or
> later).  We should arrive at those patterns, and we should try to not
> go via the more expensive formulations with shifts, which don't describe
> the hardware well, and which overestimate the cost of it.
Yes, understant!
>
> None of this belongs in generic code at all imo.  At expand time it
> should be expanded to something that works and can be optimised well,
> so not anything with :BLK (which has to be put in memory, something with
> unbounded size cannot be put in registers), not anything specifically
> tailored to any cpu, something nice and regular.  Using a subreg (of a
> pseudo!) is the standard way of writing a bitcast.
>
> So generic code would do a  (subreg:SF (reg:SI) 0)  to express a 32-bit
> integer bitcast to an IEEE SP number, and our machine description should
> make it work nicely.
Right!  So, I'm thinking a way: in generic code, we may generated
"shift+(subreg:SF (reg:SI) 0)"; and at somewhere (maybe in combiner),
using "mtvsr.." to replace the "shift+subreg".

BR,
Jeff (Jiufu)

>
>
> Segher


Re: [PATCH] loading float member of parameter stored via int registers

2022-12-26 Thread Jiufu Guo via Gcc-patches
Hi,

Segher Boessenkool  writes:

> On Fri, Dec 23, 2022 at 08:13:48PM +0100, Richard Biener wrote:
>> > Am 23.12.2022 um 17:55 schrieb Segher Boessenkool 
>> > :
>> > There are at least six very different kinds of subreg:
>> > 
>> > 0) Lvalue subregs.  Most archs have no use for it, and it can be
>> >   expressed much more clearly and cleanly always.
>> > 1) Subregs of mem.  Do not use, deprecated.  When old reload goes away
>> >   this will go away.
>> > 2) Subregs of hard registers.  Do not use, there are much better ways to
>> >   write subregs of a non-zero byte offset, and for zero offset this is
>> >   non-canonical RTL.
>> > 3) Bitcast subregs.  In principle they go from one mode to another mode
>> >   of the same size (but read on).
>> > 4) Paradoxical subregs.  A concept completely separate from the rest,
>> >   different rules for everything, it has to be special cased almost
>> >   everywhere, it would be better if it was a separate rtx_code imo.
>> > 5) Finally, normal subregs, taking a contiguous span of bits from some
>> >   value.
>> > 
>> > Now, it is invalid to have a subreg of a subreg, so a 3) of a 5) is
>> > written as just one subreg, as you say.  And a 4) of a 5) is just
>> > invalid afaics (and let's not talk about 0)..2) anymore :-) )
>> > 
>> >> Note whether targets actually support subreg operations needs to be 
>> >> queried and I’m not sure how subreg with offset validation should work 
>> >> there.
>> > 
>> > But 3) is always valid, no?  On pseudos
I also has similar question: do we need to query/recog if "SF(SI#0)" is
valid on the target, or it would always work (even through reload)?
I also hit this during debugging on ppc64le: "SF(SI#0)" is valid,
and "SF(DI#4)" is not valid. 
>> 
>> Yes, but it will eventually result in a spill/reload which is
>> undesirable when we created this from CSE from a load.  So I think
>> for CSE we do want to know whether a spill will definitely not
>> occur.
>
> Does it cause reloads though?  On any sane backend?  If no movsf pattern
> allows integer registers, can things work at all?
>
> Anyway, the normal way to test if some RTL is valid is to just generate
> it (using validate_change) and then do apply_change_group, which then
> cancels the changes if they do not work.  CSE already does some of
> this.
validate_change seems ok. Thanks!
>
> (I am doubtful doing any of this in CSE is a good idea fwiw).
Understand your concern! Especially when we need to emit additional
inns in CSE.
While CSE does some similar work. It transforms
"[sf:DI]=%x:DI; %y:DI=[sf:DI]" to "%y:DI=%x:DI".
and "see if a MEM has already been loaded with a widening operation;
if it has, we can use a subreg of that." (only for int modes).
So, it may be acceptable to do this in CSE (maybe still seems
hacking).

Thanks for so great comments!

BR,
Jeff (Jiufu)

>
>
> Segher


[RFC] Introduce -finline-memset-loops

2022-12-26 Thread Alexandre Oliva via Gcc-patches


try_store_by_multiple_pieces was added not long ago, enabling
variable-sized memset to be expanded inline when the worst-case
in-range constant length would, using conditional blocks with powers
of two to cover all possibilities of length and alignment.

This patch extends the memset expansion to start with a loop, so as to
still take advantage of known alignment even with long lengths, but
without necessarily adding store blocks for every power of two.

This makes it possible for any memset call to be expanded, even if
storing a single byte per iteration.  Surely efficient implementations
of memset can do better, with a pre-loop to increase alignment, but
that would likely be excessive for inline expansions of memset.

Still, in some cases, users prefer to inline memset, even if it's not
as performant, or when it's known to be performant in ways the
compiler can't tell, to avoid depending on a C runtime library.

With this flag, global or per-function optimizations may enable inline
expansion of memset to be selectively requested, while the
infrastructure for that may enable us to introduce per-target tuning
to enable such looping even advantageous, even if not explicitly
requested.


I realize this is late for new features in this cycle; I`d be happy to
submit it again later, but I wonder whether there's any interest in this
feature, or any objections to it.  FWIW, I've regstrapped this on
x86_64-linux-gnu, and also tested earlier versions of this patch in
earlier GCC branches with RISC-v crosses.  Is this ok for GCC 14?  Maybe
even simple enough for GCC 13, considering it's disabled by default?
TIA,


for  gcc/ChangeLog

* builtins.cc (try_store_by_multiple_pieces): Support starting
with a loop.
* common.opt (finline-memset-loops): New.
* doc/invoke.texi (-finline-memset-loops): Add.

for  gcc/testsuite/ChangeLog

* gcc.dg/torture/inline-mem-set-1.c: New.
---
 gcc/builtins.cc |   50 ++-
 gcc/common.opt  |4 ++
 gcc/doc/invoke.texi |   13 ++
 gcc/testsuite/gcc.dg/torture/inline-mem-set-1.c |   14 ++
 4 files changed, 77 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/inline-mem-set-1.c

diff --git a/gcc/builtins.cc b/gcc/builtins.cc
index 02c4fefa86f48..388bae58ce49e 100644
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -4361,9 +4361,37 @@ try_store_by_multiple_pieces (rtx to, rtx len, unsigned 
int ctz_len,
   if (max_bits >= 0)
 xlenest += ((HOST_WIDE_INT_1U << max_bits) * 2
- (HOST_WIDE_INT_1U << ctz_len));
+  bool max_loop = false;
   if (!can_store_by_pieces (xlenest, builtin_memset_read_str,
&valc, align, true))
-return false;
+{
+  if (!flag_inline_memset_loops)
+   return false;
+  while (--max_bits >= sctz_len)
+   {
+ xlenest = ((HOST_WIDE_INT_1U << max_bits) * 2
+- (HOST_WIDE_INT_1U << ctz_len));
+ if (can_store_by_pieces (xlenest + blksize,
+  builtin_memset_read_str,
+  &valc, align, true))
+   {
+ max_loop = true;
+ break;
+   }
+ if (!blksize)
+   continue;
+ if (can_store_by_pieces (xlenest,
+  builtin_memset_read_str,
+  &valc, align, true))
+   {
+ blksize = 0;
+ max_loop = true;
+ break;
+   }
+   }
+  if (!max_loop)
+   return false;
+}
 
   by_pieces_constfn constfun;
   void *constfundata;
@@ -4405,6 +4433,7 @@ try_store_by_multiple_pieces (rtx to, rtx len, unsigned 
int ctz_len,
  the least significant bit possibly set in the length.  */
   for (int i = max_bits; i >= sctz_len; i--)
 {
+  rtx_code_label *loop_label = NULL;
   rtx_code_label *label = NULL;
   blksize = HOST_WIDE_INT_1U << i;
 
@@ -4423,14 +4452,24 @@ try_store_by_multiple_pieces (rtx to, rtx len, unsigned 
int ctz_len,
   else if ((max_len & blksize) == 0)
continue;
 
+  if (max_loop && i == max_bits)
+   {
+ loop_label = gen_label_rtx ();
+ emit_label (loop_label);
+ /* Since we may run this multiple times, don't assume we
+know anything about the offset.  */
+ clear_mem_offset (to);
+   }
+
   /* Issue a store of BLKSIZE bytes.  */
+  bool update_needed = i != sctz_len || loop_label;
   to = store_by_pieces (to, blksize,
constfun, constfundata,
align, true,
-   i != sctz_len ? RETURN_END : RETURN_BEGIN);
+   update_needed ? RETURN_END : RETURN_BEGIN);
 
   /* Adjust REM and PTR, unless this is the last iteration.  */
-  if (i != sctz_len)
+  if (upd

[00/13] check hash table counts

2022-12-26 Thread Alexandre Oliva via Gcc-patches


While looking into another issue that corrupted hash tables, I added
code to check consistency of element counts, and hit numerous issues
that were concerning, of three kinds: insertion of entries that seem
empty, dangling insertions, and lookups during insertions.

These problems may all have the effect of replacing a deleted entry
with one that seems empty, which may disconnect double-hashing chains
involving that entry, and thus cause entries to go missing.

This patch, opening the patch series, only adds code to detect these
problems to the hash table verifier method.  I'm not sure it makes
sense to put it in, but I post it for the record.  Fixes and cheaper
detectors for some of these errors are going to be posted separately.

The number of bugs it revealed tells me that leaving callers in charge
of completing insertions is too error prone.  I found this
verification code a bit too expensive to enable in general.  We could
add check entry count cheaply at expand time and catch some of these
at very low cost, which would likely catch at least some of the
errors, but perhaps a safer interface could avoid them entirely.
WDYT?


I'm going to post a collection of 13 patches a as a followup to this
one, fixing various problems it has detected, or adding code to catch
some of these problems sooner.


for  gcc/ChangeLog

* hash-table.h (verify): Check elements and deleted counts.
---
 gcc/hash-table.h |   17 +
 1 file changed, 17 insertions(+)

diff --git a/gcc/hash-table.h b/gcc/hash-table.h
index 53507daae26c3..7dbeea05373a2 100644
--- a/gcc/hash-table.h
+++ b/gcc/hash-table.h
@@ -1035,6 +1035,23 @@ hash_table
  && Descriptor::equal (*entry, comparable))
hashtab_chk_error ();
 }
+
+  if (m_size < 2048)
+{
+  size_t elmts = m_n_elements, dels = m_n_deleted;
+  for (size_t i = 0; i < m_size; i++)
+   {
+ value_type *entry = &m_entries[i];
+ if (!is_empty (*entry))
+   {
+ elmts--;
+ if (is_deleted (*entry))
+   dels--;
+   }
+   }
+  if (elmts || dels)
+   hashtab_chk_error ();
+}
 }
 
 /* This function deletes an element with the given COMPARABLE value


-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about 


[01/13] scoped tables: insert before further lookups

2022-12-26 Thread Alexandre Oliva via Gcc-patches


Avoid hash table lookups between requesting an insert and storing the
inserted value in avail_exprs_stack.  Lookups before the insert is
completed could fail to find double-hashed elements.

Regstrapped on x86_64-linux-gnu.  Ok to install?


for  gcc/ChangeLog

* tree-ssa-scopedtables.cc
(avail_exprs_stack::lookup_avail_expr): Finish hash table
insertion before further lookups.
---
 gcc/tree-ssa-scopedtables.cc |   10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/tree-ssa-scopedtables.cc b/gcc/tree-ssa-scopedtables.cc
index 6d203ef89ecef..3e6e129e7d5d3 100644
--- a/gcc/tree-ssa-scopedtables.cc
+++ b/gcc/tree-ssa-scopedtables.cc
@@ -259,11 +259,6 @@ avail_exprs_stack::lookup_avail_expr (gimple *stmt, bool 
insert, bool tbaa_p,
 }
   else if (*slot == NULL)
 {
-  /* If we did not find the expression in the hash table, we may still
-be able to produce a result for some expressions.  */
-  tree retval = avail_exprs_stack::simplify_binary_operation (stmt,
- element);
-
   /* We have, in effect, allocated *SLOT for ELEMENT at this point.
 We must initialize *SLOT to a real entry, even if we found a
 way to prove ELEMENT was a constant after not finding ELEMENT
@@ -277,6 +272,11 @@ avail_exprs_stack::lookup_avail_expr (gimple *stmt, bool 
insert, bool tbaa_p,
   class expr_hash_elt *element2 = new expr_hash_elt (element);
   *slot = element2;
 
+  /* If we did not find the expression in the hash table, we may still
+be able to produce a result for some expressions.  */
+  tree retval = avail_exprs_stack::simplify_binary_operation (stmt,
+ element);
+
   record_expr (element2, NULL, '2');
   return retval;
 }

-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about 


[02/13] varpool: do not add NULL vnodes to referenced

2022-12-26 Thread Alexandre Oliva via Gcc-patches


Avoid adding NULL vnodes to referenced tables.

Regstrapped on x86_64-linux-gnu.  Ok to install?


for  gcc/ChangeLog

* varpool.c (symbol_table::remove_unreferenced_decls): Do not
add NULL vnodes to referenced table.
---
 gcc/varpool.cc |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/varpool.cc b/gcc/varpool.cc
index bfd17f1250cc0..ccbd6e50f4b01 100644
--- a/gcc/varpool.cc
+++ b/gcc/varpool.cc
@@ -680,10 +680,12 @@ symbol_table::remove_unreferenced_decls (void)
enqueue_node (vnode, &first);
  else
{
- referenced.add (vnode);
+ if (vnode)
+   referenced.add (vnode);
  while (vnode && vnode->alias && vnode->definition)
{
  vnode = vnode->get_alias_target ();
+ gcc_checking_assert (vnode);
  referenced.add (vnode);
}
}

-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about 


[03/13] tree-inline decl_map: skip mapping NULL to itself

2022-12-26 Thread Alexandre Oliva via Gcc-patches


Mapping a NULL key is no use, skip it.

Regstrapped on x86_64-linux-gnu.  Ok to install?


for  gcc/ChangeLog

* tree-inline.cc (insert_decl_map): Skip mapping a NULL decl
as value to itself.
---
 gcc/tree-inline.cc |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/tree-inline.cc b/gcc/tree-inline.cc
index c6c86af6c4ea9..bfea1cc11822e 100644
--- a/gcc/tree-inline.cc
+++ b/gcc/tree-inline.cc
@@ -148,7 +148,7 @@ insert_decl_map (copy_body_data *id, tree key, tree value)
 
   /* Always insert an identity map as well.  If we see this same new
  node again, we won't want to duplicate it a second time.  */
-  if (key != value)
+  if (key != value && value)
 id->decl_map->put (value, value);
 }
 

-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about 


[04/13] [C++] constraint: insert norm entry once

2022-12-26 Thread Alexandre Oliva via Gcc-patches


Use NO_INSERT to test whether inserting should be attempted.

Regstrapped on x86_64-linux-gnu.  Ok to install?


for  gcc/cp/ChangeLog

* constraint.cc (normalize_concept_check): Use NO_INSERT for
pre-insertion check.
---
 gcc/cp/constraint.cc |8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 37eae03afdb73..f28f96ada463e 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -777,14 +777,16 @@ normalize_concept_check (tree check, tree args, norm_info 
info)
   norm_entry entry = {tmpl, targs, NULL_TREE};
   norm_entry **slot = nullptr;
   hashval_t hash = 0;
+  bool insert = false;
   if (!info.generate_diagnostics ())
 {
   /* Cache the normal form of the substituted concept-id (when not
 diagnosing).  */
   hash = norm_hasher::hash (&entry);
-  slot = norm_cache->find_slot_with_hash (&entry, hash, INSERT);
-  if (*slot)
+  slot = norm_cache->find_slot_with_hash (&entry, hash, NO_INSERT);
+  if (slot)
return (*slot)->norm;
+  insert = true;
 }
 
   /* The concept may have been ill-formed.  */
@@ -794,7 +796,7 @@ normalize_concept_check (tree check, tree args, norm_info 
info)
 
   info.update_context (check, args);
   tree norm = normalize_expression (def, targs, info);
-  if (slot)
+  if (insert)
 {
   /* Recompute SLOT since norm_cache may have been expanded during
 the recursive call.  */

-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about 


[05/13] ssa-loop-niter: skip caching of null operands

2022-12-26 Thread Alexandre Oliva via Gcc-patches


When a TREE_OPERAND is NULL, do not cache it.

Regstrapped on x86_64-linux-gnu.  Ok to install?


for  gcc/ChangeLog

* tree-ssa-loop-niter.cc (expand_simple_operands): Refrain
from caching NULL TREE_OPERANDs.
---
 gcc/tree-ssa-loop-niter.cc |2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc
index fece876099c16..17645648326e8 100644
--- a/gcc/tree-ssa-loop-niter.cc
+++ b/gcc/tree-ssa-loop-niter.cc
@@ -2325,6 +2325,8 @@ expand_simple_operations (tree expr, tree stop, 
hash_map &cache)
   for (i = 0; i < n; i++)
{
  e = TREE_OPERAND (expr, i);
+ if (!e)
+   continue;
  /* SCEV analysis feeds us with a proper expression
 graph matching the SSA graph.  Avoid turning it
 into a tree here, thus handle tree sharing

-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about 


[07/13] postreload-gcse: no insert on mere lookup

2022-12-26 Thread Alexandre Oliva via Gcc-patches


lookup_expr_in_table is not used for insertions, but it mistakenly
used INSERT rather than NO_INSERT.

Regstrapped on x86_64-linux-gnu.  Ok to install?


for  gcc/ChangeLog

* postreload-gcse.cc (lookup_expr_in_table): Use NO_INSERT.
---
 gcc/postreload-gcse.cc |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/postreload-gcse.cc b/gcc/postreload-gcse.cc
index 1c795b43ca36b..2818f54dedd29 100644
--- a/gcc/postreload-gcse.cc
+++ b/gcc/postreload-gcse.cc
@@ -447,7 +447,7 @@ lookup_expr_in_table (rtx pat)
   tmp_expr->hash = hash;
   tmp_expr->avail_occr = NULL;
 
-  slot = expr_table->find_slot_with_hash (tmp_expr, hash, INSERT);
+  slot = expr_table->find_slot_with_hash (tmp_expr, hash, NO_INSERT);
   obstack_free (&expr_obstack, tmp_expr);
 
   if (!slot)

-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about 


[06/13] tree-inline decl_map: skip mapping result's NULL default def

2022-12-26 Thread Alexandre Oliva via Gcc-patches


If a result doesn't have a default def, don't attempt to remap it.

Regstrapped on x86_64-linux-gnu.  Ok to install?


for  gcc/ChangeLog

* tree-inline.cc (declare_return_variable): Don't remap NULL
default def of result.
---
 gcc/tree-inline.cc |9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/gcc/tree-inline.cc b/gcc/tree-inline.cc
index bfea1cc11822e..4556256dc32b1 100644
--- a/gcc/tree-inline.cc
+++ b/gcc/tree-inline.cc
@@ -3851,10 +3851,11 @@ declare_return_variable (copy_body_data *id, tree 
return_slot, tree modify_dest,
 it's default_def SSA_NAME.  */
   if (gimple_in_ssa_p (id->src_cfun)
  && is_gimple_reg (result))
-   {
- temp = make_ssa_name (temp);
- insert_decl_map (id, ssa_default_def (id->src_cfun, result), temp);
-   }
+   if (tree default_def = ssa_default_def (id->src_cfun, result))
+ {
+   temp = make_ssa_name (temp);
+   insert_decl_map (id, default_def, temp);
+ }
   insert_init_stmt (id, entry_bb, gimple_build_assign (temp, var));
 }
   else

-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about 


[08/13] tm: complete tm_restart insertion

2022-12-26 Thread Alexandre Oliva via Gcc-patches


Insertion of a tm_restart_node in tm_restart failed to record the
newly-allocated node in the hash table.

Regstrapped on x86_64-linux-gnu.  Ok to install?


for  gcc/ChangeLog

* trans-mem.cc (split_bb_make_tm_edge): Record new node in
tm_restart.
---
 gcc/trans-mem.cc |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/trans-mem.cc b/gcc/trans-mem.cc
index 131dce05476ac..cbd1b891266fd 100644
--- a/gcc/trans-mem.cc
+++ b/gcc/trans-mem.cc
@@ -3215,7 +3215,7 @@ split_bb_make_tm_edge (gimple *stmt, basic_block dest_bb,
   struct tm_restart_node *n = *slot;
   if (n == NULL)
 {
-  n = ggc_alloc ();
+  *slot = n = ggc_alloc ();
   *n = dummy;
 }
   else

-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about 


[09/13] [C++] constexpr: request insert iff depth is ok

2022-12-26 Thread Alexandre Oliva via Gcc-patches


cxx_eval_call_expression requests an INSERT even in cases when it
would later decide not to insert.  This could break double-hashing
chains.  Arrange for it to use NO_INSERT when the insertion would not
be completed.

Regstrapped on x86_64-linux-gnu.  Ok to install?


for  gcc/cp/ChangeLog

* constexpr.cc (cxx_eval_call_expression): Do not request an
INSERT that would not be completed.
---
 gcc/cp/constexpr.cc |8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index d99c49bdbe282..6d20ffa2cdeb6 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -3000,13 +3000,15 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, 
tree t,
 
   /* If we have seen this call before, we are done.  */
   maybe_initialize_constexpr_call_table ();
+  bool insert = depth_ok < constexpr_cache_depth;
   constexpr_call **slot
-   = constexpr_call_table->find_slot (&new_call, INSERT);
-  entry = *slot;
+   = constexpr_call_table->find_slot (&new_call,
+  insert ? INSERT : NO_INSERT);
+  entry = slot ? *slot : NULL;
   if (entry == NULL)
{
  /* Only cache up to constexpr_cache_depth to limit memory use.  */
- if (depth_ok < constexpr_cache_depth)
+ if (insert)
{
  /* We need to keep a pointer to the entry, not just the slot, as
 the slot can move during evaluation of the body.  */

-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about 


[10/13] lto: drop dummy partition mapping

2022-12-26 Thread Alexandre Oliva via Gcc-patches


When adding a catch-all partition, we map NULL to it.  That mapping is
ineffective and unnecessary.  Drop it.

Regstrapped on x86_64-linux-gnu.  Ok to install?


for  gcc/lto/ChangeLog

* lto-partition.cc (lto_1_to_1_map): Drop NULL partition
mapping.
---
 gcc/lto/lto-partition.cc |1 -
 1 file changed, 1 deletion(-)

diff --git a/gcc/lto/lto-partition.cc b/gcc/lto/lto-partition.cc
index ebb9c3abe128c..654d67f272e92 100644
--- a/gcc/lto/lto-partition.cc
+++ b/gcc/lto/lto-partition.cc
@@ -333,7 +333,6 @@ lto_1_to_1_map (void)
   else
{
  partition = new_partition ("");
- pmap.put (NULL, partition);
  npartitions++;
}
 

-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about 


[11/13] ada: don't map NULL decl to locus

2022-12-26 Thread Alexandre Oliva via Gcc-patches


When decl is NULL, don't record its mapping in the
decl_to_instance_map.

Regstrapped on x86_64-linux-gnu.  Ok to install?


for  gcc/ada/ChangeLog

* gcc-interface/trans.cc (Sloc_to_locus): Don't map NULL decl.
---
 gcc/ada/gcc-interface/trans.cc |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc
index 59332f93614a9..6579ad11cc284 100644
--- a/gcc/ada/gcc-interface/trans.cc
+++ b/gcc/ada/gcc-interface/trans.cc
@@ -10564,7 +10564,7 @@ Sloc_to_locus (Source_Ptr Sloc, location_t *locus, bool 
clear_column,
   *locus
 = linemap_position_for_line_and_column (line_table, map, line, column);
 
-  if (file_map && file_map[file - 1].Instance)
+  if (decl && file_map && file_map[file - 1].Instance)
 decl_to_instance_map->put (decl, file_map[file - 1].Instance);
 
   return true;

-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about 


[12/13] hash set: reject attempts to add empty values

2022-12-26 Thread Alexandre Oliva via Gcc-patches


Check, after adding a key to a hash set, that the entry does not look
empty.

Regstrapped on x86_64-linux-gnu.  Ok to install?


for  gcc/ChangeLog

* hash-set.h (add): Check that the inserted entry does not
look empty.
---
 gcc/hash-set.h |6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/hash-set.h b/gcc/hash-set.h
index 76fa7f394561e..a98121a060eed 100644
--- a/gcc/hash-set.h
+++ b/gcc/hash-set.h
@@ -58,7 +58,11 @@ public:
   Key *e = m_table.find_slot_with_hash (k, Traits::hash (k), INSERT);
   bool existed = !Traits::is_empty (*e);
   if (!existed)
-   new (e) Key (k);
+   {
+ new (e) Key (k);
+ // Catch attempts to insert e.g. a NULL pointer.
+ gcc_checking_assert (!Traits::is_empty (*e));
+   }
 
   return existed;
 }

-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about 


[13/13] hash-map: reject empty-looking insertions

2022-12-26 Thread Alexandre Oliva via Gcc-patches


Check, after inserting entries, that they don't look empty.

Regstrapped on x86_64-linux-gnu.  Ok to install?


for  gcc/ChangeLog

* hash-map.h (put, get_or_insert): Check that entry does not
look empty after insertion.
---
 gcc/hash-map.h |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/hash-map.h b/gcc/hash-map.h
index 457967f4bf1ae..63fa21cf37c5b 100644
--- a/gcc/hash-map.h
+++ b/gcc/hash-map.h
@@ -169,11 +169,12 @@ public:
 {
   hash_entry *e = m_table.find_slot_with_hash (k, Traits::hash (k),
   INSERT);
-  bool ins = hash_entry::is_empty (*e);
+  bool ins = Traits::is_empty (*e);
   if (ins)
{
  e->m_key = k;
  new ((void *) &e->m_value) Value (v);
+ gcc_checking_assert (!Traits::is_empty (*e));
}
   else
e->m_value = v;
@@ -203,6 +204,7 @@ public:
{
  e->m_key = k;
  new ((void *)&e->m_value) Value ();
+ gcc_checking_assert (!Traits::is_empty (*e));
}
 
   if (existed != NULL)

-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about 


[PATCH] xtensa: Apply a few minor fixes

2022-12-26 Thread Takayuki 'January June' Suwa via Gcc-patches
Almost cosmetic and no functional changes.

gcc/ChangeLog:

* config/xtensa/*: Tabify, and trim trailing spaces.
* config/xtensa/xtensa.h (GP_RETURN, GP_RETURN_REG_COUNT):
Change to GP_RETURN_FIRST and GP_RETURN_LAST, respectively.
* config/xtensa/xtensa.cc (xtensa_function_value,
xtensa_libcall_value, xtensa_function_value_regno_p): Ditto.
(xtensa_expand_prologue): Modify to exit the inspection loops
as soon as the necessity of stack pointer is found.
(xtensa_set_return_address): Change the style of brackets.
* config/xtensa/xtensa.md (set_frame_ptr):
Fix to reflect TARGET_DENSITY.
---
 gcc/config/xtensa/elf.h  |  32 
 gcc/config/xtensa/linux.h|   1 -
 gcc/config/xtensa/uclinux.h  |   1 -
 gcc/config/xtensa/xtensa-dynconfig.c |   6 +-
 gcc/config/xtensa/xtensa.cc  | 105 ++-
 gcc/config/xtensa/xtensa.h   |  10 +--
 gcc/config/xtensa/xtensa.md  | 105 ++-
 7 files changed, 133 insertions(+), 127 deletions(-)

diff --git a/gcc/config/xtensa/elf.h b/gcc/config/xtensa/elf.h
index fbdccc49c9b..1edc1761d74 100644
--- a/gcc/config/xtensa/elf.h
+++ b/gcc/config/xtensa/elf.h
@@ -59,7 +59,7 @@ along with GCC; see the file COPYING3.  If not see
   "crt1-sim%O%s crt0%O%s crti%O%s crtbegin%O%s _vectors%O%s"
 
 #undef ENDFILE_SPEC
-#define ENDFILE_SPEC "crtend%O%s crtn%O%s"  
+#define ENDFILE_SPEC "crtend%O%s crtn%O%s"
 
 #undef LINK_SPEC
 #define LINK_SPEC \
@@ -86,19 +86,17 @@ along with GCC; see the file COPYING3.  If not see
 /* Search for headers in $tooldir/arch/include and for libraries and
startfiles in $tooldir/arch/lib.  */
 #define GCC_DRIVER_HOST_INITIALIZATION \
-do \
-{ \
-  char *tooldir, *archdir; \
-  tooldir = concat (tooldir_base_prefix, spec_machine, \
-   dir_separator_str, NULL); \
-  if (!IS_ABSOLUTE_PATH (tooldir)) \
-tooldir = concat (standard_exec_prefix, spec_machine, dir_separator_str, \
- spec_version, dir_separator_str, tooldir, NULL); \
-  archdir = concat (tooldir, "arch", dir_separator_str, NULL); \
-  add_prefix (&startfile_prefixes, \
- concat (archdir, "lib", dir_separator_str, NULL), \
- "GCC", PREFIX_PRIORITY_LAST, 0, 1); \
-  add_prefix (&include_prefixes, archdir, \
- "GCC", PREFIX_PRIORITY_LAST, 0, 0); \
-  } \
-while (0)
+  do { \
+char *tooldir, *archdir; \
+tooldir = concat (tooldir_base_prefix, spec_machine, \
+ dir_separator_str, NULL); \
+if (!IS_ABSOLUTE_PATH (tooldir)) \
+  tooldir = concat (standard_exec_prefix, spec_machine, dir_separator_str, 
\
+   spec_version, dir_separator_str, tooldir, NULL); \
+archdir = concat (tooldir, "arch", dir_separator_str, NULL); \
+add_prefix (&startfile_prefixes, \
+   concat (archdir, "lib", dir_separator_str, NULL), \
+   "GCC", PREFIX_PRIORITY_LAST, 0, 1); \
+add_prefix (&include_prefixes, archdir, \
+   "GCC", PREFIX_PRIORITY_LAST, 0, 0); \
+  } while (0)
diff --git a/gcc/config/xtensa/linux.h b/gcc/config/xtensa/linux.h
index bc7bee71517..198edfe0553 100644
--- a/gcc/config/xtensa/linux.h
+++ b/gcc/config/xtensa/linux.h
@@ -69,4 +69,3 @@ along with GCC; see the file COPYING3.  If not see
 #define XTENSA_ALWAYS_PIC 1
 
 #undef DEBUGGER_REGNO
-
diff --git a/gcc/config/xtensa/uclinux.h b/gcc/config/xtensa/uclinux.h
index 5fcf639ccff..5787b2f1ab9 100644
--- a/gcc/config/xtensa/uclinux.h
+++ b/gcc/config/xtensa/uclinux.h
@@ -71,4 +71,3 @@ along with GCC; see the file COPYING3.  If not see
 #define TARGET_LIBC_HAS_FUNCTION no_c99_libc_has_function
 
 #undef DEBUGGER_REGNO
-
diff --git a/gcc/config/xtensa/xtensa-dynconfig.c 
b/gcc/config/xtensa/xtensa-dynconfig.c
index 056204ae946..0a611fd14b0 100644
--- a/gcc/config/xtensa/xtensa-dynconfig.c
+++ b/gcc/config/xtensa/xtensa-dynconfig.c
@@ -35,7 +35,7 @@
 
 #if !defined (HAVE_DLFCN_H) && defined (_WIN32)
 
-#define RTLD_LAZY 0  /* Dummy value.  */
+#define RTLD_LAZY 0/* Dummy value.  */
 
 static void *
 dlopen (const char *file, int mode ATTRIBUTE_UNUSED)
@@ -142,8 +142,8 @@ XTENSA_CONFIG_INSTANCE_LIST;
 #define XTENSA_CONFIG_ENTRY(a) "__" #a "=" STRINGIFY(a)
 
 static const char * const xtensa_config_strings[] = {
-XTENSA_CONFIG_ENTRY_LIST,
-NULL,
+  XTENSA_CONFIG_ENTRY_LIST,
+  NULL,
 };
 
 const struct xtensa_config_v1 *xtensa_get_config_v1 (void)
diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc
index 94a98c25f8c..66e25349521 100644
--- a/gcc/config/xtensa/xtensa.cc
+++ b/gcc/config/xtensa/xtensa.cc
@@ -176,7 +176,7 @@ static bool constantpool_address_p (const_rtx addr);
 static bool xtensa_legitimate_constant_p (machine_mode, rtx);
 static void xtensa_reorg (void);
 static bool xtensa_can_use_doloop_p (const widest_int &, const widest_int &,
- u

[PATCH v4] LoongArch: Fixed a compilation failure with '%c' in inline assembly [PR107731].

2022-12-26 Thread Lulu Cheng
Co-authored-by: Yang Yujie 

gcc/ChangeLog:

* config/loongarch/loongarch.cc (loongarch_classify_address):
Add precessint for CONST_INT.
(loongarch_print_operand_reloc): Operand modifier 'c' is supported.
(loongarch_print_operand): Increase the processing of '%c'.
* doc/extend.texi: Adds documents for LoongArch operand modifiers.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/tst-asm-const.c: Moved to...
* gcc.target/loongarch/pr107731.c: ...here.

---
V2 -> v3:
1. Correct a clerical error.
2. Adding document for loongarch operand modifiers.

v3 -> v4:
Copy the description of "%c" "%n" "%a" "%l" from gccint.pdf to gcc.pdf.


---
 gcc/config/loongarch/loongarch.cc | 14 
 gcc/doc/extend.texi   | 33 +++
 .../loongarch/{tst-asm-const.c => pr107731.c} |  6 ++--
 3 files changed, 50 insertions(+), 3 deletions(-)
 rename gcc/testsuite/gcc.target/loongarch/{tst-asm-const.c => pr107731.c} (78%)

diff --git a/gcc/config/loongarch/loongarch.cc 
b/gcc/config/loongarch/loongarch.cc
index c6b03fcf2f9..cdf190b985e 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -2075,6 +2075,11 @@ loongarch_classify_address (struct 
loongarch_address_info *info, rtx x,
   return (loongarch_valid_base_register_p (info->reg, mode, strict_p)
  && loongarch_valid_lo_sum_p (info->symbol_type, mode,
   info->offset));
+case CONST_INT:
+  /* Small-integer addresses don't occur very often, but they
+are legitimate if $r0 is a valid base register.  */
+  info->type = ADDRESS_CONST_INT;
+  return IMM12_OPERAND (INTVAL (x));
 
 default:
   return false;
@@ -4933,6 +4938,7 @@ loongarch_print_operand_reloc (FILE *file, rtx op, bool 
hi64_part,
 
'A' Print a _DB suffix if the memory model requires a release.
'b' Print the address of a memory operand, without offset.
+   'c'  Print an integer.
'C' Print the integer branch condition for comparison OP.
'd' Print CONST_INT OP in decimal.
'F' Print the FPU branch condition for comparison OP.
@@ -4979,6 +4985,14 @@ loongarch_print_operand (FILE *file, rtx op, int letter)
fputs ("_db", file);
   break;
 
+case 'c':
+  if (CONST_INT_P (op))
+   fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (op));
+  else
+   output_operand_lossage ("unsupported operand for code '%c'", letter);
+
+  break;
+
 case 'C':
   loongarch_print_int_branch_condition (file, code, letter);
   break;
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index adba057c190..1bb960266ed 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -10234,6 +10234,24 @@ generates multiple assembler instructions.
 Outputs @samp{@{}, @samp{|}, and @samp{@}} characters (respectively)
 into the assembler code.  When unescaped, these characters have special
 meaning to indicate multiple assembler dialects, as described below.
+
+@item %c@var{digit}
+It can be used to substitute an operand that is a constant value without
+the syntax that normally indicates an immediate operand.
+
+@item %n@var{digit}
+It's like @samp{%c@var{digit}} except that the value of the constant is
+negated before printing.
+
+@item %a@var{digit}
+It Can be used to substitute an operand as if it were a memory reference,
+with the actual operand treated as the address.  This may be useful when
+outputting a ``load address'' instruction, because often the assembler
+syntax for such an instruction requires you to write the operand as if it
+were a memory reference.
+
+@item %l@var{digit}
+It's used to substitute a @code{label_ref} into a jump instruction.
 @end table
 
 @subsubheading Multiple assembler dialects in @code{asm} templates
@@ -11374,6 +11392,21 @@ constant.  Used to select the specified bit position.
 @item @code{x} @tab Equivialent to @code{X}, but only for pointers.
 @end multitable
 
+@anchor{loongarchOperandmodifiers}
+@subsubsection LoongArch Operand Modifiers
+
+The list below describes the supported modifiers and their effects for 
LoongArch.
+
+@multitable @columnfractions .10 .90
+@headitem Modifier @tab Description
+@item @code{d} @tab Same as @code{c}.
+@item @code{i} @tab Print the character ''@code{i}'' if the operand is not a 
register.
+@item @code{m} @tab Same as @code{c}, but the printed value is @code{operand - 
1}.
+@item @code{X} @tab Print a constant integer operand in hexadecimal.
+@item @code{z} @tab Print the operand in its unmodified form, followed by a 
comma.
+@end multitable
+
+
 @lowersections
 @include md.texi
 @raisesections
diff --git a/gcc/testsuite/gcc.target/loongarch/tst-asm-const.c 
b/gcc/testsuite/gcc.target/loongarch/pr107731.c
similarity index 78%
rename from gcc/testsuite/gcc.target/loongarch/tst-asm-const.c
rename to gcc/testsuite/gcc.target/loongarch/pr107731.c
index 2e04b99e301..80d84c48c6e 100644
--- a/gcc