[PATCH, rtl] Fix PR84878: Segmentation fault in add_cross_iteration_register_deps

2018-03-26 Thread Peter Bergner
PR84878 shows an example where we segv while creating data dependence edges
for SMS.

ddg.c:add_cross_iteration_register_deps():

  /* Create inter-loop true dependences and anti dependences.  */
  for (r_use = DF_REF_CHAIN (last_def); r_use != NULL; r_use = r_use->next)
{
  rtx_insn *use_insn = DF_REF_INSN (r_use->ref);
    segv's

We currently have:
(gdb) pr def_insn
(insn 331 321 332 12 (parallel [
(set (reg:V4SI 239 [ vect__4.11 ])
(unspec:V4SI [
(reg:V4SF 134 [ vect_cst__39 ])
(const_int 0 [0])
] UNSPEC_VCTSXS))
(set (reg:SI 110 vscr)
(unspec:SI [
(const_int 0 [0])
] UNSPEC_SET_VSCR))
]) "bug.i":9 1812 {altivec_vctsxs}
 (expr_list:REG_UNUSED (reg:V4SI 239 [ vect__4.11 ])
(nil)))
(gdb) p DF_REF_REGNO (last_def)
$4 = 110

So we're looking at the definition of the VSCR hard register, which is a
global register (ie, global_regs[110] == 1), but there are no following
explicit uses of the VSCR reg, so:

(gdb) p DF_REF_INSN_INFO(r_use->ref)
$5 = (df_insn_info *) 0x0

DF_REF_INSN(r_use->ref) deferences DF_REF_INSN_INFO(r_use->ref), so we segv.

The following patch fixes the problems by simply skiping over the "uses"
that do not have insn info (ie, no explicit uses or artificial ones).

This passed bootstrap and regtesting with no regressions on powerpc64-linux.
Ok for trunk?

Peter


gcc/
PR rtl-optimization/84878
* ddg.c (add_cross_iteration_register_deps): Skip over uses that do
not correspond to explicit register references.

gcc/testsuite/
PR rtl-optimization/84878
* gcc.dg/pr84878.c: New test.

Index: gcc/ddg.c
===
--- gcc/ddg.c   (revision 258802)
+++ gcc/ddg.c   (working copy)
@@ -295,6 +295,11 @@ add_cross_iteration_register_deps (ddg_p
   /* Create inter-loop true dependences and anti dependences.  */
   for (r_use = DF_REF_CHAIN (last_def); r_use != NULL; r_use = r_use->next)
 {
+  /* PR84878: Some definitions of global hard registers may not have
+  any following uses or they may be artificial, so skip them.  */
+  if (DF_REF_INSN_INFO (r_use->ref) == NULL)
+   continue;
+
   rtx_insn *use_insn = DF_REF_INSN (r_use->ref);
 
   if (BLOCK_FOR_INSN (use_insn) != g->bb)
Index: gcc/testsuite/gcc.dg/pr84878.c
===
--- gcc/testsuite/gcc.dg/pr84878.c  (revision 0)
+++ gcc/testsuite/gcc.dg/pr84878.c  (working copy)
@@ -0,0 +1,20 @@
+/* PR rtl-optimization/84878 */
+/* { dg-do compile { target { powerpc*-*-* } } } */
+/* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { 
"-mcpu=G5" } } */
+/* { dg-require-effective-target powerpc_altivec_ok } */
+/* { dg-options "-O2 -mcpu=G5 -fmodulo-sched -ftree-vectorize -funroll-loops 
-fassociative-math -fno-signed-zeros -fno-trapping-math" } */
+
+int ek;
+float zu;
+
+int
+k5 (int ks)
+{
+  while (ek < 1)
+{
+  ks += (int)(0x100 + zu + !ek);
+  ++ek;
+}
+
+  return ks;
+}



[PATCH,nvptx] Fix PR85056

2018-03-26 Thread Cesar Philippidis
As noted in PR85056, the nvptx BE isn't declaring external arrays using
PTX array notation. Specifically, it's emitting code that's missing the
empty angle brackets '[]'. This patch corrects that problem.

Tom, in contrast to my earlier patch in the PR, this patch only
considers external arrays. The patch I posted incorrectly handled
zero-length arrays and empty structs.

I tested this patch with a standalone nvptx toolchain using newlib 3.0,
and I found no new regressions. However I'm still waiting for the
results that are using the older version of newlib. Is this patch OK for
trunk if the results come back clean?

Thanks,
Cesar
2018-03-26  Cesar Philippidis  

	gcc/

	PR target/85056
	* config/nvptx/nvptx.c (nvptx_assemble_decl_begin): Add '[]' to
	extern array declarations.

	gcc/testsuite/
	* testsuite/gcc.target/nvptx/pr85056.c: New test.
	* testsuite/gcc.target/nvptx/pr85056a.c: New test.


diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c
index 3cb33ae8c2d..38f25add6ab 100644
--- a/gcc/config/nvptx/nvptx.c
+++ b/gcc/config/nvptx/nvptx.c
@@ -2038,6 +2038,9 @@ static void
 nvptx_assemble_decl_begin (FILE *file, const char *name, const char *section,
 			   const_tree type, HOST_WIDE_INT size, unsigned align)
 {
+  bool atype = (TREE_CODE (type) == ARRAY_TYPE)
+&& (TYPE_DOMAIN (type) == NULL_TREE);
+
   while (TREE_CODE (type) == ARRAY_TYPE)
 type = TREE_TYPE (type);
 
@@ -2077,6 +2080,8 @@ nvptx_assemble_decl_begin (FILE *file, const char *name, const char *section,
 /* We make everything an array, to simplify any initialization
emission.  */
 fprintf (file, "[" HOST_WIDE_INT_PRINT_DEC "]", init_frag.remaining);
+  else if (atype)
+fprintf (file, "[]");
 }
 
 /* Called when the initializer for a decl has been completely output through
diff --git a/gcc/testsuite/gcc.target/nvptx/pr85056.c b/gcc/testsuite/gcc.target/nvptx/pr85056.c
new file mode 100644
index 000..fe7f8af856e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/nvptx/pr85056.c
@@ -0,0 +1,20 @@
+/* { dg-do run } */
+/* { dg-additional-sources "pr85056a.c" } */
+
+extern void abort ();
+
+extern int a[];
+
+int
+main ()
+{
+  int i, sum;
+
+  for (i = 0; i < 10; i++)
+sum += a[i];
+
+  if (sum != 55)
+abort ();
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/nvptx/pr85056a.c b/gcc/testsuite/gcc.target/nvptx/pr85056a.c
new file mode 100644
index 000..a45a5f2b07f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/nvptx/pr85056a.c
@@ -0,0 +1,3 @@
+/* { dg-skip-if "" { *-*-* } } */
+
+int a[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };


[PATCH, fortran] PR85083 - [8 Regression] ICE in gfc_convert_to_structure_constructor, at fortran/primary.c:2915

2018-03-26 Thread Harald Anlauf
The attached obvious one-liner adds a missing check for type
compatibility in a structure constructor.

Testcase from report.  Changelogs below.

Regtested on i686-pc-linux-gnu.

Whoever reviews this, please feel free to commit.

Thanks,
Harald

2018-03-26  Harald Anlauf  

PR fortran/85083
* primary.c (gfc_convert_to_structure_constructor): Check
conformance of argument types in structure constructor.


2018-03-26  Harald Anlauf  

PR fortran/85083
* gfortran.dg/pr85083.f90: New test.

Index: gcc/fortran/primary.c
===
--- gcc/fortran/primary.c   (revision 258846)
+++ gcc/fortran/primary.c   (working copy)
@@ -2898,6 +2898,7 @@
   if (this_comp->ts.type == BT_CHARACTER && !this_comp->attr.allocatable
  && this_comp->ts.u.cl && this_comp->ts.u.cl->length
  && this_comp->ts.u.cl->length->expr_type == EXPR_CONSTANT
+ && actual->expr->ts.type == BT_CHARACTER
  && actual->expr->expr_type == EXPR_CONSTANT)
{
  ptrdiff_t c, e;
Index: gcc/testsuite/gfortran.dg/pr85083.f90
===
--- gcc/testsuite/gfortran.dg/pr85083.f90   (revision 0)
+++ gcc/testsuite/gfortran.dg/pr85083.f90   (revision 0)
@@ -0,0 +1,12 @@
+! { dg-do compile }
+! PR 85083
+!
+! Testcase from PR by G. Steinmetz  
+!
+program p
+  type t
+ character(3) :: c
+  end type t
+  type(t), allocatable :: z
+  allocate (z, source=t(.true.,'abc')) ! { dg-error "Too many components" }
+end


RE: [PATCH] i386: Insert ENDBR to trampoline for -fcf-protection=branch -mibt

2018-03-26 Thread Tsimbalist, Igor V
> -Original Message-
> From: H.J. Lu [mailto:hjl.to...@gmail.com]
> Sent: Monday, March 26, 2018 5:59 PM
> To: Tsimbalist, Igor V 
> Cc: gcc-patches@gcc.gnu.org; Uros Bizjak 
> Subject: Re: [PATCH] i386: Insert ENDBR to trampoline for -fcf-
> protection=branch -mibt
> 
> On Mon, Mar 26, 2018 at 8:23 AM, Tsimbalist, Igor V
>  wrote:
> >> -Original Message-
> >> From: Lu, Hongjiu
> >> Sent: Sunday, March 25, 2018 12:50 AM
> >> To: gcc-patches@gcc.gnu.org; Uros Bizjak ;
> Tsimbalist,
> >> Igor V 
> >> Subject: [PATCH] i386: Insert ENDBR to trampoline for -fcf-
> >> protection=branch -mibt
> >>
> >> When -fcf-protection=branch -mibt are used, we need to insert ENDBR
> >> to trampoline.  TRAMPOLINE_SIZE is creased by 4 bytes to accommodate
> >> 4-byte ENDBR instruction.
> >>
> >> OK for trunk?
> >
> > Regarding the test. Is it possible to check what is generated in a
> trampoline? In particular, that endbr is generated.
> >
> 
> I think run-time test is sufficient.

Ok then.

> --
> H.J.


Re: RFC: Disable asan tests under ulimit -v

2018-03-26 Thread Jakub Jelinek
On Mon, Mar 26, 2018 at 08:33:41PM +0200, Andreas Schwab wrote:
> On Mär 26 2018, Jason Merrill  wrote:
> 
> > if [catch {exec sh ulimit -v} ulimit_v] {
> 
> expect1.1> exec sh ulimit -v
> sh: ulimit: No such file or directory
> while executing
> "exec sh ulimit -v"

Perhaps
  if [catch {exec sh -c ulimit -v} ulimit_v] {

Jakub


Re: RFC: Disable asan tests under ulimit -v

2018-03-26 Thread Jason Merrill
On Mon, Mar 26, 2018 at 2:55 PM, Andreas Schwab  wrote:
> On Mär 26 2018, Jakub Jelinek  wrote:
>> On Mon, Mar 26, 2018 at 08:33:41PM +0200, Andreas Schwab wrote:
>>> On Mär 26 2018, Jason Merrill  wrote:
>>>
>>> > if [catch {exec sh ulimit -v} ulimit_v] {
>>>
>>> expect1.1> exec sh ulimit -v
>>> sh: ulimit: No such file or directory
>>> while executing
>>> "exec sh ulimit -v"
>>
>> Perhaps
>>   if [catch {exec sh -c ulimit -v} ulimit_v] {
>
> expect1.1> exec sh -c ulimit -v
> unlimited
> expect1.2> exec sh -c {ulimit -v}
> 4194304

OK, so

if ![is_remote target] {
if [catch {exec sh -c "ulimit -v"} ulimit_v] {
# failed to get ulimit
} elseif [regexp {^[0-9]+$} $ulimit_v] {
# ulimit -v gave a numeric limit
return
}
}


[PATCH, i386]: Fix PR 85073: extra check after BLSR

2018-03-26 Thread Uros Bizjak
2018-03-26  Uros Bizjak  

PR target/85073
* config/i386/i386.md (*bmi_blsr__cmp): New insn pattern.
(*bmi_blsr__ccz): Ditto.

testsuite/ChangeLog:

2018-03-26  Uros Bizjak  

PR target/85073
* gcc.target/i386/pr85073.c: New test.

Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.
Committed to mainline SVN.

Uros.
Index: config/i386/i386.md
===
--- config/i386/i386.md (revision 258856)
+++ config/i386/i386.md (working copy)
@@ -13774,6 +13774,43 @@
(set_attr "btver2_decode" "double")
(set_attr "mode" "")])
 
+(define_insn "*bmi_blsr__cmp"
+  [(set (reg:CCZ FLAGS_REG)
+   (compare:CCZ
+ (and:SWI48
+   (plus:SWI48
+ (match_operand:SWI48 1 "nonimmediate_operand" "rm")
+ (const_int -1))
+   (match_dup 1))
+ (const_int 0)))
+   (set (match_operand:SWI48 0 "register_operand" "=r")
+   (and:SWI48
+ (plus:SWI48
+   (match_dup 1)
+   (const_int -1))
+ (match_dup 1)))]
+   "TARGET_BMI"
+   "blsr\t{%1, %0|%0, %1}"
+  [(set_attr "type" "bitmanip")
+   (set_attr "btver2_decode" "double")
+   (set_attr "mode" "")])
+
+(define_insn "*bmi_blsr__ccz"
+  [(set (reg:CCZ FLAGS_REG)
+   (compare:CCZ
+ (and:SWI48
+   (plus:SWI48
+ (match_operand:SWI48 1 "nonimmediate_operand" "rm")
+ (const_int -1))
+   (match_dup 1))
+ (const_int 0)))
+   (clobber (match_scratch:SWI48 0 "=r"))]
+   "TARGET_BMI"
+   "blsr\t{%1, %0|%0, %1}"
+  [(set_attr "type" "bitmanip")
+   (set_attr "btver2_decode" "double")
+   (set_attr "mode" "")])
+
 ;; BMI2 instructions.
 (define_expand "bmi2_bzhi_3"
   [(parallel
Index: testsuite/gcc.target/i386/pr85073.c
===
--- testsuite/gcc.target/i386/pr85073.c (nonexistent)
+++ testsuite/gcc.target/i386/pr85073.c (working copy)
@@ -0,0 +1,18 @@
+/* PR target/85073 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mbmi" } */
+
+int
+foo (unsigned x)
+{
+  int c = 0;
+  while (x)
+{
+  c += 1;
+  x = (x - 1) & x;
+}
+
+  return c;
+}
+
+/* { dg-final { scan-assembler-times "test" 1 } } */


libgo patch committed: Don't check for a stale runtime

2018-03-26 Thread Ian Lance Taylor
The runtime tests, as expected by the gotools testsuite, check whether
the runtime package is stale.  The gccgo runtime package can never be
stale, and checking for staleness can cause confusion if it winds up
checking the gc package instead.  Skip the test for gccgo.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
Index: gcc/go/gofrontend/MERGE
===
--- gcc/go/gofrontend/MERGE (revision 258725)
+++ gcc/go/gofrontend/MERGE (working copy)
@@ -1,4 +1,4 @@
-e9c0e4d8fd3d951a367bb6a50e5cb546e01b81a8
+3aa5fc91094c5f24b26747ec176ad44cde784fc7
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/go/runtime/crash_test.go
===
--- libgo/go/runtime/crash_test.go  (revision 258725)
+++ libgo/go/runtime/crash_test.go  (working copy)
@@ -150,6 +150,9 @@ var (
 
 func checkStaleRuntime(t *testing.T) {
staleRuntimeOnce.Do(func() {
+   if runtime.Compiler == "gccgo" {
+   return
+   }
// 'go run' uses the installed copy of runtime.a, which may be 
out of date.
out, err := 
testenv.CleanCmdEnv(exec.Command(testenv.GoToolPath(t), "list", 
"-gcflags=all="+os.Getenv("GO_GCFLAGS"), "-f", "{{.Stale}}", 
"runtime")).CombinedOutput()
if err != nil {


[RFC PATCH for 9] rs6000: Ordered comparisons (PR56864)

2018-03-26 Thread Segher Boessenkool
This implements ordered comparisons for most floating point variants.

It does not yet implement it for XL-compatible FP comparisons.

I do not yet know if it works correctly for emulated 128-bit IEEE FP.

There should not be performance impact, but I haven't tested it
thoroughly yet.


Segher


* config/rs6000/rs6000.c (rs6000_generate_compare): Add an UNSPEC_CMPO
to those floating-point comparisons that are not quiet.
* config/rs6000/rs6000.md (define_c_enum enspec): Add UNSPEC_CMPO.
(*cmp_fpr): Rename to ...
(*cmp_cmpu): ... this.  (SFDF)
(*cmp_cmpo): New.
(*cmp_internal1): Rename to ...
(*cmp_cmpu): ... this.  (IBM128)
(*cmp_cmpo): New.
(*cmp_hw): Rename to ...
(*cmp_cmpu): ... this.  (IEEE128)
(*cmp_cmpo): New.
* config/rs6000/dfp.md (*cmpdd_internal1): Rename to ...
(*cmpdd_cmpu): ... this.
(*cmpdd_cmpo): New.
(*cmptd_internal1): Rename to ...
(*cmptd_cmpu): ... this.
(*cmptd_cmpo): New.

gcc/testsuite/
* gcc.dg/torture/inf-compare-1.c: Remove powerpc xfail.
* gcc.dg/torture/inf-compare-2.c: Remove powerpc xfail.
* gcc.dg/torture/inf-compare-3.c: Remove powerpc xfail.
* gcc.dg/torture/inf-compare-4.c: Remove powerpc xfail.
* gcc.target/powerpc/dfp-dd.c: Expect dcmpo to be generated for the
ordered compares.
* gcc.target/powerpc/dfp-td.c: Expect dcmpoq to be generated for the
ordered compares.

---
 gcc/config/rs6000/dfp.md |   22 -
 gcc/config/rs6000/rs6000.c   |   15 -
 gcc/config/rs6000/rs6000.md  |   41 +++--
 gcc/testsuite/gcc.dg/torture/inf-compare-1.c |3 +-
 gcc/testsuite/gcc.dg/torture/inf-compare-2.c |3 +-
 gcc/testsuite/gcc.dg/torture/inf-compare-3.c |3 +-
 gcc/testsuite/gcc.dg/torture/inf-compare-4.c |3 +-
 gcc/testsuite/gcc.target/powerpc/dfp-dd.c|3 +-
 gcc/testsuite/gcc.target/powerpc/dfp-td.c|3 +-
 9 files changed, 78 insertions(+), 18 deletions(-)

diff --git a/gcc/config/rs6000/dfp.md b/gcc/config/rs6000/dfp.md
index cd15aa8..8eb5dcc 100644
--- a/gcc/config/rs6000/dfp.md
+++ b/gcc/config/rs6000/dfp.md
@@ -216,7 +216,7 @@
   "ddivq %0,%1,%2"
   [(set_attr "type" "dfp")])
 
-(define_insn "*cmpdd_internal1"
+(define_insn "*cmpdd_cmpu"
   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
(compare:CCFP (match_operand:DD 1 "gpc_reg_operand" "d")
  (match_operand:DD 2 "gpc_reg_operand" "d")))]
@@ -224,7 +224,16 @@
   "dcmpu %0,%1,%2"
   [(set_attr "type" "dfp")])
 
-(define_insn "*cmptd_internal1"
+(define_insn "*cmpdd_cmpo"
+  [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
+   (compare:CCFP (match_operand:DD 1 "gpc_reg_operand" "d")
+ (match_operand:DD 2 "gpc_reg_operand" "d")))
+   (unspec [(match_dup 1) (match_dup 2)] UNSPEC_CMPO)]
+  "TARGET_DFP"
+  "dcmpo %0,%1,%2"
+  [(set_attr "type" "dfp")])
+
+(define_insn "*cmptd_cmpu"
   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
(compare:CCFP (match_operand:TD 1 "gpc_reg_operand" "d")
  (match_operand:TD 2 "gpc_reg_operand" "d")))]
@@ -232,6 +241,15 @@
   "dcmpuq %0,%1,%2"
   [(set_attr "type" "dfp")])
 
+(define_insn "*cmptd_cmpo"
+  [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
+   (compare:CCFP (match_operand:TD 1 "gpc_reg_operand" "d")
+ (match_operand:TD 2 "gpc_reg_operand" "d")))
+   (unspec [(match_dup 1) (match_dup 2)] UNSPEC_CMPO)]
+  "TARGET_DFP"
+  "dcmpoq %0,%1,%2"
+  [(set_attr "type" "dfp")])
+
 (define_insn "floatdidd2"
   [(set (match_operand:DD 0 "gpc_reg_operand" "=d")
(float:DD (match_operand:DI 1 "gpc_reg_operand" "d")))]
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 1fe8b9a..401be74 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -22127,8 +22127,19 @@ rs6000_generate_compare (rtx cmp, machine_mode mode)
emit_insn (gen_stack_protect_testsi (compare_result, op0, op1b));
}
   else
-   emit_insn (gen_rtx_SET (compare_result,
-   gen_rtx_COMPARE (comp_mode, op0, op1)));
+   {
+ rtx compare = gen_rtx_SET (compare_result,
+gen_rtx_COMPARE (comp_mode, op0, op1));
+ if (SCALAR_FLOAT_MODE_P (mode) && HONOR_NANS (mode)
+ && (code == LT || code == GT || code == LE || code == GE))
+   {
+ rtx unspec = gen_rtx_UNSPEC (VOIDmode, gen_rtvec (2, op0, op1),
+  UNSPEC_CMPO);
+ compare = gen_rtx_PARALLEL (VOIDmode,
+ gen_rtvec (2, compare, unspec));
+   }
+ emit_insn (compare);
+   }
 }
 
   /* Some kinds of FP comparisons need an OR operation;
diff --git 

Re: RFC: Disable asan tests under ulimit -v

2018-03-26 Thread Andreas Schwab
On Mär 26 2018, Jakub Jelinek  wrote:

> On Mon, Mar 26, 2018 at 08:33:41PM +0200, Andreas Schwab wrote:
>> On Mär 26 2018, Jason Merrill  wrote:
>> 
>> > if [catch {exec sh ulimit -v} ulimit_v] {
>> 
>> expect1.1> exec sh ulimit -v
>> sh: ulimit: No such file or directory
>> while executing
>> "exec sh ulimit -v"
>
> Perhaps
>   if [catch {exec sh -c ulimit -v} ulimit_v] {

expect1.1> exec sh -c ulimit -v
unlimited
expect1.2> exec sh -c {ulimit -v}
4194304

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Re: RFC: Disable asan tests under ulimit -v

2018-03-26 Thread Andreas Schwab
On Mär 26 2018, Jason Merrill  wrote:

> if [catch {exec sh ulimit -v} ulimit_v] {

expect1.1> exec sh ulimit -v
sh: ulimit: No such file or directory
while executing
"exec sh ulimit -v"

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Re: [C++ Patch] PR 84632 ("[8 Regression] internal compiler error: tree check: expected record_type or union_type or qual_union_type, have array_type in reduced_constant_expression_p...")

2018-03-26 Thread Jason Merrill
On Mon, Mar 26, 2018 at 1:57 PM, Paolo Carlini  wrote:
> Hi,
>
> On 26/03/2018 19:12, Jason Merrill wrote:
>>
>> Your build_aggr_init change is OK, but I had in mind something more
>> general in build_vec_init:
>
> Oh nice. Shall I test it together with my build_aggr_type bits and the
> testcases and commit it if everything is Ok?

Please.

Jason


Re: RFC: Disable asan tests under ulimit -v

2018-03-26 Thread Jason Merrill
On Mon, Mar 26, 2018 at 1:31 PM, Andreas Schwab  wrote:
> On Mär 26 2018, Jason Merrill  wrote:
>
>> On Sat, Mar 24, 2018 at 4:51 AM, Andreas Schwab  
>> wrote:
>>> On Mär 23 2018, Jason Merrill  wrote:
>>>
 diff --git a/gcc/testsuite/g++.dg/asan/asan.exp 
 b/gcc/testsuite/g++.dg/asan/asan.exp
 index 4ee8dd98697..a22d2ac5e20 100644
 --- a/gcc/testsuite/g++.dg/asan/asan.exp
 +++ b/gcc/testsuite/g++.dg/asan/asan.exp
 @@ -24,6 +24,13 @@ load_lib asan-dg.exp
  dg-init
  asan_init

 +# asan doesn't work if there's a ulimit on virtual memory.
 +if ![is_remote target] {
 +if [regexp {^[0-9]+$} "[exec ulimit -v]"] {
>>>
>>> Does that actually work?
>>
>> It does for me.
>>
>>> ulimit is a shell builtin, but exec does not use the shell.
>>
>> It's also a separate executable.
>
> Not for me.
>
>>> Also, you get an error if the command returns a non-zero
>>> status, or isn't found.
>>
>> In that case, the result of the exec won't be a string of numbers, so
>> we run the tests.
>
> The error will abort the whole script.

Ah, good point.  How about this?

# asan doesn't work if there's a ulimit on virtual memory.
if ![is_remote target] {
if [catch {exec sh ulimit -v} ulimit_v] {
# failed to get ulimit
} elseif [regexp {^[0-9]+$} $ulimit_v] {
# ulimit -v gave a numeric limit
return
}
}

Jason


Re: [C++ Patch] PR 84632 ("[8 Regression] internal compiler error: tree check: expected record_type or union_type or qual_union_type, have array_type in reduced_constant_expression_p...")

2018-03-26 Thread Paolo Carlini

Hi,

On 26/03/2018 19:12, Jason Merrill wrote:

Your build_aggr_init change is OK, but I had in mind something more
general in build_vec_init:
Oh nice. Shall I test it together with my build_aggr_type bits and the 
testcases and commit it if everything is Ok? By the way - FYI - what I 
had tested was used *only* by lambda-array.C and lambda-errloc.C.


Paolo.


Re: RFC: Disable asan tests under ulimit -v

2018-03-26 Thread Andreas Schwab
On Mär 26 2018, Jason Merrill  wrote:

> On Sat, Mar 24, 2018 at 4:51 AM, Andreas Schwab  wrote:
>> On Mär 23 2018, Jason Merrill  wrote:
>>
>>> diff --git a/gcc/testsuite/g++.dg/asan/asan.exp 
>>> b/gcc/testsuite/g++.dg/asan/asan.exp
>>> index 4ee8dd98697..a22d2ac5e20 100644
>>> --- a/gcc/testsuite/g++.dg/asan/asan.exp
>>> +++ b/gcc/testsuite/g++.dg/asan/asan.exp
>>> @@ -24,6 +24,13 @@ load_lib asan-dg.exp
>>>  dg-init
>>>  asan_init
>>>
>>> +# asan doesn't work if there's a ulimit on virtual memory.
>>> +if ![is_remote target] {
>>> +if [regexp {^[0-9]+$} "[exec ulimit -v]"] {
>>
>> Does that actually work?
>
> It does for me.
>
>> ulimit is a shell builtin, but exec does not use the shell.
>
> It's also a separate executable.

Not for me.

>> Also, you get an error if the command returns a non-zero
>> status, or isn't found.
>
> In that case, the result of the exec won't be a string of numbers, so
> we run the tests.

The error will abort the whole script.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Re: C++ PATCH for c++/85032, rejects-valid with if constexpr in template

2018-03-26 Thread Jason Merrill
On Sat, Mar 24, 2018 at 6:59 AM, Marek Polacek  wrote:
> Recently the code in finish_static_assert was changed to use
> perform_implicit_conversion_flags followed by fold_non_dependent_expr.  That
> broke this test becase when in a template, p_i_c_f merely wraps the expr in
> an IMPLICIT_CONV_EXPR.  fold_non_dependent_expr should be able to fold it to
> a constant but it gave up because is_nondependent_constant_expression returned
> false.  Jason suggested to fix this roughly like the following, i.e. consider
> conversions from classes to literal types potentially constant.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2018-03-24  Marek Polacek  
>
> PR c++/85032
> * constexpr.c (potential_constant_expression_1): Consider conversions
> from classes to literal types potentially constant.
>
> * g++.dg/cpp0x/pr51225.C: Adjust error message.
> * g++.dg/cpp1z/constexpr-if17.C: New test.
>
> diff --git gcc/cp/constexpr.c gcc/cp/constexpr.c
> index bebd9f5b5d0..c4b5afe90a2 100644
> --- gcc/cp/constexpr.c
> +++ gcc/cp/constexpr.c
> @@ -5768,6 +5768,23 @@ potential_constant_expression_1 (tree t, bool 
> want_rval, bool strict, bool now,
>   TREE_TYPE (t));
>   return false;
> }
> +  /* This might be a conversion from a class to a literal type.  Let's
> +consider it potentially constant since the conversion might be
> +a constexpr user-defined conversion.  */
> +  else if (cxx_dialect >= cxx11
> +  && COMPLETE_TYPE_P (TREE_TYPE (t))
> +  && literal_type_p (TREE_TYPE (t))

We probably need to allow dependent types here, too.  And incomplete
classes, which might turn out to be literal later.

Jason


Re: [C++ Patch] PR 84632 ("[8 Regression] internal compiler error: tree check: expected record_type or union_type or qual_union_type, have array_type in reduced_constant_expression_p...")

2018-03-26 Thread Jason Merrill
On Mon, Mar 26, 2018 at 5:19 AM, Paolo Carlini  wrote:
> On 23/03/2018 13:39, Jason Merrill wrote:
>> On Fri, Mar 23, 2018 at 6:13 AM, Paolo Carlini 
>> wrote:
>>>
>>> On 22/03/2018 23:26, Jason Merrill wrote:

 On Thu, Mar 22, 2018 at 5:39 PM, Paolo Carlini
 
 wrote:
>
> ... with patch ;)
>
> If you are curious where the heck that INDIRECT_REF is coming from, is
> coming from the gimplifier, cp_gimpliify_expr, via build_vec_init.
> Grrr.

 Hmm, maybe build_vec_init should call itself directly rather than via
 build_aggr_init in the case of multidimensional arrays.
>>>
>>> Yes, arranging things like that seems doable. However, yesterday, while
>>> fiddling with the idea and instrumenting the code with some gcc_asserts,
>>> I
>>> noticed that we have yet another tree code to handle, TARGET_EXPR, as in
>>> lines #41, #47, #56 of ext/complit12.C, and in that case build_aggr_init
>>> is
>>> simply called by check_initializer via build_aggr_init_full_exprs, the
>>> "normal" path. Well, unless we want to adjust/reject complit12.C too,
>>> which
>>> clang rejects, in fact with errors on lines #19 and #29 too. The below
>>> passes testing.
>>
>> I think I'd like to allow TARGET_EXPR here, with a comment about
>> compound literals, but avoid INDIRECT_REF with that build_vec_init
>> change.
>
> I see. Having run the full testsuite a number of times with additional
> gcc_asserts, I'm very confident that something as simple as the below is
> fine, at least as far as the testsuite + variants of lambda-array.C is
> concerned. In it I'm also proposing a gcc_assert verifying that the very
> idea of not using any diagnostic conditional makes sense for the internally
> generated INDIRECT_REFs: in the existing build_aggr_init if the types were
> different from_array would be zero and, for INDIRECT_REF as init, the
> condition true.

Your build_aggr_init change is OK, but I had in mind something more
general in build_vec_init:
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index ff52c42c1ad..d689390d117 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -4367,7 +4367,10 @@ build_vec_init (tree base, tree maxindex, tree init,
 	  else
 	from = NULL_TREE;
 
-	  if (from_array == 2)
+	  if (TREE_CODE (type) == ARRAY_TYPE)
+	elt_init = build_vec_init (to, NULL_TREE, from, /*val_init*/false,
+   from_array, complain);
+	  else if (from_array == 2)
 	elt_init = cp_build_modify_expr (input_location, to, NOP_EXPR,
 	 from, complain);
 	  else if (type_build_ctor_call (type))


Re: [og7] vector_length extension part 4: target hooks and automatic parallelism

2018-03-26 Thread Tom de Vries

On 03/02/2018 08:18 PM, Cesar Philippidis wrote:

The attached patch adjusts the existing goacc validate_dims target hook


This is overkill. All we need is a function
"int oacc_get_default_dim (int dim)".

Thanks,
- Tom


Re: C++ PATCH for c++/85062, ICE with variadic alignas in wrong place

2018-03-26 Thread Jason Merrill
On Mon, Mar 26, 2018 at 11:57 AM, Jason Merrill  wrote:
> We've been passing C++11 attributes that appertain to a type-specifier
> down to decl_attributes, which gave a warning and ignored them, but it
> was confused by the pack expansion.  It seems easiest to deal with
> this by ignoring them directly in grokdeclarator.

I suppose it would make sense to allow [[gnu::vector_size]] in this
position, but that would be a change from the status quo, and it
doesn't seem urgent.

Jason


Re: [og7] vector_length extension part 4: target hooks and automatic parallelism

2018-03-26 Thread Tom de Vries

On 03/02/2018 08:18 PM, Cesar Philippidis wrote:

introduces a new goacc adjust_parallelism target hook.


That's another separate patch.

Committed.

Thanks,
- Tom
[openacc] Add target hook TARGET_GOACC_ADJUST_PARALLELISM

2018-03-26  Cesar Philippidis  
	Tom de Vries  

	* doc/tm.texi.in: Add placeholder for TARGET_GOACC_ADJUST_PARALLELISM.
	* doc/tm.texi: Regenerate.
	* omp-offload.c (oacc_loop_fixed_partitions): Use the adjust_parallelism
	hook to modify this_mask.
	(oacc_loop_auto_partitions): Use the adjust_parallelism hook to modify
	this_mask and loop->mask.
	(default_goacc_adjust_parallelism): New function.
	* target.def (adjust_parallelism): New hook.
	* targhooks.h (default_goacc_adjust_parallelism): Declare.

---
 gcc/doc/tm.texi   |  6 ++
 gcc/doc/tm.texi.in|  2 ++
 gcc/omp-offload.c | 19 +++
 gcc/target.def|  8 
 gcc/targhooks.h   |  1 +
 6 files changed, 49 insertions(+)

diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 0fcb9c6..271eb4d 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -5883,6 +5883,12 @@ This hook should return the maximum size of a particular dimension,
 or zero if unbounded.
 @end deftypefn
 
+@deftypefn {Target Hook} unsigned TARGET_GOACC_ADJUST_PARALLELISM (unsigned @var{this_mask}, unsigned @var{outer_mask})
+This hook allows the accelerator compiler to remove any unused
+parallelism exposed in the current loop @var{THIS_MASK}, and the
+enclosing loop @var{OUTER_MASK}.  It returns an adjusted mask.
+@end deftypefn
+
 @deftypefn {Target Hook} bool TARGET_GOACC_FORK_JOIN (gcall *@var{call}, const int *@var{dims}, bool @var{is_fork})
 This hook can be used to convert IFN_GOACC_FORK and IFN_GOACC_JOIN
 function calls to target-specific gimple, or indicate whether they
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index 4187da1..fc73ad1 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -4298,6 +4298,8 @@ address;  but often a machine-dependent strategy can generate better code.
 
 @hook TARGET_GOACC_DIM_LIMIT
 
+@hook TARGET_GOACC_ADJUST_PARALLELISM
+
 @hook TARGET_GOACC_FORK_JOIN
 
 @hook TARGET_GOACC_REDUCTION
diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c
index ba3f431..aa4de24 100644
--- a/gcc/omp-offload.c
+++ b/gcc/omp-offload.c
@@ -1258,6 +1258,13 @@ oacc_loop_fixed_partitions (oacc_loop *loop, unsigned outer_mask)
 	}
 }
 
+  /* FIXME: Ideally, we should be coalescing parallelism here if the
+ hardware supports it.  E.g. Instead of partitioning a loop
+ across worker and vector axes, sometimes the hardware can
+ execute those loops together without resorting to placing
+ extra thread barriers.  */
+  this_mask = targetm.goacc.adjust_parallelism (this_mask, outer_mask);
+
   mask_all |= this_mask;
 
   if (loop->flags & OLF_TILE)
@@ -1349,6 +1356,7 @@ oacc_loop_auto_partitions (oacc_loop *loop, unsigned outer_mask,
 	  this_mask ^= loop->e_mask;
 	}
 
+  this_mask = targetm.goacc.adjust_parallelism (this_mask, outer_mask);
   loop->mask |= this_mask;
 }
 
@@ -1396,7 +1404,9 @@ oacc_loop_auto_partitions (oacc_loop *loop, unsigned outer_mask,
 			" to parallelize element loop");
 	}
 
+  loop->mask = targetm.goacc.adjust_parallelism (loop->mask, outer_mask);
   loop->mask |= this_mask;
+
   if (!loop->mask && noisy)
 	warning_at (loop->loc, 0,
 		tiling
@@ -1774,6 +1784,15 @@ default_goacc_dim_limit (int ARG_UNUSED (axis))
 #endif
 }
 
+/* Default adjustment of loop parallelism is not required.  */
+
+unsigned
+default_goacc_adjust_parallelism (unsigned this_mask,
+  unsigned ARG_UNUSED (outer_mask))
+{
+  return this_mask;
+}
+
 namespace {
 
 const pass_data pass_data_oacc_device_lower =
diff --git a/gcc/target.def b/gcc/target.def
index b302d36..c878fee 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -1697,6 +1697,14 @@ int, (int axis),
 default_goacc_dim_limit)
 
 DEFHOOK
+(adjust_parallelism,
+"This hook allows the accelerator compiler to remove any unused\n\
+parallelism exposed in the current loop @var{THIS_MASK}, and the\n\
+enclosing loop @var{OUTER_MASK}.  It returns an adjusted mask.",
+unsigned, (unsigned this_mask, unsigned outer_mask),
+default_goacc_adjust_parallelism)
+
+DEFHOOK
 (fork_join,
 "This hook can be used to convert IFN_GOACC_FORK and IFN_GOACC_JOIN\n\
 function calls to target-specific gimple, or indicate whether they\n\
diff --git a/gcc/targhooks.h b/gcc/targhooks.h
index 18070df..f4f6864 100644
--- a/gcc/targhooks.h
+++ b/gcc/targhooks.h
@@ -115,6 +115,7 @@ extern bool default_goacc_validate_dims (tree, int [], int);
 extern int default_goacc_dim_limit (int);
 extern bool default_goacc_fork_join (gcall *, const int [], bool);
 extern void default_goacc_reduction (gcall *);
+extern unsigned default_goacc_adjust_parallelism (unsigned, unsigned);
 
 /* These are here, and not in hooks.[ch], because not all users of
hooks.h include tm.h, and thus we 

Re: RFC: Disable asan tests under ulimit -v

2018-03-26 Thread Jason Merrill
On Sat, Mar 24, 2018 at 4:51 AM, Andreas Schwab  wrote:
> On Mär 23 2018, Jason Merrill  wrote:
>
>> diff --git a/gcc/testsuite/g++.dg/asan/asan.exp 
>> b/gcc/testsuite/g++.dg/asan/asan.exp
>> index 4ee8dd98697..a22d2ac5e20 100644
>> --- a/gcc/testsuite/g++.dg/asan/asan.exp
>> +++ b/gcc/testsuite/g++.dg/asan/asan.exp
>> @@ -24,6 +24,13 @@ load_lib asan-dg.exp
>>  dg-init
>>  asan_init
>>
>> +# asan doesn't work if there's a ulimit on virtual memory.
>> +if ![is_remote target] {
>> +if [regexp {^[0-9]+$} "[exec ulimit -v]"] {
>
> Does that actually work?

It does for me.

> ulimit is a shell builtin, but exec does not use the shell.

It's also a separate executable.

> Also, you get an error if the command returns a non-zero
> status, or isn't found.

In that case, the result of the exec won't be a string of numbers, so
we run the tests.

Jason


Re: [PATCH] i386: Insert ENDBR to trampoline for -fcf-protection=branch -mibt

2018-03-26 Thread H.J. Lu
On Mon, Mar 26, 2018 at 8:23 AM, Tsimbalist, Igor V
 wrote:
>> -Original Message-
>> From: Lu, Hongjiu
>> Sent: Sunday, March 25, 2018 12:50 AM
>> To: gcc-patches@gcc.gnu.org; Uros Bizjak ; Tsimbalist,
>> Igor V 
>> Subject: [PATCH] i386: Insert ENDBR to trampoline for -fcf-
>> protection=branch -mibt
>>
>> When -fcf-protection=branch -mibt are used, we need to insert ENDBR
>> to trampoline.  TRAMPOLINE_SIZE is creased by 4 bytes to accommodate
>> 4-byte ENDBR instruction.
>>
>> OK for trunk?
>
> Regarding the test. Is it possible to check what is generated in a 
> trampoline? In particular, that endbr is generated.
>

I think run-time test is sufficient.

-- 
H.J.


C++ PATCH for c++/85062, ICE with variadic alignas in wrong place

2018-03-26 Thread Jason Merrill
We've been passing C++11 attributes that appertain to a type-specifier
down to decl_attributes, which gave a warning and ignored them, but it
was confused by the pack expansion.  It seems easiest to deal with
this by ignoring them directly in grokdeclarator.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 8ff034b7db80ef05cd97bb4c56a1d472b990afa8
Author: Jason Merrill 
Date:   Mon Mar 26 11:16:04 2018 -0400

PR c++/85062 - ICE with alignas in wrong place.

* decl.c (grokdeclarator): Ignore attributes on type-specifiers
here.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 96d4b723b4a..ba456737e0e 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -10946,10 +10946,10 @@ grokdeclarator (const cp_declarator *declarator,
 
   if (declspecs->std_attributes)
 {
-  /* Apply the c++11 attributes to the type preceding them.  */
-  input_location = declspecs->locations[ds_std_attribute];
-  decl_attributes (, declspecs->std_attributes, 0);
-  input_location = saved_loc;
+  location_t attr_loc = declspecs->locations[ds_std_attribute];
+  if (warning_at (attr_loc, OPT_Wattributes, "attribute ignored"))
+	inform (attr_loc, "an attribute that appertains to a type-specifier "
+		"is ignored");
 }
 
   /* Determine the type of the entity declared by recurring on the
diff --git a/gcc/testsuite/g++.dg/cpp0x/alignas16.C b/gcc/testsuite/g++.dg/cpp0x/alignas16.C
new file mode 100644
index 000..7c349929786
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/alignas16.C
@@ -0,0 +1,9 @@
+// PR c++/85062
+// { dg-do compile { target c++11 } }
+
+template struct A
+{
+  int alignas(T...) i;		// { dg-warning "ignored" }
+};
+
+A a;


RE: [PATCH] i386: Insert ENDBR to trampoline for -fcf-protection=branch -mibt

2018-03-26 Thread Tsimbalist, Igor V
> -Original Message-
> From: Lu, Hongjiu
> Sent: Sunday, March 25, 2018 12:50 AM
> To: gcc-patches@gcc.gnu.org; Uros Bizjak ; Tsimbalist,
> Igor V 
> Subject: [PATCH] i386: Insert ENDBR to trampoline for -fcf-
> protection=branch -mibt
> 
> When -fcf-protection=branch -mibt are used, we need to insert ENDBR
> to trampoline.  TRAMPOLINE_SIZE is creased by 4 bytes to accommodate
> 4-byte ENDBR instruction.
> 
> OK for trunk?

Regarding the test. Is it possible to check what is generated in a trampoline? 
In particular, that endbr is generated.

Igor

> H.J.
> 
> gcc/
> 
>   PR target/85044
>   * config/i386/i386.c (ix86_trampoline_init): Insert ENDBR for
>   -fcf-protection=branch -mibt.
>   * config/i386/i386.h (TRAMPOLINE_SIZE): Increased by 4 bytes.
> 
> gcc/testsuite/
> 
>   PR target/85044
>   * gcc.target/i386/pr85044.c: New test.
> ---
>  gcc/config/i386/i386.c  | 17 +
>  gcc/config/i386/i386.h  |  2 +-
>  gcc/testsuite/gcc.target/i386/pr85044.c | 24
> 
>  3 files changed, 42 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr85044.c
> 
> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
> index 3b264318f50..b4f6aec1434 100644
> --- a/gcc/config/i386/i386.c
> +++ b/gcc/config/i386/i386.c
> @@ -30411,6 +30411,7 @@ ix86_trampoline_init (rtx m_tramp, tree fndecl,
> rtx chain_value)
>rtx mem, fnaddr;
>int opcode;
>int offset = 0;
> +  bool need_endbr = (flag_cf_protection & CF_BRANCH) && TARGET_IBT;
> 
>fnaddr = XEXP (DECL_RTL (fndecl), 0);
> 
> @@ -30418,6 +30419,14 @@ ix86_trampoline_init (rtx m_tramp, tree fndecl,
> rtx chain_value)
>  {
>int size;
> 
> +  if (need_endbr)
> + {
> +   /* Insert ENDBR64.  */
> +   mem = adjust_address (m_tramp, SImode, offset);
> +   emit_move_insn (mem, gen_int_mode (0xfa1e0ff3, SImode));
> +   offset += 4;
> + }
> +
>/* Load the function address to r11.  Try to load address using
>the shorter movl instead of movabs.  We may want to support
>movq for kernel mode, but kernel does not use trampolines at
> @@ -30495,6 +30504,14 @@ ix86_trampoline_init (rtx m_tramp, tree fndecl,
> rtx chain_value)
>else
>   opcode = 0x68;
> 
> +  if (need_endbr)
> + {
> +   /* Insert ENDBR32.  */
> +   mem = adjust_address (m_tramp, SImode, offset);
> +   emit_move_insn (mem, gen_int_mode (0xfb1e0ff3, SImode));
> +   offset += 4;
> + }
> +
>mem = adjust_address (m_tramp, QImode, offset);
>emit_move_insn (mem, gen_int_mode (opcode, QImode));
> 
> diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
> index 7f4b04f421d..c7f9b4551b3 100644
> --- a/gcc/config/i386/i386.h
> +++ b/gcc/config/i386/i386.h
> @@ -1716,7 +1716,7 @@ typedef struct ix86_args {
> 
>  /* Length in units of the trampoline for entering a nested function.  */
> 
> -#define TRAMPOLINE_SIZE (TARGET_64BIT ? 24 : 10)
> +#define TRAMPOLINE_SIZE (TARGET_64BIT ? 28 : 14)
>  

>  /* Definitions for register eliminations.
> 
> diff --git a/gcc/testsuite/gcc.target/i386/pr85044.c
> b/gcc/testsuite/gcc.target/i386/pr85044.c
> new file mode 100644
> index 000..332f582d79b
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr85044.c
> @@ -0,0 +1,24 @@
> +/* { dg-do run { target cet } } */
> +/* { dg-options "-O2 -fcf-protection=branch -mibt" } */
> +
> +void callme (void (*callback) (void));
> +
> +int
> +main (void)
> +{
> +  int ok = 0;
> +  void callback (void) { ok = 1; }
> +
> +  callme ();
> +
> +  if (!ok)
> +   __builtin_abort ();
> +  return 0;
> +}
> +
> +__attribute__((noinline, noclone))
> +void
> +callme (void (*callback) (void))
> +{
> +  (*callback) ();
> +}
> --
> 2.14.3



Re: [PATCHv2] PR libstdc++/84654 Do not use __float128 if it is disabled by the compiler

2018-03-26 Thread Tulio Magno Quites Machado Filho
Ping?

Tulio Magno Quites Machado Filho  writes:

> Changes since v1:
>  - Completely rewrite of the patch to set ENABLE_FLOAT128 at libstdc++
>build time and undef _GLIBCXX_USE_FLOAT128 when building user code.
>
> --- 8< ---
>
> In order to use __float128 in C++ it's necessary to check if the
> compiler enabled its support too when building user code.
> This patch changes the behavior at libstdc++ build by setting
> ENABLE_FLOAT128, which is used to set the value of the exported macro
> _GLIBCXX_USE_FLOAT128.
>
> 2018-03-12  Tulio Magno Quites Machado Filho  
>
>   PR libstdc++/84654
>   * acinclude.m4: Set ENABLE_FLOAT128 instead of _GLIBCXX_USE_FLOAT128.
>   * config.h.in: Remove references to _GLIBCXX_USE_FLOAT128.
>   * configure: Regenerate.
>   * include/Makefile.am: Replace the value of _GLIBCXX_USE_FLOAT128
>   based on ENABLE_FLOAT128.
>   * include/Makefile.in: Regenerate.
>   * include/bits/c++config: Define _GLIBCXX_USE_FLOAT128.
>   [!defined(__FLOAT128__) && !defined(__SIZEOF_FLOAT128__)]: Undefine
>   _GLIBCXX_USE_FLOAT128.

-- 
Tulio Magno



C++ PATCH for c++/85049, ICE with integer_sequence

2018-03-26 Thread Jason Merrill
In this testcase, we tried to deduce template arguments between
__integer_pack(sizeof...(_Types)) and an empty argument list.  This
breaks, and we shouldn't try anyway, since that's very much a
non-deduced context.  So let's skip over packs that aren't actual
template parameter packs.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit f5e979b7434f372028215a9209f4b8076fab97d7
Author: Jason Merrill 
Date:   Sat Mar 24 07:45:02 2018 -0400

PR c++/85049 - ICE with __integer_pack.

* pt.c (unify_pack_expansion): Don't try to deduce generated packs.
* cp-tree.h (TEMPLATE_PARM_P): New.

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index c8f4bc43fa3..db79338035d 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -4554,6 +4554,12 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter)
|| TREE_CODE (NODE) == TYPE_DECL		\
|| TREE_CODE (NODE) == TEMPLATE_DECL))
 
+/* Nonzero for a raw template parameter node.  */
+#define TEMPLATE_PARM_P(NODE)	\
+  (TREE_CODE (NODE) == TEMPLATE_TYPE_PARM			\
+   || TREE_CODE (NODE) == TEMPLATE_TEMPLATE_PARM		\
+   || TREE_CODE (NODE) == TEMPLATE_PARM_INDEX)
+
 /* Mark NODE as a template parameter.  */
 #define SET_DECL_TEMPLATE_PARM_P(NODE) \
   (DECL_LANG_FLAG_0 (NODE) = 1)
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 9cf03f45e24..d6cce3e67da 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -20645,6 +20645,11 @@ unify_pack_expansion (tree tparms, tree targs, tree packed_parms,
   tree parm_pack = TREE_VALUE (pack);
   int idx, level;
 
+  /* Only template parameter packs can be deduced, not e.g. function
+	 parameter packs or __bases or __integer_pack.  */
+  if (!TEMPLATE_PARM_P (parm_pack))
+	continue;
+
   /* Determine the index and level of this parameter pack.  */
   template_parm_level_and_index (parm_pack, , );
   if (level < levels)
diff --git a/gcc/testsuite/g++.dg/ext/integer-pack3.C b/gcc/testsuite/g++.dg/ext/integer-pack3.C
new file mode 100644
index 000..d3ed1363016
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/integer-pack3.C
@@ -0,0 +1,21 @@
+// PR c++/85049
+// { dg-do compile { target c++11 } }
+
+typedef __SIZE_TYPE__ size_t;
+template
+struct integer_sequence
+{
+  typedef _Tp value_type;
+  static constexpr size_t size() noexcept { return sizeof...(_Idx); }
+};
+template
+using make_integer_sequence = integer_sequence<_Tp, __integer_pack(_Num)...>;
+template
+using make_index_sequence = make_integer_sequence;
+template
+using index_sequence_for = make_index_sequence;
+template 
+struct tuple {};
+template 
+int get(tuple);
+int x = get(tuple>{});


Re: [og7] vector_length extension part 4: target hooks and automatic parallelism

2018-03-26 Thread Cesar Philippidis
On 03/26/2018 07:14 AM, Tom de Vries wrote:
> On 03/02/2018 08:18 PM, Cesar Philippidis wrote:
>> diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c
>> index ba3f4317f4e..f15ce6b8f8d 100644
>> --- a/gcc/omp-offload.c
>> +++ b/gcc/omp-offload.c
>> @@ -626,7 +626,8 @@ oacc_parse_default_dims (const char *dims)
>>  function.  */
>>     static void
>> -oacc_validate_dims (tree fn, tree attrs, int *dims, int level,
>> unsigned used)
>> +oacc_validate_dims (tree fn, tree attrs, int *dims, int level,
>> unsigned used,
>> +    int * ARG_UNUSED (default_dims))
>>   {
>>     tree purpose[GOMP_DIM_MAX];
>>     unsigned ix;
> 
>> @@ -1604,7 +1616,8 @@ execute_oacc_device_lower ()
>>   }
>>       int dims[GOMP_DIM_MAX];
>> -  oacc_validate_dims (current_function_decl, attrs, dims, fn_level,
>> used_mask);
>> +  oacc_validate_dims (current_function_decl, attrs, dims, fn_level,
>> used_mask,
>> +  NULL);
>>       if (dump_file)
>>   {
> 
> What's the purpose of this unused parameter default_dims, that only ever
> gets to be NULL?

That's stale and can be removed. In an earlier, and more complicated,
version of the patch I was still trying to get large vector lengths to
work with multiple workers.

I'll remove it from my patch.

Thanks,
Cesar


Re: [og7] vector_length extension part 4: target hooks and automatic parallelism

2018-03-26 Thread Tom de Vries

On 03/02/2018 08:18 PM, Cesar Philippidis wrote:

diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c
index ba3f4317f4e..f15ce6b8f8d 100644
--- a/gcc/omp-offload.c
+++ b/gcc/omp-offload.c
@@ -626,7 +626,8 @@ oacc_parse_default_dims (const char *dims)
 function.  */
  
  static void

-oacc_validate_dims (tree fn, tree attrs, int *dims, int level, unsigned used)
+oacc_validate_dims (tree fn, tree attrs, int *dims, int level, unsigned used,
+   int * ARG_UNUSED (default_dims))
  {
tree purpose[GOMP_DIM_MAX];
unsigned ix;



@@ -1604,7 +1616,8 @@ execute_oacc_device_lower ()
  }
  
int dims[GOMP_DIM_MAX];

-  oacc_validate_dims (current_function_decl, attrs, dims, fn_level, used_mask);
+  oacc_validate_dims (current_function_decl, attrs, dims, fn_level, used_mask,
+ NULL);
  
if (dump_file)

  {


What's the purpose of this unused parameter default_dims, that only ever 
gets to be NULL?


Thanks,
- Tom


Re: Add workaround to std::variant for Clang bug 31852

2018-03-26 Thread Jonathan Wakely
Now with 100% more patch.



On 26 March 2018 at 14:10, Jonathan Wakely  wrote:
> This makes it possible to use our std::variant with Clang, as well as
> some minor tweaks to avoid ADL (so the compiler doesn't waste time
> looking in associated namespaces) and adjust whitespace.
>
>* include/std/variant (__get): Qualify calls to avoid ADL.
>(__select_index): Adjust whitespace.
>(variant): Add using-declaration to workaround Clang bug.
>
> Tested powerpc64le-linux, committed to trunk.. I'll backport to
> gcc-7-branch too.
commit 4b3007fd674c489b695b8b1c52d6f1e8d010f072
Author: Jonathan Wakely 
Date:   Mon Mar 26 13:49:34 2018 +0100

Add workaround to std::variant for Clang bug 31852

* include/std/variant (__get): Qualify calls to avoid ADL.
(__select_index): Adjust whitespace.
(variant): Add using-declaration to workaround Clang bug.

diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 4aba131cb73..e4ae6573ed4 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -223,13 +223,17 @@ namespace __variant
 
   template
 constexpr decltype(auto) __get(in_place_index_t<_Np>, _Union&& __u)
-{ return __get(in_place_index<_Np-1>, std::forward<_Union>(__u)._M_rest); }
+{
+  return __variant::__get(in_place_index<_Np-1>,
+ std::forward<_Union>(__u)._M_rest);
+}
 
   // Returns the typed storage for __v.
   template
 constexpr decltype(auto) __get(_Variant&& __v)
 {
-  return __get(std::in_place_index<_Np>, std::forward<_Variant>(__v)._M_u);
+  return __variant::__get(std::in_place_index<_Np>,
+ std::forward<_Variant>(__v)._M_u);
 }
 
   // Various functions as "vtable" entries, where those vtables are used by
@@ -358,10 +362,9 @@ namespace __variant
 
   template 
   using __select_index =
-typename __select_int::_Select_int_base
-::type::value_type;
+   unsigned short>::type::value_type;
 
   template
 struct _Variant_storage
@@ -1304,6 +1307,12 @@ namespace __variant
 
 #undef _VARIANT_RELATION_FUNCTION_TEMPLATE
 
+#ifdef __clang__
+public:
+  using _Base::_M_u; // See https://bugs.llvm.org/show_bug.cgi?id=31852
+private:
+#endif
+
   template
friend constexpr decltype(auto) __detail::__variant::__get(_Vp&& __v);
 


Add workaround to std::variant for Clang bug 31852

2018-03-26 Thread Jonathan Wakely
This makes it possible to use our std::variant with Clang, as well as
some minor tweaks to avoid ADL (so the compiler doesn't waste time
looking in associated namespaces) and adjust whitespace.

   * include/std/variant (__get): Qualify calls to avoid ADL.
   (__select_index): Adjust whitespace.
   (variant): Add using-declaration to workaround Clang bug.

Tested powerpc64le-linux, committed to trunk.. I'll backport to
gcc-7-branch too.


Re: [C++ Patch] Fix confusing diagnostics for invalid overrides

2018-03-26 Thread Nathan Sidwell

On 03/25/2018 10:18 AM, Volker Reichelt wrote:


Index: gcc/cp/search.c
===
--- gcc/cp/search.c    (revision 258835)
+++ gcc/cp/search.c    (working copy)
@@ -1918,12 +1918,14 @@
    if (fail == 1)
  {
    error ("invalid covariant return type for %q+#D", overrider);
-      error ("  overriding %q+#D", basefn);
+      inform (DECL_SOURCE_LOCATION (basefn),
+          "  overriding %q+#D", basefn);


In addtion to Paolo's comments, the new inform doesn't need the 
indentation.  Perhaps reword it to something like


"overridden function is %qD"

I.e. a more stand-alone message than a continuation of the error.

nathan
--
Nathan Sidwell


PING^3: [PATCH] Use dlsym to check if libdl is needed for plugin

2018-03-26 Thread H.J. Lu
On Wed, Mar 14, 2018 at 4:41 AM, H.J. Lu  wrote:
> On Wed, Feb 21, 2018 at 3:02 AM, H.J. Lu  wrote:
>> On Wed, Oct 18, 2017 at 5:25 PM, H.J. Lu  wrote:
>>> config/plugins.m4 has
>>>
>>>  if test "$plugins" = "yes"; then
>>> AC_SEARCH_LIBS([dlopen], [dl])
>>>   fi
>>>
>>> Plugin uses dlsym, but libasan.so only intercepts dlopen, not dlsym:
>>>
>>> [hjl@gnu-tools-1 binutils-text]$ nm -D /lib64/libasan.so.4| grep " dl"
>>> 00038580 W dlclose
>>>  U dl_iterate_phdr
>>> 0004dc50 W dlopen
>>>  U dlsym
>>>  U dlvsym
>>> [hjl@gnu-tools-1 binutils-text]$
>>>
>>> Testing dlopen for libdl leads to false negative when -fsanitize=address
>>> is used.  It results in link failure:
>>>
>>> ../bfd/.libs/libbfd.a(plugin.o): undefined reference to symbol 
>>> 'dlsym@@GLIBC_2.16'
>>>
>>> dlsym should be used to check if libdl is needed for plugin.
>>>
>>> OK for master?
>>>
>>> H.J.
>>> ---
>>> config/
>>>
>>> * plugins.m4 (AC_PLUGINS): Use dlsym to check if libdl is needed.
>>>
>
>
> PING.
>

PING.

-- 
H.J.


PING^4: [PATCH] i386: Insert ENDBR before the profiling counter call

2018-03-26 Thread H.J. Lu
On Fri, Jan 26, 2018 at 6:23 AM, H.J. Lu  wrote:
> On Sun, Jan 7, 2018 at 7:11 PM, H.J. Lu  wrote:
>> On Tue, Oct 24, 2017 at 10:58 AM, H.J. Lu  wrote:
>>> On Tue, Oct 24, 2017 at 10:40 AM, Andi Kleen  wrote:
 "H.J. Lu"  writes:
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr82699-4.c
> @@ -0,0 +1,11 @@
> +/* { dg-do compile { target { *-*-linux* && { ! ia32 } } } } */
> +/* { dg-options "-O2 -fpic -fcf-protection -mcet -pg -mfentry 
> -fasynchronous-unwind-tables" } */
> +/* { dg-final { scan-assembler-times {\t\.cfi_startproc\n\tendbr} 1 }
> } */

 Would add test cases for -mnop-mcount and -mrecord-mcount too

>>>
>>> Here is the updated patch to add a testcase for -mnop-mcount 
>>> -mrecord-mcount.
>>> No other changes otherwise.
>>>
>>
>> PING:
>>
>> https://gcc.gnu.org/ml/gcc-patches/2017-10/msg01741.html
>>
>>
>
> PING.

PING.


-- 
H.J.


PING^3 [PATCH] i386: Avoid PLT when shadow stack is enabled directly

2018-03-26 Thread H.J. Lu
On Sat, Mar 17, 2018 at 5:55 AM, H.J. Lu  wrote:
> On Fri, Dec 8, 2017 at 5:02 AM, H.J. Lu  wrote:
>> On Tue, Oct 24, 2017 at 5:31 AM, H.J. Lu  wrote:
>>> PLT should be avoided with shadow stack in 32-bit mode if more than 2
>>> parameters are passed in registers since only 2 parameters can be passed
>>> in registers for external function calls via PLT with shadow stack
>>> enabled.
>>>
>>> OK for trunk if there is no regressions?
>>
>> Here is the updated patch.
>>
>> PING.
>>
>
> https://gcc.gnu.org/ml/gcc-patches/2017-12/msg00485.html
>
> PING.
>

PING.


-- 
H.J.


PING: [GCC 6] PATCH: Backport -mindirect-branch= patches

2018-03-26 Thread H.J. Lu
On Mon, Mar 19, 2018 at 10:04 AM, H.J. Lu  wrote:
>>
>> Here are GCC 6 patches to backport all -mindirect-branch= patches.
>> OK for GCC 6.
>>
>

PING:

https://gcc.gnu.org/ml/gcc-patches/2018-03/msg00884.html

-- 
H.J.


Re: [PATCH] Fix ICE for static vars in offloaded functions

2018-03-26 Thread Tom de Vries

On 03/07/2018 04:01 PM, Richard Biener wrote:

On Wed, 7 Mar 2018, Tom de Vries wrote:


On 03/07/2018 02:29 PM, Richard Biener wrote:

On Wed, 7 Mar 2018, Jakub Jelinek wrote:


On Wed, Mar 07, 2018 at 02:20:26PM +0100, Tom de Vries wrote:

Fix ICE for static vars in offloaded functions

2018-03-06  Tom de Vries  

PR lto/84592
* varpool.c (varpool_node::get_create): Mark static variables in
offloaded functions as offloadable.

* testsuite/libgomp.c/pr84592-2.c: New test.
* testsuite/libgomp.c/pr84592.c: New test.
* testsuite/libgomp.oacc-c-c++-common/pr84592-3.c: New test.


Ok, thanks


+  bool in_offload_func
+   = (cfun
+  && TREE_STATIC (decl)
+  && (lookup_attribute ("omp target entr

I think you want to use decl_function_context (decl) here,
not rely on magic cfun being set.  The whole varpool.c file
doesn't mention cfun yet and you shoudln't either.



decl_function_context (decl) returns main:
...
(gdb) call debug_generic_expr (decl)
test
(gdb) call  decl_function_context (decl)
$2 = (tree_node *) 0x76978c00
(gdb) call debug_generic_expr ($2)
main
...
while the function annotated as being an offload function is main._omp_fn.0.


Well, that's because the static isn't duplicated (it can't be) so it
retains the original context.



[ Actually the static is duplicated in replace_by_duplicate_decl, but 
the statements using it are not rewritten to use the duplicate, so 
indeed, effectively it's not duplicated. ]



The varpool_node::get_create is called during cgraph_edge::rebuild_edges here
in expand_omp_target:


But at this point it's not created but just looked up, right?



No, the varpool_node is created at that point.


I think the fix is to mark the decl as offloaded when we walk the IL
of the outlined function.  The current point looks like a hack.



OK, I'll try to find a better fix location.

Thanks,
- Tom


Richard.


...
7087  /* Fix the callgraph edges for child_cfun.  Those for cfun will
be
7088 fixed in a following pass.  */
7089  push_cfun (child_cfun);
7090  if (need_asm)
7091assign_assembler_name_if_needed (child_fn);
7092  cgraph_edge::rebuild_edges ();
...

Thanks,
- Tom








Re: [C++ Patch] PR 84632 ("[8 Regression] internal compiler error: tree check: expected record_type or union_type or qual_union_type, have array_type in reduced_constant_expression_p...")

2018-03-26 Thread Paolo Carlini

Hi,

On 23/03/2018 13:39, Jason Merrill wrote:

On Fri, Mar 23, 2018 at 6:13 AM, Paolo Carlini  wrote:

On 22/03/2018 23:26, Jason Merrill wrote:

On Thu, Mar 22, 2018 at 5:39 PM, Paolo Carlini 
wrote:

... with patch ;)

If you are curious where the heck that INDIRECT_REF is coming from, is
coming from the gimplifier, cp_gimpliify_expr, via build_vec_init. Grrr.

Hmm, maybe build_vec_init should call itself directly rather than via
build_aggr_init in the case of multidimensional arrays.

Yes, arranging things like that seems doable. However, yesterday, while
fiddling with the idea and instrumenting the code with some gcc_asserts, I
noticed that we have yet another tree code to handle, TARGET_EXPR, as in
lines #41, #47, #56 of ext/complit12.C, and in that case build_aggr_init is
simply called by check_initializer via build_aggr_init_full_exprs, the
"normal" path. Well, unless we want to adjust/reject complit12.C too, which
clang rejects, in fact with errors on lines #19 and #29 too. The below
passes testing.

I think I'd like to allow TARGET_EXPR here, with a comment about
compound literals, but avoid INDIRECT_REF with that build_vec_init
change.
I see. Having run the full testsuite a number of times with additional 
gcc_asserts, I'm very confident that something as simple as the below is 
fine, at least as far as the testsuite + variants of lambda-array.C is 
concerned. In it I'm also proposing a gcc_assert verifying that the very 
idea of not using any diagnostic conditional makes sense for the 
internally generated INDIRECT_REFs: in the existing build_aggr_init if 
the types were different from_array would be zero and, for INDIRECT_REF 
as init, the condition true.


Thanks, Paolo.

///
Index: cp/init.c
===
--- cp/init.c   (revision 258846)
+++ cp/init.c   (working copy)
@@ -1688,14 +1688,6 @@ build_aggr_init (tree exp, tree init, int flags, t
}
   else
{
- /* An array may not be initialized use the parenthesized
-initialization form -- unless the initializer is "()".  */
- if (init && TREE_CODE (init) == TREE_LIST)
-   {
- if (complain & tf_error)
-   error ("bad array initializer");
- return error_mark_node;
-   }
  /* Must arrange to initialize each element of EXP
 from elements of INIT.  */
  if (cv_qualified_p (type))
@@ -1705,14 +1697,17 @@ build_aggr_init (tree exp, tree init, int flags, t
  from_array = (itype && same_type_p (TREE_TYPE (init),
  TREE_TYPE (exp)));
 
- if (init && !from_array
- && !BRACE_ENCLOSED_INITIALIZER_P (init))
+ if (init && !BRACE_ENCLOSED_INITIALIZER_P (init)
+ && (!from_array
+ || (TREE_CODE (init) != CONSTRUCTOR
+ /* Can happen, eg, handling the compound-literals
+extension (ext/complit12.C).  */
+ && TREE_CODE (init) != TARGET_EXPR)))
{
  if (complain & tf_error)
-   permerror (init_loc, "array must be initialized "
-  "with a brace-enclosed initializer");
- else
-   return error_mark_node;
+   error_at (init_loc, "array must be initialized "
+ "with a brace-enclosed initializer");
+ return error_mark_node;
}
}
 
@@ -4371,7 +4366,19 @@ build_vec_init (tree base, tree maxindex, tree ini
elt_init = cp_build_modify_expr (input_location, to, NOP_EXPR,
 from, complain);
  else if (type_build_ctor_call (type))
-   elt_init = build_aggr_init (to, from, 0, complain);
+   {
+ if (TREE_CODE (type) == ARRAY_TYPE
+ && from && TREE_CODE (from) == INDIRECT_REF)
+   {
+ gcc_assert (same_type_ignoring_top_level_qualifiers_p
+ (type, TREE_TYPE (from)));
+ elt_init = build_vec_init (to, NULL_TREE, from,
+/*explicit_value_init_p=*/false,
+/*from_array=*/1, complain);
+   }
+ else
+   elt_init = build_aggr_init (to, from, 0, complain);
+   }
  else if (from)
elt_init = cp_build_modify_expr (input_location, to, NOP_EXPR, from,
 complain);
Index: testsuite/g++.dg/init/array49.C
===
--- testsuite/g++.dg/init/array49.C (nonexistent)
+++ testsuite/g++.dg/init/array49.C (working copy)
@@ -0,0 +1,6 @@
+// PR c++/84632
+// { dg-additional-options "-w" }
+
+class {
+// { 

Re: [PATCH, PR85063] Fix switch conversion in offloading functions

2018-03-26 Thread Jakub Jelinek
On Mon, Mar 26, 2018 at 11:05:52AM +0200, Tom de Vries wrote:
> OK for stage4 or stage1?

Ok for stage4, thanks.

Just a small nit below.

> --- /dev/null
> +++ b/libgomp/testsuite/libgomp.c/switch-conversion-2.c
> @@ -0,0 +1,28 @@

No /* { dg-additional-options "-ftree-switch-conversion" } */
here, but:

> --- /dev/null
> +++ b/libgomp/testsuite/libgomp.c/switch-conversion.c
> @@ -0,0 +1,35 @@
> +/* { dg-additional-options "-ftree-switch-conversion" } */

only here.  Either you don't need it at all, the default
flags are -O2 I think, or use it explicitly in all the testcases, not just 2
of them.  And, please add
/* PR tree-optimization/85063 */
as the first line of all those new testcases.

Jakub


[PATCH, PR85063] Fix switch conversion in offloading functions

2018-03-26 Thread Tom de Vries

Hi,

this patch fixes an ICE that occurs in lto1 after switch conversion 
triggers in an offloading function.



Consider this OpenMP test-case:
...
#include 

int
main (void)
{
  int n[1];

  n[0] = 3;

#pragma omp target
  {
int m = n[0];
switch (m & 3)
{
case 0: m = 4; break;
case 1: m = 3; break;
case 2: m = 2; break;
default:
  m = 1; break;
}
n[0] = m;
  }

  if (n[0] != 1)
abort ();

  return 0;
}
...

When compiling this at -O2, we run into an ICE in lto1.

Switch conversion introduces a static variable CSWTCH.x, and lto1 ICEs 
because CSWITCH.x ends up in a different partition than the partition 
for main._omp_fn.0 (the offloading function corresponding to the omp 
target region).


Fixed by marking the CSWTCH.x variable with atrribute "omp declare 
target" in offloading functions.


Bootstrapped and reg-tested on x86_64.
Build x86_64 with nvptx accelerator and reg-tested libgomp.

OK for stage4 or stage1?

Thanks,
- Tom
Fix switch conversion in offloading functions

2018-03-25  Tom de Vries  

	PR tree-optimization/85063
	* omp-general.c (offloading_function_p): New function.  Factor out
	of ...
	* omp-offload.c (pass_omp_target_link::gate): ... here.
	* omp-general.h (offloading_function_p): Declare.
	* tree-switch-conversion.c (build_one_array): Mark CSWTCH.x variable
	with attribute omp declare target for offloading functions.

	* testsuite/libgomp.c/switch-conversion-2.c: New test.
	* testsuite/libgomp.c/switch-conversion.c: New test.
	* testsuite/libgomp.oacc-c-c++-common/switch-conversion-2.c: New test.
	* testsuite/libgomp.oacc-c-c++-common/switch-conversion.c: New test.

---
 gcc/omp-general.c  | 10 +++
 gcc/omp-general.h  |  1 +
 gcc/omp-offload.c  |  4 +--
 gcc/tree-switch-conversion.c   |  5 
 libgomp/testsuite/libgomp.c/switch-conversion-2.c  | 28 +
 libgomp/testsuite/libgomp.c/switch-conversion.c| 35 ++
 .../switch-conversion-2.c  | 28 +
 .../libgomp.oacc-c-c++-common/switch-conversion.c  | 34 +
 8 files changed, 142 insertions(+), 3 deletions(-)

diff --git a/gcc/omp-general.c b/gcc/omp-general.c
index 3ef6ce7..cac 100644
--- a/gcc/omp-general.c
+++ b/gcc/omp-general.c
@@ -612,6 +612,16 @@ oacc_get_fn_attrib (tree fn)
   return lookup_attribute (OACC_FN_ATTRIB, DECL_ATTRIBUTES (fn));
 }
 
+/* Return true if FN is an OpenMP or OpenACC offloading function.  */
+
+bool
+offloading_function_p (tree fn)
+{
+  tree attrs = DECL_ATTRIBUTES (fn);
+  return (lookup_attribute ("omp declare target", attrs)
+	  || lookup_attribute ("omp target entrypoint", attrs));
+}
+
 /* Extract an oacc execution dimension from FN.  FN must be an
offloaded function or routine that has already had its execution
dimensions lowered to the target-specific values.  */
diff --git a/gcc/omp-general.h b/gcc/omp-general.h
index 481a885..66f0a33 100644
--- a/gcc/omp-general.h
+++ b/gcc/omp-general.h
@@ -85,6 +85,7 @@ extern void oacc_replace_fn_attrib (tree fn, tree dims);
 extern void oacc_set_fn_attrib (tree fn, tree clauses, vec *args);
 extern tree oacc_build_routine_dims (tree clauses);
 extern tree oacc_get_fn_attrib (tree fn);
+extern bool offloading_function_p (tree fn);
 extern int oacc_get_fn_dim_size (tree fn, int axis);
 extern int oacc_get_ifn_dim_arg (const gimple *stmt);
 
diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c
index 9cbc51d..0abf028 100644
--- a/gcc/omp-offload.c
+++ b/gcc/omp-offload.c
@@ -1967,9 +1967,7 @@ public:
   virtual bool gate (function *fun)
 {
 #ifdef ACCEL_COMPILER
-  tree attrs = DECL_ATTRIBUTES (fun->decl);
-  return lookup_attribute ("omp declare target", attrs)
-	 || lookup_attribute ("omp target entrypoint", attrs);
+  return offloading_function_p (fun->decl);
 #else
   (void) fun;
   return false;
diff --git a/gcc/tree-switch-conversion.c b/gcc/tree-switch-conversion.c
index 2da7068..b0470ef 100644
--- a/gcc/tree-switch-conversion.c
+++ b/gcc/tree-switch-conversion.c
@@ -49,6 +49,7 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
 #include "alloc-pool.h"
 #include "target.h"
 #include "tree-into-ssa.h"
+#include "omp-general.h"
 
 /* ??? For lang_hooks.types.type_for_mode, but is there a word_mode
type in the GIMPLE type system that is language-independent?  */
@@ -1162,6 +1163,10 @@ build_one_array (gswitch *swtch, int num, tree arr_index_type,
   TREE_CONSTANT (decl) = 1;
   TREE_READONLY (decl) = 1;
   DECL_IGNORED_P (decl) = 1;
+  if (offloading_function_p (cfun->decl))
+	DECL_ATTRIBUTES (decl)
+	  = tree_cons (get_identifier ("omp declare target"), NULL_TREE,
+		   NULL_TREE);
   varpool_node::finalize_decl (decl);
 
   fetch = build4 (ARRAY_REF, value_type, decl, tidx, NULL_TREE,
diff 

[PATCH] Fix PR85066 testcase for -mx32

2018-03-26 Thread Richard Biener

Committed.

Richard.

2018-03-26  Richard Biener  

PR testsuite/85066
* gcc.dg/vect/costmodel/x86_64/costmodel-pr84986.c: Use long long
instead of long.

Index: testsuite/gcc.dg/vect/costmodel/x86_64/costmodel-pr84986.c
===
--- testsuite/gcc.dg/vect/costmodel/x86_64/costmodel-pr84986.c  (revision 
258800)
+++ testsuite/gcc.dg/vect/costmodel/x86_64/costmodel-pr84986.c  (working copy)
@@ -1,10 +1,10 @@
 /* { dg-do compile } */
-/* { dg-require-effective-target vect_long } */
+/* { dg-require-effective-target vect_long_long } */
 
 int N;
-long fn1(void) {
+long long fn1(void) {
   short i;
-  long a;
+  long long a;
   i = a = 0;
   while (i < N)
 a -= i++;