[PATCH, fortran, committed] Remove unnecessary fold_convert in gfc_(un)likely

2017-09-24 Thread Janne Blomqvist
This patch removes an unnecessary fold_convert to boolean_type_node at
the end of gfc_likely and gfc_unlikely.  It makes no difference to the
generated code, but makes tree dumps a little bit cleaner.

2017-09-25  Janne Blomqvist  

* trans.c (gfc_unlikely): Remove unnecessary fold_convert.
(gfc_likely): Likewise.

Regtested on x86_64-pc-linux-gnu. Committed as obvious.
---
 gcc/fortran/trans.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/gcc/fortran/trans.c b/gcc/fortran/trans.c
index 149f482..53bc428 100644
--- a/gcc/fortran/trans.c
+++ b/gcc/fortran/trans.c
@@ -2275,7 +2275,6 @@ gfc_unlikely (tree cond, enum br_predictor predictor)
  build_int_cst (integer_type_node,
 predictor));
 }
-  cond = fold_convert (boolean_type_node, cond);
   return cond;
 }
 
@@ -2297,7 +2296,6 @@ gfc_likely (tree cond, enum br_predictor predictor)
  build_int_cst (integer_type_node,
 predictor));
 }
-  cond = fold_convert (boolean_type_node, cond);
   return cond;
 }
 
-- 
2.7.4



Re: 0005-Part-5.-Add-x86-CET-documentation

2017-09-24 Thread Sandra Loosemore

On 09/20/2017 08:13 AM, Uros Bizjak wrote:

On Wed, Sep 20, 2017 at 11:20 AM, Tsimbalist, Igor V
 wrote:

Uros, could you please review this patch as it's a part of x86 specific changes 
you have reviewed already.


Please proofread and spell-check the text. There are grammatical errors, e.g.:
[snip]


If/when there is a newer version of this patch, cc it to me and I will 
also make a pass through it.


-Sandra



Re: 0002-Part-2.-Document-finstrument-control-flow-and-notrack attribute

2017-09-24 Thread Sandra Loosemore

On 09/19/2017 07:45 AM, Tsimbalist, Igor V wrote:

Here is an updated patch (version #2). Mainly attribute and option  names were 
changed.

gcc/doc/
* extend.texi: Add 'nocf_check' documentation.
* gimple.texi: Add second parameter to gimple_build_call_from_tree.
* invoke.texi: Add -fcf-protection documentation.
* rtl.texi: Add REG_CALL_NOTRACK documenation.

Is it ok for trunk?
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index cd5733e..6bdb183 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -5646,6 +5646,56 @@ Specify which floating-point unit to use.  You must 
specify the
 @code{target("fpmath=sse,387")} option as
 @code{target("fpmath=sse+387")} because the comma would separate
 different options.
+
+@item nocf_check
+@cindex @code{nocf_check} function attribute
+The @code{nocf_check} attribute on a function is used to inform the
+compiler that the function's prolog should not be instrumented when


s/prolog/prologue/


+compiled with the @option{-fcf-protection=branch} option.  The
+compiler assumes that the function's address is a valid target for a
+control-flow transfer.
+
+The @code{nocf_check} attribute on a type of pointer to function is
+used to inform the compiler that a call through the pointer should
+not be instrumented when compiled with the
+@option{-fcf-protection=branch} option.  The compiler assumes
+that the function's address from the pointer is a valid target for
+a control-flow transfer.  A direct function call through a function
+name is assumed as a safe call thus direct calls will not be


...is assumed to be a safe call, thus direct calls are not...


+instrumented by the compiler.
+
+The @code{nocf_check} attribute is applied to an object's type.  A
+The @code{nocf_check} attribute is transfered to a call instruction at
+the GIMPLE and RTL translation phases.  The attribute is not propagated
+through assignment, store and load.


extend.texi is user-facing documentation, but the second sentence here 
is implementor-speak and not meaningful to users of GCC.  I don't 
understand what the third sentence is trying to say.



+
+@smallexample
+@{
+int foo (void) __attribute__(nocf_check);
+void (*foo1)(void) __attribute__(nocf_check);
+void (*foo2)(void);
+
+int
+foo (void) /* The function's address is assumed as valid.  */


s/as valid/to be valid/


+
+  /* This call site is not checked for control-flow validness.  */


s/validness/validity/g


+  (*foo1)();
+
+  foo1 = foo2;
+  /* This call site is still not checked for control-flow validness.  */
+  (*foo1)();
+
+  /* This call site is checked for control-flow validness.  */
+  (*foo2)();
+
+  foo2 = foo1;
+  /* This call site is still checked for control-flow validness.  */
+  (*foo2)();
+
+  return 0;
+@}
+@end smallexample
+
 @end table

 On the x86, the inliner does not inline a
diff --git a/gcc/doc/gimple.texi b/gcc/doc/gimple.texi
index 635abd3..b6d9149 100644
--- a/gcc/doc/gimple.texi
+++ b/gcc/doc/gimple.texi
@@ -1310,9 +1310,11 @@ operand is validated with @code{is_gimple_operand}).
 @end deftypefn


