[PATCH] diagnostics: fix gcc-urlifier.cc bootstrap failure [PR112379]

2023-11-04 Thread Sergei Trofimovich
From: Sergei Trofimovich 

Without the change `./configure --enable-checking=release` bootstrap
fails as:

gcc/gcc-urlifier.cc:100:1: error: 'get_url_suffix_for_quoted_text()'
defined but not used [-Werror=unused-function]

This happens because the helper is used only in `ASSERT` macros which
don't always get expanded to executable code.

The fix marks helper function with `ATTRIBUTE_UNUSED`.

gcc/
PR bootstrap/112379
* gcc-urlifier.cc (get_url_suffix_for_quoted_text): Mark as
ATTRIBUTE_UNUSED.
---
 gcc/gcc-urlifier.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/gcc-urlifier.cc b/gcc/gcc-urlifier.cc
index 269246bc703..0dbff985313 100644
--- a/gcc/gcc-urlifier.cc
+++ b/gcc/gcc-urlifier.cc
@@ -37,7 +37,8 @@ public:
   char *get_url_for_quoted_text (const char *p, size_t sz) const final 
override;
 
   const char *get_url_suffix_for_quoted_text (const char *p, size_t sz) const;
-  const char *get_url_suffix_for_quoted_text (const char *p) const;
+  /* We use ATTRIBUTE_UNUSED as this helper is called only from ASSERTs.  */
+  const char *get_url_suffix_for_quoted_text (const char *p) const 
ATTRIBUTE_UNUSED;
 
 private:
   static char *
-- 
2.42.0



Re: [PATCH] libgcc: make heap-based trampolines conditional on libc presence

2023-10-23 Thread Sergei Trofimovich
On Mon, 23 Oct 2023 13:54:01 +0100
Iain Sandoe  wrote:

> hi Sergei,
> 
> > On 23 Oct 2023, at 13:43, Sergei Trofimovich  wrote:
> > 
> > From: Sergei Trofimovich 
> > 
> > To build `libc` for a target one needs to build `gcc` without `libc`
> > support first. Commit r14-4823-g8abddb187b3348 "libgcc: support
> > heap-based trampolines" added unconditional `libc` dependency and broke
> > libc-less `gcc` builds.
> > 
> > An example failure on `x86_64-unknown-linux-gnu`:
> > 
> >$ mkdir -p /tmp/empty
> >$ ../gcc/configure \
> >--disable-multilib \
> >--without-headers \
> >--with-newlib \
> >--enable-languages=c \
> >--disable-bootstrap \
> >--disable-gcov \
> >--disable-threads \
> >--disable-shared \
> >--disable-libssp \
> >--disable-libquadmath \
> >--disable-libgomp \
> >--disable-libatomic \
> >--with-build-sysroot=/tmp/empty
> >$ make
> >...
> >/tmp/gb/./gcc/xgcc -B/tmp/gb/./gcc/ 
> > -B/usr/local/x86_64-pc-linux-gnu/bin/ -B/usr/local/x86_64-pc-linux-gnu/lib/ 
> > -isystem /usr/local/x86_64-pc-linux-gnu/include -isystem 
> > /usr/local/x86_64-pc-linux-gnu/sys-include --sysroot=/tmp/empty   -g -O2 
> > -O2  -g -O2 -DIN_GCC   -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual 
> > -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition  -isystem 
> > ./include  -fpic -mlong-double-80 -DUSE_ELF_SYMVER -fcf-protection -mshstk 
> > -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -Dinhibit_libc -fpic 
> > -mlong-double-80 -DUSE_ELF_SYMVER -fcf-protection -mshstk -I. -I. 
> > -I../.././gcc -I/home/slyfox/dev/git/gcc/libgcc 
> > -I/home/slyfox/dev/git/gcc/libgcc/. 
> > -I/home/slyfox/dev/git/gcc/libgcc/../gcc 
> > -I/home/slyfox/dev/git/gcc/libgcc/../include  -DHAVE_CC_TLS  -DUSE_TLS  -o 
> > heap-trampoline.o -MT heap-trampoline.o -MD -MP -MF heap-trampoline.dep  -c 
> > .../gcc/libgcc/config/i386/heap-trampoline.c -fvisibility=hidden 
> > -DHIDE_EXPORTS
> >../gcc/libgcc/config/i386/heap-trampoline.c:3:10: fatal error: unistd.h: 
> > No such file or directory
> >3 | #include 
> >  |  ^~
> >compilation terminated.
> >make[2]: *** [.../gcc/libgcc/static-object.mk:17: heap-trampoline.o] 
> > Error 1
> >make[2]: Leaving directory '/tmp/gb/x86_64-pc-linux-gnu/libgcc'
> >make[1]: *** [Makefile:13307: all-target-libgcc] Error 2
> > 
> > The change inhibits any heap-based trampoline code.  
> 
> That looks reasonable to me (I was considering using __has_include(), but the 
> inhibit_libc is neater).
> 
> The fact that this first compiler is buit without heap-trampoline support, 
> would become relevant, I guess if libc wanted to use them, it would need 
> another iteration.
> 
> so, it looks fine, but I cannot actually approve it.

Sounds good. Let's wait for others to chime in. Maybe Richard? :)

AFAIU libcs (like `glibc`) try hard not to use link tests and uses
mainly preprocessor and code generator to specifically accommodate this
case. Maybe there is a way to pass the support flag to libc without the
reliance on code presence in libgcc.

Otherwise we could use __builtin_trap() as an implementation for exposed
symbols.

> 
> > 
> > libgcc/
> > 
> > * libgcc/config/aarch64/heap-trampoline.c: Disable when libc is
> >   not present.
> > ---
> > libgcc/config/aarch64/heap-trampoline.c | 5 +
> > libgcc/config/i386/heap-trampoline.c| 5 +
> > 2 files changed, 10 insertions(+)
> > 
> > diff --git a/libgcc/config/aarch64/heap-trampoline.c 
> > b/libgcc/config/aarch64/heap-trampoline.c
> > index c8b83681ed7..f22233987ca 100644
> > --- a/libgcc/config/aarch64/heap-trampoline.c
> > +++ b/libgcc/config/aarch64/heap-trampoline.c
> > @@ -1,5 +1,8 @@
> > /* Copyright The GNU Toolchain Authors. */
> > 
> > +/* libc is required to allocate trampolines.  */
> > +#ifndef inhibit_libc
> > +
> > #include 
> > #include 
> > #include 
> > @@ -170,3 +173,5 @@ __builtin_nested_func_ptr_deleted (void)
> >   tramp_ctrl_curr = prev;
> > }
> > }
> > +
> > +#endif /* !inhibit_libc */
> > diff --git a/libgcc/config/i386/heap-trampoline.c 
> > b/libgcc/config/i386/heap-trampoline.c
> > index 96e13bf828e..4b9f4365868 100644
> > --- a/libgcc/config/i386/heap-trampoline.c
> > +++ b/libgcc/config/i386/heap-trampoline.c
> > @@ -1,5 +1,8 @@
> > /* Copyright The GNU Toolchain Authors. */
> > 
> > +/* libc is required to allocate trampolines.  */
> > +#ifndef inhibit_libc
> > +
> > #include 
> > #include 
> > #include 
> > @@ -170,3 +173,5 @@ __builtin_nested_func_ptr_deleted (void)
> >   tramp_ctrl_curr = prev;
> > }
> > }
> > +
> > +#endif /* !inhibit_libc */
> > -- 
> > 2.42.0
> >   
> 


-- 

  Sergei


[PATCH] libgcc: make heap-based trampolines conditional on libc presence

2023-10-23 Thread Sergei Trofimovich
From: Sergei Trofimovich 

To build `libc` for a target one needs to build `gcc` without `libc`
support first. Commit r14-4823-g8abddb187b3348 "libgcc: support
heap-based trampolines" added unconditional `libc` dependency and broke
libc-less `gcc` builds.

An example failure on `x86_64-unknown-linux-gnu`:

$ mkdir -p /tmp/empty
$ ../gcc/configure \
--disable-multilib \
--without-headers \
--with-newlib \
--enable-languages=c \
--disable-bootstrap \
--disable-gcov \
--disable-threads \
--disable-shared \
--disable-libssp \
--disable-libquadmath \
--disable-libgomp \
--disable-libatomic \
--with-build-sysroot=/tmp/empty
$ make
...
/tmp/gb/./gcc/xgcc -B/tmp/gb/./gcc/ -B/usr/local/x86_64-pc-linux-gnu/bin/ 
-B/usr/local/x86_64-pc-linux-gnu/lib/ -isystem 
/usr/local/x86_64-pc-linux-gnu/include -isystem 
/usr/local/x86_64-pc-linux-gnu/sys-include --sysroot=/tmp/empty   -g -O2 -O2  
-g -O2 -DIN_GCC   -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual 
-Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition  -isystem 
./include  -fpic -mlong-double-80 -DUSE_ELF_SYMVER -fcf-protection -mshstk -g 
-DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -Dinhibit_libc -fpic 
-mlong-double-80 -DUSE_ELF_SYMVER -fcf-protection -mshstk -I. -I. -I../.././gcc 
-I/home/slyfox/dev/git/gcc/libgcc -I/home/slyfox/dev/git/gcc/libgcc/. 
-I/home/slyfox/dev/git/gcc/libgcc/../gcc 
-I/home/slyfox/dev/git/gcc/libgcc/../include  -DHAVE_CC_TLS  -DUSE_TLS  -o 
heap-trampoline.o -MT heap-trampoline.o -MD -MP -MF heap-trampoline.dep  -c 
.../gcc/libgcc/config/i386/heap-trampoline.c -fvisibility=hidden -DHIDE_EXPORTS
../gcc/libgcc/config/i386/heap-trampoline.c:3:10: fatal error: unistd.h: No 
such file or directory
3 | #include 
  |  ^~
compilation terminated.
make[2]: *** [.../gcc/libgcc/static-object.mk:17: heap-trampoline.o] Error 1
make[2]: Leaving directory '/tmp/gb/x86_64-pc-linux-gnu/libgcc'
make[1]: *** [Makefile:13307: all-target-libgcc] Error 2

The change inhibits any heap-based trampoline code.

libgcc/

* libgcc/config/aarch64/heap-trampoline.c: Disable when libc is
  not present.
---
 libgcc/config/aarch64/heap-trampoline.c | 5 +
 libgcc/config/i386/heap-trampoline.c| 5 +
 2 files changed, 10 insertions(+)

diff --git a/libgcc/config/aarch64/heap-trampoline.c 
b/libgcc/config/aarch64/heap-trampoline.c
index c8b83681ed7..f22233987ca 100644
--- a/libgcc/config/aarch64/heap-trampoline.c
+++ b/libgcc/config/aarch64/heap-trampoline.c
@@ -1,5 +1,8 @@
 /* Copyright The GNU Toolchain Authors. */
 
+/* libc is required to allocate trampolines.  */
+#ifndef inhibit_libc
+
 #include 
 #include 
 #include 
@@ -170,3 +173,5 @@ __builtin_nested_func_ptr_deleted (void)
   tramp_ctrl_curr = prev;
 }
 }
+
+#endif /* !inhibit_libc */
diff --git a/libgcc/config/i386/heap-trampoline.c 
b/libgcc/config/i386/heap-trampoline.c
index 96e13bf828e..4b9f4365868 100644
--- a/libgcc/config/i386/heap-trampoline.c
+++ b/libgcc/config/i386/heap-trampoline.c
@@ -1,5 +1,8 @@
 /* Copyright The GNU Toolchain Authors. */
 
+/* libc is required to allocate trampolines.  */
+#ifndef inhibit_libc
+
 #include 
 #include 
 #include 
@@ -170,3 +173,5 @@ __builtin_nested_func_ptr_deleted (void)
   tramp_ctrl_curr = prev;
 }
 }
+
+#endif /* !inhibit_libc */
-- 
2.42.0



[PATCH v4] ipa-utils: avoid uninitialized probabilities on ICF [PR111559]

2023-10-05 Thread Sergei Trofimovich
On Thu, Oct 05, 2023 at 03:04:55PM +0200, Jan Hubicka wrote:
> > diff --git a/gcc/ipa-utils.cc b/gcc/ipa-utils.cc
> > index 956c6294fd7..1355ccac6f0 100644
> > --- a/gcc/ipa-utils.cc
> > +++ b/gcc/ipa-utils.cc
> > @@ -651,13 +651,16 @@ ipa_merge_profiles (struct cgraph_node *dst,
> > {
> >   edge srce = EDGE_SUCC (srcbb, i);
> >   edge dste = EDGE_SUCC (dstbb, i);
> > - dste->probability = 
> > -   dste->probability * dstbb->count.ipa ().probability_in
> > -(dstbb->count.ipa ()
> > - + srccount.ipa ())
> > -   + srce->probability * srcbb->count.ipa ().probability_in
> > -(dstbb->count.ipa ()
> > - + srccount.ipa ());
> > + profile_count sum =
> > +   dstbb->count.ipa () + srccount.ipa ();
> > + if (sum.nonzero_p ())
> > +   dste->probability =
> > + dste->probability * dstbb->count.ipa ().probability_in
> > +  (dstbb->count.ipa ()
> > +   + srccount.ipa ())
> > + + srce->probability * srcbb->count.ipa ().probability_in
> > +  (dstbb->count.ipa ()
> > +   + srccount.ipa ());
> 
> looks good.  You can use probability_in (sum) 
> in both of the places.

Oh, great point! Completely forgot about it. Attached v4.

If it still looks reasonable I'll check again if `python` and
`profiledbootstrap` still survives it and will push.

-- 

  Sergei
>From cb9852216b5b2524f72964b399c133557ec98df0 Mon Sep 17 00:00:00 2001
From: Sergei Trofimovich 
Date: Wed, 27 Sep 2023 14:29:12 +0100
Subject: [PATCH v4] ipa-utils: avoid uninitialized probabilities on ICF
 [PR111559]

r14-3459-g0c78240fd7d519 "Check that passes do not forget to define profile"
exposed check failures in cases when gcc produces uninitialized profile
probabilities. In case of PR/111559 uninitialized profile is generated
by edges executed 0 times reported by IPA profile:

$ gcc -O2 -fprofile-generate pr111559.c -o b -fopt-info
$ ./b
$ gcc -O2 -fprofile-use -fprofile-correction pr111559.c -o b -fopt-info

pr111559.c: In function 'rule1':
pr111559.c:6:13: error: probability of edge 3->4 not initialized
6 | static void rule1(void) { if (p) edge(); }
  | ^
during GIMPLE pass: fixup_cfg
pr111559.c:6:13: internal compiler error: verify_flow_info failed

The change conservatively ignores updates with zero execution counts and
uses initially assigned probabilities (`always` probability in case of
the example).

PR ipa/111283
PR gcov-profile/111559

gcc/
* ipa-utils.cc (ipa_merge_profiles): Avoid producing
uninitialized probabilities when merging counters with zero
denominators.

gcc/testsuite/
* gcc.dg/tree-prof/pr111559.c: New test.
---
 gcc/ipa-utils.cc  | 15 ---
 gcc/testsuite/gcc.dg/tree-prof/pr111559.c | 16 
 2 files changed, 24 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-prof/pr111559.c

diff --git a/gcc/ipa-utils.cc b/gcc/ipa-utils.cc
index 956c6294fd7..6024ac69cc2 100644
--- a/gcc/ipa-utils.cc
+++ b/gcc/ipa-utils.cc
@@ -651,13 +651,14 @@ ipa_merge_profiles (struct cgraph_node *dst,
{
  edge srce = EDGE_SUCC (srcbb, i);
  edge dste = EDGE_SUCC (dstbb, i);
- dste->probability = 
-   dste->probability * dstbb->count.ipa ().probability_in
-(dstbb->count.ipa ()
- + srccount.ipa ())
-   + srce->probability * srcbb->count.ipa ().probability_in
-(dstbb->count.ipa ()
- + srccount.ipa ());
+ profile_count sum =
+   dstbb->count.ipa () + srccount.ipa ();
+ if (sum.nonzero_p ())
+   dste->probability =
+ dste->probability * dstbb->count.ipa ().probability_in
+  (sum)
+ + srce->probability * srcbb->count.ipa ().probability_in
+  (sum);
}
  dstbb->count = dstbb->count.ipa () + srccount.ipa ();
}
diff --git

Re: [PATCH v2] ipa-utils: avoid uninitialized probabilities on ICF [PR111559]

2023-10-05 Thread Sergei Trofimovich
On Thu, Oct 05, 2023 at 01:52:30PM +0200, Jan Hubicka wrote:
> > From: Sergei Trofimovich 
> > 
> > r14-3459-g0c78240fd7d519 "Check that passes do not forget to define profile"
> > exposed check failures in cases when gcc produces uninitialized profile
> > probabilities. In case of PR/111559 uninitialized profile is generated
> > by edges executed 0 times reported by IPA profile:
> > 
> > $ gcc -O2 -fprofile-generate pr111559.c -o b -fopt-info
> > $ ./b
> > $ gcc -O2 -fprofile-use -fprofile-correction pr111559.c -o b -fopt-info
> > 
> > pr111559.c: In function 'rule1':
> > pr111559.c:6:13: error: probability of edge 3->4 not initialized
> > 6 | static void rule1(void) { if (p) edge(); }
> >   | ^
> > during GIMPLE pass: fixup_cfg
> > pr111559.c:6:13: internal compiler error: verify_flow_info failed
> > 
> > The change conservatively ignores updates with uninitialized values and
> > uses initially assigned probabilities (`always` probability in case of
> > the example).
> > 
> > PR ipa/111283
> > PR gcov-profile/111559
> > 
> > gcc/
> > * ipa-utils.cc (ipa_merge_profiles): Avoid producing
> > uninitialized probabilities when merging counters with zero
> > denominators.
> > 
> > gcc/testsuite/
> > * gcc.dg/tree-prof/pr111559.c: New test.
> > ---
> >  gcc/ipa-utils.cc  |  6 +-
> >  gcc/testsuite/gcc.dg/tree-prof/pr111559.c | 16 
> >  2 files changed, 21 insertions(+), 1 deletion(-)
> >  create mode 100644 gcc/testsuite/gcc.dg/tree-prof/pr111559.c
> > 
> > diff --git a/gcc/ipa-utils.cc b/gcc/ipa-utils.cc
> > index 956c6294fd7..7c53ae9dd45 100644
> > --- a/gcc/ipa-utils.cc
> > +++ b/gcc/ipa-utils.cc
> > @@ -651,13 +651,17 @@ ipa_merge_profiles (struct cgraph_node *dst,
> > {
> >   edge srce = EDGE_SUCC (srcbb, i);
> >   edge dste = EDGE_SUCC (dstbb, i);
> > - dste->probability = 
> > + profile_probability merged =
> > dste->probability * dstbb->count.ipa ().probability_in
> >  (dstbb->count.ipa ()
> >   + srccount.ipa ())
> > + srce->probability * srcbb->count.ipa ().probability_in
> >  (dstbb->count.ipa ()
> >   + srccount.ipa ());
> > + /* We produce uninitialized probabilities when
> > +denominator is zero: https://gcc.gnu.org/PR111559.  */
> > + if (merged.initialized_p ())
> > +   dste->probability = merged;
> 
> Thanks for the patch.
> We usually avoid the uninitialized value here by simply checking that
> parameter of probability_in satifies nonzero_p.  So I think it would be
> more consistent doing it here to:
> 
>   profile_probability sum = dstbb->count.ipa () + srccount.ipa ()
>   if (sum.nonzero_p ())
>   {
>  dste->probability = .
>   }

Aha, sounds good! I had to do `s/profile_probability/profile_count` as
it's a denominator value for probability.

Attached v3 just in case.

> OK with this change.
> Honza
> > }
> >   dstbb->count = dstbb->count.ipa () + srccount.ipa ();
> > }
> > diff --git a/gcc/testsuite/gcc.dg/tree-prof/pr111559.c 
> > b/gcc/testsuite/gcc.dg/tree-prof/pr111559.c
> > new file mode 100644
> > index 000..43202c6c888
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.dg/tree-prof/pr111559.c
> > @@ -0,0 +1,16 @@
> > +/* { dg-options "-O2" } */
> > +
> > +__attribute__((noipa)) static void edge(void) {}
> > +
> > +int p = 0;
> > +
> > +__attribute__((noinline))
> > +static void rule1(void) { if (p) edge(); }
> > +
> > +__attribute__((noinline))
> > +static void rule1_same(void) { if (p) edge(); }
> > +
> > +__attribute__((noipa)) int main(void) {
> > +rule1();
> > +rule1_same();
> > +}
> > -- 
> > 2.42.0
> > 

-- 

  Sergei
>From 97122ebae5a7ed43b6c31574c761a54bee3a96ec Mon Sep 17 00:00:00 2001
From: Sergei Trofimovich 
Date: Wed, 27 Sep 2023 14:29:12 +0100
Subject: [PATCH v3] ipa-utils: avoid uninitialized probabilities on ICF
 [PR111559]

r14-3459-g0c78240fd7d519 "Check that passes do not forget to define profile"
exposed check failures in cases when gcc produces uninit

[PATCH] Makefile.tpl: disable -Werror for feedback stage [PR111663]

2023-10-02 Thread Sergei Trofimovich
From: Sergei Trofimovich 

Without the change profiled bootstrap fails for various warnings on
master branch as:

$ ../gcc/configure
$ make profiledbootstrap
...
gcc/genmodes.cc: In function ‘int main(int, char**)’:
gcc/genmodes.cc:2152:1: error: ‘gcc/build/genmodes.gcda’ profile count data 
file not found [-Werror=missing-profile]
...
gcc/gengtype-parse.cc: In function ‘void parse_error(const char*, ...)’:
gcc/gengtype-parse.cc:142:21: error: ‘%s’ directive argument is null 
[-Werror=format-overflow=]

The change removes -Werror just like autofeedback does today.

/

PR bootstrap/111663
* Makefile.tpl (STAGEfeedback_CONFIGURE_FLAGS): Disable -Werror.
* Makefile.in: Regenerate.
---
 Makefile.in  | 4 
 Makefile.tpl | 4 
 2 files changed, 8 insertions(+)

diff --git a/Makefile.in b/Makefile.in
index 2f136839c35..e0e3c4c8fe8 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -638,6 +638,10 @@ STAGEtrain_TFLAGS = $(filter-out 
-fchecking=1,$(STAGE3_TFLAGS))
 
 STAGEfeedback_CFLAGS = $(STAGE4_CFLAGS) -fprofile-use 
-fprofile-reproducible=parallel-runs
 STAGEfeedback_TFLAGS = $(STAGE4_TFLAGS)
+# Disable warnings as errors for a few reasons:
+# - sources for gen* binaries do not have .gcda files available
+# - inlining decisions generate extra warnings
+STAGEfeedback_CONFIGURE_FLAGS = $(filter-out 
--enable-werror-always,$(STAGE_CONFIGURE_FLAGS))
 
 STAGEautoprofile_CFLAGS = $(filter-out -gtoggle,$(STAGE2_CFLAGS)) -g
 STAGEautoprofile_TFLAGS = $(STAGE2_TFLAGS)
diff --git a/Makefile.tpl b/Makefile.tpl
index 5872dd03f2c..8b7783bb4f1 100644
--- a/Makefile.tpl
+++ b/Makefile.tpl
@@ -561,6 +561,10 @@ STAGEtrain_TFLAGS = $(filter-out 
-fchecking=1,$(STAGE3_TFLAGS))
 
 STAGEfeedback_CFLAGS = $(STAGE4_CFLAGS) -fprofile-use 
-fprofile-reproducible=parallel-runs
 STAGEfeedback_TFLAGS = $(STAGE4_TFLAGS)
+# Disable warnings as errors for a few reasons:
+# - sources for gen* binaries do not have .gcda files available
+# - inlining decisions generate extra warnings
+STAGEfeedback_CONFIGURE_FLAGS = $(filter-out 
--enable-werror-always,$(STAGE_CONFIGURE_FLAGS))
 
 STAGEautoprofile_CFLAGS = $(filter-out -gtoggle,$(STAGE2_CFLAGS)) -g
 STAGEautoprofile_TFLAGS = $(STAGE2_TFLAGS)
-- 
2.42.0



[PATCH v2] ipa-utils: avoid uninitialized probabilities on ICF [PR111559]

2023-10-01 Thread Sergei Trofimovich
From: Sergei Trofimovich 

r14-3459-g0c78240fd7d519 "Check that passes do not forget to define profile"
exposed check failures in cases when gcc produces uninitialized profile
probabilities. In case of PR/111559 uninitialized profile is generated
by edges executed 0 times reported by IPA profile:

$ gcc -O2 -fprofile-generate pr111559.c -o b -fopt-info
$ ./b
$ gcc -O2 -fprofile-use -fprofile-correction pr111559.c -o b -fopt-info

pr111559.c: In function 'rule1':
pr111559.c:6:13: error: probability of edge 3->4 not initialized
6 | static void rule1(void) { if (p) edge(); }
  | ^
during GIMPLE pass: fixup_cfg
pr111559.c:6:13: internal compiler error: verify_flow_info failed

The change conservatively ignores updates with uninitialized values and
uses initially assigned probabilities (`always` probability in case of
the example).

PR ipa/111283
PR gcov-profile/111559

gcc/
* ipa-utils.cc (ipa_merge_profiles): Avoid producing
uninitialized probabilities when merging counters with zero
denominators.

gcc/testsuite/
* gcc.dg/tree-prof/pr111559.c: New test.
---
 gcc/ipa-utils.cc  |  6 +-
 gcc/testsuite/gcc.dg/tree-prof/pr111559.c | 16 
 2 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-prof/pr111559.c

diff --git a/gcc/ipa-utils.cc b/gcc/ipa-utils.cc
index 956c6294fd7..7c53ae9dd45 100644
--- a/gcc/ipa-utils.cc
+++ b/gcc/ipa-utils.cc
@@ -651,13 +651,17 @@ ipa_merge_profiles (struct cgraph_node *dst,
{
  edge srce = EDGE_SUCC (srcbb, i);
  edge dste = EDGE_SUCC (dstbb, i);
- dste->probability = 
+ profile_probability merged =
dste->probability * dstbb->count.ipa ().probability_in
 (dstbb->count.ipa ()
  + srccount.ipa ())
+ srce->probability * srcbb->count.ipa ().probability_in
 (dstbb->count.ipa ()
  + srccount.ipa ());
+ /* We produce uninitialized probabilities when
+denominator is zero: https://gcc.gnu.org/PR111559.  */
+ if (merged.initialized_p ())
+   dste->probability = merged;
}
  dstbb->count = dstbb->count.ipa () + srccount.ipa ();
}
diff --git a/gcc/testsuite/gcc.dg/tree-prof/pr111559.c 
b/gcc/testsuite/gcc.dg/tree-prof/pr111559.c
new file mode 100644
index 000..43202c6c888
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-prof/pr111559.c
@@ -0,0 +1,16 @@
+/* { dg-options "-O2" } */
+
+__attribute__((noipa)) static void edge(void) {}
+
+int p = 0;
+
+__attribute__((noinline))
+static void rule1(void) { if (p) edge(); }
+
+__attribute__((noinline))
+static void rule1_same(void) { if (p) edge(); }
+
+__attribute__((noipa)) int main(void) {
+rule1();
+rule1_same();
+}
-- 
2.42.0



[PATCH v2] rtl: fix build failure on -fchecking=2 [PR111642]

2023-09-30 Thread Sergei Trofimovich
From: Sergei Trofimovich 

Before the change `make bootstrap4` (or `make profiledbootstrap`) failed
as:

gcc/rtl-tests.cc:249:25:   in ‘constexpr’ expansion of ‘poly_int<1, long 
int>(1, 1)’
gcc/poly-int.h:453:5: error: too many initializers for ‘long int [1]’

The failure happened only in stage4 due to a gcc bug which accepts
invalid C++ without `-fchecking=2`: https://gcc.gnu.org/PR111647#c1.

The change hides tests that rely on 2 and more polynomials under `#if`.

gcc/
PR bootstrap/111642
* rtl-tests.cc (const_poly_int_tests): Guard tests with
NUM_POLY_INT_COEFFS > 1.
* simplify-rtx.cc (simplify_const_poly_int_tests): Ditto.
---
 gcc/rtl-tests.cc| 23 +++
 gcc/simplify-rtx.cc | 21 ++---
 2 files changed, 13 insertions(+), 31 deletions(-)

diff --git a/gcc/rtl-tests.cc b/gcc/rtl-tests.cc
index ae8669419b6..d4130572501 100644
--- a/gcc/rtl-tests.cc
+++ b/gcc/rtl-tests.cc
@@ -228,24 +228,14 @@ test_uncond_jump ()
  jump_insn);
 }
 
