Re: [PATCH] PR fortran/95880 - [9/10/11 Regression] ICE in gfc_add_type, at fortran/symbol.c:2030

2020-06-28 Thread Thomas Koenig via Gcc-patches

Hi Harald,


A rather straightforward issue (mis-)referencing the proper symbol name
in an error message.

OK for master / backport?


OK, but don't forget the test case :-)

Because the if takes up quite a few lines, it is also an option to
write something like

gfc_error ("Symbol %qs at %L cannot have a type",
   sym->ns->proc_name->name
 ? sym->ns->proc_name->name : sym->name , where);

simply to have more code on the screen at one time.  If you happen
to be inclined that way, that variant is also OK.

Thanks for the patch!

Regards

Thomas


[pushed] coroutines, testsuite: Update log messages. [NFC, PR95519]

2020-06-28 Thread Iain Sandoe via Gcc-patches
Hi.

this corrects some pastos in the user error messages for the
testcases, in PR95519.  NFC.

tested on x86_64-darwin, applied to master.
thanks
Iain


This does not affect the test functionality, but only user-
facing debug messages when the tests are run outside the
test-suite.

gcc/testsuite/ChangeLog:

PR c++/95519
* g++.dg/coroutines/torture/pr95519-02-final_suspend.C:
Amend log messages.
* g++.dg/coroutines/torture/pr95519-03-return-value.C:
Likewise.
* g++.dg/coroutines/torture/pr95519-04-yield-value.C:
Likewise.
* g++.dg/coroutines/torture/pr95519-05-gro.C: Likewise.
---
 .../g++.dg/coroutines/torture/pr95519-02-final_suspend.C  | 2 +-
 .../g++.dg/coroutines/torture/pr95519-03-return-value.C   | 2 +-
 .../g++.dg/coroutines/torture/pr95519-04-yield-value.C| 2 +-
 gcc/testsuite/g++.dg/coroutines/torture/pr95519-05-gro.C  | 4 ++--
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/g++.dg/coroutines/torture/pr95519-02-final_suspend.C 
b/gcc/testsuite/g++.dg/coroutines/torture/pr95519-02-final_suspend.C
index 8e7ba11c723..4200c333ee3 100644
--- a/gcc/testsuite/g++.dg/coroutines/torture/pr95519-02-final_suspend.C
+++ b/gcc/testsuite/g++.dg/coroutines/torture/pr95519-02-final_suspend.C
@@ -63,7 +63,7 @@ int main ()
 bar ();
 if (called_fs_op != 1 || called_lambda != 1)
   {
-PRINT ("Failed to call one of the initial_suspend cases");
+PRINT ("Failed to call one of the final_suspend cases");
 abort ();
   }
 }
diff --git a/gcc/testsuite/g++.dg/coroutines/torture/pr95519-03-return-value.C 
b/gcc/testsuite/g++.dg/coroutines/torture/pr95519-03-return-value.C
index 7d01509001c..cf4c43d1a90 100644
--- a/gcc/testsuite/g++.dg/coroutines/torture/pr95519-03-return-value.C
+++ b/gcc/testsuite/g++.dg/coroutines/torture/pr95519-03-return-value.C
@@ -74,7 +74,7 @@ int main ()
 
   if (called_rv_op != 1 || called_lambda != 1)
 {
-  PRINT ("Failed to call one of the return_void cases");
+  PRINT ("Failed to call one of the return_value cases");
   abort ();
 }
 }
diff --git a/gcc/testsuite/g++.dg/coroutines/torture/pr95519-04-yield-value.C 
b/gcc/testsuite/g++.dg/coroutines/torture/pr95519-04-yield-value.C
index d09e5ba1075..5f1be4e00f4 100644
--- a/gcc/testsuite/g++.dg/coroutines/torture/pr95519-04-yield-value.C
+++ b/gcc/testsuite/g++.dg/coroutines/torture/pr95519-04-yield-value.C
@@ -78,7 +78,7 @@ int main ()
 
   if (called_yv_op != 1 || called_lambda != 1)
 {
-  PRINT ("Failed to call one of the return_void cases");
+  PRINT ("Failed to call one of the yield_value cases");
   abort ();
 }
 }
diff --git a/gcc/testsuite/g++.dg/coroutines/torture/pr95519-05-gro.C 
b/gcc/testsuite/g++.dg/coroutines/torture/pr95519-05-gro.C
index ba0a1e3dc60..fbbce97ed17 100644
--- a/gcc/testsuite/g++.dg/coroutines/torture/pr95519-05-gro.C
+++ b/gcc/testsuite/g++.dg/coroutines/torture/pr95519-05-gro.C
@@ -46,13 +46,13 @@ int main ()
   foo (f);
   if (f.done())
 {
-  PRINT ("unexptected finished f coro");
+  PRINT ("unexpected finished foo coro");
   abort ();
}
   f.resume();
   if (!f.done())
 {
-  PRINT ("expected f to be finished");
+  PRINT ("expected foo to be finished");
   abort ();
}
 