-@deftypefn {GIMPLE function} gcall *gimple_build_call_from_tree (tree 
call_expr)
-Build a @code{GIMPLE_CALL} from a @code{CALL_EXPR} node.  The arguments and the
-function are taken from the expression directly.  This routine
+@deftypefn {GIMPLE function} gcall *gimple_build_call_from_tree (tree 
call_expr, @
+tree fnptrtype)
+Build a @code{GIMPLE_CALL} from a @code{CALL_EXPR} node.  The arguments and
+the function are taken from the expression directly.  The type is set from
+the second parameter passed by a caller.  This routine
 assumes that @code{call_expr} is already in GIMPLE form.  That is, its
 operands are GIMPLE values and the function call needs no further
 simplification.  All the call flags in @code{call_expr} are copied over
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index e4cacf2..578bc25 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -460,6 +460,7 @@ Objective-C and Objective-C++ Dialects}.
 -fchkp-check-read  -fchkp-check-write  -fchkp-store-bounds @gol
 -fchkp-instrument-calls  -fchkp-instrument-marked-only @gol
 -fchkp-use-wrappers  -fchkp-flexible-struct-trailing-arrays@gol
+-fcf-protection=@r{[}@var{full}|@var{branch}|@var{return}|@var{none}@r{]} @gol


Are full/branch/return/none supposed to be literal strings?  @var is the 
wrong markup for that.



 -fstack-protector  -fstack-protector-all  -fstack-protector-strong @gol
 -fstack-protector-explicit  -fstack-check @gol
 -fstack-limit-register=@var{reg}  -fstack-limit-symbol=@var{sym} @gol
@@ -11348,6 +11349,35 @@ is used to link a program, the GCC driver 
automatically links
 against @file{libmpxwrappers}.  See also @option{-static-libmpxwrappers}.
 Enabled by default.

+@item -fcf-protection=@r{[}@var{full}|@var{branch}|@var{return}|@var{none}@r{]}


Again, markup?


+@opindex fcf-protection
+Enable code instrumentation of control-flow transfers to increase
+a pro

Re: [patch, fortran] Warn about out-of-bounds access with DO subscripts

2017-09-24 Thread Jerry DeLisle
On 09/23/2017 05:33 AM, Thomas Koenig wrote:
> Hello world,
> 
> here is an update and a ping for my patch at
> 
> https://gcc.gnu.org/ml/gcc-patches/2017-09/msg01104.html
> 
> This patch warns unconditionally for
> 
>   REAL A(3)
>   DO I=1,4
>  A(I) = 42.
>   END DO
> 
> while only warning conditionally, dependent on a new flag,
> for when the statement containing the expression is hidden
> behind some IF or SELECT CASE statement or if there
> is something in the DO loop which could potentially exit the loop,
> so
> 
>   REAL A(3)
>   DO I=1,4
>     IF (CONDITON) A(I) = 42.
>   END DO
> 
> will require the new -Wdo-subscript or the -Wextra flag.
> 
> Regression-tested. OK for trunk?
> 
> Regards
> 
> Thomas

Yes OK,

Jerry


correct attribute ifunc C++ type safety (PR 82301)

2017-09-24 Thread Martin Sebor

r253041 enhanced type checking for alias and ifunc attributes to
detect declarations of incompatible aliases, or ifunc resolvers
that return pointers to functions of an incompatible type.  More
extensive testing exposed a bug in the implementation of the ifunc
attribute handling in C++ where the checker expected the ifunc
resolver to return a pointer to a member function when the
implementation actually expects it return a pointer to a non-
member function.

In a discussion of the test suite failures, Jakub also suggested
to break the enhanced warning out of -Wattributes and issue it
under a different option.