-template
-struct const_poly_int_tests
-{
-  static void run ();
-};
-
-template<>
-struct const_poly_int_tests<1>
-{
-  static void run () {}
-};
-
 /* Test various CONST_POLY_INT properties.  */
 
-template
-void
-const_poly_int_tests::run ()
+static void
+const_poly_int_tests ()
 {
+  /* `poly_int64` call with two parameters requires target with at
+   least 2 COEFFs.  */
+#if NUM_POLY_INT_COEFFS > 1
   rtx x1 = gen_int_mode (poly_int64 (1, 1), QImode);
   rtx x255 = gen_int_mode (poly_int64 (1, 255), QImode);
 
@@ -282,6 +272,7 @@ const_poly_int_tests::run ()
 gen_int_mode (poly_int64 (5, -2), QImode));
   ASSERT_EQ (plus_constant (QImode, x1, poly_int64 (4, -2)),
 gen_int_mode (poly_int64 (5, -1), QImode));
+#endif
 }
 
 /* Check dumping of repeated RTL vectors.  */
@@ -317,7 +308,7 @@ rtl_tests_cc_tests ()
   test_dumping_rtx_reuse ();
   test_single_set ();
   test_uncond_jump ();
-  const_poly_int_tests::run ();
+  const_poly_int_tests ();
   test_dumping_repeat ();
 
   /* Purge state.  */
diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
index 170406aa28b..39361b11b1a 100644
--- a/gcc/simplify-rtx.cc
+++ b/gcc/simplify-rtx.cc
@@ -8671,24 +8671,14 @@ test_vector_ops ()
 }
 }
 
-template
-struct simplify_const_poly_int_tests
-{
-  static void run ();
-};
-
-template<>
-struct simplify_const_poly_int_tests<1>
-{
-  static void run () {}
-};
-
 /* Test various CONST_POLY_INT properties.  */
 
-template
 void
-simplify_const_poly_int_tests::run ()
+simplify_const_poly_int_tests ()
 {
+  /* `poly_int64` call with two parameters requires target with at
+   least 2 COEFFs.  */
+#if NUM_POLY_INT_COEFFS > 1
   rtx x1 = gen_int_mode (poly_int64 (1, 1), QImode);
   rtx x2 = gen_int_mode (poly_int64 (-80, 127), QImode);
   rtx x3 = gen_int_mode (poly_int64 (-79, -128), QImode);
@@ -8716,6 +8706,7 @@ simplify_const_poly_int_tests::run ()
   ASSERT_EQ (simplify_binary_operation (IOR, QImode, x4, two), x7);
   ASSERT_EQ (simplify_subreg (HImode, x5, QImode, 0), x8);
   ASSERT_EQ (simplify_subreg (QImode, x8, HImode, offset), x5);
+#endif
 }
 
 /* Run all of the selftests within this file.  */
@@ -8725,7 +8716,7 @@ simplify_rtx_cc_tests ()
 {
   test_scalar_ops ();
   test_vector_ops ();
-  simplify_const_poly_int_tests::run ();
+  simplify_const_poly_int_tests ();
 }
 
 } // namespace selftest
-- 
2.42.0



[PATCH] rtl: fix buidl failure on -fchecking=2 [PR111642]

2023-09-30 Thread Sergei Trofimovich
From: Sergei Trofimovich 

Before the change `make bootstrap4` (or `make profiledbootstrap`) failed
as:

gcc/rtl-tests.cc:249:25:   in ‘constexpr’ expansion of ‘poly_int<1, long 
int>(1, 1)’
gcc/poly-int.h:453:5: error: too many initializers for ‘long int [1]’

The failure happened only in stage4 due to a gcc bug which accepts
invalid C++ without `-fchecking=2`: https://gcc.gnu.org/PR111647#c1.

The change hides tests that rely on 2 and more polynomials under `#if`.

gcc/
PR bootstrap/111642
* rtl-tests.cc (const_poly_int_tests): Guard tests with
NUM_POLY_INT_COEFFS > 1.
* simplify-rtx.cc (simplify_const_poly_int_tests): Ditto.
---
 gcc/rtl-tests.cc| 25 -
 gcc/simplify-rtx.cc | 21 ++---
 2 files changed, 14 insertions(+), 32 deletions(-)

diff --git a/gcc/rtl-tests.cc b/gcc/rtl-tests.cc
index ae8669419b6..85c1e56048d 100644
--- a/gcc/rtl-tests.cc
+++ b/gcc/rtl-tests.cc
@@ -228,24 +228,14 @@ test_uncond_jump ()
  jump_insn);
 }
 
-template
-struct const_poly_int_tests
-{
-  static void run ();
-};
-
-template<>
-struct const_poly_int_tests<1>
-{
-  static void run () {}
-};
-
 /* Test various CONST_POLY_INT properties.  */
 
-template
-void
-const_poly_int_tests::run ()
+static void
+const_poly_int_tests ()
 {
+  /* `poly_int64` call with two parameters requires target with at
+   least 2 COEFFs.  */
+#if NUM_POLY_INT_COEFFS > 1
   rtx x1 = gen_int_mode (poly_int64 (1, 1), QImode);
   rtx x255 = gen_int_mode (poly_int64 (1, 255), QImode);
 
@@ -263,7 +253,7 @@ const_poly_int_tests::run ()
   ASSERT_KNOWN_EQ (rtx_to_poly_int64 (x255), poly_int64 (1, -1));
   ASSERT_MAYBE_NE (rtx_to_poly_int64 (x255), poly_int64 (1, 255));
 
-  /* Test plus_constant of a symbol.  */
+  /* Test plus_consctant of a symbol.  */
   rtx symbol = gen_rtx_SYMBOL_REF (Pmode, "foo");
   rtx offset1 = gen_int_mode (poly_int64 (9, 11), Pmode);
   rtx sum1 = gen_rtx_CONST (Pmode, gen_rtx_PLUS (Pmode, symbol, offset1));
@@ -282,6 +272,7 @@ const_poly_int_tests::run ()
 gen_int_mode (poly_int64 (5, -2), QImode));
   ASSERT_EQ (plus_constant (QImode, x1, poly_int64 (4, -2)),
 gen_int_mode (poly_int64 (5, -1), QImode));
+#endif
 }
 
 /* Check dumping of repeated RTL vectors.  */
@@ -317,7 +308,7 @@ rtl_tests_cc_tests ()
   test_dumping_rtx_reuse ();
   test_single_set ();
   test_uncond_jump ();
-  const_poly_int_tests::run ();
+  const_poly_int_tests ();
   test_dumping_repeat ();
 
   /* Purge state.  */
diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
index 170406aa28b..39361b11b1a 100644
--- a/gcc/simplify-rtx.cc
+++ b/gcc/simplify-rtx.cc
@@ -8671,24 +8671,14 @@ test_vector_ops ()
 }
 }
 
-template
-struct simplify_const_poly_int_tests
-{
-  static void run ();
-};
-
-template<>
-struct simplify_const_poly_int_tests<1>
-{
-  static void run () {}
-};
-
 /* Test various CONST_POLY_INT properties.  */
 
-template
 void
-simplify_const_poly_int_tests::run ()
+simplify_const_poly_int_tests ()
 {
+  /* `poly_int64` call with two parameters requires target with at
+   least 2 COEFFs.  */
+#if NUM_POLY_INT_COEFFS > 1
   rtx x1 = gen_int_mode (poly_int64 (1, 1), QImode);
   rtx x2 = gen_int_mode (poly_int64 (-80, 127), QImode);
   rtx x3 = gen_int_mode (poly_int64 (-79, -128), QImode);
@@ -8716,6 +8706,7 @@ simplify_const_poly_int_tests::run ()
   ASSERT_EQ (simplify_binary_operation (IOR, QImode, x4, two), x7);
   ASSERT_EQ (simplify_subreg (HImode, x5, QImode, 0), x8);
   ASSERT_EQ (simplify_subreg (QImode, x8, HImode, offset), x5);
+#endif
 }
 
 /* Run all of the selftests within this file.  */
@@ -8725,7 +8716,7 @@ simplify_rtx_cc_tests ()
 {
   test_scalar_ops ();
   test_vector_ops ();
-  simplify_const_poly_int_tests::run ();
+  simplify_const_poly_int_tests ();
 }
 
 } // namespace selftest
-- 
2.42.0



[PATCH] ggc: do not wipe out unrelated data via gt_ggc_rtab

2023-09-28 Thread Sergei Trofimovich
From: Sergei Trofimovich 

There are 3 GC root tables:

   gt_ggc_rtab
   gt_ggc_deletable_rtab
   gt_pch_scalar_rtab

`deletable` and `scalar` tables are both simple: each element always
contains a pointer to the beginning of the object and it's size is the
full object.

`rtab` is different: it's `base` is a pointer in the middle of the
struct and `stride` points to the next GC pointer in the array.

Before the change there were 2 problems:

1. We memset()ed not just pointers but data around them.
2. We wen out of bounds of the last object described by gt_ggc_rtab
   and triggered bootstrap failures in profile and asan bootstraps.

After the change we handle only pointers themselves like the rest of
ggc-common.cc code.

gcc/
PR/111505
* ggc-common.cc (ggc_zero_out_root_pointers): New helper.
* ggc-common.cc (ggc_common_finalize): Use helper instead of
memset() to wipe out pointers.
---
 gcc/ggc-common.cc | 15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/gcc/ggc-common.cc b/gcc/ggc-common.cc
index 95803fa95a1..39e2581affd 100644
--- a/gcc/ggc-common.cc
+++ b/gcc/ggc-common.cc
@@ -75,6 +75,18 @@ ggc_mark_root_tab (const_ggc_root_tab_t rt)
   (*rt->cb) (*(void **) ((char *)rt->base + rt->stride * i));
 }
 
+/* Zero out all the roots in the table RT.  */
+
+static void
+ggc_zero_rtab_roots (const_ggc_root_tab_t rt)
+{
+  size_t i;
+
+  for ( ; rt->base != NULL; rt++)
+for (i = 0; i < rt->nelt; i++)
+  (*(void **) ((char *)rt->base + rt->stride * i)) = (void*)0;
+}
+
 /* Iterate through all registered roots and mark each element.  */
 
 void
@@ -1307,8 +1319,7 @@ ggc_common_finalize ()
   memset (rti->base, 0, rti->stride * rti->nelt);
 
   for (rt = gt_ggc_rtab; *rt; rt++)
-for (rti = *rt; rti->base != NULL; rti++)
-  memset (rti->base, 0, rti->stride * rti->nelt);
+ggc_zero_rtab_roots (*rt);
 
   for (rt = gt_pch_scalar_rtab; *rt; rt++)
 for (rti = *rt; rti->base != NULL; rti++)
-- 
2.42.0



[PATCH] ipa-utils: avoid generating uninitialized probabilities on merges.

2023-09-27 Thread Sergei Trofimovich
From: Sergei Trofimovich 

r14-3459-g0c78240fd7d519 "Check that passes do not forget to define profile"
exposed check failures in cases when gcc produces uninitialized profile
probabilities. In case of PR/111559 uninitialized profile is generated
by edges executed 0 times during profile:

__attribute__((noipa)) static void edge(void) {}

int p = 0;

__attribute__((noinline))
static void rule1(void) { if (p) edge(); }

__attribute__((noinline))
static void rule1_same(void) { if (p) edge(); }

__attribute__((noipa)) int main(void) {
rule1();
rule1_same();
}

$ gcc -O2 -fprofile-generate bug.c -o b -fopt-info
$ ./b
$ gcc -O2 -fprofile-use -fprofile-correction bug.c -o b -fopt-info

bug.c: In function 'rule1':
bug.c:6:13: error: probability of edge 3->4 not initialized
6 | static void rule1(void) { if (p) edge(); }
  | ^
during GIMPLE pass: fixup_cfg
bug.c:6:13: internal compiler error: verify_flow_info failed

The change conservatively ignores updates with uninitialized values and
uses initially assigned probabilities (`always` probability in case of
the example).

gcc/
PR/111283
PR/111559
* ipa-utils.cc (ipa_merge_profiles): Avoid producing
  uninitialized probabilities when merging counters with zero
  denominators.
---
 gcc/ipa-utils.cc | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/ipa-utils.cc b/gcc/ipa-utils.cc
index 956c6294fd7..7c53ae9dd45 100644
--- a/gcc/ipa-utils.cc
+++ b/gcc/ipa-utils.cc
@@ -651,13 +651,17 @@ ipa_merge_profiles (struct cgraph_node *dst,
{
  edge srce = EDGE_SUCC (srcbb, i);
  edge dste = EDGE_SUCC (dstbb, i);
- dste->probability = 
+ profile_probability merged =
dste->probability * dstbb->count.ipa ().probability_in
 (dstbb->count.ipa ()
  + srccount.ipa ())
+ srce->probability * srcbb->count.ipa ().probability_in
 (dstbb->count.ipa ()
  + srccount.ipa ());
+ /* We produce uninitialized probabilities when
+denominator is zero: https://gcc.gnu.org/PR111559.  */
+ if (merged.initialized_p ())
+   dste->probability = merged;
}
  dstbb->count = dstbb->count.ipa () + srccount.ipa ();
}
-- 
2.42.0



[PATCH] Drop unused enum vrp_mode.

2023-08-16 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

Follow removal of EVRP and clean up unused defines.

gcc/
* flag-types.h (vrp_mode): Remove unused.
---
 gcc/flag-types.h | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/gcc/flag-types.h b/gcc/flag-types.h
index 36305de589e..7466c1106f2 100644
--- a/gcc/flag-types.h
+++ b/gcc/flag-types.h
@@ -478,13 +478,6 @@ enum threader_debug
   THREADER_DEBUG_ALL = 1
 };
 