-- 
2.24.1



[PATCH] libstdc++: Add a __nonnnull__ attribute to std::string's _CharT* constructor

2020-06-28 Thread Ville Voutilainen via Gcc-patches
2020-06-28  Ville Voutilainen  

Add a __nonnnull__ attribute to std::string's _CharT* constructor
* include/bits/basic_string.h (string(_CharT*, const _Alloc&)):
Add a __nonnull__ attribute.
* testsuite/21_strings/basic_string/cons/char/nonnull.cc: New.
* testsuite/21_strings/basic_string/cons/wchar_t/nonnull.cc: Likewise.
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index bc0c256b65e..d5e5eb06e1b 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -522,6 +522,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   // 3076. basic_string CTAD ambiguity
   template>
 #endif
+  __attribute__((__nonnull__))
   basic_string(const _CharT* __s, const _Alloc& __a = _Alloc())
   : _M_dataplus(_M_local_data(), __a)
   { _M_construct(__s, __s ? __s + traits_type::length(__s) : __s+npos); }
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/nonnull.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/nonnull.cc
new file mode 100644
index 000..b56bdc78b51
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/nonnull.cc
@@ -0,0 +1,29 @@
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library 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.
+
+// This library 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 this library; see the file COPYING3.  If not see
+// .
+
+// { dg-options "-std=gnu++11 -Wnonnull" }
+// { dg-do compile { target c++11 } }
+
+#include 
+
+void
+test01()
+{
+  std::string s((const char*)nullptr); // { dg-warning "null arg" }
+  std::string t((char*)nullptr);   // { dg-warning "null arg" }
+  std::string u(nullptr);	   // { dg-warning "null arg" }
+}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/nonnull.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/nonnull.cc
new file mode 100644
index 000..8196821f163
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/nonnull.cc
@@ -0,0 +1,29 @@
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library 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.
+
+// This library 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 this library; see the file COPYING3.  If not see
+// .
+
+// { dg-options "-std=gnu++11 -Wnonnull" }
+// { dg-do compile { target c++11 } }
+
+#include 
+
+void
+test01()
+{
+  std::wstring s((const wchar_t*)nullptr); // { dg-warning "null arg" }
+  std::wstring t((wchar_t*)nullptr);	   // { dg-warning "null arg" }
+  std::wstring u(nullptr);		   // { dg-warning "null arg" }
+}


Re: [PATCH] libstdc++: Add a __nonnnull__ attribute to std::string's _CharT* constructor

2020-06-28 Thread Ville Voutilainen via Gcc-patches
On Sun, 28 Jun 2020 at 13:56, Ville Voutilainen
 wrote:
>
> 2020-06-28  Ville Voutilainen  
>
> Add a __nonnnull__ attribute to std::string's _CharT* constructor
> * include/bits/basic_string.h (string(_CharT*, const _Alloc&)):
> Add a __nonnull__ attribute.
> * testsuite/21_strings/basic_string/cons/char/nonnull.cc: New.
> * testsuite/21_strings/basic_string/cons/wchar_t/nonnull.cc: Likewise.


Hmm, let's use dg-additional-options here too, and axe the pointless
-std=gnu++11.
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index bc0c256b65e..d5e5eb06e1b 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -522,6 +522,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   // 3076. basic_string CTAD ambiguity
   template>
 #endif
+  __attribute__((__nonnull__))
   basic_string(const _CharT* __s, const _Alloc& __a = _Alloc())
   : _M_dataplus(_M_local_data(), __a)
   { _M_construct(__s, __s ? __s + traits_type::length(__s) : __s+npos); }
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/nonnull.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/nonnull.cc
new file mode 100644
index 000..1c09a1d2207
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/nonnull.cc
@@ -0,0 +1,29 @@
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library 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.
+
+// This library 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 this library; see the file COPYING3.  If not see
+// .
+
+// { dg-additional-options "-Wnonnull" }
+// { dg-do compile { target c++11 } }
+
+#include 
+
+void
+test01()
+{
+  std::string s((const char*)nullptr); // { dg-warning "null arg" }
+  std::string t((char*)nullptr);   // { dg-warning "null arg" }
+  std::string u(nullptr);	   // { dg-warning "null arg" }
+}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/nonnull.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/nonnull.cc
new file mode 100644
index 000..456efed6c8c
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/nonnull.cc
@@ -0,0 +1,29 @@
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library 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.
+
+// This library 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 this library; see the file COPYING3.  If not see
+// .
+
+// { dg-additional-options "-Wnonnull" }
+// { dg-do compile { target c++11 } }
+
+#include 
+
+void
+test01()
+{
+  std::wstring s((const wchar_t*)nullptr); // { dg-warning "null arg" }
+  std::wstring t((wchar_t*)nullptr);	   // { dg-warning "null arg" }
+  std::wstring u(nullptr);		   // { dg-warning "null arg" }
+}