The attached patch corrects the C++ problem and moves the warning
under -Wincompatible-pointer-types.  Since this is a C-only option,
the patch also enables for it C++.  Since the option is enabled by
default, the patch further requires -Wextra to issue the warning
for ifunc resolvers returning void*.  However, the patched checker
diagnoses other incompatibilities without it.

Martin
PR c/82301 - Updated test case g++.dg/ext/attr-ifunc-1.C (and others) in r253041 segfault on powerpc64

gcc/ChangeLog:

	PR other/82301
	* cgraphunit.c (maybe_diag_incompatible_alias): New function.
	(handle_alias_pairs): Call it.
	* doc/extend.texi (ifunc attribute): Discuss C++ specifics.
	* doc/invoke.texi (-Wincompatible-pointer-types): Ditto.

gcc/c-family/ChangeLog:

	PR other/82301
	* c.opt (-Wincompatible-pointer-types): Enable for C++.

gcc/testsuite/ChangeLog:

	PR other/82301
	* g++.dg/ext/attr-ifunc-1.C: Update.
	* g++.dg/ext/attr-ifunc-2.C: Same.
	* g++.dg/ext/attr-ifunc-3.C: Same.
	* g++.dg/ext/attr-ifunc-4.C: Same.
	* g++.dg/ext/attr-ifunc-5.C: Same.
	* g++.dg/ext/attr-ifunc-6.C: New test.
	* gcc.dg/attr-ifunc-6.c: New test.
	* gcc.dg/attr-ifunc-7.c: New test.
	* gcc.dg/pr81854.c: Update.
	* lib/target-supports.exp: Update.

Index: gcc/c-family/c.opt
===
--- gcc/c-family/c.opt	(revision 253099)
+++ gcc/c-family/c.opt	(working copy)
@@ -592,7 +592,7 @@ C C++ Var(warn_ignored_attributes) Init(1) Warning
 Warn whenever attributes are ignored.
 
 Wincompatible-pointer-types
-C ObjC Var(warn_incompatible_pointer_types) Init(1) Warning
+C C++ ObjC ObjcC++ Var(warn_incompatible_pointer_types) Init(1) Warning
 Warn when there is a conversion between pointers that have incompatible types.
 
 Winit-self
Index: gcc/cgraphunit.c
===
--- gcc/cgraphunit.c	(revision 253099)
+++ gcc/cgraphunit.c	(working copy)
@@ -1296,6 +1296,106 @@ analyze_functions (bool first_time)
   input_location = saved_loc;
 }
 