-/* VRP modes.  */
-enum vrp_mode
-{
-  VRP_MODE_VRP,
-  VRP_MODE_RANGER
-};
-
 /* Modes of OpenACC 'kernels' constructs handling.  */
 enum openacc_kernels
 {
-- 
2.41.0



[PATCH] mh-mingw: drop unused BOOT_CXXFLAGS variable

2023-07-21 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

gcc's build system has BOOT_CFLAGS and various STAGE_C{,XX}FLAGS
variables. BOOT_CXXFLAGS is not handled anywhere.

config/

* mh-mingw: Drop assignment of unused BOOT_CXXFLAGS variable.
---
 config/mh-mingw | 1 -
 1 file changed, 1 deletion(-)

diff --git a/config/mh-mingw b/config/mh-mingw
index e91367a7112..f5fb064813f 100644
--- a/config/mh-mingw
+++ b/config/mh-mingw
@@ -1,7 +1,6 @@
 # Add -D__USE_MINGW_ACCESS to enable the built compiler to work on Windows
 # Vista (see PR33281 for details).
 BOOT_CFLAGS += -D__USE_MINGW_ACCESS -Wno-pedantic-ms-format
-BOOT_CXXFLAGS += -D__USE_MINGW_ACCESS -Wno-pedantic-ms-format
 CFLAGS += -D__USE_MINGW_ACCESS
 CXXFLAGS += -D__USE_MINGW_ACCESS
 STAGE1_CXXFLAGS += -D__USE_MINGW_ACCESS
-- 
2.41.0



PING [PATCH] gcc/config/t-i386: add build dependencies on i386-builtin-types.inc

2022-10-03 Thread Sergei Trofimovich via Gcc-patches
On Thu, 22 Sep 2022 22:07:52 +0100
Sergei Trofimovich  wrote:

> On Fri, 16 Sept 2022 at 19:49, Sergei Trofimovich  wrote:
> >
> > From: Sergei Trofimovich 
> >
> > i386-builtin-types.inc is included indirectly via i386-builtins.h
> > into 4 files: i386.cc i386-builtins.cc i386-expand.cc i386-features.cc
> >
> > Only i386.cc dependency was present in gcc/config/t-i386 makefile.
> >
> > As a result parallel builds occasionally fail as:
> >
> > g++ ... -o i386-builtins.o ... 
> > ../../gcc-13-20220911/gcc/config/i386/i386-builtins.cc
> > In file included from 
> > ../../gcc-13-20220911/gcc/config/i386/i386-builtins.cc:92:
> > ../../gcc-13-20220911/gcc/config/i386/i386-builtins.h:25:10:
> >  fatal error: i386-builtin-types.inc: No such file or directory
> >25 | #include "i386-builtin-types.inc"
> >   |  ^~~~
> > compilation terminated.
> > make[3]: *** [../../gcc-13-20220911/gcc/config/i386/t-i386:54: 
> > i386-builtins.o]
> >   Error 1 shuffle=1663349189
> >
> > gcc/
> > * config/i386/t-i386: Add build-time dependencies against
> > i386-builtin-types.inc to i386-builtins.o, i386-expand.o,
> > i386-features.o.
> > ---
> >  gcc/config/i386/t-i386 | 5 +
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/gcc/config/i386/t-i386 b/gcc/config/i386/t-i386
> > index 4e2a0efc615..ffdbbdfe8ce 100644
> > --- a/gcc/config/i386/t-i386
> > +++ b/gcc/config/i386/t-i386
> > @@ -62,7 +62,12 @@ i386-features.o: $(srcdir)/config/i386/i386-features.cc
> > $(COMPILE) $<
> > $(POSTCOMPILE)
> >
> > +# i386-builtin-types.inc is included into i386-builtins.h.
> > +# Below are direct users of i386-builtins.h:
> >  i386.o: i386-builtin-types.inc
> > +i386-builtins.o: i386-builtin-types.inc
> > +i386-expand.o: i386-builtin-types.inc
> > +i386-features.o: i386-builtin-types.inc
> >
> >  i386-builtin-types.inc: s-i386-bt ; @true
> >  s-i386-bt: $(srcdir)/config/i386/i386-builtin-types.awk \
> > --
> > 2.37.2
> >  
> 
> Is it a reasonable approach? Maybe gcc has an equivalent of automake's
> BUILT_SOURCES to avoid explicit tracking of such dependencies?
> 
> -- 
> Sergei


-- 

  Sergei


Re: [PATCH] gcc/config/t-i386: add build dependencies on i386-builtin-types.inc

2022-09-22 Thread Sergei Trofimovich via Gcc-patches
On Fri, 16 Sept 2022 at 19:49, Sergei Trofimovich  wrote:
>
> From: Sergei Trofimovich 
>
> i386-builtin-types.inc is included indirectly via i386-builtins.h
> into 4 files: i386.cc i386-builtins.cc i386-expand.cc i386-features.cc
>
> Only i386.cc dependency was present in gcc/config/t-i386 makefile.
>
> As a result parallel builds occasionally fail as:
>
> g++ ... -o i386-builtins.o ... 
> ../../gcc-13-20220911/gcc/config/i386/i386-builtins.cc
> In file included from 
> ../../gcc-13-20220911/gcc/config/i386/i386-builtins.cc:92:
> ../../gcc-13-20220911/gcc/config/i386/i386-builtins.h:25:10:
>  fatal error: i386-builtin-types.inc: No such file or directory
>25 | #include "i386-builtin-types.inc"
>   |  ^~~~
> compilation terminated.
> make[3]: *** [../../gcc-13-20220911/gcc/config/i386/t-i386:54: 
> i386-builtins.o]
>   Error 1 shuffle=1663349189
>
> gcc/
> * config/i386/t-i386: Add build-time dependencies against
> i386-builtin-types.inc to i386-builtins.o, i386-expand.o,
> i386-features.o.
> ---
>  gcc/config/i386/t-i386 | 5 +
>  1 file changed, 5 insertions(+)
>
> diff --git a/gcc/config/i386/t-i386 b/gcc/config/i386/t-i386
> index 4e2a0efc615..ffdbbdfe8ce 100644
> --- a/gcc/config/i386/t-i386
> +++ b/gcc/config/i386/t-i386
> @@ -62,7 +62,12 @@ i386-features.o: $(srcdir)/config/i386/i386-features.cc
> $(COMPILE) $<
> $(POSTCOMPILE)
>
> +# i386-builtin-types.inc is included into i386-builtins.h.
> +# Below are direct users of i386-builtins.h:
>  i386.o: i386-builtin-types.inc
> +i386-builtins.o: i386-builtin-types.inc
> +i386-expand.o: i386-builtin-types.inc
> +i386-features.o: i386-builtin-types.inc
>
>  i386-builtin-types.inc: s-i386-bt ; @true
>  s-i386-bt: $(srcdir)/config/i386/i386-builtin-types.awk \
> --
> 2.37.2
>

Is it a reasonable approach? Maybe gcc has an equivalent of automake's
BUILT_SOURCES to avoid explicit tracking of such dependencies?

-- 
Sergei


[PATCH] gcc/config/t-i386: add build dependencies on i386-builtin-types.inc

2022-09-16 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

i386-builtin-types.inc is included indirectly via i386-builtins.h
into 4 files: i386.cc i386-builtins.cc i386-expand.cc i386-features.cc

Only i386.cc dependency was present in gcc/config/t-i386 makefile.

As a result parallel builds occasionally fail as:

g++ ... -o i386-builtins.o ... 
../../gcc-13-20220911/gcc/config/i386/i386-builtins.cc
In file included from 
../../gcc-13-20220911/gcc/config/i386/i386-builtins.cc:92:
../../gcc-13-20220911/gcc/config/i386/i386-builtins.h:25:10:
 fatal error: i386-builtin-types.inc: No such file or directory
   25 | #include "i386-builtin-types.inc"
  |  ^~~~
compilation terminated.
make[3]: *** [../../gcc-13-20220911/gcc/config/i386/t-i386:54: 
i386-builtins.o]
  Error 1 shuffle=1663349189

gcc/
* config/i386/t-i386: Add build-time dependencies against
i386-builtin-types.inc to i386-builtins.o, i386-expand.o,
i386-features.o.
---
 gcc/config/i386/t-i386 | 5 +
 1 file changed, 5 insertions(+)

diff --git a/gcc/config/i386/t-i386 b/gcc/config/i386/t-i386
index 4e2a0efc615..ffdbbdfe8ce 100644
--- a/gcc/config/i386/t-i386
+++ b/gcc/config/i386/t-i386
@@ -62,7 +62,12 @@ i386-features.o: $(srcdir)/config/i386/i386-features.cc
$(COMPILE) $<
$(POSTCOMPILE)
 
+# i386-builtin-types.inc is included into i386-builtins.h.
+# Below are direct users of i386-builtins.h:
 i386.o: i386-builtin-types.inc
+i386-builtins.o: i386-builtin-types.inc
+i386-expand.o: i386-builtin-types.inc
+i386-features.o: i386-builtin-types.inc
 
 i386-builtin-types.inc: s-i386-bt ; @true
 s-i386-bt: $(srcdir)/config/i386/i386-builtin-types.awk \
-- 
2.37.2



[PATCH] Makefile.def: drop remnants of unused libelf

2022-08-18 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

Use of libelf was removed from gcc in
misc/cutover-cvs2svn-32781-g48215350c24 ("re PR lto/46273 (Failed to
bootstrap)") around 2010, before gcc-4.6.0.

This change removes unused references to libelf from top-level condifure
and Makefile.

/
* Makefile.def: Drop libelf module and gcc-configure dependency
on it.
* Makefile.in: Regenerate with 'autogen Makefile.def'.
* Makefile.tpl (HOST_EXPORTS): Drop unused LIBELFLIBS and
LIBELFINC.
* configure: Regenrate.
* configure.ac (host_libs): Drop unused libelf.
---
 Makefile.def |4 -
 Makefile.in  | 1288 +-
 Makefile.tpl |6 -
 configure|2 +-
 configure.ac |2 +-
 5 files changed, 3 insertions(+), 1299 deletions(-)

diff --git a/Makefile.def b/Makefile.def
index 11e9f23dc42..3291b126b26 100644
--- a/Makefile.def
+++ b/Makefile.def
@@ -70,9 +70,6 @@ host_modules= { module= isl; lib_path=.libs; bootstrap=true;
extra_configure_flags='--disable-shared 
@extra_isl_gmp_configure_flags@';
extra_make_flags='V=1';
no_install= true; };
-host_modules= { module= libelf; lib_path=.libs; bootstrap=true;
-   extra_configure_flags='--disable-shared';
-   no_install= true; };
 host_modules= { module= gold; bootstrap=true; };
 host_modules= { module= gprof; };
 host_modules= { module= intl; bootstrap=true; };
@@ -353,7 +350,6 @@ dependencies = { module=configure-gcc; on=all-binutils; };
 dependencies = { module=configure-gcc; on=all-gas; };
 dependencies = { module=configure-gcc; on=all-ld; };
 dependencies = { module=configure-gcc; on=all-gold; };
-dependencies = { module=configure-gcc; on=all-libelf; };
 dependencies = { module=configure-gcc; on=all-libiconv; };
 dependencies = { module=all-gcc; on=all-libiberty; hard=true; };
 dependencies = { module=all-gcc; on=all-intl; };
diff --git a/Makefile.in b/Makefile.in
index 60077a6aa36..1919dfee829 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -236,8 +236,6 @@ HOST_EXPORTS = \
GMPINC="$(HOST_GMPINC)"; export GMPINC; \
ISLLIBS="$(HOST_ISLLIBS)"; export ISLLIBS; \
ISLINC="$(HOST_ISLINC)"; export ISLINC; \
-   LIBELFLIBS="$(HOST_LIBELFLIBS)"; export LIBELFLIBS; \
-   LIBELFINC="$(HOST_LIBELFINC)"; export LIBELFINC; \
XGCC_FLAGS_FOR_TARGET="$(XGCC_FLAGS_FOR_TARGET)"; export 
XGCC_FLAGS_FOR_TARGET; \
 @if gcc-bootstrap
$(RPATH_ENVVAR)=`echo "$(TARGET_LIB_PATH)$$$(RPATH_ENVVAR)" | sed 
's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR); \
@@ -343,10 +341,6 @@ HOST_GMPINC = @gmpinc@
 HOST_ISLLIBS = @isllibs@
 HOST_ISLINC = @islinc@
 
-# Where to find libelf
-HOST_LIBELFLIBS = @libelflibs@
-HOST_LIBELFINC = @libelfinc@
-
 # --
 # Programs producing files for the BUILD machine
 # --
@@ -754,7 +748,7 @@ TARGET_LIB_PATH_libatomic = 
$$r/$(TARGET_SUBDIR)/libatomic/.libs:
 
 # This is the list of directories that may be needed in RPATH_ENVVAR
 # so that programs built for the host machine work.
-HOST_LIB_PATH = 
$(HOST_LIB_PATH_gmp)$(HOST_LIB_PATH_mpfr)$(HOST_LIB_PATH_mpc)$(HOST_LIB_PATH_isl)$(HOST_LIB_PATH_libelf)
+HOST_LIB_PATH = 
$(HOST_LIB_PATH_gmp)$(HOST_LIB_PATH_mpfr)$(HOST_LIB_PATH_mpc)$(HOST_LIB_PATH_isl)
 
 # Define HOST_LIB_PATH_gcc here, for the sake of TARGET_LIB_PATH, ouch
 @if gcc
@@ -782,11 +776,6 @@ HOST_LIB_PATH_isl = \
   $$r/$(HOST_SUBDIR)/isl/.libs:$$r/$(HOST_SUBDIR)/prev-isl/.libs:
 @endif isl
 
-@if libelf
-HOST_LIB_PATH_libelf = \
-  $$r/$(HOST_SUBDIR)/libelf/.libs:$$r/$(HOST_SUBDIR)/prev-libelf/.libs:
-@endif libelf
-
 
 CXX_FOR_TARGET_FLAG_TO_PASS = \
"CXX_FOR_TARGET=$(CXX_FOR_TARGET)"
@@ -1078,7 +1067,6 @@ configure-host:  \
 maybe-configure-mpfr \
 maybe-configure-mpc \
 maybe-configure-isl \
-maybe-configure-libelf \
 maybe-configure-gold \
 maybe-configure-gprof \
 maybe-configure-intl \
@@ -1229,9 +1217,6 @@ all-host: maybe-all-mpc
 @if isl-no-bootstrap
 all-host: maybe-all-isl
 @endif isl-no-bootstrap
-@if libelf-no-bootstrap
-all-host: maybe-all-libelf
-@endif libelf-no-bootstrap
 @if gold-no-bootstrap
 all-host: maybe-all-gold
 @endif gold-no-bootstrap
@@ -1370,7 +1355,6 @@ info-host: maybe-info-gmp
 info-host: maybe-info-mpfr
 info-host: maybe-info-mpc
 info-host: maybe-info-isl
-info-host: maybe-info-libelf
 info-host: maybe-info-gold
 info-host: maybe-info-gprof
 info-host: maybe-info-intl
@@ -1460,7 +1444,6 @@ dvi-host: maybe-dvi-gmp
 dvi-host: maybe-dvi-mpfr
 dvi-host: maybe-dvi-mpc
 dvi-host: maybe-dvi-isl
-dvi-host: maybe-dvi-libelf
 dvi-host: maybe-dvi-gold
 dvi-host: maybe-dvi-gprof
 dvi-host: maybe-dvi-intl
@@ -1550,7 +1533,6 @@ pdf-host: maybe-pdf-gmp
 pdf-host: maybe-pdf-mpfr
 pdf-host: maybe-pdf-mpc
 pdf-host: maybe-pdf

[PATCH] Add libgo dependency on libbacktrace.

2022-08-18 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

Noticed missing dependency when regenerated Makefile.in for unrelated
change with 'autoget Makefile.def'.

The change was lost in basepoints/gcc-12-6861-gaeac414923a
("Revert "Fix PR 67102: Add libstdc++ dependancy to libffi" [PR67102]").

/
Makefile.in: Regenerate.
---
 Makefile.in | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Makefile.in b/Makefile.in
index 13ee95a2602..60077a6aa36 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -66523,6 +66523,7 @@ all-target-liboffloadmic: maybe-all-target-libgomp
 configure-target-newlib: maybe-all-binutils
 configure-target-newlib: maybe-all-ld
 configure-target-libgfortran: maybe-all-target-libbacktrace
+configure-target-libgo: maybe-all-target-libbacktrace
 @endunless gcc-bootstrap
 
 # Dependencies for target modules on other target modules are
-- 
2.37.1



[PATCH] driver: fix environ corruption after putenv() [PR106624]

2022-08-16 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

The bug appeared afte r13-2010-g1270ccda70ca09 "Factor out
jobserver_active_p" slightly changed `putenv()` use from allocating
to non-allocating:

-xputenv (concat ("MAKEFLAGS=", dup, NULL));
+xputenv (jinfo.skipped_makeflags.c_str ());

`xputenv()` (and `putenv()`) don't copy strings and only store the
pointer in the `environ` global table. As a result `environ` got
corrupted as soon as `jinfo.skipped_makeflags` store got deallocated.

This started causing bootstrap crashes in `execv()` calls:

xgcc: fatal error: cannot execute '/build/build/./prev-gcc/collect2': 
execv: Bad address

The change restores memory allocation for `xputenv()` argument.

gcc/

PR driver/106624
* gcc (driver::detect_jobserver): Allocate storage xputenv()
argument using xstrdup().
---
 gcc/gcc.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index cac11c1a117..75ca0ece1a4 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -9182,7 +9182,7 @@ driver::detect_jobserver () const
 {
   jobserver_info jinfo;
   if (!jinfo.is_active && !jinfo.skipped_makeflags.empty ())
-xputenv (jinfo.skipped_makeflags.c_str ());
+xputenv (xstrdup (jinfo.skipped_makeflags.c_str ()));
 }
 
 /* Determine what the exit code of the driver should be.  */
-- 
2.37.1



[PATCH v2] jit: avoid calloc() poisoning on musl [PR106102]

2022-06-28 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

On musl  uses calloc() (via ). jit/ includes
it directly and exposes use of poisoned calloc():

/build/build/./prev-gcc/xg++ ... 
../../gcc-13-20220626/gcc/jit/jit-playback.cc
make[3]: *** [Makefile:1143: jit/libgccjit.o] Error 1
make[3]: *** Waiting for unfinished jobs
In file included from /<>/musl-1.2.3-dev/include/pthread.h:30,
 from ../../gcc-13-20220626/gcc/jit/jit-playback.cc:44:
/<>/musl-1.2.3-dev/include/sched.h:84:7: error: attempt to use 
poisoned "calloc"
   84 | void *calloc(size_t, size_t);
  |   ^
/<>/musl-1.2.3-dev/include/sched.h:124:36: error: attempt to use 
poisoned "calloc"
  124 | #define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n)))
  |^

The change moves  inclusion to "system.h" under new
INCLUDE_PTHREAD_H guard and uses this mechanism in libgccjit.

gcc/

PR c++/106102
* system.h: Introduce INCLUDE_PTHREAD_H macros to include .

gcc/jit/

PR c++/106102
* jit-playback.cc: Include  via "system.h" to avoid calloc()
poisoning.
* jit-recording.cc: Ditto.
* libgccjit.cc: Ditto.
---
 gcc/jit/jit-playback.cc  | 3 +--
 gcc/jit/jit-recording.cc | 2 +-
 gcc/jit/libgccjit.cc | 2 +-
 gcc/system.h | 4 
 4 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc
index 6be6bdf8dea..79714132b91 100644
--- a/gcc/jit/jit-playback.cc
+++ b/gcc/jit/jit-playback.cc
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_PTHREAD_H
 #include "system.h"
 #include "coretypes.h"
 #include "target.h"
@@ -41,8 +42,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "diagnostic.h"
 #include "stmt.h"
 
-#include 
-
 #include "jit-playback.h"
 #include "jit-result.h"
 #include "jit-builtins.h"
diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc
index 697dee66e73..f78daed2d71 100644
--- a/gcc/jit/jit-recording.cc
+++ b/gcc/jit/jit-recording.cc
@@ -19,13 +19,13 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_PTHREAD_H
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
 #include "pretty-print.h"
 #include "toplev.h"
 
-#include 
 
 #include "jit-builtins.h"
 #include "jit-recording.h"
diff --git a/gcc/jit/libgccjit.cc b/gcc/jit/libgccjit.cc
index 0e76097b4ba..ca862662777 100644
--- a/gcc/jit/libgccjit.cc
+++ b/gcc/jit/libgccjit.cc
@@ -19,12 +19,12 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_PTHREAD_H
 #include "system.h"
 #include "coretypes.h"
 #include "timevar.h"
 #include "typed-splay-tree.h"
 #include "cppbuiltin.h"
-#include 
 
 #include "libgccjit.h"
 #include "jit-recording.h"
diff --git a/gcc/system.h b/gcc/system.h
index 67158b70c78..f8d42ff6815 100644
--- a/gcc/system.h
+++ b/gcc/system.h
@@ -753,6 +753,10 @@ extern int vsnprintf (char *, size_t, const char *, 
va_list);
 #endif
 #endif
 
+#ifdef INCLUDE_PTHREAD_H
+#include 
+#endif
+
 #ifdef INCLUDE_ISL
 #ifdef HAVE_isl
 #include 
-- 
2.36.1



[PATCH] jit: avoid calloc() poisoning on musl [PR106102]

2022-06-27 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

On musl  uses calloc() (via ). jit/ includes
it directly and exposes use of poisoned calloc():

/build/build/./prev-gcc/xg++ ... 
../../gcc-13-20220626/gcc/jit/jit-playback.cc
make[3]: *** [Makefile:1143: jit/libgccjit.o] Error 1
make[3]: *** Waiting for unfinished jobs
In file included from /<>/musl-1.2.3-dev/include/pthread.h:30,
 from ../../gcc-13-20220626/gcc/jit/jit-playback.cc:44:
/<>/musl-1.2.3-dev/include/sched.h:84:7: error: attempt to use 
poisoned "calloc"
   84 | void *calloc(size_t, size_t);
  |   ^
/<>/musl-1.2.3-dev/include/sched.h:124:36: error: attempt to use 
poisoned "calloc"
  124 | #define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n)))
  |^

The change moves sys-specific header before "system.h" inclusion
to evade poisoning.

gcc/jit/

PR c++/106102
* jit-playback.cc: Include  before "system.h" to avoid 
calloc()
poisoning.
* jit-recording.cc: Ditto.
* libgccjit.cc: Ditto.
---
 gcc/jit/jit-playback.cc  | 5 +++--
 gcc/jit/jit-recording.cc | 4 +++-
 gcc/jit/libgccjit.cc | 4 +++-
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc
index 6be6bdf8dea..4ab7b59cab9 100644
--- a/gcc/jit/jit-playback.cc
+++ b/gcc/jit/jit-playback.cc
@@ -19,6 +19,9 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+/*  has to go before "system.h" as it pull in to-be-poisoned
+   symbols on musl like calloc().  */
+#include 
 #include "system.h"
 #include "coretypes.h"
 #include "target.h"
@@ -41,8 +44,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "diagnostic.h"
 #include "stmt.h"
 
-#include 
-
 #include "jit-playback.h"
 #include "jit-result.h"
 #include "jit-builtins.h"
diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc
index 697dee66e73..9505ed3b279 100644
--- a/gcc/jit/jit-recording.cc
+++ b/gcc/jit/jit-recording.cc
@@ -19,13 +19,15 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+/*  has to go before "system.h" as it pull in to-be-poisoned
+   symbols on musl like calloc().  */
+#include 
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
 #include "pretty-print.h"
 #include "toplev.h"
 
-#include 
 
 #include "jit-builtins.h"
 #include "jit-recording.h"
diff --git a/gcc/jit/libgccjit.cc b/gcc/jit/libgccjit.cc
index 0e76097b4ba..6a0ac8aaba2 100644
--- a/gcc/jit/libgccjit.cc
+++ b/gcc/jit/libgccjit.cc
@@ -19,12 +19,14 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+/*  has to go before "system.h" as it pull in to-be-poisoned
+   symbols on musl like calloc().  */
+#include 
 #include "system.h"
 #include "coretypes.h"
 #include "timevar.h"
 #include "typed-splay-tree.h"
 #include "cppbuiltin.h"
-#include 
 
 #include "libgccjit.h"
 #include "jit-recording.h"
-- 
2.36.1



[PATCH] c++: avoid poisoning on musl [PR106102]

2022-06-27 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

On musl  uses calloc() (via ).  includes
it indirectly and exposes use of poisoned calloc() when module code
is built:

/build/build/./prev-gcc/xg++ ... 
../../gcc-13-20220626/gcc/cp/mapper-resolver.cc
In file included from /<>/musl-1.2.3-dev/include/pthread.h:30,
 from 
/build/build/prev-x86_64-unknown-linux-musl/libstdc++-v3/include/x86_64-unknown-linux-musl/bits/gthr-default.h:35,
 
 from 
/build/build/prev-x86_64-unknown-linux-musl/libstdc++-v3/include/memory:77,
 from ../../gcc-13-20220626/gcc/../libcody/cody.hh:24,
 from ../../gcc-13-20220626/gcc/cp/../../c++tools/resolver.h:25,
 from 
../../gcc-13-20220626/gcc/cp/../../c++tools/resolver.cc:23,
 from ../../gcc-13-20220626/gcc/cp/mapper-resolver.cc:32:
/<>/musl-1.2.3-dev/include/sched.h:84:7: error: attempt to use 
poisoned "calloc"
   84 | void *calloc(size_t, size_t);
  |   ^
/<>/musl-1.2.3-dev/include/sched.h:124:36: error: attempt to use 
poisoned "calloc"
  124 | #define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n)))
  |^

gcc/cp/
* mapper-client.cc: Include  via "system.h".
* mapper-resolver.cc: Ditto.
* module.cc: Ditto.

libcc1/
* libcc1plugin.cc: Ditto.
* libcp1plugin.cc: Ditto.
---
 gcc/cp/mapper-client.cc   | 1 +
 gcc/cp/mapper-resolver.cc | 1 +
 gcc/cp/module.cc  | 1 +
 libcc1/libcc1plugin.cc| 1 +
 libcc1/libcp1plugin.cc| 1 +
 5 files changed, 5 insertions(+)

diff --git a/gcc/cp/mapper-client.cc b/gcc/cp/mapper-client.cc
index 8603a886a09..fe9544b5ba4 100644
--- a/gcc/cp/mapper-client.cc
+++ b/gcc/cp/mapper-client.cc
@@ -27,6 +27,7 @@ along with GCC; see the file COPYING3.  If not see
 #define INCLUDE_STRING
 #define INCLUDE_VECTOR
 #define INCLUDE_MAP
+#define INCLUDE_MEMORY
 #include "system.h"
 
 #include "line-map.h"
diff --git a/gcc/cp/mapper-resolver.cc b/gcc/cp/mapper-resolver.cc
index e3d29fb5ada..e70d1b4ae2c 100644
--- a/gcc/cp/mapper-resolver.cc
+++ b/gcc/cp/mapper-resolver.cc
@@ -25,6 +25,7 @@ along with GCC; see the file COPYING3.  If not see
 #define INCLUDE_VECTOR
 #define INCLUDE_ALGORITHM
 #define INCLUDE_MAP
+#define INCLUDE_MEMORY
 #include "system.h"
 
 // We don't want or need to be aware of networking
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index e7ce40ef464..99f10733d4b 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -206,6 +206,7 @@ Classes used:
 
 #define _DEFAULT_SOURCE 1 /* To get TZ field of struct tm, if available.  */
 #include "config.h"
+#define INCLUDE_MEMORY
 #define INCLUDE_STRING
 #define INCLUDE_VECTOR
 #include "system.h"
diff --git a/libcc1/libcc1plugin.cc b/libcc1/libcc1plugin.cc
index 12ab5a57c8d..bdd0bdabe77 100644
--- a/libcc1/libcc1plugin.cc
+++ b/libcc1/libcc1plugin.cc
@@ -31,6 +31,7 @@
 #undef PACKAGE_TARNAME
 #undef PACKAGE_VERSION
 
+#define INCLUDE_MEMORY
 #include "gcc-plugin.h"
 #include "system.h"
 #include "coretypes.h"
diff --git a/libcc1/libcp1plugin.cc b/libcc1/libcp1plugin.cc
index 83dab7f58b1..e2d5039a0a1 100644
--- a/libcc1/libcp1plugin.cc
+++ b/libcc1/libcp1plugin.cc
@@ -32,6 +32,7 @@
 #undef PACKAGE_TARNAME
 #undef PACKAGE_VERSION
 
+#define INCLUDE_MEMORY
 #include "gcc-plugin.h"
 #include "system.h"
 #include "coretypes.h"
-- 
2.36.1



[PATCH, gcc-11 backport] gcov-profile: Allow negative counts of indirect calls [PR105282]

2022-04-19 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

TOPN metrics are histograms that contain overall count and per-bucket
count. Overall count can be negative when two profiles merge and some
of per-bucket metrics are disacarded.

Noticed as an ICE on python PGO build where gcc crashes as:

during IPA pass: modref
a.c:36:1: ICE: in stream_out_histogram_value, at value-prof.cc:340
   36 | }
  | ^
stream_out_histogram_value(output_block*, histogram_value_t*)
gcc/value-prof.cc:340

gcc/ChangeLog:

PR gcov-profile/105282
* value-prof.cc (stream_out_histogram_value): Allow negative counts
on HIST_TYPE_INDIR_CALL.

(cherry picked from commit 90a29845bfe7d6002e6c2fd49a97820b00fbc4a3)
---
 gcc/value-prof.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/gcc/value-prof.c b/gcc/value-prof.c
index 42748771192..688089b04d2 100644
--- a/gcc/value-prof.c
+++ b/gcc/value-prof.c
@@ -336,6 +336,10 @@ stream_out_histogram_value (struct output_block *ob, 
histogram_value hist)
/* Note that the IOR counter tracks pointer values and these can have
   sign bit set.  */
;
+  else if (hist->type == HIST_TYPE_INDIR_CALL && i == 0)
+   /* 'all' counter overflow is stored as a negative value. Individual
+  counters and values are expected to be non-negative.  */
+   ;
   else
gcc_assert (value >= 0);
 
-- 
2.35.1



[PATCH] gcov-profile: Allow negavive counts of indirect calls [PR105282]

2022-04-15 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

TOPN metrics are histograms that contain overall count and per-bucket
count. Overall count can be nevative when two profiles merge and some
of per-bucket metrics are dropped.

Noticed as an ICE on python PGO build where gcc crashes as:

during IPA pass: modref
a.c:36:1: ICE: in stream_out_histogram_value, at value-prof.cc:340
   36 | }
  | ^
stream_out_histogram_value(output_block*, histogram_value_t*)
gcc/value-prof.cc:340

gcc/ChangeLog:

PR gcov-profile/105282
* value-prof.cc (stream_out_histogram_value): Allow negavive counts
on HIST_TYPE_INDIR_CALL.
---
 gcc/value-prof.cc | 4 
 1 file changed, 4 insertions(+)

diff --git a/gcc/value-prof.cc b/gcc/value-prof.cc
index 9785c7a03ea..4927d119aa0 100644
--- a/gcc/value-prof.cc
+++ b/gcc/value-prof.cc
@@ -319,40 +319,44 @@ stream_out_histogram_value (struct output_block *ob, 
histogram_value hist)
   streamer_write_bitpack ();
   switch (hist->type)
 {
 case HIST_TYPE_INTERVAL:
   streamer_write_hwi (ob, hist->hdata.intvl.int_start);
   streamer_write_uhwi (ob, hist->hdata.intvl.steps);
   break;
 default:
   break;
 }
   for (i = 0; i < hist->n_counters; i++)
 {
   /* When user uses an unsigned type with a big value, constant converted
 to gcov_type (a signed type) can be negative.  */
   gcov_type value = hist->hvalue.counters[i];
   if (hist->type == HIST_TYPE_TOPN_VALUES
  || hist->type == HIST_TYPE_IOR)
/* Note that the IOR counter tracks pointer values and these can have
   sign bit set.  */
;
+  else if (hist->type == HIST_TYPE_INDIR_CALL && i == 0)
+   /* 'all' counter overflow is stored as a negative value. Individual
+  counters and values are expected to be non-negative.  */
+   ;
   else
gcc_assert (value >= 0);
 
   streamer_write_gcov_count (ob, value);
 }
   if (hist->hvalue.next)
 stream_out_histogram_value (ob, hist->hvalue.next);
 }
 
 /* Dump information about HIST to DUMP_FILE.  */
 
 void
 stream_in_histogram_value (class lto_input_block *ib, gimple *stmt)
 {
   enum hist_type type;
   unsigned int ncounters = 0;
   struct bitpack_d bp;
   unsigned int i;
   histogram_value new_val;
   bool next;
-- 
2.35.1



[PATCH] libgcc: IA64: don't compile glibc-based unwinder without libc headers

2022-04-07 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

In --without-headers mode gcc fails to bootstrap on libgcc as:

/build/build/./gcc/xgcc -B/build/build/./gcc/ ... -Dinhibit_libc -c 
fde-glibc.c
../../../gcc-12-20220403/libgcc/config/ia64/fde-glibc.c:33:10:
fatal error: stdlib.h: No such file or directory

Most other linux targets are able to build the --without-headers
compiler without additional effort. This change adds IA64 to the fold.

The change drops part of the code that relies on DYNAMIC glibc
section traversal for backtraces.

Tested bootstrap of ia64-unknown-linux-gnu with and without libc
headers present.

libgcc/
* config/ia64/fde-glibc.c: Make a no-op in inhibit_libc mode.
---
 libgcc/config/ia64/fde-glibc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libgcc/config/ia64/fde-glibc.c b/libgcc/config/ia64/fde-glibc.c
index 9caac2bca24..bd74847fa85 100644
--- a/libgcc/config/ia64/fde-glibc.c
+++ b/libgcc/config/ia64/fde-glibc.c
@@ -22,20 +22,21 @@
see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
<http://www.gnu.org/licenses/>.  */
 
 /* Locate the FDE entry for a given address, using glibc ld.so routines
to avoid register/deregister calls at DSO load/unload.  */
 
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE 1
 #endif
 #include "config.h"
+#ifndef inhibit_libc
 #include 
 #include 
 #include 
 #include "unwind-ia64.h"
 
 #if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 2) \
 || (__GLIBC__ == 2 && __GLIBC_MINOR__ == 2 && !defined(DT_CONFIG))
 # error You need GLIBC 2.2.4 or later on IA-64 Linux
 #endif
 
@@ -152,10 +153,11 @@ _Unwind_FindTableEntry (void *pc, unw_word *segment_base, 
unw_word *gp,
   data.pc = (Elf64_Addr) pc;
   data.segment_base = segment_base;
   data.gp = gp;
   data.ret = NULL;
 
   if (dl_iterate_phdr (_Unwind_IteratePhdrCallback, ) < 0)
 return NULL;
 
   return data.ret;
 }
+#endif
-- 
2.35.1



[PATCH v2] Fortran manual: extend deprecated BOZ examples with X'ABC'

2021-11-21 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

gcc/fortran/
* gfortran.texi (BOZ literal constants): add X'ABC' to the list
of valid examples.
---
 gcc/fortran/gfortran.texi | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi
index 326470964b0..f7184147a82 100644
--- a/gcc/fortran/gfortran.texi
+++ b/gcc/fortran/gfortran.texi
@@ -1465,10 +1465,10 @@ dependent.  Gfortran interprets the sign bit as a user 
would expect.
 As a deprecated extension, GNU Fortran allows hexadecimal BOZ literal
 constants to be specified using the @code{X} prefix.  That the BOZ literal
 constant can also be specified by adding a suffix to the string, for
-example, @code{Z'ABC'} and @code{'ABC'X} are equivalent.  Additionally,
-as extension, BOZ literals are permitted in some contexts outside of
-@code{DATA} and the intrinsic functions listed in the Fortran standard.
-Use @option{-fallow-invalid-boz} to enable the extension.
+example, @code{Z'ABC'}, @code{'ABC'X} and @code{X'ABC'} are equivalent.
+Additionally, as extension, BOZ literals are permitted in some contexts
+outside of @code{DATA} and the intrinsic functions listed in the Fortran
+standard. Use @option{-fallow-invalid-boz} to enable the extension.
 
 @node Real array indices
 @subsection Real array indices
-- 
2.33.1



[PATCH] Fortran manual: fix invalid BOZ 'ABC'X example to be X'ABC'.

2021-11-21 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

gcc/fortran/
* gfortran.texi (BOZ literal constants): fix invalid BOZ 'ABC'X
example to be X'ABC'.
---
 gcc/fortran/gfortran.texi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi
index 326470964b0..f01a49c47cc 100644
--- a/gcc/fortran/gfortran.texi
+++ b/gcc/fortran/gfortran.texi
@@ -1465,7 +1465,7 @@ dependent.  Gfortran interprets the sign bit as a user 
would expect.
 As a deprecated extension, GNU Fortran allows hexadecimal BOZ literal
 constants to be specified using the @code{X} prefix.  That the BOZ literal
 constant can also be specified by adding a suffix to the string, for
-example, @code{Z'ABC'} and @code{'ABC'X} are equivalent.  Additionally,
+example, @code{Z'ABC'} and @code{X'ABC'} are equivalent.  Additionally,
 as extension, BOZ literals are permitted in some contexts outside of
 @code{DATA} and the intrinsic functions listed in the Fortran standard.
 Use @option{-fallow-invalid-boz} to enable the extension.
-- 
2.33.1



Re: [PATCH] libbacktrace: fix fd leak tests on systems with extra descriptors

2021-08-13 Thread Sergei Trofimovich via Gcc-patches
On Fri, 13 Aug 2021 09:52:53 -0700
Ian Lance Taylor  wrote:

> On Fri, Aug 13, 2021 at 12:05 AM Sergei Trofimovich  wrote:
> >
> > On Thu, 12 Aug 2021 16:16:04 -0700
> > Ian Lance Taylor  wrote:
> >  
> > > On Thu, Aug 12, 2021 at 3:34 PM Sergei Trofimovich via Gcc-patches
> > >  wrote:  
> > > >
> > > > From: Sergei Trofimovich 
> > > >
> > > > I noticed test failures when ran gcc test suite from under mc shell.
> > > > mc opens fd=9 and exposes it to child processes. As a result a few
> > > > tests failes:
> > > > FAIL: b2test_buildid
> > > > FAIL: btest_gnudebuglink
> > > > FAIL: btest
> > > > FAIL: btest_lto
> > > > FAIL: btest_alloc
> > > > FAIL: ctestg
> > > > FAIL: ctesta
> > > > FAIL: ctestg_alloc
> > > > FAIL: ctesta_alloc
> > > > FAIL: dwarf5
> > > > FAIL: dwarf5_alloc
> > > >
> > > > Instead of trying to close file descripts in range test polls for
> > > > first available file descriptor by creating it via dup(1).
> > > >
> > > > libbacktrace/
> > > >
> > > > * btest.c (check_open_files): Use last free file descriptor as a
> > > > signal for flie descriptor leak.  
> > >
> > > This isn't a useful replacement, as this will pass as long as
> > > libbacktrace closes the first file descriptor that it opens.  It won't
> > > check whether libbacktrace left any other file descriptors open.
> > >
> > > Perhaps at program startup we could fstat descriptors up to 10 and
> > > record whether they are valid, and then skip those files in
> > > check_open_files.  
> >
> > Oh, great point! Completely missed it. Changed the patch to poll for present
> > file descriptors with fcntl(fd, F_GETFD) to compare before/after.  
> 
> I believe that we currently run some of the tests on Windows systems.
> Do you know if fcntl(fd, F_GETFD) will work there?

Ah, it does not. At least mingw does not expose fcntl. I'll look
at possible equivalent on it and send another version.

-- 

  Sergei


Re: [PATCH] libbacktrace: fix fd leak tests on systems with extra descriptors

2021-08-13 Thread Sergei Trofimovich via Gcc-patches
On Thu, 12 Aug 2021 16:16:04 -0700
Ian Lance Taylor  wrote:

> On Thu, Aug 12, 2021 at 3:34 PM Sergei Trofimovich via Gcc-patches
>  wrote:
> >
> > From: Sergei Trofimovich 
> >
> > I noticed test failures when ran gcc test suite from under mc shell.
> > mc opens fd=9 and exposes it to child processes. As a result a few
> > tests failes:
> > FAIL: b2test_buildid
> > FAIL: btest_gnudebuglink
> > FAIL: btest
> > FAIL: btest_lto
> > FAIL: btest_alloc
> > FAIL: ctestg
> > FAIL: ctesta
> > FAIL: ctestg_alloc
> > FAIL: ctesta_alloc
> > FAIL: dwarf5
> > FAIL: dwarf5_alloc
> >
> > Instead of trying to close file descripts in range test polls for
> > first available file descriptor by creating it via dup(1).
> >
> > libbacktrace/
> >
> > * btest.c (check_open_files): Use last free file descriptor as a
> > signal for flie descriptor leak.  
> 
> This isn't a useful replacement, as this will pass as long as
> libbacktrace closes the first file descriptor that it opens.  It won't
> check whether libbacktrace left any other file descriptors open.
> 
> Perhaps at program startup we could fstat descriptors up to 10 and
> record whether they are valid, and then skip those files in
> check_open_files.

Oh, great point! Completely missed it. Changed the patch to poll for present
file descriptors with fcntl(fd, F_GETFD) to compare before/after.

-- 

  Sergei
From dba67cc728d6be521f59a4c0d3abe7879de2db4c Mon Sep 17 00:00:00 2001
From: Sergei Trofimovich 
Date: Thu, 12 Aug 2021 23:27:00 +0100
Subject: [PATCH v2] libbacktrace: fix fd leak tests on systems with extra
 descriptors

I noticed test failures when ran gcc test suite from under mc shell.
mc opens fd=9 and exposes it to child processes. As a result a few
tests failes:
FAIL: b2test_buildid
FAIL: btest_gnudebuglink
FAIL: btest
FAIL: btest_lto
FAIL: btest_alloc
FAIL: ctestg
FAIL: ctesta
FAIL: ctestg_alloc
FAIL: ctesta_alloc
FAIL: dwarf5
FAIL: dwarf5_alloc

Instead of trying to close file descripts in range test polls for
their presence with with fcntl(fd, F_GETFD) before and after test.

libbacktrace/

	* btest.c (check_open_files): Use fcntl to poll for file
	descriptor presence.
---
 libbacktrace/btest.c | 18 --
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/libbacktrace/btest.c b/libbacktrace/btest.c
index 9f9c03babf3..c08c1540fa6 100644
--- a/libbacktrace/btest.c
+++ b/libbacktrace/btest.c
@@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.  */
libbacktrace library.  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -458,6 +459,18 @@ test5 (void)
   return failures;
 }
 
+#define MAX_FDS 10
+static int fd_states[MAX_FDS];
+
+static void
+store_open_files (void)
+{
+  int i;
+
+  for (i = 0; i < MAX_FDS; i++)
+fd_states[i] = fcntl (i, F_GETFD);
+}
+
 /* Check that are no files left open.  */
 
 static void
@@ -465,9 +478,9 @@ check_open_files (void)
 {
   int i;
 
-  for (i = 3; i < 10; i++)
+  for (i = 0; i < MAX_FDS; i++)
 {
-  if (close (i) == 0)
+  if (fcntl (i, F_GETFD) != fd_states[i])
 	{
 	  fprintf (stderr,
 		   "ERROR: descriptor %d still open after tests complete\n",
@@ -484,6 +497,7 @@ main (int argc ATTRIBUTE_UNUSED, char **argv)
 {
   state = backtrace_create_state (argv[0], BACKTRACE_SUPPORTS_THREADS,
   error_callback_create, NULL);
+  store_open_files ();
 
 #if BACKTRACE_SUPPORTED
   test1 ();
-- 
2.32.0



pgpWbxhsEY6HB.pgp
Description: Цифровая подпись OpenPGP


[PATCH] libbacktrace: fix b2test_buildid test on non-english locales

2021-08-12 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

On LANG=ru_RU.UTF-8 'b2test_buildid' test fails due to localized readelf
output:

$ LANG=ru_RU.UTF-8 readelf -n b2test | fgrep 4e37e8f
ID сборки: 4e37e8fead8d6e8b0a9dc95ea25cd784dff3a393
$ LANG=C readelf -n b2test | fgrep 4e37e8f
Build ID: 4e37e8fead8d6e8b0a9dc95ea25cd784dff3a393

libbacktrace/

* install-debuginfo-for-buildid.sh.in: Force non-localized readelf
output with LANG=C.
---
 libbacktrace/install-debuginfo-for-buildid.sh.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libbacktrace/install-debuginfo-for-buildid.sh.in 
b/libbacktrace/install-debuginfo-for-buildid.sh.in
index 1364779d703..91dfdfe89a4 100644
--- a/libbacktrace/install-debuginfo-for-buildid.sh.in
+++ b/libbacktrace/install-debuginfo-for-buildid.sh.in
@@ -47,7 +47,7 @@ mkdir_p="@MKDIR_P@"
 build_id_dir="$1"
 src="$2"
 
-buildid=$($readelf -n $src \
+buildid=$(LANG=C $readelf -n $src \
  | $grep "Build ID" \
  | $awk '{print $3}')
 
-- 
2.32.0



[PATCH] libbacktrace: fix fd leak tests on systems with extra descriptors

2021-08-12 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

I noticed test failures when ran gcc test suite from under mc shell.
mc opens fd=9 and exposes it to child processes. As a result a few
tests failes:
FAIL: b2test_buildid
FAIL: btest_gnudebuglink
FAIL: btest
FAIL: btest_lto
FAIL: btest_alloc
FAIL: ctestg
FAIL: ctesta
FAIL: ctestg_alloc
FAIL: ctesta_alloc
FAIL: dwarf5
FAIL: dwarf5_alloc

Instead of trying to close file descripts in range test polls for
first available file descriptor by creating it via dup(1).

libbacktrace/

* btest.c (check_open_files): Use last free file descriptor as a
signal for flie descriptor leak.
---
 libbacktrace/btest.c | 35 ---
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/libbacktrace/btest.c b/libbacktrace/btest.c
index 9f9c03babf3..d5cf321640c 100644
--- a/libbacktrace/btest.c
+++ b/libbacktrace/btest.c
@@ -458,22 +458,32 @@ test5 (void)
   return failures;
 }
 
+/* Peek at first free flie descriptior.  */
+
+static int probe_first_dree_fd (void) {
+  int fd;
+
+  fd = dup(1);
+  close(fd);
+
+  return fd;
+}
+
 /* Check that are no files left open.  */
 
 static void
-check_open_files (void)
+check_open_files (int last_free_fd)
 {
-  int i;
+  int fd;
+
+  fd = probe_first_dree_fd();
 
-  for (i = 3; i < 10; i++)
+  if (fd != last_free_fd)
 {
-  if (close (i) == 0)
-   {
- fprintf (stderr,
-  "ERROR: descriptor %d still open after tests complete\n",
-  i);
- ++failures;
-   }
+  fprintf (stderr,
+  "ERROR: descriptor %d still open after tests complete\n",
+  last_free_fd);
+  ++failures;
 }
 }
 
@@ -482,8 +492,11 @@ check_open_files (void)
 int
 main (int argc ATTRIBUTE_UNUSED, char **argv)
 {
+  int first_free_fd;
+
   state = backtrace_create_state (argv[0], BACKTRACE_SUPPORTS_THREADS,
  error_callback_create, NULL);
+  first_free_fd = probe_first_dree_fd ();
 
 #if BACKTRACE_SUPPORTED
   test1 ();
@@ -495,7 +508,7 @@ main (int argc ATTRIBUTE_UNUSED, char **argv)
 #endif
 #endif
 
-  check_open_files ();
+  check_open_files (first_free_fd);
 
   exit (failures ? EXIT_FAILURE : EXIT_SUCCESS);
 }
-- 
2.32.0



Re: [PATCH] c++: suppress all warnings on memper pointers to work around dICE [PR101219]

2021-08-11 Thread Sergei Trofimovich via Gcc-patches
On Wed, 11 Aug 2021 15:19:58 -0400
Jason Merrill  wrote:

> On 8/6/21 11:34 AM, Sergei Trofimovich wrote:
> > On Thu, 29 Jul 2021 11:41:39 -0400
> > Jason Merrill  wrote:
> >   
> >> On 7/22/21 7:15 PM, Sergei Trofimovich wrote:  
> >>> From: Sergei Trofimovich 
> >>>
> >>> r12-1804 ("cp: add support for per-location warning groups.") among other
> >>> things removed warning suppression from a few places including 
> >>> ptrmemfuncs.
> >>>
> >>> Currently ptrmemfuncs don't have valid BINFO attached which causes ICEs
> >>> in access checks:
> >>>
> >>>   crash_signal
> >>>   gcc/toplev.c:328
> >>>   perform_or_defer_access_check(tree_node*, tree_node*, tree_node*, 
> >>> int, access_failure_info*)
> >>>   gcc/cp/semantics.c:490
> >>>   finish_non_static_data_member(tree_node*, tree_node*, tree_node*)
> >>>   gcc/cp/semantics.c:2208
> >>>   ...
> >>>
> >>> The change suppresses warnings again until we provide BINFOs for 
> >>> ptrmemfuncs.  
> >>
> >> We don't need BINFOs for PMFs, we need to avoid paths that expect them.
> >>
> >> It looks like the problem is with tsubst_copy_and_build calling
> >> finish_non_static_data_member instead of build_ptrmemfunc_access_expr.  
> > 
> > Sounds good. I'm not sure what would be the best way to match it. Here is
> > my attempt seems to survive all regtests:
> > 
> > --- a/gcc/cp/pt.c
> > +++ b/gcc/cp/pt.c
> > @@ -20530,7 +20530,13 @@ tsubst_copy_and_build (tree t,
> >  if (member == error_mark_node)
> >RETURN (error_mark_node);
> > 
> > -   if (TREE_CODE (member) == FIELD_DECL)
> > +   if (object_type && TYPE_PTRMEMFUNC_P(object_type)
> > +   && TREE_CODE (member) == FIELD_DECL)
> > + {
> > +   r = build_ptrmemfunc_access_expr (object, DECL_NAME(member));
> > +   RETURN (r);
> > + }
> > +   else if (TREE_CODE (member) == FIELD_DECL)
> >{
> >  r = finish_non_static_data_member (member, object, NULL_TREE);
> >  if (TREE_CODE (r) == COMPONENT_REF)
> >   
> >>>   PR c++/101219
> >>>
> >>> gcc/cp/ChangeLog:
> >>>
> >>>   * typeck.c (build_ptrmemfunc_access_expr): Suppress all warnings
> >>>   to avoid ICE.
> >>>
> >>> gcc/testsuite/ChangeLog:
> >>>
> >>>   * g++.dg/torture/pr101219.C: New test.  
> >>
> >> This doesn't need to be in torture; it has nothing to do with 
> >> optimization.  
> > 
> > Aha, moved to gcc/testsuite/g++.dg/warn/pr101219.C.
> > 
> > --- /dev/null
> > +++ b/gcc/testsuite/g++.dg/warn/pr101219.C
> > @@ -0,0 +1,11 @@
> > +/* PR c++/101219 - ICE on use of uninitialized memfun pointer
> > +   { dg-do compile }
> > +   { dg-options "-Wall" } */
> > +
> > +struct S { void m(); };
> > +
> > +template  bool f() {
> > +  void (S::*mp)();
> > +
> > +  return ::m == mp; // no warning emitted here (no instantiation)
> > +}
> > 
> > Another question: Is it expected that gcc generates no warnings here?
> > It's an uninstantiated function (-1 for warn), but from what I
> > understand it's guaranteed to generate comparison with uninitialized
> > data if it ever gets instantiated. Given that we used to ICE in
> > warning code gcc could possibly flag it? (+1 for warn)  
> 
> Generally it's desirable to diagnose templates for which no valid 
> instantiation is possible.  It seems reasonable in most cases to also 
> warn about templates for which all instantiations would warn.
> 
> But uninitialized warnings rely on flow analysis that we only do on 
> instantiated functions, and in any case the ICE doesn't depend on mp 
> being uninitialized; I get the same crash if I add = 0 to the declaration.

Aha. That makes sense. Let's just fix ICE then.

> > +   if (object_type && TYPE_PTRMEMFUNC_P(object_type)  
> 
> Missing space before (.
> 
> > +   && TREE_CODE (member) == FIELD_DECL)
> > + {
> > +   r = build_ptrmemfunc_access_expr (object, DECL_NAME(member));  
> 
> And here.

Added both. Attached as v3.

-- 

  Sergei
>From dbb17a22383faa7837bdd2ea9c902bfab53fa8f2 Mon Sep 17 00:00:00 2001
From: Sergei Trofimovich 
Date: Fri, 6 Aug 2021 16:14:16 +0100
Subject: [PATCH v3

Re: [PATCH] c++: suppress all warnings on memper pointers to work around dICE [PR101219]

2021-08-06 Thread Sergei Trofimovich via Gcc-patches
On Thu, 29 Jul 2021 11:41:39 -0400
Jason Merrill  wrote:

> On 7/22/21 7:15 PM, Sergei Trofimovich wrote:
> > From: Sergei Trofimovich 
> > 
> > r12-1804 ("cp: add support for per-location warning groups.") among other
> > things removed warning suppression from a few places including ptrmemfuncs.
> > 
> > Currently ptrmemfuncs don't have valid BINFO attached which causes ICEs
> > in access checks:
> > 
> >  crash_signal
> >  gcc/toplev.c:328
> >  perform_or_defer_access_check(tree_node*, tree_node*, tree_node*, int, 
> > access_failure_info*)
> >  gcc/cp/semantics.c:490
> >  finish_non_static_data_member(tree_node*, tree_node*, tree_node*)
> >  gcc/cp/semantics.c:2208
> >  ...
> > 
> > The change suppresses warnings again until we provide BINFOs for 
> > ptrmemfuncs.  
> 
> We don't need BINFOs for PMFs, we need to avoid paths that expect them.
> 
> It looks like the problem is with tsubst_copy_and_build calling 
> finish_non_static_data_member instead of build_ptrmemfunc_access_expr.

Sounds good. I'm not sure what would be the best way to match it. Here is
my attempt seems to survive all regtests:

--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -20530,7 +20530,13 @@ tsubst_copy_and_build (tree t,
if (member == error_mark_node)
  RETURN (error_mark_node);

-   if (TREE_CODE (member) == FIELD_DECL)
+   if (object_type && TYPE_PTRMEMFUNC_P(object_type)
+   && TREE_CODE (member) == FIELD_DECL)
+ {
+   r = build_ptrmemfunc_access_expr (object, DECL_NAME(member));
+   RETURN (r);
+ }
+   else if (TREE_CODE (member) == FIELD_DECL)
  {
r = finish_non_static_data_member (member, object, NULL_TREE);
if (TREE_CODE (r) == COMPONENT_REF)

> > PR c++/101219
> > 
> > gcc/cp/ChangeLog:
> > 
> > * typeck.c (build_ptrmemfunc_access_expr): Suppress all warnings
> > to avoid ICE.
> > 
> > gcc/testsuite/ChangeLog:
> > 
> > * g++.dg/torture/pr101219.C: New test.  
> 
> This doesn't need to be in torture; it has nothing to do with optimization.

Aha, moved to gcc/testsuite/g++.dg/warn/pr101219.C.

--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/pr101219.C
@@ -0,0 +1,11 @@
+/* PR c++/101219 - ICE on use of uninitialized memfun pointer
+   { dg-do compile }
+   { dg-options "-Wall" } */
+
+struct S { void m(); };
+
+template  bool f() {
+  void (S::*mp)();
+
+  return ::m == mp; // no warning emitted here (no instantiation)
+}

Another question: Is it expected that gcc generates no warnings here?
It's an uninstantiated function (-1 for warn), but from what I
understand it's guaranteed to generate comparison with uninitialized
data if it ever gets instantiated. Given that we used to ICE in
warning code gcc could possibly flag it? (+1 for warn)

Attached full patch as well. Full 'make check' shows no regressions on
x86_64-linux.

-- 

  Sergei
>From 9c51dbc598d8633167729de9637c8cdb5f3089fe Mon Sep 17 00:00:00 2001
From: Sergei Trofimovich 
Date: Fri, 6 Aug 2021 16:14:16 +0100
Subject: [PATCH v2] c++: fix ptrmemfunc template instantiation [PR101219]

r12-1804 ("cp: add support for per-location warning groups.") among other
things removed warning suppression from a few places including ptrmemfuncs.

This exposed a bug in warning detection code as a reference to missing
BINFO (it's intentionally missing for ptrmemfunc types):

crash_signal
gcc/toplev.c:328
perform_or_defer_access_check(tree_node*, tree_node*, tree_node*, int, access_failure_info*)
gcc/cp/semantics.c:490
finish_non_static_data_member(tree_node*, tree_node*, tree_node*)
gcc/cp/semantics.c:2208
...

The change special cases ptrmemfuncs in templace substitution by using
build_ptrmemfunc_access_expr() instead of finish_non_static_data_member().

PR c++/101219

gcc/cp/ChangeLog:

* pt.c (tsubst_copy_and_build): Use build_ptrmemfunc_access_expr
to construct ptrmemfunc expression instantiation.

gcc/testsuite/ChangeLog:

* g++.dg/warn/pr101219.C: New test.

Signed-off-by: Sergei Trofimovich 
---
 gcc/cp/pt.c  |  8 +++-
 gcc/testsuite/g++.dg/warn/pr101219.C | 11 +++
 2 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/warn/pr101219.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index b396ddd0089..c7a0317cbfb 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -20530,7 +20530,13 @@ tsubst_copy_and_build (tree t,
 	if (member == error_mark_node)
 	  RETURN (error_mark_node);
 
-	if (TREE_CODE (member) == FIELD_DECL)
+	if (object_type && TYPE_PTRMEMFUNC_P(object_type)
+	&& TREE_CODE (member) == FIELD_DECL)
+	  {
+	r = build_ptrmemfu

Re: [PATCH] c++: suppress all warnings on memper pointers to work around dICE [PR101219]

2021-07-23 Thread Sergei Trofimovich via Gcc-patches
On Fri, 23 Jul 2021 10:33:09 -0600
Jeff Law  wrote:

> On 7/22/2021 5:15 PM, Sergei Trofimovich via Gcc-patches wrote:
> > From: Sergei Trofimovich 
> >
> > r12-1804 ("cp: add support for per-location warning groups.") among other
> > things removed warning suppression from a few places including ptrmemfuncs.
> >
> > Currently ptrmemfuncs don't have valid BINFO attached which causes ICEs
> > in access checks:
> >
> >  crash_signal
> >  gcc/toplev.c:328
> >  perform_or_defer_access_check(tree_node*, tree_node*, tree_node*, int, 
> > access_failure_info*)
> >  gcc/cp/semantics.c:490
> >  finish_non_static_data_member(tree_node*, tree_node*, tree_node*)
> >  gcc/cp/semantics.c:2208
> >  ...
> >
> > The change suppresses warnings again until we provide BINFOs for 
> > ptrmemfuncs.
> >
> > PR c++/101219
> >
> > gcc/cp/ChangeLog:
> >
> > * typeck.c (build_ptrmemfunc_access_expr): Suppress all warnings
> > to avoid ICE.
> >
> > gcc/testsuite/ChangeLog:
> >
> > * g++.dg/torture/pr101219.C: New test.  
> The C++ maintainers have the final say here, but ISTM that warning 
> suppression shouldn't be used to avoid an ICE, even an ICE within the 
> warning or diagnostic code itself.

Sounds good. I agree fixing it correctly is preferable and should improve
diagnostic on this very test case compared to gcc-11.

I'll need some help plumbing TYPE_BINFO() around build_ptrmemfunc_type().
My attempts to use `xref_basetypes (t, NULL_TREE);` to derive it for a
fresh expression only shuffles ICEs around.

-- 

  Sergei


[PATCH] c++: suppress all warnings on memper pointers to work around dICE [PR101219]

2021-07-22 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

r12-1804 ("cp: add support for per-location warning groups.") among other
things removed warning suppression from a few places including ptrmemfuncs.

Currently ptrmemfuncs don't have valid BINFO attached which causes ICEs
in access checks:

crash_signal
gcc/toplev.c:328
perform_or_defer_access_check(tree_node*, tree_node*, tree_node*, int, 
access_failure_info*)
gcc/cp/semantics.c:490
finish_non_static_data_member(tree_node*, tree_node*, tree_node*)
gcc/cp/semantics.c:2208
...

The change suppresses warnings again until we provide BINFOs for ptrmemfuncs.

PR c++/101219

gcc/cp/ChangeLog:

* typeck.c (build_ptrmemfunc_access_expr): Suppress all warnings
to avoid ICE.

gcc/testsuite/ChangeLog:

* g++.dg/torture/pr101219.C: New test.
---
 gcc/cp/typeck.c |  6 +-
 gcc/testsuite/g++.dg/torture/pr101219.C | 10 ++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/torture/pr101219.C

diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index a483e1f988d..aa91fd21c7b 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -3326,7 +3326,11 @@ build_ptrmemfunc_access_expr (tree ptrmem, tree 
member_name)
member = DECL_CHAIN (member))
 if (DECL_NAME (member) == member_name)
   break;
-  return build_simple_component_ref (ptrmem, member);
+  tree r = build_simple_component_ref (ptrmem, member);
+  /* Suppress warning to avoid exposing missing BINFO for ptrmem
+ synthetic structs: PR101219.  */
+  suppress_warning(r);
+  return r;
 }
 
 /* Given an expression PTR for a pointer, return an expression
diff --git a/gcc/testsuite/g++.dg/torture/pr101219.C 
b/gcc/testsuite/g++.dg/torture/pr101219.C
new file mode 100644
index 000..c8d30448187
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr101219.C
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-Wall" } */
+struct S { void m(); };
+
+template  bool f() {
+  /* In PR101219 gcc used to ICE in warning code. */
+  void (S::*mp)();
+
+  return ::m == mp;
+}
-- 
2.32.0



[PATCH] musl: always use 'lib' directory for all x86_64 ABIs [PR90077]

2021-07-05 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

musl library intentionally does not support glibc-style multilib layout
and usually assumes --libdir=lib (Gentoo and Alpine Linux both use it).

Before the change --disable-multilib x86_64-gentoo-linux-musl returned:

$ gcc -print-multi-os-directory
../lib64
$ gcc -print-multi-os-directory -m32
../lib32
$ gcc -print-multi-os-directory -mx32
../libx32

After the change the layout is always the same:

$ gcc -print-multi-os-directory
../lib
$ gcc -print-multi-os-directory -m32
../lib
$ gcc -print-multi-os-directory -mx32
../lib

The discrepancy was noticed in meson build system which uses
-print-multi-os-directory to find out target directory.

Debian's multi-arch setup should not change.

PR target/90077

gcc/ChangeLog

* gcc/config.gcc: Specal case musl to t-linux64-musl.

* gcc/config/i386/t-linux64-musl: New file based on t-linux64
that pins MULTILIB_OSDIRNAMES to lib.
---
 gcc/config.gcc | 10 --
 gcc/config/i386/t-linux64-musl | 28 
 2 files changed, 36 insertions(+), 2 deletions(-)
 create mode 100644 gcc/config/i386/t-linux64-musl

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 0230bb88861..a87a59c9403 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1923,7 +1923,10 @@ i[34567]86-*-linux* | i[34567]86-*-kfreebsd*-gnu | 
i[34567]86-*-gnu* | i[34567]8
if test x$enable_targets = xall; then
tm_file="${tm_file} i386/x86-64.h 
i386/gnu-user-common.h i386/gnu-user64.h i386/linux-common.h i386/linux64.h"
tm_defines="${tm_defines} TARGET_BI_ARCH=1"
-   tmake_file="${tmake_file} i386/t-linux64"
+   case $target in
+   *-*-*musl*) tmake_file="${tmake_file} 
i386/t-linux64-musl";;
+   *) tmake_file="${tmake_file} i386/t-linux64";;
+   esac
x86_multilibs="${with_multilib_list}"
if test "$x86_multilibs" = "default"; then
x86_multilibs="m64,m32"
@@ -1983,7 +1986,10 @@ x86_64-*-linux* | x86_64-*-kfreebsd*-gnu)
tm_file="${tm_file} kfreebsd-gnu.h i386/kfreebsd-gnu64.h"
;;
esac
-   tmake_file="${tmake_file} i386/t-linux64"
+   case $target in
+   *-*-*musl*) tmake_file="${tmake_file} i386/t-linux64-musl";;
+   *) tmake_file="${tmake_file} i386/t-linux64";;
+   esac
x86_multilibs="${with_multilib_list}"
if test "$x86_multilibs" = "default"; then
case ${with_abi} in
diff --git a/gcc/config/i386/t-linux64-musl b/gcc/config/i386/t-linux64-musl
new file mode 100644
index 000..58e23c3c7dc
--- /dev/null
+++ b/gcc/config/i386/t-linux64-musl
@@ -0,0 +1,28 @@
+# Copyright (C) 2002-2021 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, 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; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# musl explicitly does not support lib/lib32/lib64 layouts and always
+# uses lib layout. On debian full arch suffix is used. Thus we populate
+# all the m32/m64/mx32 with the same lib and apply multiarch suffix.
+
+comma=,
+MULTILIB_OPTIONS= $(subst $(comma),/,$(TM_MULTILIB_CONFIG))
+MULTILIB_DIRNAMES   = $(patsubst m%, %, $(subst /, ,$(MULTILIB_OPTIONS)))
+MULTILIB_OSDIRNAMES = m64=../lib$(call if_multiarch,:x86_64-linux-gnu)
+MULTILIB_OSDIRNAMES+= m32=../lib$(call if_multiarch,:i386-linux-gnu)
+MULTILIB_OSDIRNAMES+= mx32=../lib$(call if_multiarch,:x86_64-linux-gnux32)
-- 
2.32.0



[PATCH] docs: drop unbalanced parenthesis in rtl.texi

2021-06-21 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

gcc/ChangeLog:

* doc/rtl.texi: drop unbalanced parenthesis.
---
 gcc/doc/rtl.texi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/doc/rtl.texi b/gcc/doc/rtl.texi
index 5af71137a87..e1e76a93a8b 100644
--- a/gcc/doc/rtl.texi
+++ b/gcc/doc/rtl.texi
@@ -144,7 +144,7 @@ Currently, @file{rtl.def} defines these classes:
 @item RTX_OBJ
 An RTX code that represents an actual object, such as a register
 (@code{REG}) or a memory location (@code{MEM}, @code{SYMBOL_REF}).
-@code{LO_SUM}) is also included; instead, @code{SUBREG} and
+@code{LO_SUM} is also included; instead, @code{SUBREG} and
 @code{STRICT_LOW_PART} are not in this class, but in class
 @code{RTX_EXTRA}.
 
-- 
2.32.0



[PATCH] tree-optimization/98499 - fix modref analysis on RVO statements

2021-01-30 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

Before the change RVO gimple statements were treated as local
stores by modres analysis. But in practice RVO escapes target.

2021-01-30  Sergei Trofimovich  

gcc/ChangeLog:

PR tree-optimization/98499
* ipa-modref.c: treat RVO conservatively and assume
all possible side-effects.

gcc/testsuite/ChangeLog:

PR tree-optimization/98499
* g++.dg/pr98499.C: new test.
---
 gcc/ipa-modref.c   | 14 --
 gcc/testsuite/g++.dg/pr98499.C | 31 +++
 2 files changed, 43 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/pr98499.C

diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c
index b362de77e74..7aaf53be8f4 100644
--- a/gcc/ipa-modref.c
+++ b/gcc/ipa-modref.c
@@ -1621,9 +1621,19 @@ analyze_ssa_name_flags (tree name, vec 
, int depth,
   else if (gcall *call = dyn_cast  (use_stmt))
{
  tree callee = gimple_call_fndecl (call);
-
+ /* Return slot optiomization would require bit of propagation;
+give up for now.  */
+ if (gimple_call_return_slot_opt_p (call)
+ && gimple_call_lhs (call) != NULL_TREE
+ && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (call
+   {
+ if (dump_file)
+   fprintf (dump_file, "%*s  Unhandled return slot opt\n",
+depth * 4, "");
+ lattice[index].merge (0);
+   }
  /* Recursion would require bit of propagation; give up for now.  */
- if (callee && !ipa && recursive_call_p (current_function_decl,
+ else if (callee && !ipa && recursive_call_p (current_function_decl,
  callee))
lattice[index].merge (0);
  else
diff --git a/gcc/testsuite/g++.dg/pr98499.C b/gcc/testsuite/g++.dg/pr98499.C
new file mode 100644
index 000..ace088aeed9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr98499.C
@@ -0,0 +1,31 @@
+/* PR tree-optimization/98499.  */
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+struct string {
+  // pointer to local store
+  char * _M_buf;
+  // local store
+  char _M_local_buf[16];
+
+  __attribute__((noinline)) string() : _M_buf(_M_local_buf) {}
+
+  ~string() {
+if (_M_buf != _M_local_buf)
+  __builtin_trap();
+  }
+
+  string(const string &__str); // no copies
+};
+
+__attribute__((noinline)) static string dir_name() { return string(); }
+class Importer {
+  string base_path;
+
+public:
+  __attribute__((noinline)) Importer() : base_path (dir_name()) {}
+};
+
+int main() {
+  Importer imp;
+}
-- 
2.30.0



[PATCH] ipa-modref: avoid linebreak split in debug print

2021-01-07 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

* ipa-modref.c (merge_call_side_effects): Fix
linebreak split by reordering two print calls.
---
 gcc/ipa-modref.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c
index fcc676d25e4..04613201f1f 100644
--- a/gcc/ipa-modref.c
+++ b/gcc/ipa-modref.c
@@ -835,10 +835,6 @@ merge_call_side_effects (modref_summary *cur_summary,
   auto_vec  parm_map;
   bool changed = false;
 
-  if (dump_file)
-fprintf (dump_file, " - Merging side effects of %s with parm map:",
-callee_node->dump_name ());
-
   /* We can not safely optimize based on summary of callee if it does
  not always bind to current def: it is possible that memory load
  was optimized out earlier which may not happen in the interposed
@@ -850,6 +846,10 @@ merge_call_side_effects (modref_summary *cur_summary,
   cur_summary->loads->collapse ();
 }
 
+  if (dump_file)
+fprintf (dump_file, " - Merging side effects of %s with parm map:",
+callee_node->dump_name ());
+
   parm_map.safe_grow_cleared (gimple_call_num_args (stmt), true);
   for (unsigned i = 0; i < gimple_call_num_args (stmt); i++)
 {
-- 
2.30.0



Re: [PATCH] PR preprocessor/94657: use $AR, not 'ar',

2020-11-13 Thread Sergei Trofimovich via Gcc-patches
On Fri, 13 Nov 2020 11:45:56 -0700
Jeff Law  wrote:

> 
> On 4/22/20 4:05 PM, Sergei Trofimovich wrote:
> > From: Sergei Trofimovich 
> >
> > On system with 'ar' and '${CHOST}-ar' the latter is preferred.
> > as it might not match default 'ar'.
> >
> > Bug is initially reported downstream as https://bugs.gentoo.org/718004.
> >
> > libcpp/ChangeLog:
> >
> > PR libcpp/94657
> > * Makefile.in: use @AR@ placeholder
> > * configure.ac: use AC_CHECK_TOOL to find 'ar'
> > * configure: regenerate
> 
> This was subsumed by David Edelsohn's patch to libcpp and libdecnumber
> which does effectively the same thing.

Agreed. It was also mentioned in
  https://gcc.gnu.org/pipermail/gcc-patches/2020-May/546756.html
Probably should not have changed the topic to be mre visible.

-- 

  Sergei


[PATCH gcc-10] gcov: fix TOPN streaming from shared libraries

2020-09-25 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

Before the change gcc did not stream correctly TOPN counters
if counters belonged to a non-local shared object.

As a result zero-section optimization generated TOPN sections
in a form not recognizable by '__gcov_merge_topn'.

The problem happens because in a case of multiple shared objects
'__gcov_merge_topn' function is present in address space multiple
times (once per each object).

The fix is to never rely on function address and predicate on TOPN
counter types.

libgcc/ChangeLog:

PR gcov-profile/96913
* libgcov-driver.c (write_one_data): Avoid function pointer
comparison in TOP streaming decision.

(backported commit 4ecf368f4b4223fb2df4f3887429dfbb48852e38)
---
 libgcc/libgcov-driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c
index fb320738e1e..37438883d37 100644
--- a/libgcc/libgcov-driver.c
+++ b/libgcc/libgcov-driver.c
@@ -242,7 +242,7 @@ prune_counters (struct gcov_info *gi)
  if (gi->merge[j] == NULL)
continue;
 
- if (gi->merge[j] == __gcov_merge_topn)
+ if (j == GCOV_COUNTER_V_TOPN || j == GCOV_COUNTER_V_INDIR)
{
  gcc_assert (!(ci->num % GCOV_TOPN_VALUES_COUNTERS));
  for (unsigned k = 0; k < (ci->num / GCOV_TOPN_VALUES_COUNTERS);
-- 
2.28.0



Re: [PATCH] gcov: fix TOPN streaming from shared libraries

2020-09-21 Thread Sergei Trofimovich via Gcc-patches
On Mon, 21 Sep 2020 20:38:07 +0300 (MSK)
Alexander Monakov  wrote:

> On Mon, 21 Sep 2020, Martin Liška wrote:
> 
> > On 9/6/20 1:24 PM, Sergei Trofimovich wrote:  
> > > From: Sergei Trofimovich 
> > > 
> > > Before the change gcc did not stream correctly TOPN counters
> > > if counters belonged to a non-local shared object.
> > > 
> > > As a result zero-section optimization generated TOPN sections
> > > in a form not recognizable by '__gcov_merge_topn'.
> > > 
> > > The problem happens because in a case of multiple shared objects
> > > '__gcov_merge_topn' function is present in address space multiple
> > > times (once per each object).
> > > 
> > > The fix is to never rely on function address and predicate on TOPN
> > > counter types.  
> > 
> > Hello.
> > 
> > Thank you for the analysis! I think it's the correct fix and it's probably
> > similar to what we used to see for indirect_call_tuple.
> > 
> > @Alexander: Am I right?  
> 
> Yes, analysis presented by Sergei in Bugzilla looks correct. Pedantically I
> wouldn't say the indirect call issue was similar: it's a different gotcha
> arising from mixing static and dynamic linking. There we had some symbols
> preempted by the main executable (but not all symbols), here we have lack
> of preemption/unification as relevant libgcov symbol is hidden.
> 
> I cannot judge if the fix is correct (don't know the code that well) but it
> looks reasonable. If you could come up with a clearer wording for the new
> comment it would be nice, I struggled to understand it.

Yeah, I agree the comment is very misleading. The code is already very clear
about special casing of TOPN counters. How about dropping the comment?

v2:

From 300585164f0a719a3a283c8da3a4061615f6da3a Mon Sep 17 00:00:00 2001
From: Sergei Trofimovich 
Date: Sun, 6 Sep 2020 12:13:54 +0100
Subject: [PATCH v2] gcov: fix TOPN streaming from shared libraries

Before the change gcc did not stream correctly TOPN counters
if counters belonged to a non-local shared object.

As a result zero-section optimization generated TOPN sections
in a form not recognizable by '__gcov_merge_topn'.

The problem happens because in a case of multiple shared objects
'__gcov_merge_topn' function is present in address space multiple
times (once per each object).

The fix is to never rely on function address and predicate on TOPN
counter types.

libgcc/ChangeLog:

PR gcov-profile/96913
* libgcov-driver.c (write_one_data): Avoid function pointer
comparison in TOP streaming decision.
---
 libgcc/libgcov-driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c
index 58914268d4e..e53e4dc392a 100644
--- a/libgcc/libgcov-driver.c
+++ b/libgcc/libgcov-driver.c
@@ -424,7 +424,7 @@ write_one_data (const struct gcov_info *gi_ptr,

  n_counts = ci_ptr->num;

- if (gi_ptr->merge[t_ix] == __gcov_merge_topn)
+ if (t_ix == GCOV_COUNTER_V_TOPN || t_ix == GCOV_COUNTER_V_INDIR)
write_top_counters (ci_ptr, t_ix, n_counts);
  else
{
-- 

  Sergei
>From 300585164f0a719a3a283c8da3a4061615f6da3a Mon Sep 17 00:00:00 2001
From: Sergei Trofimovich 
Date: Sun, 6 Sep 2020 12:13:54 +0100
Subject: [PATCH v2] gcov: fix TOPN streaming from shared libraries

Before the change gcc did not stream correctly TOPN counters
if counters belonged to a non-local shared object.

As a result zero-section optimization generated TOPN sections
in a form not recognizable by '__gcov_merge_topn'.

The problem happens because in a case of multiple shared objects
'__gcov_merge_topn' function is present in address space multiple
times (once per each object).

The fix is to never rely on function address and predicate on TOPN
counter types.

libgcc/ChangeLog:

	PR gcov-profile/96913
	* libgcov-driver.c (write_one_data): Avoid function pointer
	comparison in TOP streaming decision.
---
 libgcc/libgcov-driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c
index 58914268d4e..e53e4dc392a 100644
--- a/libgcc/libgcov-driver.c
+++ b/libgcc/libgcov-driver.c
@@ -424,7 +424,7 @@ write_one_data (const struct gcov_info *gi_ptr,
 
 	  n_counts = ci_ptr->num;
 
-	  if (gi_ptr->merge[t_ix] == __gcov_merge_topn)
+	  if (t_ix == GCOV_COUNTER_V_TOPN || t_ix == GCOV_COUNTER_V_INDIR)
 	write_top_counters (ci_ptr, t_ix, n_counts);
 	  else
 	{
-- 
2.28.0



Re: [PATCH] -fprofile-reproducible: fix option value handling

2020-09-14 Thread Sergei Trofimovich via Gcc-patches
On Mon, 14 Sep 2020 09:34:08 +0200
Richard Biener  wrote:

> On Fri, Sep 11, 2020 at 11:56 PM Sergei Trofimovich via Gcc-patches
>  wrote:
> >
> > From: Sergei Trofimovich 
> >
> > Before the change option handling did not accept an argument:
> >   xgcc: error: unknown profile reproducibility method '=serial'
> >   xgcc: note: valid arguments to '-fprofile-reproducible' are: 
> > multithreaded parallel-runs serial; did you mean 'serial'?
> >
> > The change also includes trailing '=' as part of option prefix.  
> 
> Does it still work without an option then?

'-fprofile-reproducible' seems to be unacceptable value.

Initially when I sent the patch I though there was no way to pass
the option to gcc. But now I understand how to do it (case 4):

Before:
  1 $ gcc-11.0.0 -c -fprofile-reproducible a.c -o a
  gcc-11.0.0: error: missing argument to '-fprofile-reproducible'
  2 $ gcc-11.0.0 -c -fprofile-reproducible= a.c -o a
  gcc-11.0.0: error: unknown profile reproducibility method '='
  gcc-11.0.0: note: valid arguments to '-fprofile-reproducible' are: 
multithreaded parallel-runs serial
  3 $ gcc-11.0.0 -c -fprofile-reproducible=serial a.c -o a
  gcc-11.0.0: error: unknown profile reproducibility method '=serial'
  gcc-11.0.0: note: valid arguments to '-fprofile-reproducible' are: 
multithreaded parallel-runs serial; did you mean 'serial'?
  4 $ gcc-11.0.0 -c -fprofile-reproducibleserial a.c -o a
  # ok

Note: case 4 was a way to pass the option.

After:
  1 $ ./xgcc -B. -c -fprofile-reproducible a.c -o a.o
  xgcc: error: unrecognized command-line option '-fprofile-reproducible'; did 
you mean '-fprofile-reproducible='?
  2 $ ./xgcc -B. -c -fprofile-reproducible= a.c -o a.o
  xgcc: error: missing argument to '-fprofile-reproducible='
  3 $ ./xgcc -B. -c -fprofile-reproducible=serial a.c -o a.o
  # ok
  4 $ ./xgcc -B. -c -fprofile-reproducibleserial a.c -o a.o
  xgcc: error: unrecognized command-line option '-fprofile-reproducibleserial'; 
did you mean '-fprofile-reproducible=serial'?

Note: two problems here:
a) case 2 got worse diagnostic
b) case 4 broke something that worked before

I'll look at "a)" to check if it can be easily fixed. Is "b)" worth handling as 
well?
I'll need a hint or example how to handle an alias like that.

> OK if so.
> 
> > gcc/ChangeLog:
> >
> > * common.opt: Fix handling of '-fprofile-reproducible' option.
> > ---
> >  gcc/common.opt | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/gcc/common.opt b/gcc/common.opt
> > index dd68c61ae1d..84bf521128d 100644
> > --- a/gcc/common.opt
> > +++ b/gcc/common.opt
> > @@ -2228,7 +2228,7 @@ Enum(profile_reproducibility) String(parallel-runs) 
> > Value(PROFILE_REPRODUCIBILIT
> >  EnumValue
> >  Enum(profile_reproducibility) String(multithreaded) 
> > Value(PROFILE_REPRODUCIBILITY_MULTITHREADED)
> >
> > -fprofile-reproducible
> > +fprofile-reproducible=
> >  Common Joined RejectNegative Var(flag_profile_reproducible) 
> > Enum(profile_reproducibility) Init(PROFILE_REPRODUCIBILITY_SERIAL)
> >  -fprofile-reproducible=[serial|parallel-runs|multithreaded]Control 
> > level of reproducibility of profile gathered by -fprofile-generate.
> >
> > --
> > 2.28.0
> >  


-- 

  Sergei


[PATCH] doc: use @code{} instead of @samp{@command{}} around 'date %s'

2020-09-11 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

Before the change 'man gcc' rendered "SOURCE_DATE_EPOCH" section as:
... the output of @command{date +%s} on GNU/Linux ...
After the change it renders as:
... the output of "date +%s" on GNU/Linux ...

gcc/ChangeLog:

* doc/cppenv.texi: Use @code{} instead of @samp{@command{}}
around 'date %s'.
---
 gcc/doc/cppenv.texi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/doc/cppenv.texi b/gcc/doc/cppenv.texi
index 123df5c464c..e1e408a2974 100644
--- a/gcc/doc/cppenv.texi
+++ b/gcc/doc/cppenv.texi
@@ -89,7 +89,7 @@ reproducible.
 The value of @env{SOURCE_DATE_EPOCH} must be a UNIX timestamp,
 defined as the number of seconds (excluding leap seconds) since
 01 Jan 1970 00:00:00 represented in ASCII; identical to the output of
-@samp{@command{date +%s}} on GNU/Linux and other systems that support the
+@code{date +%s} on GNU/Linux and other systems that support the
 @code{%s} extension in the @code{date} command.
 
 The value should be a known timestamp such as the last modification
-- 
2.28.0



[PATCH] doc: fix spelling of -fprofile-reproducibility

2020-09-11 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

gcc/ChangeLog:

* doc/invoke.texi: fix '-fprofile-reproducibility' option
spelling in maunal.
---
 gcc/doc/invoke.texi | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index bca8c856dc8..183ce7715d1 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -557,7 +557,8 @@ Objective-C and Objective-C++ Dialects}.
 -fprofile-dir=@var{path}  -fprofile-generate  -fprofile-generate=@var{path} 
@gol
 -fprofile-note=@var{path} -fprofile-prefix-path=@var{path} @gol
 -fprofile-update=@var{method} -fprofile-filter-files=@var{regex} @gol
--fprofile-exclude-files=@var{regex} -fprofile-reproducibility @gol
+-fprofile-exclude-files=@var{regex} @gol
+-fprofile-reproducible=@r{[}multithreaded@r{|}parallel-runs@r{|}serial@r{]} 
@gol
 -fsanitize=@var{style}  -fsanitize-recover  -fsanitize-recover=@var{style} @gol
 -fasan-shadow-offset=@var{number}  -fsanitize-sections=@var{s1},@var{s2},... 
@gol
 -fsanitize-undefined-trap-on-error  -fbounds-check @gol
@@ -13889,14 +13890,14 @@ any of the regular expressions (separated by 
semi-colons).
 For example, @option{-fprofile-exclude-files=/usr/.*} will prevent 
instrumentation
 of all files that are located in the @file{/usr/} folder.
 
-@item -fprofile-reproducible
+@item 
-fprofile-reproducible=@r{[}multithreaded@r{|}parallel-runs@r{|}serial@r{]}
 @opindex fprofile-reproducible
 Control level of reproducibility of profile gathered by
 @code{-fprofile-generate}.  This makes it possible to rebuild program
 with same outcome which is useful, for example, for distribution
 packages.
 
-With @option{-fprofile-reproducibility=serial} the profile gathered by
+With @option{-fprofile-reproducible=serial} the profile gathered by
 @option{-fprofile-generate} is reproducible provided the trained program
 behaves the same at each invocation of the train run, it is not
 multi-threaded and profile data streaming is always done in the same
@@ -13911,7 +13912,7 @@ Such non-reproducible part of programs may be annotated 
by
 @option{-l} can be used to dump gathered data and verify that they are
 indeed reproducible.
 
-With @option{-fprofile-reproducibility=parallel-runs} collected profile
+With @option{-fprofile-reproducible=parallel-runs} collected profile
 stays reproducible regardless the order of streaming of the data into
 gcda files.  This setting makes it possible to run multiple instances of
 instrumented program in parallel (such as with @code{make -j}). This
-- 
2.28.0



[PATCH] -fprofile-reproducible: fix option value handling

2020-09-11 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

Before the change option handling did not accept an argument:
  xgcc: error: unknown profile reproducibility method '=serial'
  xgcc: note: valid arguments to '-fprofile-reproducible' are: multithreaded 
parallel-runs serial; did you mean 'serial'?

The change also includes trailing '=' as part of option prefix.

gcc/ChangeLog:

* common.opt: Fix handling of '-fprofile-reproducible' option.
---
 gcc/common.opt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/common.opt b/gcc/common.opt
index dd68c61ae1d..84bf521128d 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2228,7 +2228,7 @@ Enum(profile_reproducibility) String(parallel-runs) 
Value(PROFILE_REPRODUCIBILIT
 EnumValue
 Enum(profile_reproducibility) String(multithreaded) 
Value(PROFILE_REPRODUCIBILITY_MULTITHREADED)
 
-fprofile-reproducible
+fprofile-reproducible=
 Common Joined RejectNegative Var(flag_profile_reproducible) 
Enum(profile_reproducibility) Init(PROFILE_REPRODUCIBILITY_SERIAL)
 -fprofile-reproducible=[serial|parallel-runs|multithreaded]Control level 
of reproducibility of profile gathered by -fprofile-generate.
 
-- 
2.28.0



[PATCH] gcov: fix TOPN streaming from shared libraries

2020-09-06 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

Before the change gcc did not stream correctly TOPN counters
if counters belonged to a non-local shared object.

As a result zero-section optimization generated TOPN sections
in a form not recognizable by '__gcov_merge_topn'.

The problem happens because in a case of multiple shared objects
'__gcov_merge_topn' function is present in address space multiple
times (once per each object).

The fix is to never rely on function address and predicate on TOPN
counter types.

libgcc/ChangeLog:

PR gcov-profile/96913
* libgcov-driver.c (write_one_data): Avoid function pointer
comparison in TOP streaming decision.
---
 libgcc/libgcov-driver.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c
index 58914268d4e..86a6b5ad68a 100644
--- a/libgcc/libgcov-driver.c
+++ b/libgcc/libgcov-driver.c
@@ -424,10 +424,15 @@ write_one_data (const struct gcov_info *gi_ptr,
 
  n_counts = ci_ptr->num;
 
- if (gi_ptr->merge[t_ix] == __gcov_merge_topn)
+ /* Do not zero-compress top counters because:
+  * - __gcv_merge_topn does not handle such sections
+  * - GCOV_COUNTER_V_INDIR contains non-zero keys
+  */
+ if (t_ix == GCOV_COUNTER_V_TOPN || t_ix == GCOV_COUNTER_V_INDIR)
write_top_counters (ci_ptr, t_ix, n_counts);
  else
{
+
  /* Do not stream when all counters are zero.  */
  int all_zeros = 1;
  for (unsigned i = 0; i < n_counts; i++)
-- 
2.28.0



[PATCH] profile: clarify comment around histogram format

2020-09-04 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

gcc/ChangeLog:

* gcc/profile.c (sort_hist_values): Clarify hist format:
start with a value, not counter.
---
 gcc/profile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/profile.c b/gcc/profile.c
index f5c206813c7..fe8963cc9e9 100644
--- a/gcc/profile.c
+++ b/gcc/profile.c
@@ -771,7 +771,7 @@ sort_hist_values (histogram_value hist)
   int counters = hist->hvalue.counters[1];
   for (int i = 0; i < counters - 1; i++)
   /* Hist value is organized as:
- [total_executions, N, counter1, ..., valueN, counterN]
+ [total_executions, N, value1, counter1, ..., valueN, counterN]
  Use decrease bubble sort to rearrange it.  The sort starts from  and compares counter first.  If counter is same, compares the
  value, exchange it if small to keep stable.  */
-- 
2.28.0



[PATCH] var-tracking: fix uninitialised use of 'in_pending' [PR96404]

2020-08-02 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

r11-2447-g:1212cfad093 ("Improve var-tracking dataflow
iteration order") changed 'in_pending' initialization
from:

in_pending = sbitmap_alloc (last_basic_block_for_fn (cfun));
bitmap_ones (in_pending);

to more complex partial bit population algorithm. Due to presence
of uninitialized bits gcc started injecting extra debug entries
in seemigly arbitrary locations and started failing stage2/stage3
bootstrap comparison.

valgrind detected unilitialized bits as:

  Conditional jump or move depends on uninitialised value(s)
 at 0xDBED3B: vt_find_locations() (var-tracking.c:7230)
 by 0xDBF2FB: variable_tracking_main_1() (var-tracking.c:10519)
 ...
   Uninitialised value was created by a heap allocation
 at 0x483779F: malloc (vg_replace_malloc.c:307)
 by 0x14EE80B: xmalloc (xmalloc.c:147)
 by 0x14911F9: sbitmap_alloc(unsigned int) (sbitmap.c:51)
 ...

The fix explicitly initializes 'in_pending' bitmap with zeros.

gcc:

2020-08-02  Sergei Trofimovich  

PR bootstrap96404
* var-tracking.c (vt_find_locations): Fully initialize
all 'in_pending' bits.

Signed-off-by: Sergei Trofimovich 
---
 gcc/var-tracking.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/var-tracking.c b/gcc/var-tracking.c
index 743f5dcecf6..52aea47a053 100644
--- a/gcc/var-tracking.c
+++ b/gcc/var-tracking.c
@@ -7096,6 +7096,7 @@ vt_find_locations (void)
   in_worklist = sbitmap_alloc (last_basic_block_for_fn (cfun));
   in_pending = sbitmap_alloc (last_basic_block_for_fn (cfun));
   bitmap_clear (in_worklist);
+  bitmap_clear (in_pending);
 
   /* We're performing the dataflow iteration independently over the
  toplevel SCCs plus leading non-cyclic entry blocks and separately
-- 
2.28.0



Re: [PATCH] ipa/96291: don't crash on unoptimized lto functions

2020-07-27 Thread Sergei Trofimovich via Gcc-patches
On Mon, 27 Jul 2020 14:41:14 +0200
Martin Jambor  wrote:

> Hi,
> 
> On Mon, Jul 27 2020, Richard Biener via Gcc-patches wrote:
> > On Sat, Jul 25, 2020 at 8:35 PM Sergei Trofimovich via Gcc-patches
> >  wrote:  
> >>
> >> From: Sergei Trofimovich 
> >>
> >> In PR ipa/96291 the test contained an SCC with one
> >> unoptimized function. This tricked ipa-cp into NULL dereference.
> >>
> >> has_undead_caller_from_outside_scc_p() did not take into account
> >> that unoptimized funtions don't have IPA summary analysis. and
> >> dereferenced NULL pointer causing an ICE.  
> >
> > Can you create a single-unit testcase with a SCC with one function
> > having the no_ipa attribute?  
> 
> This bug is LTO specific because otherwise a summary (although marked as
> quite useless) will be left over from the summary building stage.

Yeah, I was not able to shrink the example even down to 2 files.

> So Sergei, if you can afford to spend an extra while providing a
> testcase, you'll need to add three files into gcc/testsuite/gcc.dg/lto,
> with either the second or third (numbered _1 or _2)) having

Sounds good! I tried is as:
https://gcc.gnu.org/pipermail/gcc-patches/2020-July/550817.html

> /* { dg-lto-options { { -flto -O0 } } } */

I used "/* { dg-options {-O0} } */" looking at pr88077_1.c which uses
"/* { dg-options {-fcommon} } */".  But only now looked closer at your
suggestion.

Should I resend with "/* { dg-lto-options { { -flto -O0 } } } */"? I need
a bit or help to understand the difference :)

-- 

  Sergei


[PATCH v2] ipa/96291: don't crash on unoptimized lto functions

2020-07-27 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

In PR ipa/96291 the test contained an SCC with one
unoptimized function. This tricked ipa-cp into NULL dereference.

has_undead_caller_from_outside_scc_p() did not take into account
that unoptimized funtions don't have IPA summary analysis. And
dereferenced NULL pointer causing an ICE.

gcc/
PR ipa/96291
* ipa-cp.c (has_undead_caller_from_outside_scc_p): Consider
unoptimized callers as undead.

gcc/testsuite/
PR ipa/96291
* gcc.dg/lto/pr96291_0.c: New testcase.
* gcc.dg/lto/pr96291_1.c: Support file.
* gcc.dg/lto/pr96291_2.c: Likewise.
* gcc.dg/lto/pr96291.h: Likewise.
---
 gcc/ipa-cp.c |  5 +++--
 gcc/testsuite/gcc.dg/lto/pr96291.h   |  4 
 gcc/testsuite/gcc.dg/lto/pr96291_0.c | 11 +++
 gcc/testsuite/gcc.dg/lto/pr96291_1.c |  3 +++
 gcc/testsuite/gcc.dg/lto/pr96291_2.c |  7 +++
 5 files changed, 28 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/lto/pr96291.h
 create mode 100644 gcc/testsuite/gcc.dg/lto/pr96291_0.c
 create mode 100644 gcc/testsuite/gcc.dg/lto/pr96291_1.c
 create mode 100644 gcc/testsuite/gcc.dg/lto/pr96291_2.c

diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index b0c8f405260..fe010ff457c 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -5667,8 +5667,9 @@ has_undead_caller_from_outside_scc_p (struct cgraph_node 
*node,
  (has_undead_caller_from_outside_scc_p, NULL, true))
   return true;
 else if (!ipa_edge_within_scc (cs)
-&& !IPA_NODE_REF (cs->caller)->node_dead)
-  return true;
+&& (!IPA_NODE_REF (cs->caller) /* Unoptimized caller.  */
+|| !IPA_NODE_REF (cs->caller)->node_dead))
+ return true;
   return false;
 }
 
diff --git a/gcc/testsuite/gcc.dg/lto/pr96291.h 
b/gcc/testsuite/gcc.dg/lto/pr96291.h
new file mode 100644
index 000..70eb3cb71b8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/pr96291.h
@@ -0,0 +1,4 @@
+void e(void);
+void f(void);
+void a(void *, void *);
+void c(int);
diff --git a/gcc/testsuite/gcc.dg/lto/pr96291_0.c 
b/gcc/testsuite/gcc.dg/lto/pr96291_0.c
new file mode 100644
index 000..07e63038e03
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/pr96291_0.c
@@ -0,0 +1,11 @@
+/* { dg-lto-do link } */
+
+#include "pr96291.h"
+
+static void * b;
+void c(int d) {
+  f();
+  a(b, b);
+}
+
+void e(void) { c(0); }
diff --git a/gcc/testsuite/gcc.dg/lto/pr96291_1.c 
b/gcc/testsuite/gcc.dg/lto/pr96291_1.c
new file mode 100644
index 000..44744a94941
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/pr96291_1.c
@@ -0,0 +1,3 @@
+#include "pr96291.h"
+
+void f(void) { c(0); }
diff --git a/gcc/testsuite/gcc.dg/lto/pr96291_2.c 
b/gcc/testsuite/gcc.dg/lto/pr96291_2.c
new file mode 100644
index 000..5febffbb00c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/pr96291_2.c
@@ -0,0 +1,7 @@
+/* { dg-options {-O0} } */
+
+#include "pr96291.h"
+
+void a(void * a1, void * a2) { e(); }
+
+int main(){}
-- 
2.27.0



[PATCH] ipa/96291: don't crash on unoptimized lto functions

2020-07-25 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

In PR ipa/96291 the test contained an SCC with one
unoptimized function. This tricked ipa-cp into NULL dereference.

has_undead_caller_from_outside_scc_p() did not take into account
that unoptimized funtions don't have IPA summary analysis. and
dereferenced NULL pointer causing an ICE.

PR ipa/96291
* ipa-cp.c (has_undead_caller_from_outside_scc_p): Consider
unoptimized callers as undead.
---
 gcc/ipa-cp.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index b0c8f405260..d5082576962 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -5666,9 +5666,15 @@ has_undead_caller_from_outside_scc_p (struct cgraph_node 
*node,
&& cs->caller->call_for_symbol_thunks_and_aliases
  (has_undead_caller_from_outside_scc_p, NULL, true))
   return true;
-else if (!ipa_edge_within_scc (cs)
-&& !IPA_NODE_REF (cs->caller)->node_dead)
-  return true;
+else if (!ipa_edge_within_scc (cs))
+  {
+   /* Unoptimized callers don't have IPA information.
+  Conservatively assume callers are undead.  */
+   if (!IPA_NODE_REF (cs->caller))
+ return true;
+   if (!IPA_NODE_REF (cs->caller)->node_dead)
+ return true;
+  }
   return false;
 }
 
-- 
2.27.0



Re: [PATCH v2] sparc/sparc64: use crtendS.o for default-pie executables [PR96190]

2020-07-20 Thread Sergei Trofimovich via Gcc-patches
On Fri, 17 Jul 2020 10:19:41 +0200
Eric Botcazou  wrote:

> > Oh! Sent out v3 with tweaked description as
> > https://gcc.gnu.org/pipermail/gcc-patches/2020-July/550168.html  
> 
> Thanks.
> 
> > I don't have a push access to gcc tree. Should I request one via
> > https://sourceware.org/cgi-bin/pdw/ps_form.cgi ?  
> 
> Sure, you can put me (ebotca...@libertysurf.fr) as sponsor if need be.

Got access and pushed as https://gcc.gnu.org/g:87891d5eafe8
Will cherry-pick it to gcc-10 as well after 10.2 release.

Thank you!

-- 

  Sergei


Re: [PATCH v2] sparc/sparc64: use crtendS.o for default-pie executables [PR96190]

2020-07-16 Thread Sergei Trofimovich via Gcc-patches
On Wed, 15 Jul 2020 13:46:12 +0200
Eric Botcazou  wrote:

> > This should be:
> > 
> > PR target/96190
> > * config/sparc/linux.h (ENDFILE_SPEC): Use GNU_USER_TARGET_ENDFILE_SPEC
> > to get crtendS.o for !no-pie mode.
> > * config/sparc/linux64.h(ENDFILE_SPEC): Ditto.  
> 
>   * config/sparc/linux64.h (ENDFILE_SPEC): Ditto.
> 
> > OK for mainline with this change.  You can also put it on the 10 branch
> > after the 10.1 release is out if this is deemed necessary.  
> 
> 10.2

Oh! Sent out v3 with tweaked description as
https://gcc.gnu.org/pipermail/gcc-patches/2020-July/550168.html

I don't have a push access to gcc tree. Should I request one via
https://sourceware.org/cgi-bin/pdw/ps_form.cgi ?

-- 

  Sergei


[PATCH v3] sparc/sparc64: use crtendS.o for default-pie executables [PR96190]

2020-07-16 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

In --enable-default-pie mode compiler should switch from
using crtend.o to crtendS.o. On sparc it is especially important
because crtend.o contains PIC-unfriendly code.

We use GNU_USER_TARGET_ENDFILE_SPEC as a baseline spec to get
crtendS.o instead of crtend.o in !no-pie mode.

gcc:

2020-07-14  Sergei Trofimovich  

PR target/96190
* config/sparc/linux.h (ENDFILE_SPEC): Use GNU_USER_TARGET_ENDFILE_SPEC
to get crtendS.o for !no-pie mode.
* config/sparc/linux64.h (ENDFILE_SPEC): Ditto.
---
 gcc/config/sparc/linux.h   | 10 ++
 gcc/config/sparc/linux64.h | 10 ++
 2 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/gcc/config/sparc/linux.h b/gcc/config/sparc/linux.h
index 81201e67a2f..63853e60c03 100644
--- a/gcc/config/sparc/linux.h
+++ b/gcc/config/sparc/linux.h
@@ -27,16 +27,10 @@ along with GCC; see the file COPYING3.  If not see
 }  \
   while (0)
 
-/* Provide a ENDFILE_SPEC appropriate for GNU/Linux.  Here we tack on
-   the GNU/Linux magical crtend.o file (see crtstuff.c) which
-   provides part of the support for getting C++ file-scope static
-   object constructed before entering `main', followed by a normal
-   GNU/Linux "finalizer" file, `crtn.o'.  */
-
 #undef  ENDFILE_SPEC
 #define ENDFILE_SPEC \
-  "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s\
-   %{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}"
+  GNU_USER_TARGET_ENDFILE_SPEC \
+  "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}"
 
 /* -mcpu=native handling only makes sense with compiler running on
a SPARC chip.  */
diff --git a/gcc/config/sparc/linux64.h b/gcc/config/sparc/linux64.h
index a1a0efd8f28..19ce84d7adb 100644
--- a/gcc/config/sparc/linux64.h
+++ b/gcc/config/sparc/linux64.h
@@ -44,16 +44,10 @@ along with GCC; see the file COPYING3.  If not see
 #undef ASM_CPU64_DEFAULT_SPEC
 #define ASM_CPU64_DEFAULT_SPEC "-Av9a"
 
-/* Provide a ENDFILE_SPEC appropriate for GNU/Linux.  Here we tack on
-   the GNU/Linux magical crtend.o file (see crtstuff.c) which
-   provides part of the support for getting C++ file-scope static
-   object constructed before entering `main', followed by a normal
-   GNU/Linux "finalizer" file, `crtn.o'.  */
-
 #undef ENDFILE_SPEC
 #define ENDFILE_SPEC \
-  "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s\
-   %{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}"
+  GNU_USER_TARGET_ENDFILE_SPEC \
+  "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}"
 
 /* The default code model.  */
 #undef SPARC_DEFAULT_CMODEL
-- 
2.27.0



[PATCH v2] sparc/sparc64: use crtendS.o for default-pie executables [PR96190]

2020-07-14 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

In --enable-default-pie mode compiler should switch from
using crtend.o to crtendS.o. On sparc it is especially important
because crtend.o contains PIC-unfriendly code.

We use GNU_USER_TARGET_ENDFILE_SPEC as a baseline spec to get
crtendS.o instead of crtend.o in !no-pie mode.

gcc:

2020-07-14  Sergei Trofimovich  

PR target/96190
* config/sparc/linux.h: Extend GNU_USER_TARGET_ENDFILE_SPEC
to get crtendS.o for !no-pie mode.
* config/sparc/linux64.h: Ditto.
---
 gcc/config/sparc/linux.h   | 10 ++
 gcc/config/sparc/linux64.h | 10 ++
 2 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/gcc/config/sparc/linux.h b/gcc/config/sparc/linux.h
index 81201e67a2f..63853e60c03 100644
--- a/gcc/config/sparc/linux.h
+++ b/gcc/config/sparc/linux.h
@@ -27,16 +27,10 @@ along with GCC; see the file COPYING3.  If not see
 }  \
   while (0)
 
-/* Provide a ENDFILE_SPEC appropriate for GNU/Linux.  Here we tack on
-   the GNU/Linux magical crtend.o file (see crtstuff.c) which
-   provides part of the support for getting C++ file-scope static
-   object constructed before entering `main', followed by a normal
-   GNU/Linux "finalizer" file, `crtn.o'.  */
-
 #undef  ENDFILE_SPEC
 #define ENDFILE_SPEC \
-  "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s\
-   %{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}"
+  GNU_USER_TARGET_ENDFILE_SPEC \
+  "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}"
 
 /* -mcpu=native handling only makes sense with compiler running on
a SPARC chip.  */
diff --git a/gcc/config/sparc/linux64.h b/gcc/config/sparc/linux64.h
index a1a0efd8f28..19ce84d7adb 100644
--- a/gcc/config/sparc/linux64.h
+++ b/gcc/config/sparc/linux64.h
@@ -44,16 +44,10 @@ along with GCC; see the file COPYING3.  If not see
 #undef ASM_CPU64_DEFAULT_SPEC
 #define ASM_CPU64_DEFAULT_SPEC "-Av9a"
 
-/* Provide a ENDFILE_SPEC appropriate for GNU/Linux.  Here we tack on
-   the GNU/Linux magical crtend.o file (see crtstuff.c) which
-   provides part of the support for getting C++ file-scope static
-   object constructed before entering `main', followed by a normal
-   GNU/Linux "finalizer" file, `crtn.o'.  */
-
 #undef ENDFILE_SPEC
 #define ENDFILE_SPEC \
-  "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s\
-   %{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}"
+  GNU_USER_TARGET_ENDFILE_SPEC \
+  "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}"
 
 /* The default code model.  */
 #undef SPARC_DEFAULT_CMODEL
-- 
2.27.0



[PATCH] sparc/sparc64: use PIE_SPEC to select crtendS.o [PR96190]

2020-07-14 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

In --enable-default-pie mode compiler should switch from
using crtend.o to crtendS.o. On sparc it is especially visible
because crtend.o contains PIC-unfriendly code.

gcc:

2020-07-14  Sergei Trofimovich  

PR driver/96190
* config/sparc/linux.h: Use PIE_SPEC to select crtendS.o.
* config/sparc/linux64.h: ditto
---
 gcc/config/sparc/linux.h   | 2 +-
 gcc/config/sparc/linux64.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/config/sparc/linux.h b/gcc/config/sparc/linux.h
index 81201e67a2f..13d1d60 100644
--- a/gcc/config/sparc/linux.h
+++ b/gcc/config/sparc/linux.h
@@ -35,7 +35,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #undef  ENDFILE_SPEC
 #define ENDFILE_SPEC \
-  "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s\
+  "%{shared|" PIE_SPEC ":crtendS.o%s;:crtend.o%s} crtn.o%s\
%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}"
 
 /* -mcpu=native handling only makes sense with compiler running on
diff --git a/gcc/config/sparc/linux64.h b/gcc/config/sparc/linux64.h
index a1a0efd8f28..be937dbaaf6 100644
--- a/gcc/config/sparc/linux64.h
+++ b/gcc/config/sparc/linux64.h
@@ -52,7 +52,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #undef ENDFILE_SPEC
 #define ENDFILE_SPEC \
-  "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s\
+  "%{shared|" PIE_SPEC ":crtendS.o%s;:crtend.o%s} crtn.o%s\
%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}"
 
 /* The default code model.  */
-- 
2.27.0



[OBSOLETE][PATCH] PR preprocessor/94657: use $AR, not 'ar',

2020-05-28 Thread Sergei Trofimovich via Gcc-patches
On Thu, 7 May 2020 08:18:31 +0100
Sergei Trofimovich via Gcc-patches  wrote:

> On Wed, 22 Apr 2020 23:05:38 +0100
> Sergei Trofimovich  wrote:
> 
> > From: Sergei Trofimovich 
> > 
> > On system with 'ar' and '${CHOST}-ar' the latter is preferred.
> > as it might not match default 'ar'.
> > 
> > Bug is initially reported downstream as https://bugs.gentoo.org/718004.
> > 
> > libcpp/ChangeLog:
> > 
> > PR libcpp/94657
> > * Makefile.in: use @AR@ placeholder
> > * configure.ac: use AC_CHECK_TOOL to find 'ar'
> > * configure: regenerate
> > ---
> >  libcpp/ChangeLog|  7 
> >  libcpp/Makefile.in  |  2 +-
> >  libcpp/configure| 94 +
> >  libcpp/configure.ac |  1 +
> >  4 files changed, 103 insertions(+), 1 deletion(-)
> > 
> > diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
> > index 307cf3add94..77145768a3d 100644
> > --- a/libcpp/ChangeLog
> > +++ b/libcpp/ChangeLog
> > @@ -1,3 +1,10 @@
> > +2020-04-22  Sergei Trofimovich  
> > +
> > +   PR preprocessor/94657: use $AR, not 'ar'
> > +   * Makefile.in: use @AR@ placeholder
> > +   * configure.ac: use AC_CHECK_TOOL to find 'ar'
> > +   * configure: regenerate
> > +
> >  2020-02-14  Jakub Jelinek  
> >  
> > Partially implement P1042R1: __VA_OPT__ wording clarifications
> > diff --git a/libcpp/Makefile.in b/libcpp/Makefile.in
> > index 8f8c8f65eb3..af7a0c6f73e 100644
> > --- a/libcpp/Makefile.in
> > +++ b/libcpp/Makefile.in
> > @@ -25,7 +25,7 @@ srcdir = @srcdir@
> >  top_builddir = .
> >  VPATH = @srcdir@
> >  INSTALL = @INSTALL@
> > -AR = ar
> > +AR = @AR@
> >  ARFLAGS = cru
> >  ACLOCAL = @ACLOCAL@
> >  AUTOCONF = @AUTOCONF@
> > diff --git a/libcpp/configure b/libcpp/configure
> > index 11da199083b..a6dcf5dcb61 100755
> > --- a/libcpp/configure
> > +++ b/libcpp/configure
> > @@ -657,6 +657,7 @@ ACLOCAL
> >  EGREP
> >  GREP
> >  CPP
> > +AR
> >  RANLIB
> >  ac_ct_CXX
> >  CXXFLAGS
> > @@ -1039,6 +1040,7 @@ do
> >| -silent | --silent | --silen | --sile | --sil)
> >  silent=yes ;;
> >  
> > +
> >-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
> >  ac_prev=sbindir ;;
> >-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
> > @@ -4008,6 +4010,98 @@ else
> >RANLIB="$ac_cv_prog_RANLIB"
> >  fi
> >  
> > +if test -n "$ac_tool_prefix"; then
> > +  # Extract the first word of "${ac_tool_prefix}ar", so it can be a 
> > program name with args.
> > +set dummy ${ac_tool_prefix}ar; ac_word=$2
> > +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
> > +$as_echo_n "checking for $ac_word... " >&6; }
> > +if ${ac_cv_prog_AR+:} false; then :
> > +  $as_echo_n "(cached) " >&6
> > +else
> > +  if test -n "$AR"; then
> > +  ac_cv_prog_AR="$AR" # Let the user override the test.
> > +else
> > +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
> > +for as_dir in $PATH
> > +do
> > +  IFS=$as_save_IFS
> > +  test -z "$as_dir" && as_dir=.
> > +for ac_exec_ext in '' $ac_executable_extensions; do
> > +  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
> > +ac_cv_prog_AR="${ac_tool_prefix}ar"
> > +$as_echo "$as_me:${as_lineno-$LINENO}: found 
> > $as_dir/$ac_word$ac_exec_ext" >&5
> > +break 2
> > +  fi
> > +done
> > +  done
> > +IFS=$as_save_IFS
> > +
> > +fi
> > +fi
> > +AR=$ac_cv_prog_AR
> > +if test -n "$AR"; then
> > +  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5
> > +$as_echo "$AR" >&6; }
> > +else
> > +  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
> > +$as_echo "no" >&6; }
> > +fi
> > +
> > +
> > +fi
> > +if test -z "$ac_cv_prog_AR"; then
> > +  ac_ct_AR=$AR
> > +  # Extract the first word of "ar", so it can be a program name with args.
> > +set dummy ar; ac_word=$2
> > +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
> > +$as_echo_n "checking for $ac_word... " >&6; }
> > +if ${ac_cv_prog_ac_ct_AR+:} false; then :
> > +  $as_echo_n "(cached) " >&6
> >

Re: [PATCH] PR preprocessor/94657: use $AR, not 'ar',

2020-05-07 Thread Sergei Trofimovich via Gcc-patches
On Wed, 22 Apr 2020 23:05:38 +0100
Sergei Trofimovich  wrote:

> From: Sergei Trofimovich 
> 
> On system with 'ar' and '${CHOST}-ar' the latter is preferred.
> as it might not match default 'ar'.
> 
> Bug is initially reported downstream as https://bugs.gentoo.org/718004.
> 
> libcpp/ChangeLog:
> 
>   PR libcpp/94657
>   * Makefile.in: use @AR@ placeholder
>   * configure.ac: use AC_CHECK_TOOL to find 'ar'
>   * configure: regenerate
> ---
>  libcpp/ChangeLog|  7 
>  libcpp/Makefile.in  |  2 +-
>  libcpp/configure| 94 +
>  libcpp/configure.ac |  1 +
>  4 files changed, 103 insertions(+), 1 deletion(-)
> 
> diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
> index 307cf3add94..77145768a3d 100644
> --- a/libcpp/ChangeLog
> +++ b/libcpp/ChangeLog
> @@ -1,3 +1,10 @@
> +2020-04-22  Sergei Trofimovich  
> +
> + PR preprocessor/94657: use $AR, not 'ar'
> + * Makefile.in: use @AR@ placeholder
> + * configure.ac: use AC_CHECK_TOOL to find 'ar'
> + * configure: regenerate
> +
>  2020-02-14  Jakub Jelinek  
>  
>   Partially implement P1042R1: __VA_OPT__ wording clarifications
> diff --git a/libcpp/Makefile.in b/libcpp/Makefile.in
> index 8f8c8f65eb3..af7a0c6f73e 100644
> --- a/libcpp/Makefile.in
> +++ b/libcpp/Makefile.in
> @@ -25,7 +25,7 @@ srcdir = @srcdir@
>  top_builddir = .
>  VPATH = @srcdir@
>  INSTALL = @INSTALL@
> -AR = ar
> +AR = @AR@
>  ARFLAGS = cru
>  ACLOCAL = @ACLOCAL@
>  AUTOCONF = @AUTOCONF@
> diff --git a/libcpp/configure b/libcpp/configure
> index 11da199083b..a6dcf5dcb61 100755
> --- a/libcpp/configure
> +++ b/libcpp/configure
> @@ -657,6 +657,7 @@ ACLOCAL
>  EGREP
>  GREP
>  CPP
> +AR
>  RANLIB
>  ac_ct_CXX
>  CXXFLAGS
> @@ -1039,6 +1040,7 @@ do
>| -silent | --silent | --silen | --sile | --sil)
>  silent=yes ;;
>  
> +
>-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
>  ac_prev=sbindir ;;
>-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
> @@ -4008,6 +4010,98 @@ else
>RANLIB="$ac_cv_prog_RANLIB"
>  fi
>  
> +if test -n "$ac_tool_prefix"; then
> +  # Extract the first word of "${ac_tool_prefix}ar", so it can be a program 
> name with args.
> +set dummy ${ac_tool_prefix}ar; ac_word=$2
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
> +$as_echo_n "checking for $ac_word... " >&6; }
> +if ${ac_cv_prog_AR+:} false; then :
> +  $as_echo_n "(cached) " >&6
> +else
> +  if test -n "$AR"; then
> +  ac_cv_prog_AR="$AR" # Let the user override the test.
> +else
> +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
> +for as_dir in $PATH
> +do
> +  IFS=$as_save_IFS
> +  test -z "$as_dir" && as_dir=.
> +for ac_exec_ext in '' $ac_executable_extensions; do
> +  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
> +ac_cv_prog_AR="${ac_tool_prefix}ar"
> +$as_echo "$as_me:${as_lineno-$LINENO}: found 
> $as_dir/$ac_word$ac_exec_ext" >&5
> +break 2
> +  fi
> +done
> +  done
> +IFS=$as_save_IFS
> +
> +fi
> +fi
> +AR=$ac_cv_prog_AR
> +if test -n "$AR"; then
> +  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5
> +$as_echo "$AR" >&6; }
> +else
> +  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
> +$as_echo "no" >&6; }
> +fi
> +
> +
> +fi
> +if test -z "$ac_cv_prog_AR"; then
> +  ac_ct_AR=$AR
> +  # Extract the first word of "ar", so it can be a program name with args.
> +set dummy ar; ac_word=$2
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
> +$as_echo_n "checking for $ac_word... " >&6; }
> +if ${ac_cv_prog_ac_ct_AR+:} false; then :
> +  $as_echo_n "(cached) " >&6
> +else
> +  if test -n "$ac_ct_AR"; then
> +  ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test.
> +else
> +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
> +for as_dir in $PATH
> +do
> +  IFS=$as_save_IFS
> +  test -z "$as_dir" && as_dir=.
> +for ac_exec_ext in '' $ac_executable_extensions; do
> +  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
> +ac_cv_prog_ac_ct_AR="ar"
> +$as_echo "$as_me:${as_lineno-$LINENO}: found 
> $as_dir/$ac_word$ac_exec_ext" >&5
> +break 2
> +  fi
> +done
> +  done
> +IFS=$as_save_IFS

[PATCH] PR preprocessor/94657: use $AR, not 'ar',

2020-04-22 Thread Sergei Trofimovich
From: Sergei Trofimovich 

On system with 'ar' and '${CHOST}-ar' the latter is preferred.
as it might not match default 'ar'.

Bug is initially reported downstream as https://bugs.gentoo.org/718004.

libcpp/ChangeLog:

PR libcpp/94657
* Makefile.in: use @AR@ placeholder
* configure.ac: use AC_CHECK_TOOL to find 'ar'
* configure: regenerate
---
 libcpp/ChangeLog|  7 
 libcpp/Makefile.in  |  2 +-
 libcpp/configure| 94 +
 libcpp/configure.ac |  1 +
 4 files changed, 103 insertions(+), 1 deletion(-)

diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 307cf3add94..77145768a3d 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,10 @@
+2020-04-22  Sergei Trofimovich  
+
+   PR preprocessor/94657: use $AR, not 'ar'
+   * Makefile.in: use @AR@ placeholder
+   * configure.ac: use AC_CHECK_TOOL to find 'ar'
+   * configure: regenerate
+
 2020-02-14  Jakub Jelinek  
 
Partially implement P1042R1: __VA_OPT__ wording clarifications
diff --git a/libcpp/Makefile.in b/libcpp/Makefile.in
index 8f8c8f65eb3..af7a0c6f73e 100644
--- a/libcpp/Makefile.in
+++ b/libcpp/Makefile.in
@@ -25,7 +25,7 @@ srcdir = @srcdir@
 top_builddir = .
 VPATH = @srcdir@
 INSTALL = @INSTALL@
-AR = ar
+AR = @AR@
 ARFLAGS = cru
 ACLOCAL = @ACLOCAL@
 AUTOCONF = @AUTOCONF@
diff --git a/libcpp/configure b/libcpp/configure
index 11da199083b..a6dcf5dcb61 100755
--- a/libcpp/configure
+++ b/libcpp/configure
@@ -657,6 +657,7 @@ ACLOCAL
 EGREP
 GREP
 CPP
+AR
 RANLIB
 ac_ct_CXX
 CXXFLAGS
@@ -1039,6 +1040,7 @@ do
   | -silent | --silent | --silen | --sile | --sil)
 silent=yes ;;
 
+
   -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
 ac_prev=sbindir ;;
   -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@@ -4008,6 +4010,98 @@ else
   RANLIB="$ac_cv_prog_RANLIB"
 fi
 
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}ar", so it can be a program 
name with args.
+set dummy ${ac_tool_prefix}ar; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_AR+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$AR"; then
+  ac_cv_prog_AR="$AR" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ac_cv_prog_AR="${ac_tool_prefix}ar"
+$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" 
>&5
+break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+AR=$ac_cv_prog_AR
+if test -n "$AR"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5
+$as_echo "$AR" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_AR"; then
+  ac_ct_AR=$AR
+  # Extract the first word of "ar", so it can be a program name with args.
+set dummy ar; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_AR+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_AR"; then
+  ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ac_cv_prog_ac_ct_AR="ar"
+$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" 
>&5
+break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_AR=$ac_cv_prog_ac_ct_AR
+if test -n "$ac_ct_AR"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5
+$as_echo "$ac_ct_AR" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_AR" = x; then
+AR=""
+  else
+case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not 
prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" 
>&2;}
+ac_tool_warned=yes ;;
+esac
+AR=$ac_ct_AR
+  fi
+else
+  AR="$ac_cv_prog_AR"
+fi
+
 
 
 ac_ext=c
diff --git a/libcpp/configure.ac b/libcpp/configure.ac
index 1779562a3a7..9ccfb02aa13 100644
--- a/libcpp/configure.ac
+++ b/libcpp/configure.ac
@@ -12,6 +12,7 @@ AC_PROG_INSTALL
 AC_PROG_CC
 AC_PROG_CXX
 AC_PROG_RANLIB
+AC_CHECK_TOOL(AR, ar)
 
 AC_USE_SYSTEM_EXTENSIONS
 AC_SYS_LARGEFILE
-- 
2.26.2



Re: [PATCH] asan_test.C: disable -Wstringop-overflow, PR/93058

2020-01-24 Thread Sergei Trofimovich via gcc-patches
On Fri, 24 Jan 2020 22:20:43 +0100
Jakub Jelinek  wrote:

> On Fri, Jan 24, 2020 at 07:57:22AM +, slyfox.inbox.ru via gcc-patches 
> wrote:
> > From: Sergei Trofimovich 
> > 
> > From: Sergei Trofimovich 
> > 
> > asan's test allocates 2 pages via pvalloc(kPageSize + 100)
> > and makes sure dereference of 'kPageSize + 101' does not
> > trigger asan checks.
> > 
> > glibc's and gcc's malloc-like attribute checkers trigger
> > a warning:
> > asan_test.cc:129:22: error: writing 1 byte into a region
> > of size 0 [-Werror=stringop-overflow=]
> > 
> > As there is no easy way to convey pvalloc()'s granularity
> > to gcc let's just disable the warning for this test.
> > 
> > * g++.dg/asan/asan_test.C: disable -Wstringop-overflow.  
> 
> No.  That is a glibc bug and it has been fixed in glibc already, if we
> disabled this, we might never discovered it.

Aha, I assume it was fixed by 
https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=768c83b7f60d82db6677e19dc51be9f341e0f3fc

I'll close gcc PR as invalid then.

Thank you!

-- 

  Sergei


pgpvHeT_dmPCm.pgp
Description: Цифровая подпись OpenPGP


Re: [PATCH v2] libgcc: m68k: avoid TEXTRELs in shared library (PR 86224)

2018-09-17 Thread Sergei Trofimovich via gcc-patches
On Mon, 17 Sep 2018 15:29:08 -0600
Jeff Law  wrote:

> On 9/17/18 3:18 PM, Sergei Trofimovich wrote:
> > On Sat, 28 Jul 2018 20:42:02 +0100
> > "slyfox.inbox.ru via gcc-patches"  wrote:
> >   
> >> From: Sergei Trofimovich 
> >>
> >> Cc: Ian Lance Taylor 
> >> Cc: Jeff Law 
> >> Cc: Andreas Schwab 
> >> Signed-off-by: Sergei Trofimovich 
> >> ---
> >>  libgcc/config/m68k/lb1sf68.S | 3 +++
> >>  1 file changed, 3 insertions(+)
> >>
> >> diff --git a/libgcc/config/m68k/lb1sf68.S b/libgcc/config/m68k/lb1sf68.S
> >> index 325a7c17d9b..d5240d4aa55 100644
> >> --- a/libgcc/config/m68k/lb1sf68.S
> >> +++ b/libgcc/config/m68k/lb1sf68.S
> >> @@ -435,6 +435,7 @@ $_exception_handler:
> >>.text
> >>FUNC(__mulsi3)
> >>.globl  SYM (__mulsi3)
> >> +  .hidden SYM (__mulsi3)
> >>  SYM (__mulsi3):
> >>movew   sp@(4), d0  /* x0 -> d0 */
> >>muluw   sp@(10), d0 /* x0*y1 */
> >> @@ -458,6 +459,7 @@ SYM (__mulsi3):
> >>.text
> >>FUNC(__udivsi3)
> >>.globl  SYM (__udivsi3)
> >> +  .hidden SYM (__udivsi3)
> >>  SYM (__udivsi3):
> >>  #ifndef __mcoldfire__
> >>movel   d2, sp@-
> >> @@ -534,6 +536,7 @@ L2:subql   IMM (1),d4
> >>.text
> >>FUNC(__divsi3)
> >>.globl  SYM (__divsi3)
> >> +  .hidden SYM (__divsi3)
> >>  SYM (__divsi3):
> >>movel   d2, sp@-
> >>  
> >> -- 
> >> 2.18.0
> >>  
> > 
> > Patch ping. Not sure which is preferable v1 (as other targets do) or v2.  
> Hmm, I thought Andreas NAK'd V1.  And I think Rich's comments
> essentially NAK'd V2.

Aha. I'm trying to clarify the desired state then to try to tweak
patch properly:

Current:
  - static library:
* global public __divsi3
  - shared library: 
* global public __divsi3

Desired:
  - static library:
* global hidden __divsi3 [ABI change:public->hidden]
  - shared library: 
* global public __divsi3 [no change]
* global hidden __divsi3_internal [change:new symbol for internal 
references]

Does that sound reasonable?
Should all targets follow the same pattern? I think they don't today.

v1 was a step in desired direction but without user-visible ABI change.

-- 

  Sergei


pgppmyTjSoYAk.pgp
Description: Цифровая подпись OpenPGP


Re: [PATCH v2] libgcc: m68k: avoid TEXTRELs in shared library (PR 86224)

2018-09-17 Thread Sergei Trofimovich via gcc-patches
On Sat, 28 Jul 2018 20:42:02 +0100
"slyfox.inbox.ru via gcc-patches"  wrote:

> From: Sergei Trofimovich 
> 
> Cc: Ian Lance Taylor 
> Cc: Jeff Law 
> Cc: Andreas Schwab 
> Signed-off-by: Sergei Trofimovich 
> ---
>  libgcc/config/m68k/lb1sf68.S | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/libgcc/config/m68k/lb1sf68.S b/libgcc/config/m68k/lb1sf68.S
> index 325a7c17d9b..d5240d4aa55 100644
> --- a/libgcc/config/m68k/lb1sf68.S
> +++ b/libgcc/config/m68k/lb1sf68.S
> @@ -435,6 +435,7 @@ $_exception_handler:
>   .text
>   FUNC(__mulsi3)
>   .globl  SYM (__mulsi3)
> + .hidden SYM (__mulsi3)
>  SYM (__mulsi3):
>   movew   sp@(4), d0  /* x0 -> d0 */
>   muluw   sp@(10), d0 /* x0*y1 */
> @@ -458,6 +459,7 @@ SYM (__mulsi3):
>   .text
>   FUNC(__udivsi3)
>   .globl  SYM (__udivsi3)
> + .hidden SYM (__udivsi3)
>  SYM (__udivsi3):
>  #ifndef __mcoldfire__
>   movel   d2, sp@-
> @@ -534,6 +536,7 @@ L2:   subql   IMM (1),d4
>   .text
>   FUNC(__divsi3)
>   .globl  SYM (__divsi3)
> + .hidden SYM (__divsi3)
>  SYM (__divsi3):
>   movel   d2, sp@-
>  
> -- 
> 2.18.0
> 

Patch ping. Not sure which is preferable v1 (as other targets do) or v2.

-- 

  Sergei


pgpLNOtBofVZq.pgp
Description: Цифровая подпись OpenPGP


Re: [PATCH] libgcc: m68k: avoid TEXTRELs in shared library (PR 86224)

2018-07-29 Thread Sergei Trofimovich via gcc-patches
On Sat, 28 Jul 2018 21:11:22 -0400
Rich Felker  wrote:

> On Sat, Jul 28, 2018 at 08:47:33PM +0200, Andreas Schwab wrote:
> > On Jul 28 2018, sly...@inbox.ru wrote:
> >   
> > > From: Sergei Trofimovich 
> > >
> > > Cc: Ian Lance Taylor 
> > > Cc: Jeff Law 
> > > Cc: Andreas Schwab 
> > > Signed-off-by: Sergei Trofimovich 
> > > ---
> > >  libgcc/config/m68k/lb1sf68.S | 19 ++-
> > >  1 file changed, 14 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/libgcc/config/m68k/lb1sf68.S b/libgcc/config/m68k/lb1sf68.S
> > > index 325a7c17d9b..16c6dc3f5a7 100644
> > > --- a/libgcc/config/m68k/lb1sf68.S
> > > +++ b/libgcc/config/m68k/lb1sf68.S
> > > @@ -435,7 +435,10 @@ $_exception_handler:
> > >   .text
> > >   FUNC(__mulsi3)
> > >   .globl  SYM (__mulsi3)
> > > + .globl  SYM (__mulsi3_internal)
> > > + .hidden SYM (__mulsi3_internal)  
> > 
> > No need for extra entry symbols, just mark the real entry point as
> > hidden, like in the static library.  
> 
> That's clearly not correct or valid, as these are public interfaces.
> If you make them hidden they'll be dropped from the dynamic symbol
> table of libgcc_s.so.
> 
> Of course for libgcc.a they need to be hidden (it's an ABI bug if
> they're not hidden there already but I think there's a separate layer
> of the build system that forces them to be hidden).
> 
> Rich

Oh, that's a good point! gcc/doc/libgcc.texi also suggests __
is the libgcc_s API. Would it make sense for gcc/doc/libgcc.texi to be
expanded to more explicitly articulate expectation of symbol visibility
on ELF platforms?

-- 

  Sergei


pgpFr9m_8Gb8s.pgp
Description: Цифровая подпись OpenPGP


[PATCH] gcc/configure.ac: add --disable-systemtap switch

2018-05-12 Thread Sergei Trofimovich via gcc-patches
From: Sergei Trofimovich <sly...@gentoo.org>

Before the change systemtap probes were enabled
if target headers had sys/sdt.h at ./configure time.

After the change explicitly ask to enable or disable
for probe support and not rely on automagic dependency
discovery.

Bug: https://bugs.gentoo.org/654748
Bug: https://gcc.gnu.org/bugzilla/PR61257
Signed-off-by: Sergei Trofimovich <sly...@gentoo.org>
---
 gcc/configure| 34 ++
 gcc/configure.ac | 30 ++
 2 files changed, 48 insertions(+), 16 deletions(-)

diff --git a/gcc/configure b/gcc/configure
index 7d69faf549d..5e96c4f99fc 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -946,6 +946,7 @@ enable_gnu_unique_object
 enable_linker_build_id
 enable_libssp
 enable_default_ssp
+enable_systemtap
 with_long_double_128
 with_long_double_format
 with_gc
@@ -1688,6 +1689,7 @@ Optional Features:
   compiler will always pass --build-id to linker
   --enable-libssp enable linking against libssp
   --enable-default-sspenable Stack Smashing Protection as default
+  --disable-systemtap enable systemtap static probe points [default=auto]
   --enable-maintainer-mode
   enable make rules and dependencies not useful (and
   sometimes confusing) to the casual installer
@@ -18448,7 +18450,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18451 "configure"
+#line 18453 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -18554,7 +18556,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18557 "configure"
+#line 18559 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -29297,17 +29299,33 @@ fi
 
 # Test for  on the target.
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking sys/sdt.h in the target C 
library" >&5
+
+# Check whether --enable-systemtap was given.
+if test "${enable_systemtap+set}" = set; then :
+  enableval=$enable_systemtap; enable_systemtap=$enableval
+else
+  enable_systemtap=auto
+fi
+
+
+if test x$enable_systemtap != xno; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking sys/sdt.h in the target C 
library" >&5
 $as_echo_n "checking sys/sdt.h in the target C library... " >&6; }
-have_sys_sdt_h=no
-if test -f $target_header_dir/sys/sdt.h; then
-  have_sys_sdt_h=yes
+  have_sys_sdt_h=no
+  if test -f $target_header_dir/sys/sdt.h ; then
+have_sys_sdt_h=yes
 
 $as_echo "#define HAVE_SYS_SDT_H 1" >>confdefs.h
 
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_sys_sdt_h" >&5
+  fi
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_sys_sdt_h" >&5
 $as_echo "$have_sys_sdt_h" >&6; }
+  if test x$enable_systemtap = xyes ; then
+if test x$have_sys_sdt_h = xno ; then
+  as_fn_error "sys/sdt.h was not found" "$LINENO" 5
+fi
+  fi
+fi
 
 # Check if TFmode long double should be used by default or not.
 # Some glibc targets used DFmode long double, but with glibc 2.4
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 36124b8ce90..8356e579a20 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -5965,14 +5965,28 @@ AC_SUBST([enable_default_ssp])
 
 # Test for  on the target.
 GCC_TARGET_TEMPLATE([HAVE_SYS_SDT_H])
-AC_MSG_CHECKING(sys/sdt.h in the target C library)
-have_sys_sdt_h=no
-if test -f $target_header_dir/sys/sdt.h; then
-  have_sys_sdt_h=yes
-  AC_DEFINE(HAVE_SYS_SDT_H, 1,
-[Define if your target C library provides sys/sdt.h])
-fi
-AC_MSG_RESULT($have_sys_sdt_h)
+
+AC_ARG_ENABLE(systemtap,
+[AS_HELP_STRING([--disable-systemtap],
+  [enable systemtap static probe points [default=auto]])],
+  enable_systemtap=$enableval,
+  enable_systemtap=auto)
+
+if test x$enable_systemtap != xno; then
+  AC_MSG_CHECKING(sys/sdt.h in the target C library)
+  have_sys_sdt_h=no
+  if test -f $target_header_dir/sys/sdt.h ; then
+have_sys_sdt_h=yes
+AC_DEFINE(HAVE_SYS_SDT_H, 1,
+  [Define if your target C library provides sys/sdt.h])
+  fi
+  AC_MSG_RESULT($have_sys_sdt_h)
+  if test x$enable_systemtap = xyes ; then
+if test x$have_sys_sdt_h = xno ; then
+  AC_MSG_ERROR([sys/sdt.h was not found])
+fi
+  fi
+fi
 
 # Check if TFmode long double should be used by default or not.
 # Some glibc targets used DFmode long double, but with glibc 2.4
-- 
2.17.0



[PING from 2013][PATCH] fixincludes: handle symlinks with multiple slashes

2017-08-17 Thread Sergei Trofimovich
Looks like the following patch falled through the cracks
https://gcc.gnu.org/ml/gcc-patches/2012-12/msg01397.html
https://bugs.gentoo.org/show_bug.cgi?id=434180#c16

Thanks!

-- 

  Sergei


pgpUpEUwrmHQi.pgp
Description: Цифровая подпись OpenPGP


Re: [PATCH] x86_64: fix 'gather' avx2 builtin names

2016-09-25 Thread Sergei Trofimovich
On Sun, 25 Sep 2016 19:01:14 +0200
Jakub Jelinek <ja...@redhat.com> wrote:

> On Sun, Sep 25, 2016 at 02:48:19PM +0100, Sergei Trofimovich wrote:
> > From: Sergei Trofimovich <siarh...@google.com>
> > 
> > Today I traced AVX2 optimisation bug in gcc and
> > distilled it down to '__builtin_ia32_gatheraltdiv4si256'
> > generated by gcc.
> > 
> > When I attempted to use this builtin directly
> > in a simple program gcc refused to recognise
> > it as known:
> > 
> >   #include 
> > 
> >   void a (void) {
> > __builtin_ia32_gatheraltdiv4si256 (1);
> >   }
> > 
> >   $ LANG=C gcc -c -march=core-avx2 a.c
> > a.c: In function 'a':
> > a.c:4:5: warning: implicit declaration of function
> > '__builtin_ia32_gatheraltdiv4si256' 
> > [-Wimplicit-function-declaration]
> > 
> > The cause is trailing whitespace in builtin definition:
> > 
> >   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltdiv4si256 
> > ",
> > 
> > Fixed by dropping trailing whitespace.  
> 
> No, that isn't a fix, adding such characters has been an older way to
> express internal only builtins that aren't ever meant to be available to
> users (these days we'd use internal-fn.* stuff, except we don't have support
> for backends adding their own internal functions).

Aha, got it. Having a seemingly callable name is very confusing.

I did grab the name from one of -fdump-tree-all outputs
(bug.c.165t.optimized) which looked as:

  vect_.16_59 = VIEW_CONVERT_EXPR<vector(4) long long int>(vect_var_.12_56);
  vect_var_.14_60 = __builtin_ia32_gatheraltdiv4si256  ({ -1, -1, -1, -1, -1, 
-1, -1, -1 }, , vect_.16_59, { -1, -1, -1, 
-1, -1, -1, -1, -1 }, 4);
  vect_.17_61 = VIEW_CONVERT_EXPR<vector(4) long long int>(vect_var_.12_57);
  vect_var_.14_62 = __builtin_ia32_gatheraltdiv4si256  ({ -1, -1, -1, -1, -1, 
-1, -1, -1 }, , vect_.17_61, { -1, -1, -1, 
-1, -1, -1, -1, -1 }, 4);

and I assumed that builtin can be used directly to reproduce
smaller example. Sorry for the noise.

-- 

  Sergei


pgpmQcY54o8k2.pgp
Description: Цифровая подпись OpenPGP


[PATCH] x86_64: fix 'gather' avx2 builtin names

2016-09-25 Thread Sergei Trofimovich
From: Sergei Trofimovich <siarh...@google.com>

Today I traced AVX2 optimisation bug in gcc and
distilled it down to '__builtin_ia32_gatheraltdiv4si256'
generated by gcc.

When I attempted to use this builtin directly
in a simple program gcc refused to recognise
it as known:

  #include 

  void a (void) {
__builtin_ia32_gatheraltdiv4si256 (1);
  }

  $ LANG=C gcc -c -march=core-avx2 a.c
a.c: In function 'a':
a.c:4:5: warning: implicit declaration of function
'__builtin_ia32_gatheraltdiv4si256' [-Wimplicit-function-declaration]

The cause is trailing whitespace in builtin definition:

  def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltdiv4si256 ",

Fixed by dropping trailing whitespace.

Signed-off-by: Sergei Trofimovich <siarh...@google.com>
---
 gcc/config/i386/i386.c | 32 
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 143b905..48a5354 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -31403,19 +31403,19 @@ ix86_init_mmx_sse_builtins (void)
   V4SI_FTYPE_V4SI_PCINT_V4DI_V4SI_INT,
   IX86_BUILTIN_GATHERDIV8SI);
 
-  def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltsiv4df ",
+  def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltsiv4df",
   V4DF_FTYPE_V4DF_PCDOUBLE_V8SI_V4DF_INT,
   IX86_BUILTIN_GATHERALTSIV4DF);
 
-  def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltdiv4sf256 ",
+  def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltdiv4sf256",
   V8SF_FTYPE_V8SF_PCFLOAT_V4DI_V8SF_INT,
   IX86_BUILTIN_GATHERALTDIV8SF);
 
-  def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltsiv4di ",
+  def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltsiv4di",
   V4DI_FTYPE_V4DI_PCINT64_V8SI_V4DI_INT,
   IX86_BUILTIN_GATHERALTSIV4DI);
 
-  def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltdiv4si256 ",
+  def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltdiv4si256",
   V8SI_FTYPE_V8SI_PCINT_V4DI_V8SI_INT,
   IX86_BUILTIN_GATHERALTDIV8SI);
 
@@ -31452,19 +31452,19 @@ ix86_init_mmx_sse_builtins (void)
   V8DI_FTYPE_V8DI_PCINT64_V8DI_QI_INT,
   IX86_BUILTIN_GATHER3DIV8DI);
 
-  def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltsiv8df ",
+  def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltsiv8df",
   V8DF_FTYPE_V8DF_PCDOUBLE_V16SI_QI_INT,
   IX86_BUILTIN_GATHER3ALTSIV8DF);
 
-  def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltdiv8sf ",
+  def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltdiv8sf",
   V16SF_FTYPE_V16SF_PCFLOAT_V8DI_HI_INT,
   IX86_BUILTIN_GATHER3ALTDIV16SF);
 
-  def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltsiv8di ",
+  def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltsiv8di",
   V8DI_FTYPE_V8DI_PCINT64_V16SI_QI_INT,
   IX86_BUILTIN_GATHER3ALTSIV8DI);
 
-  def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltdiv8si ",
+  def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltdiv8si",
   V16SI_FTYPE_V16SI_PCINT_V8DI_HI_INT,
   IX86_BUILTIN_GATHER3ALTDIV16SI);
 
@@ -31565,19 +31565,19 @@ ix86_init_mmx_sse_builtins (void)
   V4SI_FTYPE_V4SI_PCINT_V4DI_QI_INT,
   IX86_BUILTIN_GATHER3DIV8SI);
 
-  def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altsiv4df ",
+  def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altsiv4df",
   V4DF_FTYPE_V4DF_PCDOUBLE_V8SI_QI_INT,
   IX86_BUILTIN_GATHER3ALTSIV4DF);
 
-  def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altdiv8sf ",
+  def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altdiv8sf",
   V8SF_FTYPE_V8SF_PCFLOAT_V4DI_QI_INT,
   IX86_BUILTIN_GATHER3ALTDIV8SF);
 
-  def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altsiv4di ",
+  def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altsiv4di",
   V4DI_FTYPE_V4DI_PCINT64_V8SI_QI_INT,
   IX86_BUILTIN_GATHER3ALTSIV4DI);
 
-  def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altdiv8si ",
+  def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altdiv8si",
   V8SI_FTYPE_V8SI_PCINT_V4DI_QI_INT,
   IX86_BUILTIN_GATHER3ALTDIV8SI);
 
@@ -31644,19 +31644,19 @@ ix86_init_mmx_sse_builtins (void)
   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia

Re: [PATCH v2] ia64: don't use dynamic relocations for local symbols

2016-01-05 Thread Sergei Trofimovich
On Sat, 2 Jan 2016 11:50:56 +
Sergei Trofimovich <sly...@inbox.ru> wrote:

> Attached updated patch and test runs on a crosscompiler before
> and after the change.
> 
> Now I'm building on real ia64 hardware as
> make bootstrap
> make -k check
> 
> for both clean and patched trees.

'make bootstrap' works fine on ia64 but I've failed to run 'make check'.
Testsuite's LD_LIBRARY_PATHs are not correct and can run tests.

Executing on host: /root/gcc-build/gcc/xgcc -B/root/gcc-build/gcc/  
-fno-diagnostics-show-caret -fdiagnostics-color=never-O0  -w -c   -o 
2105-1.o /root/gcc/gcc/testsuite/gcc.c-torture/compile/2105-1.c
(timeout = 300)
spawn /root/gcc-build/gcc/xgcc -B/root/gcc-build/gcc/ 
-fno-diagnostics-show-caret -fdiagnostics-color=never -O0 -w -c -o 21
05-1.o /root/gcc/gcc/testsuite/gcc.c-torture/compile/2105-1.c
compiler exited with status -1
output is:
spawn failed

But running builds manually works:

gcc-build # /root/gcc-build/gcc/xgcc -B/root/gcc-build/gcc/  
-fno-diagnostics-show-caret -fdiagnostics-color=never-O0  -w -c   -o 
2105-1.o /root/gcc/gcc/testsuite/gcc.c-torture/compile/2105-1.c  && 
echo ok
ok

-- 

  Sergei


signature.asc
Description: PGP signature


Re: [PATCH v2] ia64: don't use dynamic relocations for local symbols

2016-01-05 Thread Sergei Trofimovich
On Tue, 5 Jan 2016 10:41:14 -0700
Jeff Law  wrote:

> On 01/05/2016 02:39 AM, Eric Botcazou wrote:
> >> 'make bootstrap' works fine on ia64 but I've failed to run 'make check'.
> >> Testsuite's LD_LIBRARY_PATHs are not correct and can run tests.
> >
> > You need to run 'make -k check' from the top level build directory.
> No worries.  I had an ia64 box provisioned when I looked at this and I 
> just let it run the regression tests overnight.  Everything looks good.
> 
> jeff

Thank you!

[ Also found real cause of broken 'make -k check':
  I did not have devpts subsystem set correctly.
  Expect requires pseudoterminals to really work.
  Fixed that and tests run fine now. ]

-- 

  Sergei


signature.asc
Description: PGP signature


[PATCH v2] ia64: don't use dynamic relocations for local symbols

2016-01-02 Thread Sergei Trofimovich
On Sat, 2 Jan 2016 00:30:58 -0700
Jeff Law <l...@redhat.com> wrote:

> > That way gcc will be able to compile glibc's ld: PR/60465
> Egad. PIC on ia64 is a mess. I can kind of see what Richard was trying 
> to do, but ewww. I don't think it's worth the effort to deep dive into 
> the PIC support and make ia64 handle things like most other ports -- 
> it's a dead architecture so ISTM the easiest fix is the right fix.
> 
> A few, relatively minor things.

> > diff --git a/gcc/config/ia64/ia64.c b/gcc/config/ia64/ia64.c
> > index f48cebc..6ea5072 100644
> > --- a/gcc/config/ia64/ia64.c
> > +++ b/gcc/config/ia64/ia64.c
> > @@ -1105,6 +1105,8 @@ ia64_expand_load_address (rtx dest, rtx src)
> >   emit_insn (gen_load_fptr (dest, src));
> > else if (sdata_symbolic_operand (src, VOIDmode))
> >   emit_insn (gen_load_gprel (dest, src));
> > +  else if (local_symbolic_operand64 (src, VOIDmode))
> > +emit_insn (gen_load_gprel64 (dest, src));
> Comment here.  Something like
> 
> /* We want to use gprel rather than ltoff relocations for
> local symbolic operands.  */
Done. Hope not too wordy :)

> 
> >
> > +;; True if OP refers to a local symbol +any large offset).
> ;; True if OP refers to a local symbol [+ any offset ]
> 
> I haven't dug into the ia64 port (and I'm not planning to) to see if/how 
> it MINUS in symbolic expressions.  It's been the source of problems in 
> various ports trough the years.
> 
> Can you take the testcase from your post as well as the one from BZ60465 
> comment #37 (from you) and add them to the testsuite?
Added both tests.

> Note you're not running the full testsuite, just a few dozen ia64 
> specific tests, which will include your new tests.  ANd you're not 
> rebuilding the whole compiler between those steps, just ia64.o and 
> relinking the compiler.  So it ought to be reasonably fast.
> 
> So to summarize, I think your patch needs the two trivial comment fixes 
> noted above, 2 testcases and the before/after results of running just 
> the ia64.exp tests.  Repost with that and I'll get it into the tree.

--- ia64-before.log 2016-01-02 11:20:21.0 +
+++ ia64-after.log  2016-01-02 11:22:37.0 +
@@ -1 +1 @@
-Test Run By slyfox on Sat Jan  2 11:19:38 2016
+Test Run By slyfox on Sat Jan  2 11:22:16 2016
@@ -26,2 +25,0 @@
-FAIL: gcc.target/ia64/pr60465-gprel64-c37.c scan-assembler-not @ltoffx
-FAIL: gcc.target/ia64/pr60465-gprel64.c scan-assembler-not @ltoffx
@@ -31,2 +29,2 @@
-# of expected passes147
-# of unexpected failures11
+# of expected passes149
+# of unexpected failures9

I did ran tests only on amd64 host thus the execution failure tests.

Attached updated patch and test runs on a crosscompiler before
and after the change.

Now I'm building on real ia64 hardware as
make bootstrap
make -k check

for both clean and patched trees.

-- 

  Sergei
From 04a34fd97cffae4f40e1c226489129f42f3ceb2a Mon Sep 17 00:00:00 2001
From: Sergei Trofimovich <siarh...@google.com>
Date: Mon, 28 Dec 2015 17:33:43 +
Subject: [PATCH] ia64: don't use dynamic relocations for local symbols

Tested on the following example:

void * a[77] __attribute((visibility("hidden")));
void f(long o, void * v) { a[0x6eff - o + 66] = v; }

Before the patch generated code uses .GOT entry:

addl r14 = @ltoffx(a#), r1
ld8.mov r14 = [r14], a#

After the patch generated code uses static gprel relocation:

    movl r14 = @gprel(a#)
add r14 = r1, r14

That way gcc will be able to compile glibc's ld: PR/60465

Bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60465
Signed-off-by: Sergei Trofimovich <siarh...@google.com>
---
 gcc/config/ia64/ia64.c |  9 
 gcc/config/ia64/predicates.md  | 26 +
 .../gcc.target/ia64/pr60465-gprel64-c37.c  | 10 
 gcc/testsuite/gcc.target/ia64/pr60465-gprel64.c| 27 ++
 4 files changed, 72 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/ia64/pr60465-gprel64-c37.c
 create mode 100644 gcc/testsuite/gcc.target/ia64/pr60465-gprel64.c

diff --git a/gcc/config/ia64/ia64.c b/gcc/config/ia64/ia64.c
index f48cebc..ccf2bec 100644
--- a/gcc/config/ia64/ia64.c
+++ b/gcc/config/ia64/ia64.c
@@ -1105,6 +1105,15 @@ ia64_expand_load_address (rtx dest, rtx src)
 emit_insn (gen_load_fptr (dest, src));
   else if (sdata_symbolic_operand (src, VOIDmode))
 emit_insn (gen_load_gprel (dest, src));
+  else if (local_symbolic_operand64 (src, VOIDmode))
+{
+  /* We want to use @gprel rather than @ltoff relocations for local
+symbols:
+ - @gprel does not require dynamic linker
+ - and does not use .sdata section
+https://gcc.gnu

[PATCH] ia64: don't use dynamic relocations for local symbols

2015-12-28 Thread Sergei Trofimovich
From: Sergei Trofimovich <siarh...@google.com>

Tested on the following example:

void * a[77] __attribute((visibility("hidden")));
void f(long o, void * v) { a[0x6eff - o + 66] = v; }

Before the patch generated code uses .GOT entry:

addl r14 = @ltoffx(a#), r1
ld8.mov r14 = [r14], a#

After the patch generated code uses static gprel relocation:

movl r14 = @gprel(a#)
add r14 = r1, r14

That way gcc will be able to compile glibc's ld: PR/60465

Bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60465
Signed-off-by: Sergei Trofimovich <siarh...@google.com>
---
 gcc/config/ia64/ia64.c|  2 ++
 gcc/config/ia64/predicates.md | 26 ++
 2 files changed, 28 insertions(+)

diff --git a/gcc/config/ia64/ia64.c b/gcc/config/ia64/ia64.c
index f48cebc..6ea5072 100644
--- a/gcc/config/ia64/ia64.c
+++ b/gcc/config/ia64/ia64.c
@@ -1105,6 +1105,8 @@ ia64_expand_load_address (rtx dest, rtx src)
 emit_insn (gen_load_fptr (dest, src));
   else if (sdata_symbolic_operand (src, VOIDmode))
 emit_insn (gen_load_gprel (dest, src));
+  else if (local_symbolic_operand64 (src, VOIDmode))
+emit_insn (gen_load_gprel64 (dest, src));
   else
 {
   HOST_WIDE_INT addend = 0;
diff --git a/gcc/config/ia64/predicates.md b/gcc/config/ia64/predicates.md
index 2aa7a78..9c6951d 100644
--- a/gcc/config/ia64/predicates.md
+++ b/gcc/config/ia64/predicates.md
@@ -97,6 +97,32 @@
 }
 })
 
+;; True if OP refers to a local symbol +any large offset).
+;; To be encoded as:
+;;   movl % = @gprel(symbol+offset)
+;;   add  % = %, gp
+(define_predicate "local_symbolic_operand64" 
+  (match_code "symbol_ref,const")
+{
+  switch (GET_CODE (op))
+{
+case CONST:
+  op = XEXP (op, 0);
+  if (GET_CODE (op) != PLUS
+ || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
+ || GET_CODE (XEXP (op, 1)) != CONST_INT)
+   return false;
+  op = XEXP (op, 0);
+  /* FALLTHRU */
+
+case SYMBOL_REF:
+   return SYMBOL_REF_LOCAL_P (op);
+
+default:
+   gcc_unreachable ();
+}
+})
+
 ;; True if OP refers to a symbol in the small address area.
 (define_predicate "small_addr_symbolic_operand" 
   (match_code "symbol_ref,const")
-- 
2.6.4