Aw: Re: [PATCH] PR fortran/95880 - [9/10/11 Regression] ICE in gfc_add_type, at fortran/symbol.c:2030

2020-06-28 Thread Harald Anlauf
Hi Thomas,

> OK, but don't forget the test case :-)

the testcase was in the patch.  I just do not add it to the commit message,
because that's now done automagically by the new scripts.

> Because the if takes up quite a few lines, it is also an option to
> write something like
>
> gfc_error ("Symbol %qs at %L cannot have a type",
>  sym->ns->proc_name->name
>? sym->ns->proc_name->name : sym->name , where);
>
> simply to have more code on the screen at one time.  If you happen
> to be inclined that way, that variant is also OK.

Done.  It actually came to my mind after submitting the patch.

I'm more a Fortran programmer than C, and the ternary MERGE would
be forbidden in that situation.

> Thanks for the patch!

And thanks for the comments!

Harald



[PATCH PR95855]A missing ifcvt optimization to generate fcsel

2020-06-28 Thread yangyang (ET)
Hi, 

This is a simple fix for pr95855.

With this fix, pass_split_paths can recognize the if-conversion opportunity 
of the testcase and doesn't duplicate the corresponding block. 

Added one testcase for this. Bootstrap and tested on both aarch64 and x86 
Linux platform, no new regression witnessed.

Ok for trunk?

Thanks,
Yang Yang


+2020-06-28  Yang Yang  
+
+   PR tree-optimization/95855
+   * gimple-ssa-split-paths.c (is_feasible_trace): Add extra
+   checks to recognize a missed if-conversion opportunity when
+   judging whether to duplicate a block.
+

+2020-06-28 Yang Yang  
+
+   PR tree-optimization/95855
+   * gcc.dg/tree-ssa/split-paths-12.c: New testcase.
+


PR95855-v0.patch
Description: PR95855-v0.patch


[pushed] coroutines: Handle namespaces while scanning local vars [PR95711].

2020-06-28 Thread Iain Sandoe
Hi,

We need to skip past namespace decls when scanning the bind
expression var lists checking for local vars.

The PR notes that this omission results in an ice-on-valid.

tested on x86_64-linux, darwin, powerpc64-linux,

applied to master as obvious (and will backport to 10.2).

thanks
Iain

gcc/cp/ChangeLog:

PR c++/95711
* coroutines.cc (register_local_var_uses): Skip past
namespace decls.

gcc/testsuite/ChangeLog:

PR c++/95711
* g++.dg/coroutines/pr95711.C: New test.
---
 gcc/cp/coroutines.cc  |  3 +-
 gcc/testsuite/g++.dg/coroutines/pr95711.C | 79 +++
 2 files changed, 81 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/coroutines/pr95711.C

diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index bab03d44863..54f9cb3b4e4 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -3563,7 +3563,8 @@ register_local_var_uses (tree *stmt, int *do_subtree, 
void *d)
  local_var.field_idx = local_var.field_id = NULL_TREE;
 
  /* Make sure that we only present vars to the tests below.  */
- if (TREE_CODE (lvar) == TYPE_DECL)
+ if (TREE_CODE (lvar) == TYPE_DECL
+ || TREE_CODE (lvar) == NAMESPACE_DECL)
continue;
 
  /* We don't move static vars into the frame. */
diff --git a/gcc/testsuite/g++.dg/coroutines/pr95711.C 
b/gcc/testsuite/g++.dg/coroutines/pr95711.C
new file mode 100644
index 000..f6aedb16ebd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/coroutines/pr95711.C
@@ -0,0 +1,79 @@
+//  { dg-do run }
+
+#if __has_include()
+#include 
+#else
+#include 
+namespace std {
+using namespace std::experimental;
+}
+#endif
+#include 
+
+template 
+struct generator{
+struct promise_type;
+using coro_handle = std::coroutine_handle;
+
+struct promise_type{
+std::suspend_always yield_value (T value){
+value_ = value;
+return {};
+}
+std::suspend_always initial_suspend (){
+return {};
+}
+std::suspend_always final_suspend (){
+return {};
+}
+
+std::suspend_never return_void()
+{
+return {};
+}
+generator get_return_object () {
+return {coro_handle::from_promise(*this)};
+}
+void unhandled_exception () {
+return;
+}
+T value_;
+};
+coro_handle handle;
+generator(coro_handle h)
+:handle(h)
+{}
+~generator(){
+if(handle)
+handle.destroy();
+}
+
+bool resume(){
+if(not handle.done())
+handle.resume();
+return not handle.done();
+};
+
+T get () {
+return handle.promise().value_;
+}
+};
+namespace A
+{
+}
+
+generator
+parse()
+{
+namespace B = A;
+co_yield 1;
+}
+
+int main()
+{
+auto gen = parse();
+gen.handle.resume (); /* init suspend. */
+if (gen.get() != 1)
+  abort ();
+  return 0;
+}
-- 
2.24.1