+/* Check declaration of the type of ALIAS for compatibility with its TARGET
+   (which may be an ifunc resolver) and issue a diagnostic when they are
+   not compatible according to language rules (plus a C++ extension for
+   non-static member functions).  */
+
+static void
+maybe_diag_incompatible_alias (tree alias, tree target)
+{
+  tree altype = TREE_TYPE (alias);
+  tree targtype = TREE_TYPE (target);
+
+  bool ifunc = lookup_attribute ("ifunc", DECL_ATTRIBUTES (alias));
+  if (ifunc)
+{
+  /* Handle attribute ifunc first.  */
+
+  tree funcptr = altype;
+
+  /* Set FUNCPTR to the type of the alias target.  If the type
+	 is a non-static member function of class C, construct a type
+	 of an ordinary function taking C* as the first argument,
+	 followed by the member function argument list, and use it
+	 instead to check for compatibilties.  FUNCPTR is used only
+	 in diagnostics.  */
+
+  if (TREE_CODE (altype) == METHOD_TYPE)
+	{
+	  tree rettype = TREE_TYPE (altype);
+	  tree args = TYPE_ARG_TYPES (altype);
+	  altype = build_function_type (rettype, args);
+	  funcptr = altype;
+	}
+
+  targtype = TREE_TYPE (targtype);
+
+  if (POINTER_TYPE_P (targtype))
+	{
+	  targtype = TREE_TYPE (targtype);
+
+	  /* Only issue Wincompatible-pointer-types for conversions
+	 to void* with -Wextra.  */
+	  if (VOID_TYPE_P (targtype) && !extra_warnings)
+	return;
+
+	  if ((!FUNC_OR_METHOD_TYPE_P (targtype)
+	   || (prototype_p (altype)
+		   && prototype_p (targtype)
+		   && !types_compatible_p (altype, targtype
+	{
+	  funcptr = build_pointer_type (funcptr);
+
+	  if (warning_at (DECL_SOURCE_LOCATION (target),
+			  OPT_Wincompatible_pointer_types,
+			  "% resolver for %qD should return %qT",
+			  alias, funcptr))
+		inform (DECL_SOURCE_LOCATION (alias),
+			"resolver indirect function declared here");
+	}
+	}
+  else
+	{
+	  /* Deal with static member function pointers.  */
+	  if (TREE_CODE (targtype) != RECORD_TYPE
+	  || TYPE_FIELDS (targtype)
+	  || TREE_CODE (TREE_TYPE (TYPE_FIELDS (targtype))) != POINTER_TYPE
+	  || (TREE_CODE (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (targtype
+		  != METHOD_TYPE))
+	{
+	  funcptr = build_pointer_type (funcptr);
+
+	  error ("% resolver for %qD must return %qT",

Re: [PATCH] PR target/80556

2017-09-24 Thread Mike Stump
On Sep 22, 2017, at 2:55 AM, Iain Sandoe  wrote:
> 
>> On 18 Sep 2017, at 22:08, Simon Wright  wrote:
>> 
>> On 18 Sep 2017, at 21:09, Iain Sandoe  wrote:
>>> 
> 
 If I propose this alternative patch, should it be a new post, or should I 
 continue this thread?
>>> 
>>> thanks for the patch.
>>> 
>>> The basic idea seems sound - as a workaround (as noted in comment #20 in 
>>> the PR, we should really rationalise the libgcc/crts stuff to reflect the 
>>> modern world, but these things take time...).
>>> 
>>> The patch as you have it would apply to every version of Darwin.
>>> 
>>> AFAICT from the published sources, i386 Darwin should be able to work with 
>>> the libgcc unwinder (and all earlier Darwin *have* to) - so I’ve proposed a 
>>> modified patch in the PR that makes the changes specific to m64 x86 and 
>>> doesn’t make any alteration for PPC and/or Darwin < 10.
>> 
>> That sounds like the right thing to do. I hadn't considered the older 
>> hardware/os issues (I only have kit back to macOS 10.11, Darwin 15).
> 
> So here’s the revised version with the comments slightly updated, checked 
> Darwin10,15,16 x86_64 and i386 in progress,
> OK if i386 succeeds?

Ok.

smime.p7s
Description: S/MIME cryptographic signature


[fortran, test case, committed]

2017-09-24 Thread Thomas Koenig

Hello world,

this seems to be a productive day for gfortran :-)

Here is another commit of a test case for a bug that
was fixed some time ago.  This is r253126.

Regards

Thomas

2017-09-24  Thomas Koenig  
PR fortran/66328

* gfortran.dg/data_derived_1.f90: New test.
! { dg-do  run }
! PR 66328 - this used to give a wrong value for integer values for DATA
program main
  TYPE t
REAL r
  END TYPE t
  TYPE (t) e1, e2
  
  DATA e1 / t(1) /
  DATA e2 / t(1.0) /
  if (abs(e1%r - 1.0) > 1e-6) call abort
  if (abs(e2%r - 1.0) > 1e-6) call abort
END


[PATCH gfortran] PR 61450: ICE in gfc_global_used()

2017-09-24 Thread Dominique d'Humières
Rebased FX’s patch.

Tested on x86_64-apple-darwin16.Is it OK with the proper log entries added?

TIA

Dominique

diff -up ../_clean/gcc/fortran/parse.c gcc/fortran/parse.c
--- ../_clean/gcc/fortran/parse.c   2017-01-22 20:50:56.0 +0100
+++ gcc/fortran/parse.c 2017-01-24 10:01:32.0 +0100
@@ -5724,34 +5724,33 @@ gfc_global_used (gfc_gsymbol *sym, locus
   switch(sym->type)
 {
 case GSYM_PROGRAM:
-  name = "PROGRAM";
+  name = "as a PROGRAM ";
   break;
 case GSYM_FUNCTION:
-  name = "FUNCTION";
+  name = "as a FUNCTION ";
   break;
 case GSYM_SUBROUTINE:
-  name = "SUBROUTINE";
+  name = "as a SUBROUTINE ";
   break;
 case GSYM_COMMON:
-  name = "COMMON";
+  name = "as a COMMON ";
   break;
 case GSYM_BLOCK_DATA:
-  name = "BLOCK DATA";
+  name = "as a BLOCK DATA ";
   break;
 case GSYM_MODULE:
-  name = "MODULE";
+  name = "as a MODULE ";
   break;
 default:
-  gfc_internal_error ("gfc_global_used(): Bad type");
-  name = NULL;
+  name = "";
 }
 
   if (sym->binding_label)
-gfc_error ("Global binding name %qs at %L is already being used as a %s "
+gfc_error ("Global binding name %qs at %L is already being used %s"
   "at %L", sym->binding_label, where, name, &sym->where);
   else
-gfc_error ("Global name %qs at %L is already being used as a %s at %L",
-  sym->name, where, name, &sym->where);
+gfc_error ("Global name %qs at %L is already being used %s"
+  "at %L", sym->name, where, name, &sym->where);
 }
 
 
--- ../_clean/gcc/testsuite/gfortran.dg/binding_label_tests_28.f90  
1970-01-01 01:00:00.0 +0100
+++ gcc/testsuite/gfortran.dg/binding_label_tests_28.f902017-01-13 
17:32:01.0 +0100
@@ -0,0 +1,12 @@
+! { dg-do compile }
+!
+! PR fortran/61450
+! Contributed by Francois-Xavier Coudert  
+!
+module p
+  integer i1 ! { dg-error "Global binding name 'foo' at .1. is already being 
used at .2." }
+  bind(c,name="foo") :: i1
+end module
+
+subroutine truc() bind(c,name="foo") ! { dg-error "Global binding name 'foo' 
at .1. is already being used at .2." }
+end



[test cases, fortran, committed] Test cases for PR 54633

2017-09-24 Thread Thomas Koenig

Hi,

I have committed the test cases below for the PR, which
have been fixed by an unknown commit, to make sure that
no regression occurs.

Since the main part of the PR is fixed, but there is one
more unrelated test case, I will close this one and open
a new one (following Dominique's suggestion in the PR).

Regards

Thomas

2017-09-24  Thomas Koenig  

PR fortran/54633
* gfortran.dg/intrinsic_bounds_1.f90: New test.
* gfortran.dg/intrinsic_param_1.f90: New test.


[patch, fortran, committed] Fix PR 79612

2017-09-24 Thread Dominique d'Humières
Patch committed after approval by Thomas Koenig on IRC

Dominique



Re: [PATCH] x32: Encode %esp as %rsp to avoid 0x67 prefix

2017-09-24 Thread H.J. Lu
On 9/24/17, Uros Bizjak  wrote:
> On Sat, Sep 23, 2017 at 11:16 PM, H.J. Lu  wrote:
>> Since the upper 32 bits of stack register are always zero for x32, we
>> can encode %esp as %rsp to avoid 0x67 prefix in address if there is no
>> index or base register.
>>
>> Tested on x86-64.  OK for trunk?
>>
>> H.J.
>> 
>> gcc/
>>
>> PR target/82267
>> * config/i386/i386.c (ix86_print_operand_address_as): Encode
>> %esp as %rsp to avoid 0x67 prefix if there is no index or base
>> register.
>>
>> gcc/testsuite/
>>
>> PR target/82267
>> * gcc.target/i386/pr82267.c: New tests.
>> ---
>>  gcc/config/i386/i386.c  | 17 +
>>  gcc/testsuite/gcc.target/i386/pr82267.c | 14 ++
>>  2 files changed, 31 insertions(+)
>>  create mode 100644 gcc/testsuite/gcc.target/i386/pr82267.c
>>
>> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
>> index 5e8f58c5e9f..519fdb0ffae 100644
>> --- a/gcc/config/i386/i386.c
>> +++ b/gcc/config/i386/i386.c
>> @@ -19849,6 +19849,23 @@ ix86_print_operand_address_as (FILE *file, rtx
>> addr,
>>disp = parts.disp;
>>scale = parts.scale;
>>
>> +  /* Since the upper 32 bits of RSP are always zero for x32, we can
>> + encode %esp as %rsp to avoid 0x67 prefix if there is no index or
>> + base register.  */
>> +  if (TARGET_X32
>> +  && Pmode == SImode
>> +  && (!index || !base)
>> +  && index != base)
>> +{
>> +  if (base)
>> +   {
>> + if (REGNO (base) == SP_REG)
>> +   base = gen_rtx_REG (DImode, SP_REG);
>> +   }
>> +  else if (REGNO (index) == SP_REG)
>> +   index = gen_rtx_REG (DImode, SP_REG);
>> +}
>> +
>
> We can use 'q' modifier just before register output part (plus a small
> simplification).
>
> Can you try the attached (untested) patch?
>

Yes, it works.

Thanks.

-- 
H.J.


Re: [PATCH] x32: Encode %esp as %rsp to avoid 0x67 prefix

2017-09-24 Thread Uros Bizjak
On Sat, Sep 23, 2017 at 11:16 PM, H.J. Lu  wrote:
> Since the upper 32 bits of stack register are always zero for x32, we
> can encode %esp as %rsp to avoid 0x67 prefix in address if there is no
> index or base register.
>
> Tested on x86-64.  OK for trunk?
>
> H.J.
> 
> gcc/
>
> PR target/82267
> * config/i386/i386.c (ix86_print_operand_address_as): Encode
> %esp as %rsp to avoid 0x67 prefix if there is no index or base
> register.
>
> gcc/testsuite/
>
> PR target/82267
> * gcc.target/i386/pr82267.c: New tests.
> ---
>  gcc/config/i386/i386.c  | 17 +
>  gcc/testsuite/gcc.target/i386/pr82267.c | 14 ++
>  2 files changed, 31 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr82267.c
>
> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
> index 5e8f58c5e9f..519fdb0ffae 100644
> --- a/gcc/config/i386/i386.c
> +++ b/gcc/config/i386/i386.c
> @@ -19849,6 +19849,23 @@ ix86_print_operand_address_as (FILE *file, rtx addr,
>disp = parts.disp;
>scale = parts.scale;
>
> +  /* Since the upper 32 bits of RSP are always zero for x32, we can
> + encode %esp as %rsp to avoid 0x67 prefix if there is no index or
> + base register.  */
> +  if (TARGET_X32
> +  && Pmode == SImode
> +  && (!index || !base)
> +  && index != base)
> +{
> +  if (base)
> +   {
> + if (REGNO (base) == SP_REG)
> +   base = gen_rtx_REG (DImode, SP_REG);
> +   }
> +  else if (REGNO (index) == SP_REG)
> +   index = gen_rtx_REG (DImode, SP_REG);
> +}
> +

We can use 'q' modifier just before register output part (plus a small
simplification).

Can you try the attached (untested) patch?

Uros.
Index: i386.c
===
--- i386.c  (revision 253118)
+++ i386.c  (working copy)
@@ -19953,6 +19953,14 @@ ix86_print_operand_address_as (FILE *file, rtx add
  code = 'k';
}
 
+  /* Since the upper 32 bits of RSP are always zero for x32, we can
+encode %esp as %rsp to avoid 0x67 prefix if there is no index or
+base register.  */
+  if (TARGET_X32 && Pmode == SImode
+ && ((!index && base && REGNO (base) == SP_REG)
+ || (!base && index && REGNO (index) == SP_REG)))
+   code = 'q';
+
   if (ASSEMBLER_DIALECT == ASM_ATT)
{
  if (disp)


[patch, fortran, committed] Fix PR 80118

2017-09-24 Thread Thomas Koenig

Hello world,

Steve had analyzed the bug and provided a patch in the PR;
I modified the patch stylistically and committed it as
obvious after regression-testing (r253123).

Thanks Steve!

Since this is a regression, I will backport soon.

Regards

Thomas

2017-09-24  Thomas Koenig  
Steven G. Kargl  

PR fortran/80118
* expr.c (gfc_get_full_arrayspec_from_expr): If there is
no symtree, set array spec to NULL.

2017-09-24  Thomas Koenig  
Steven G. Kargl  

PR fortran/80118
* gfortran.dg/zero_sized_7.f90: New test.
! { dg-do compile }
! PR 80118 - this used to ICE
! Original test case by Marco Restelli
module m
implicit none

  integer, parameter :: not_empty(1) = 0
  integer, parameter :: empty1(0) = (/integer :: /)
  integer, parameter :: empty2(0) = 0

contains

 subroutine sub(v)
  integer, allocatable, intent(out) :: v(:)
   v = 2*empty2 ! internal compiler error
 end subroutine sub

end module m
Index: expr.c
===
--- expr.c	(Revision 253116)
+++ expr.c	(Arbeitskopie)
@@ -4568,7 +4568,11 @@ gfc_get_full_arrayspec_from_expr (gfc_expr *expr)
   if (expr->expr_type == EXPR_VARIABLE
   || expr->expr_type == EXPR_CONSTANT)
 {
-  as = expr->symtree->n.sym->as;
+  if (expr->symtree)
+	as = expr->symtree->n.sym->as;
+  else
+	as = NULL;
+
   for (ref = expr->ref; ref; ref = ref->next)
 	{
 	  switch (ref->type)