[PATCH] x86: Enable FMA in rsqrt2 expander

2020-06-28 Thread H.J. Lu via Gcc-patches
Enable FMA in rsqrt2 expander and fold rsqrtv16sf2 expander into
rsqrt2 expander which expands to UNSPEC_RSQRT28 for TARGET_AVX512ER.
Although it doesn't show performance change in our workloads, FMA can
improve other workloads.

gcc/

PR target/88713
* config/i386/i386-expand.c (ix86_emit_swsqrtsf): Enable FMA.
* config/i386/sse.md (VF_AVX512VL_VF1_128_256): New.
(rsqrt2): Replace VF1_128_256 with VF_AVX512VL_VF1_128_256.
(rsqrtv16sf2): Removed.

gcc/testsuite/

PR target/88713
* gcc.target/i386/pr88713-1.c: New test.
* gcc.target/i386/pr88713-2.c: Likewise.
---
 gcc/config/i386/i386-expand.c | 18 -
 gcc/config/i386/sse.md| 24 ++-
 gcc/testsuite/gcc.target/i386/pr88713-1.c | 13 
 gcc/testsuite/gcc.target/i386/pr88713-2.c |  6 ++
 4 files changed, 42 insertions(+), 19 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr88713-1.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr88713-2.c

diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c
index d81dd73f034..49718b7a41c 100644
--- a/gcc/config/i386/i386-expand.c
+++ b/gcc/config/i386/i386-expand.c
@@ -15535,14 +15535,22 @@ void ix86_emit_swsqrtsf (rtx res, rtx a, machine_mode 
mode, bool recip)
}
 }
 
+  mthree = force_reg (mode, mthree);
+
   /* e0 = x0 * a */
   emit_insn (gen_rtx_SET (e0, gen_rtx_MULT (mode, x0, a)));
-  /* e1 = e0 * x0 */
-  emit_insn (gen_rtx_SET (e1, gen_rtx_MULT (mode, e0, x0)));
 
-  /* e2 = e1 - 3. */
-  mthree = force_reg (mode, mthree);
-  emit_insn (gen_rtx_SET (e2, gen_rtx_PLUS (mode, e1, mthree)));
+  if (TARGET_FMA || TARGET_AVX512F)
+emit_insn (gen_rtx_SET (e2,
+   gen_rtx_FMA (mode, e0, x0, mthree)));
+  else
+{
+  /* e1 = e0 * x0 */
+  emit_insn (gen_rtx_SET (e1, gen_rtx_MULT (mode, e0, x0)));
+
+  /* e2 = e1 - 3. */
+  emit_insn (gen_rtx_SET (e2, gen_rtx_PLUS (mode, e1, mthree)));
+}
 
   mhalf = force_reg (mode, mhalf);
   if (recip)
diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index 431571a4bc1..d3ad5833e1f 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -326,6 +326,12 @@ (define_mode_iterator VF_AVX512VL
   [V16SF (V8SF "TARGET_AVX512VL") (V4SF "TARGET_AVX512VL")
V8DF (V4DF "TARGET_AVX512VL") (V2DF "TARGET_AVX512VL")])
 
+;; AVX512VL SF/DF plus 128- and 256-bit SF vector modes
+(define_mode_iterator VF_AVX512VL_VF1_128_256
+  [(V16SF "TARGET_AVX512F") (V8SF "TARGET_AVX") V4SF
+   (V8DF "TARGET_AVX512F") (V4DF "TARGET_AVX512VL")
+   (V2DF "TARGET_AVX512VL")])
+
 (define_mode_iterator VF2_AVX512VL
   [V8DF (V4DF "TARGET_AVX512VL") (V2DF "TARGET_AVX512VL")])
 
@@ -2070,26 +2076,16 @@ (define_insn 
"*_vmsqrt2"
(set_attr "mode" "")])
 
 (define_expand "rsqrt2"
-  [(set (match_operand:VF1_128_256 0 "register_operand")
-   (unspec:VF1_128_256
- [(match_operand:VF1_128_256 1 "vector_operand")] UNSPEC_RSQRT))]
+  [(set (match_operand:VF_AVX512VL_VF1_128_256 0 "register_operand")
+   (unspec:VF_AVX512VL_VF1_128_256
+ [(match_operand:VF_AVX512VL_VF1_128_256 1 "vector_operand")]
+ UNSPEC_RSQRT))]
   "TARGET_SSE && TARGET_SSE_MATH"
 {
   ix86_emit_swsqrtsf (operands[0], operands[1], mode, true);
   DONE;
 })
 
-(define_expand "rsqrtv16sf2"
-  [(set (match_operand:V16SF 0 "register_operand")
-   (unspec:V16SF
- [(match_operand:V16SF 1 "vector_operand")]
- UNSPEC_RSQRT28))]
-  "TARGET_AVX512ER && TARGET_SSE_MATH"
-{
-  ix86_emit_swsqrtsf (operands[0], operands[1], V16SFmode, true);
-  DONE;
-})
-
 (define_insn "_rsqrt2"
   [(set (match_operand:VF1_128_256 0 "register_operand" "=x")
(unspec:VF1_128_256
diff --git a/gcc/testsuite/gcc.target/i386/pr88713-1.c 
b/gcc/testsuite/gcc.target/i386/pr88713-1.c
new file mode 100644
index 000..2f583b6d1a4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr88713-1.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Ofast -mno-avx512f -mfma" } */
+
+extern float sqrtf (float);
+
+void
+rsqrt (float* restrict r, float* restrict a)
+{
+  for (int i = 0; i < 64; i++)
+r[i] = sqrtf(a[i]);
+}
+
+/* { dg-final { scan-assembler "\tvfmadd\[123\]+ps" } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr88713-2.c 
b/gcc/testsuite/gcc.target/i386/pr88713-2.c
new file mode 100644
index 000..559026df485
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr88713-2.c
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Ofast -march=skylake-avx512 -mno-fma" } */
+
+#include "pr88713-1.c"
+
+/* { dg-final { scan-assembler "\tvfmadd\[123\]+ps" } } */
-- 
2.26.2



[PATCH, committed] PR fortran/95340 - [10/11 Regression] ICE in gfc_match_select_rank, at fortran/match.c:6690

2020-06-28 Thread Harald Anlauf
Committed as obvious.

NULL pointer dereference originally found by Steve.  My patch is shorter. :-)

Regtested on x86_64-pc-linux-gnu.

Thanks,
Harald


PR fortran/95340 - ICE in gfc_match_select_rank, at fortran/match.c:6690

Do not dereference NULL pointer when querying array shape of possibly
improperly delared variable.

gcc/fortran/
PR fortran/95340
* match.c (gfc_match_select_rank): Do not dereference NULL pointer.

diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
index b011634792e..db5174f3f21 100644
--- a/gcc/fortran/match.c
+++ b/gcc/fortran/match.c
@@ -6695,7 +6695,8 @@ gfc_match_select_rank (void)
   if (expr1->symtree)
 	{
 	  sym = expr1->symtree->n.sym;
-	  as = sym->ts.type == BT_CLASS ? CLASS_DATA (sym)->as : sym->as;
+	  as = (sym->ts.type == BT_CLASS
+		&& CLASS_DATA (sym)) ? CLASS_DATA (sym)->as : sym->as;
 	}

   if (expr1->expr_type != EXPR_VARIABLE
diff --git a/gcc/testsuite/gfortran.dg/pr95340.f90 b/gcc/testsuite/gfortran.dg/pr95340.f90
new file mode 100644
index 000..edcdc935057
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr95340.f90
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! PR fortran/95340 - ICE in gfc_match_select_rank, at fortran/match.c:6690
+
+program p
+  type t
+  end type t
+  class(t) :: z   ! { dg-error "must be dummy, allocatable or pointer" }
+  select rank (z) ! { dg-error "must be an assumed rank variable" }
+  end select  ! { dg-error "Expecting END PROGRAM" }
+end


[committed] d: Merge upstream dmd 8508c4e68.

2020-06-28 Thread Iain Buclaw via Gcc-patches
Hi,

This patch merges the D front-end implementation with upstream dmd
8508c4e68.  Fixes a performance bug where 'static foreach' would take an
exponentially long time to expand during CTFE.

In the following example:

static foreach (i; 0..3) {}

Compilation time had been reduced from around 40 to 0.08 seconds.
Memory consumption is also reduced from 3.5GB to 55MB.

Bootstrapped and regression tested on x86_64-linux-gnu, committed to
mainline, and backported to the gcc-10 branch.

Regards
Iain

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 8508c4e68.
---
 gcc/d/dmd/MERGE  |  2 +-
 gcc/d/dmd/cond.c | 73 +++-
 2 files changed, 61 insertions(+), 14 deletions(-)

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index 7de89351482..b99e9f3353d 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-4be011355dd2c5e2e54b99f9369d5faeabca2ca5
+8508c4e683f065eb3deab76b610f7fecb3258a8e
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
diff --git a/gcc/d/dmd/cond.c b/gcc/d/dmd/cond.c
index 12fef59d820..beda133ffdb 100644
--- a/gcc/d/dmd/cond.c
+++ b/gcc/d/dmd/cond.c
@@ -92,13 +92,23 @@ static void lowerArrayAggregate(StaticForeach *sfe, Scope 
*sc)
 el = el->ctfeInterpret();
 if (el->op == TOKint64)
 {
-dinteger_t length = el->toInteger();
-Expressions *es = new Expressions();
-for (size_t i = 0; i < length; i++)
+Expressions *es;
+if (ArrayLiteralExp *ale = aggr->isArrayLiteralExp())
 {
-IntegerExp *index = new IntegerExp(sfe->loc, i, Type::tsize_t);
-Expression *value = new IndexExp(aggr->loc, aggr, index);
-es->push(value);
+// Directly use the elements of the array for the TupleExp creation
+es = ale->elements;
+}
+else
+{
+size_t length = (size_t)el->toInteger();
+es = new Expressions();
+es->setDim(length);
+for (size_t i = 0; i < length; i++)
+{
+IntegerExp *index = new IntegerExp(sfe->loc, i, Type::tsize_t);
+Expression *value = new IndexExp(aggr->loc, aggr, index);
+(*es)[i] = value;
+}
 }
 sfe->aggrfe->aggr = new TupleExp(aggr->loc, es);
 sfe->aggrfe->aggr = semantic(sfe->aggrfe->aggr, sc);
@@ -307,13 +317,50 @@ static void lowerNonArrayAggregate(StaticForeach *sfe, 
Scope *sc)
 Expression *catass = new CatAssignExp(aloc, new IdentifierExp(aloc, 
idres), res[1]);
 s2->push(createForeach(sfe, aloc, pparams[1], new ExpStatement(aloc, 
catass)));
 s2->push(new ReturnStatement(aloc, new IdentifierExp(aloc, idres)));
-Expression *aggr = wrapAndCall(aloc, new CompoundStatement(aloc, s2));
-sc = sc->startCTFE();
-aggr = semantic(aggr, sc);
-aggr = resolveProperties(sc, aggr);
-sc = sc->endCTFE();
-aggr = aggr->optimize(WANTvalue);
-aggr = aggr->ctfeInterpret();
+
+Expression *aggr;
+Type *indexty;
+
+if (sfe->rangefe && (indexty = ety->semantic(aloc, sc))->isintegral())
+{
+sfe->rangefe->lwr->type = indexty;
+sfe->rangefe->upr->type = indexty;
+IntRange lwrRange = getIntRange(sfe->rangefe->lwr);
+IntRange uprRange = getIntRange(sfe->rangefe->upr);
+
+const dinteger_t lwr = sfe->rangefe->lwr->toInteger();
+dinteger_t upr = sfe->rangefe->upr->toInteger();
+size_t length = 0;
+
+if (lwrRange.imin <= uprRange.imax)
+length = (size_t)(upr - lwr);
+
+Expressions *exps = new Expressions();
+exps->setDim(length);
+
+if (sfe->rangefe->op == TOKforeach)
+{
+for (size_t i = 0; i < length; i++)
+(*exps)[i] = new IntegerExp(aloc, lwr + i, indexty);
+}
+else
+{
+--upr;
+for (size_t i = 0; i < length; i++)
+(*exps)[i] = new IntegerExp(aloc, upr - i, indexty);
+}
+aggr = new ArrayLiteralExp(aloc, indexty->arrayOf(), exps);
+}
+else
+{
+aggr = wrapAndCall(aloc, new CompoundStatement(aloc, s2));
+sc = sc->startCTFE();
+aggr = semantic(aggr, sc);
+aggr = resolveProperties(sc, aggr);
+sc = sc->endCTFE();
+aggr = aggr->optimize(WANTvalue);
+aggr = aggr->ctfeInterpret();
+}
 
 assert(!!sfe->aggrfe ^ !!sfe->rangefe);
 sfe->aggrfe = new ForeachStatement(sfe->loc, TOKforeach, pparams[2], aggr,
-- 
2.25.1



[PATCH] PR fortran/71706 - [8/9/10/11 Regression] [Coarray] ICE on using sync images with integer(kind<>4), with -fcoarray=lib -fcheck=bounds

2020-06-28 Thread Harald Anlauf
Here's a fix to bounds-checking code that manifests itself essentially
with checking enabled.  Once found and understood, the fix is trivial:
just properly convert the argument kind of SYNC IMAGES for checking.

Regtested on x86_64-pc-linux-gnu.

OK for master / backports where appropriate?

Thanks,
Harald


PR fortran/71706 - ICE on using sync images with -fcheck=bounds

The run-time checking code did not properly convert the kind of the
argument to SYNC IMAGES, leading to an error in verify_gimple.  Fix that.

gcc/fortran/
PR fortran/71706
* trans-stmt.c (gfc_trans_sync): Do proper kind conversion in
bounds-checking code.

diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c
index 4e9b5ad2932..54b56c4f01d 100644
--- a/gcc/fortran/trans-stmt.c
+++ b/gcc/fortran/trans-stmt.c
@@ -1228,6 +1228,7 @@ gfc_trans_sync (gfc_code *code, gfc_exec_op type)
   if (code->expr1 && (gfc_option.rtcheck & GFC_RTCHECK_BOUNDS)
   && code->expr1->rank == 0)
 {
+  tree images2 = fold_convert (integer_type_node, images);
   tree cond;
   if (flag_coarray != GFC_FCOARRAY_LIB)
 	cond = fold_build2_loc (input_location, NE_EXPR, logical_type_node,
@@ -1239,7 +1240,7 @@ gfc_trans_sync (gfc_code *code, gfc_exec_op type)
  2, integer_zero_node,
  build_int_cst (integer_type_node, -1));
 	  cond = fold_build2_loc (input_location, GT_EXPR, logical_type_node,
-  images, tmp);
+  images2, tmp);
 	  cond2 = fold_build2_loc (input_location, LT_EXPR, logical_type_node,
    images,
    build_int_cst (TREE_TYPE (images), 1));
@@ -1248,8 +1249,7 @@ gfc_trans_sync (gfc_code *code, gfc_exec_op type)
 	}
   gfc_trans_runtime_check (true, false, cond, &se.pre,
 			   &code->expr1->where, "Invalid image number "
-			   "%d in SYNC IMAGES",
-			   fold_convert (integer_type_node, images));
+			   "%d in SYNC IMAGES", images2);
 }

   /* Per F2008, 8.5.1, a SYNC MEMORY is implied by calling the
diff --git a/gcc/testsuite/gfortran.dg/pr71706.f90 b/gcc/testsuite/gfortran.dg/pr71706.f90
new file mode 100644
index 000..860c1c8be80
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr71706.f90
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=lib -fcheck=all -fdefault-integer-8" }
+! PR fortran/71706 - ICE on using sync images with -fcheck=bounds
+
+program p
+  integer, volatile :: me = 1
+  sync images (me)
+  sync images (int (me, 2))
+  sync images (int (me, 8))
+end


Re: [PING][PATCH] underline null argument in -Wnonnull (PR c++/86568)

2020-06-28 Thread Martin Sebor via Gcc-patches

On 6/26/20 3:58 PM, Jeff Law wrote:

On Mon, 2020-06-22 at 12:02 -0600, Martin Sebor wrote:

Ping: https://gcc.gnu.org/pipermail/gcc-patches/2020-June/547415.html

Jason already approved the C++ changes (with a couple of minor
tweaks).  I'm still looking for an approval of the corresponding
middle end diff.

Do you need an auto_digantosic_group in the tree-ssa-ccp.c changes too?  If so,
add it.  If not, then it's OK as-is.


I added it there as well.

My understanding is that auto_diagnostic_group is a placeholder for
a future enhancement that David wants to add, and it doesn't yet do
anything useful, so there's no way to test the code.

Martin


Re: [PATCH] libstdc++: Add a __nonnnull__ attribute to std::string's _CharT* constructor

2020-06-28 Thread Jonathan Wakely via Gcc-patches

On 28/06/20 14:01 +0300, Ville Voutilainen via Libstdc++ wrote:

On Sun, 28 Jun 2020 at 13:56, Ville Voutilainen
 wrote:


2020-06-28  Ville Voutilainen  

Add a __nonnnull__ attribute to std::string's _CharT* constructor
* include/bits/basic_string.h (string(_CharT*, const _Alloc&)):
Add a __nonnull__ attribute.
* testsuite/21_strings/basic_string/cons/char/nonnull.cc: New.
* testsuite/21_strings/basic_string/cons/wchar_t/nonnull.cc: Likewise.



Hmm, let's use dg-additional-options here too, and axe the pointless
-std=gnu++11.


I agree the -std=gnu++11 isn't needed, but thre doesn't seem to be any
advantage to dg-additional-options here. The reason I suggested it for
th other tests was that it can take a target selector, so it can be
used to add options for some targets only (in the case of the variant
tests, only if the dialect is c++17 or later).

Here you want the -Wnonnull added unconditionally, with no target
selector, so dg-options works fine.

No big deal though, they work equivalently for this case.

OK for master, thanks.




Re: [PATCH] libstdc++: std::variant doesn't like types with a defaulted virtual destructor [PR95915]

2020-06-28 Thread Jonathan Wakely via Gcc-patches

On 27/06/20 18:20 +0300, Ville Voutilainen via Libstdc++ wrote:

On Sat, 27 Jun 2020 at 17:53, Ville Voutilainen
 wrote:


On Fri, 26 Jun 2020 at 21:20, Jonathan Wakely  wrote:
> For these three tests I think this would be slightly better:
>
> // { dg-additional-options "-Wno-deprecated" { target c++17 } }
>
> That way we only ignore the warning when actually needed.

Sure thing. The test run revealed some additional things to tweak. OK for trunk
and GCC 10?


With a twist, I mean. I don't plan to backport the deprecation, just
the bug fix for variant.



OK, thanks




Re: [PATCH] libstdc++: Add a __nonnnull__ attribute to std::string's _CharT* constructor

2020-06-28 Thread Ville Voutilainen via Gcc-patches
On Mon, 29 Jun 2020 at 00:16, Jonathan Wakely  wrote:
> >Hmm, let's use dg-additional-options here too, and axe the pointless
> >-std=gnu++11.
>
> I agree the -std=gnu++11 isn't needed, but thre doesn't seem to be any
> advantage to dg-additional-options here. The reason I suggested it for
> th other tests was that it can take a target selector, so it can be
> used to add options for some targets only (in the case of the variant
> tests, only if the dialect is c++17 or later).
>
> Here you want the -Wnonnull added unconditionally, with no target
> selector, so dg-options works fine.

Right, I somehow managed to think that dg-additional-options amends options
and dg-options overrides them. Here my intent is certainly the former.


Re: [PATCH] handle MEM_REF with void* arguments (PR c++/95768)

2020-06-28 Thread Martin Sebor via Gcc-patches

On 6/23/20 1:12 AM, Richard Biener wrote:

On Tue, Jun 23, 2020 at 12:22 AM Martin Sebor via Gcc-patches
 wrote:


On 6/22/20 12:55 PM, Jason Merrill wrote:

On 6/22/20 1:25 PM, Martin Sebor wrote:

The attached fix parallels the one for the equivalent C bug 95580
where the pretty printers don't correctly handle MEM_REF arguments
with type void* or other pointers to an incomplete type.

The incorrect handling was exposed by the recent change to
-Wuninitialized which includes such expressions in diagnostics.



+if (tree size = TYPE_SIZE_UNIT (TREE_TYPE (argtype)))
+  if (!integer_onep (size))
+{
+  pp_cxx_left_paren (pp);
+  dump_type (pp, ptr_type_node, flags);
+  pp_cxx_right_paren (pp);
+}


Don't we want to print the cast if the pointer target type is incomplete?


I suppose, yes, although after some more testing I think what should
be output is the type of the access.  The target pointer type isn't
meaningful (at least not in this case).

Here's what the warning looks like in C for the test case in
gcc.dg/pr95580.c:

warning: ‘*((void *)(p)+1)’ may be used uninitialized

and like this in C++:

warning: ‘*(p +1)’ may be used uninitialized

The +1 is a byte offset, which is correct given that incrementing
a void* in GCC is the same as adding 1 to the byte address, but
dereferencing a void* doesn't correspond to what's going on in
the source.

Even for a complete type (with size greater than 1), printing
the type of the argument plus a byte offset is wrong.  It ends
up with this for the C++ test case from 95768:

warning: ‘*((int*) +4)’ is used uninitialized

when the access is actually ‘*((int*) +1)’

So it seems to me for MEM_REF, to make the output meaningful,
it's the type of the access (i.e., the MEM_REF type) that should
be printed here, and the offset should either be in elements of
the accessed type, i.e.,

warning: ‘*((int*) +1)’ is used uninitialized

or, if the access is misaligned, the argument should first be
cast to char*, the offset added, and the result then cast to
the access type, like this:

warning: ‘*(T*)((char*) +1)’ is used uninitialized

The attached revised and less than fully tested patch implements
this for C++ only for now.  If we agree on this approach I'll see
about making the corresponding change in C.


Note that there is no C/C++ way of fully expressing MEM_REF
semantics.  __MEM  ((T *)p + 1) is not actually
*(int *)((char *)p + 1) because that does not reflect that the
effective type of the lvalue when TBAA is concerned is 'T'
rather than 'int'.


What form would you say is closest to the C/C++ semantics, or
likely the most useful to users, that GCC could print instead?


Note for MEM_REF the offset is always
a constant byte offset but it indeed does not have to be a
multiple of the MEM_REF type size.

I wonder whether printing the MEM_REF in full provides
any real diagnostic value in the more "obfuscated" cases.


I'm not sure what obfuscated cases you're thinking of, or what
you mean by printing it in full.  I instrumented the code to
print every MEM_REF in that comes up in warn_uninitialized_vars
and rebuilt GCC.  There are 17,456 distinct instances so I didn't
review them all but those I did look at all look reasonable.
Probably the least useful are those that mention  by
itself (i.e.,  or *).  Those with an offset
are more informative (e.g., *((access**) +1).  In
a few the offset is very large, such as *((unsigned int*)sp
+4611686018427387900), but that doesn't seem like a problem.
I'd be happy to share the result.



I'd also not print  but .


I also don't find  helpful, but I don't see 
as an improvement.  I think printing the SSA variable would be
more informative here since its name is usually related to
the variable it was derived from in the source.  But making that
change (or any other like it) feels like too much feature creep
for this fix.  I'd be happy to do it in a follow up if we agree
it's a good idea.

Either way, please let me know if the patch is okay as is or,
if not, what type it should mention.

Martin