[Patch, Fortran] PR40276/PR57711 - improve generic diagnostic

2013-06-26 Thread Tobias Burnus
This patch attempts to improve the diagnostic for generic matches, if a 
dummy procedure is used which has nonmatching characteristics.



Before the patch:

call gen(sub)
 1
Error: There is no specific subroutine for the generic 'gen' at (1)


After the patch:

call gen(sub)
 1
Error: Interface mismatch in dummy procedure 'a' at (1): INTENT mismatch 
in argument 'x'



The idea is that if the argument is a procedure* in generic resolution, 
there cannot be nonambiguous specific where the characters match. Thus, 
we first claim that there is a generic match - and later (after all 
arguments match) re-check whether the characteristics of the 
actual/dummy procedures are indeed the same.


Build and regtested on x86-64-gnu-linux.
OK for the trunk?

Tobias

* For completness: In F2008, one can distinguish a subroutine from a 
function; I think that's not yet implemented and but it shouldn't affect 
this patch, either.


PS: I think there could be some additional cases, which should be 
handled likewise (e.g. pureness, pointer/allocatable attribute etc.) - 
but I haven't thought about those. - PR57711 additionally shows that the 
interface mismatch is not detected when directly invoking the specific 
procedure and not using the generic one.
2012-06-26  Tobias Burnus  

	PR fortran/40276
	PR fortran/57711
	* interface.c (compare_parameter): Always claim generic match if
	actual and formal are procedures and "where" unset.
	(compare_actual_formal): For generic match (where unset), add a
	second round if a match has found to check the interface.

2012-06-26  Tobias Burnus  

	PR fortran/40276
	PR fortran/57711
	* gfortran.dg/generic_28.f90: New.
	* gfortran.dg/generic_29.f90: New.

diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c
index f06ecfe..d74df1a 100644
--- a/gcc/fortran/interface.c
+++ b/gcc/fortran/interface.c
@@ -1915,12 +1915,14 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual,
 	  return 0;
 	}
 
-  if (!gfc_compare_interfaces (formal, act_sym, act_sym->name, 0, 1, err,
-   sizeof(err), NULL, NULL))
+  /* If where is not set (i.e. generic resolution), we claim a successful match
+ (in terms of amiguity) - such that it can be later diagnosed in a second
+ round.  */
+  if (where && !gfc_compare_interfaces (formal, act_sym, act_sym->name,
+	0, 1, err, sizeof(err), NULL, NULL))
 	{
-	  if (where)
-	gfc_error ("Interface mismatch in dummy procedure '%s' at %L: %s",
-		   formal->name, &actual->where, err);
+	  gfc_error ("Interface mismatch in dummy procedure '%s' at %L: %s",
+		 formal->name, &actual->where, err);
 	  return 0;
 	}
 
@@ -2453,6 +2455,7 @@ compare_actual_formal (gfc_actual_arglist **ap, gfc_formal_arglist *formal,
   int i, n, na;
   unsigned long actual_size, formal_size;
   bool full_array = false;
+  bool has_procedure = false;
 
   actual = *ap;
 
@@ -2679,6 +2682,8 @@ compare_actual_formal (gfc_actual_arglist **ap, gfc_formal_arglist *formal,
 		   f->sym->name, &a->expr->where);
 	  return 0;
 	}
+  else
+has_procedure = true;
 
   if (f->sym->as && f->sym->as->type == AS_ASSUMED_SHAPE
 	  && a->expr->expr_type == EXPR_VARIABLE
@@ -2926,6 +2931,16 @@ compare_actual_formal (gfc_actual_arglist **ap, gfc_formal_arglist *formal,
 if (a->expr == NULL && a->label == NULL)
   a->missing_arg_type = f->sym->ts.type;
 
+  /* Whe have a generic match, now check whether the dummy-procedure interface
+ has the same characteristics.  */
+  if (!where && has_procedure)
+{
+  for (a = *ap, f = formal; a; a = a->next, f = f->next)
+	if (a->expr && f && f->sym->attr.flavor == FL_PROCEDURE)
+	  compare_parameter (f->sym, a->expr, ranks_must_agree,
+			 is_elemental, &a->expr->where);
+}
+
   return 1;
 }
 
--- /dev/null	2013-06-26 08:23:53.976189029 +0200
+++ gcc/gcc/testsuite/gfortran.dg/generic_28.f90	2013-06-26 09:19:11.918274187 +0200
@@ -0,0 +1,24 @@
+! { dg-do compile }
+!
+! PR fortran/40276
+! PR fortran/57711
+!
+module m
+  implicit none
+  interface gen
+subroutine specific(a)
+  interface
+subroutine a(x)
+  integer, intent(in) :: x
+end subroutine a
+  end interface
+end subroutine specific
+  end interface gen
+contains
+  subroutine test()
+call gen(sub) ! { dg-error "Interface mismatch in dummy procedure 'a' at .1.: INTENT mismatch in argument 'x'" }
+  end subroutine test
+  subroutine sub(a)
+integer, intent(inout) :: a
+  end subroutine sub
+end module m
--- /dev/null	2013-06-26 08:23:53.976189029 +0200
+++ gcc/gcc/testsuite/gfortran.dg/generic_29.f90	2013-06-26 09:19:28.576180621 +0200
@@ -0,0 +1,88 @@
+! { dg-do compile }
+!
+! PR fortran/40276
+! PR fortran/57711
+!
+! Contributed by Dmitry Kabanov
+!
+  MODULE VODE_INT
+  IMPLICIT NONE
+  PRIVATE
+
+! Fortran 90 Interface
+  INTERFACE VODE
+MODULE PROCEDURE D_VODE
+  END INTERFACE
+
+  PUBL

Re: [Patch, Fortran] Add end-of-scope finalization (Part 2 of 2)

2013-06-26 Thread Dominique Dhumieres
Dear Tobias,

Failures in 32 bit mode again!-(
With your patch, I get the following failures with -m32:

FAIL: gfortran.dg/class_48.f90  -O2  (test for excess errors)
FAIL: gfortran.dg/class_48.f90  -Os  (test for excess errors)
FAIL: gfortran.dg/finalize_18.f90  -O   scan-tree-dump-times original 
"y.cc._vptr->_final \\(&desc.5, \\(integer\\(kind=8\\)\\) y.cc._vptr->_size, 
1\\);" 1
FAIL: gfortran.dg/finalize_18.f90  -O   scan-tree-dump-times original 
"y.dd._vptr->_final \\(&y.dd._data, \\(integer\\(kind=8\\)\\) 
y.dd._vptr->_size, 1\\);" 1

The failures for finalize_18.f90 are

/opt/gcc/work/gcc/testsuite/gfortran.dg/class_48.f90: In function 
'__final_test2_T.2138.constprop.0':
/opt/gcc/work/gcc/testsuite/gfortran.dg/class_48.f90:39:0: warning: iteration 
2147483648 invokes undefined behavior [-Waggressive-loop-optimizations]
 class(t), allocatable :: a
 ^
/opt/gcc/work/gcc/testsuite/gfortran.dg/class_48.f90:39:0: note: containing loop

and for finalize_18.f90, grepping for _vptr->_size yields

y.cc._vptr->_final (&desc.5, y.cc._vptr->_size, 1);
y.dd._vptr->_final (&y.dd._data, y.dd._vptr->_size, 1);

TIA

Dominique


Re: [PATCH, ARM] Fix unrecognizable vector comparisons

2013-06-26 Thread Zhenqiang Chen
On 18 June 2013 17:41, Ramana Radhakrishnan  wrote:
> On 06/18/13 09:50, Zhenqiang Chen wrote:
>>
>> Hi,
>>
>> During expand, function vcond inverses some CMP, e.g.
>>
>> a LE b -> b GE a
>>
>> But if "b" is "CONST0_RTX", "b GE a" will be an illegal insn.
>>
>> (insn 933 932 934 113 (set (reg:V4SI 1027)
>>  (unspec:V4SI [
>>  (const_vector:V4SI [
>>  (const_int 0 [0])
>>  (const_int 0 [0])
>>  (const_int 0 [0])
>>  (const_int 0 [0])
>>  ])
>>  (reg:V4SI 1023 [ vect_var_.49 ])
>>  (const_int 1 [0x1])
>>  ] UNSPEC_VCGE)) PUGHSlab/Mapping.c:567 -1
>>   (nil))
>>
>> Refer https://bugs.launchpad.net/linaro-toolchain-binaries/+bug/1189445
>> for more. And the bug also happens for FSF trunk.
>>
>> The similar issue
>> (https://bugs.launchpad.net/linaro-toolchain-binaries/+bug/1163942)
>> had fixed on AARCH64:
>> http://gcc.gnu.org/ml/gcc-patches/2013-04/msg00581.html
>>
>> The patch is similar to the fix for aarch64.
>>
>> Bootstrap and no make check regression on Panda Board.
>>
>> Is it OK for trunk and 4.8?
>
>
> No, not without an appropriate set of testcases that exercise these cases.

Thanks for the comments. Patch is updated with a test case.

diff --git a/gcc/config/arm/neon.md b/gcc/config/arm/neon.md
index 2761adb..6d9f604 100644
--- a/gcc/config/arm/neon.md
+++ b/gcc/config/arm/neon.md
@@ -1710,6 +1710,9 @@
 case LE:
 case UNLE:
   inverse = 1;
+  /* Can not inverse "a LE 0" to "0 GE a".  */
+  if (operands[5] == CONST0_RTX (mode))
+   inverse = 0;
   /* Fall through.  */
 case GT:
 case UNGT:
diff --git a/gcc/testsuite/gcc.target/arm/lp1189445.c
b/gcc/testsuite/gcc.target/arm/lp1189445.c
new file mode 100644
index 000..8ce4b97
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/lp1189445.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -mfpu=neon -mcpu=cortex-a9 -mthumb
-mfloat-abi=hard -S" } */
+
+int id;
+int
+test (const long int *data)
+{
+  int i, retval;
+  retval = id;
+  for (i = 0; i < id; i++)
+{
+  retval &= (data[i] <= 0);
+}
+
+  return (retval);
+}


Re: [Patch ARM] Add Cortex A15 neon scheduler

2013-06-26 Thread Tom de Vries
On 18/10/12 18:48, Ramana Radhakrishnan wrote:
> +(define_insn_reservation "cortex_a15_vfp_adds_subs" 6
> +  (and (eq_attr "tune" "cortexa15")
> +   (eq_attr "type" "fadds"))
> +  "ca15_issue1,ca15_cx_vfp")

Ramana,

I noticed you use here the fadds value for the type attribute to activate this 
rule.

This same test is also used in this generic_vfp rule:
...
(define_insn_reservation "vfp_farith" 8
 (and (eq_attr "generic_vfp" "yes")
  (eq_attr "type" "fadds,faddd,fconsts,fconstd,f_cvt,fmuls,fmacs,ffmas"))
 "fmac")
...
and the generic_vfp is yes for cortex-a15, so these 2 rules are active at the
same time.

The documentation states:
...
You should remember that you will be in trouble if condition for two or more
different define_insn_reservation constructions is TRUE for an insn. In this
case what reservation will be used for the insn is not defined.
...

I made an example, looked at the sched2 dump and found that the cortex-a15 rule
was active. Moving vfp11.md to before cortex-a15.md made the other rule active.

Are we exploiting some undocumented (partially) defined behavior here with
respect to order, or is this a latent bug?

Thanks,
- Tom


Re: [PATCH] Cilk Plus Array Notation for C++

2013-06-26 Thread Aldy Hernandez

On 06/25/13 13:42, Iyer, Balaji V wrote:


What remaining obstacles are there to sharing most of the expansion
code between C and C++?  That can be a separate patch, of course.

Jason




??


[c++-concepts] class template constraints

2013-06-26 Thread Andrew Sutton
I changed the method by which class (and alias) template constraints
are checked. Rather than waiting until instantiation, they are now
checked after computing the binding in lookup_class template.
Actually, after the hashtable lookup so we don't re-check constraints
for previously instantiated specializations.

Previously, this was allowed:

  vector* p;

Assuming that vector restricted its arguments to only object types.
The program is ill-formed if vector is ever instantiated. This
patch causes formation of the type vector to result in an error.

Changelog:

2013-06-25  Andrew Sutton  
* gcc/cp/constraint.cc (check_constraints): Don't check against
dependent arguments. Just return true.
* gcc/cp/ptr.c (lookup_class_template_1): Check template constraints
and diagnose failures. Removing specific check for alias templates.
(instantiate_class_template_1): Remove constraints check during
template instantiation.

Andrew


class.patch
Description: Binary data


[Patch, Fortran] PR57721 - improve out-of-bounds error message for components

2013-06-26 Thread Tobias Burnus

The patch changes the out-of-bounds message for "k==11"
  z(i)%y(j)%x(k)=0
from:
  Fortran runtime error: Index '11' of dimension 1 of array 'z' above 
upper bound of 10

to
  Fortran runtime error: Index '11' of dimension 1 of array 'z%y%x' 
above upper bound of 10


(For j out of bounds, it would show "z%y" and for i out of bounds "z".)

Build and regtested on x86-64-gnu-linux.
OK for the trunk?

Tobias
2013-06-26  Tobias Burnus  

	PR fortran/29800
	* trans-array.c (gfc_conv_array_ref): Improve out-of-bounds
	diagnostic message.
	* trans-array.c (gfc_conv_array_ref): Update prototype.
	* trans-expr.c (gfc_conv_variable): Update call.

2013-06-26  Tobias Burnus  

	PR fortran/29800
	* gfortran.dg/bounds_check_17.f90: New.

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 96162e5..d118f75 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -3145,7 +3145,7 @@ build_array_ref (tree desc, tree offset, tree decl)
a(i, j, k) = base[offset + i * stride[0] + j * stride[1] + k * stride[2]]*/
 
 void
-gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, gfc_symbol * sym,
+gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, gfc_expr *expr,
 		locus * where)
 {
   int n;
@@ -3154,6 +3154,8 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, gfc_symbol * sym,
   tree stride;
   gfc_se indexse;
   gfc_se tmpse;
+  gfc_symbol * sym = expr->symtree->n.sym;
+  char *var_name = NULL;
 
   if (ar->dimen == 0)
 {
@@ -3184,6 +3186,35 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, gfc_symbol * sym,
   return;
 }
 
+  if (gfc_option.rtcheck & GFC_RTCHECK_BOUNDS)
+{
+  size_t len;
+  gfc_ref *ref;
+
+  len = strlen (sym->name) + 1;
+  for (ref = expr->ref; ref; ref = ref->next)
+	{
+	  if (ref->type == REF_ARRAY && &ref->u.ar == ar)
+	break;
+	  if (ref->type == REF_COMPONENT)
+	len += 1 + strlen (ref->u.c.component->name);
+	}
+
+  var_name = XALLOCAVEC (char, len);
+  strcpy (var_name, sym->name);
+
+  for (ref = expr->ref; ref; ref = ref->next)
+	{
+	  if (ref->type == REF_ARRAY && &ref->u.ar == ar)
+	break;
+	  if (ref->type == REF_COMPONENT)
+	{
+	  strcat (var_name, "%%");
+	  strcat (var_name, ref->u.c.component->name);
+	}
+	}
+}
+
   cst_offset = offset = gfc_index_zero_node;
   add_to_offset (&cst_offset, &offset, gfc_conv_array_offset (se->expr));
 
@@ -3219,7 +3250,7 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, gfc_symbol * sym,
 	  cond = fold_build2_loc (input_location, LT_EXPR, boolean_type_node,
   indexse.expr, tmp);
 	  asprintf (&msg, "Index '%%ld' of dimension %d of array '%s' "
-		"below lower bound of %%ld", n+1, sym->name);
+		"below lower bound of %%ld", n+1, var_name);
 	  gfc_trans_runtime_check (true, false, cond, &se->pre, where, msg,
    fold_convert (long_integer_type_node,
 		 indexse.expr),
@@ -3243,7 +3274,7 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, gfc_symbol * sym,
 	  cond = fold_build2_loc (input_location, GT_EXPR,
   boolean_type_node, indexse.expr, tmp);
 	  asprintf (&msg, "Index '%%ld' of dimension %d of array '%s' "
-			"above upper bound of %%ld", n+1, sym->name);
+			"above upper bound of %%ld", n+1, var_name);
 	  gfc_trans_runtime_check (true, false, cond, &se->pre, where, msg,
    fold_convert (long_integer_type_node,
 		 indexse.expr),
diff --git a/gcc/fortran/trans-array.h b/gcc/fortran/trans-array.h
index 8d9e461..878a5c0 100644
--- a/gcc/fortran/trans-array.h
+++ b/gcc/fortran/trans-array.h
@@ -123,7 +123,7 @@ void gfc_conv_resolve_dependencies (gfc_loopinfo *, gfc_ss *, gfc_ss *);
 tree gfc_build_null_descriptor (tree);
 
 /* Get a single array element.  */
-void gfc_conv_array_ref (gfc_se *, gfc_array_ref *, gfc_symbol *, locus *);
+void gfc_conv_array_ref (gfc_se *, gfc_array_ref *, gfc_expr *, locus *);
 /* Translate a reference to a temporary array.  */
 void gfc_conv_tmp_array_ref (gfc_se * se);
 /* Translate a reference to an array temporary.  */
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 56dc766..7a726db 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -1910,7 +1910,7 @@ gfc_conv_variable (gfc_se * se, gfc_expr * expr)
 	  && ref->next == NULL && (se->descriptor_only))
 	return;
 
-	  gfc_conv_array_ref (se, &ref->u.ar, sym, &expr->where);
+	  gfc_conv_array_ref (se, &ref->u.ar, expr, &expr->where);
 	  /* Return a pointer to an element.  */
 	  break;
 
--- /dev/null	2013-06-26 08:23:53.976189029 +0200
+++ gcc/gcc/testsuite/gfortran.dg/bounds_check_17.f90	2013-06-26 15:10:24.528309201 +0200
@@ -0,0 +1,26 @@
+! { dg-do run }
+! { dg-options "-fcheck=bounds" }
+! { dg-shouldfail "above upper bound" }
+!
+! PR fortran/29800
+!
+! Contributed by Joost VandeVondele
+!
+
+TYPE data
+  INTEGER :: x(10)
+END TYPE
+TYPE data_areas
+  TYPE(data) :: y(10)
+END TYPE
+
+TYPE(data_areas) :: z(10)
+
+integer, vo

[patch] documentation: clarify that Cilk Plus implementation is incomplete

2013-06-26 Thread Aldy Hernandez
This is a small cleanup to the Cilk Plus mention in our documentation, 
but more importantly, it clarifies that the Cilk Plus implementation in 
GCC is only partial.


OK for trunk?
* doc/invoke.texi (-fcilkplus): Clarify that implementation is
incomplete.

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index dd82880..3150c8d 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -1804,13 +1804,17 @@ have support for @option{-pthread}.
 @item -fcilkplus
 @opindex fcilkplus
 @cindex Enable Cilk Plus
-Enable the usage of Cilk Language extension features for C/C++.  When the flag
-@option{-fcilkplus} is specified, all the Cilk Plus components are converted 
-to the appropriate C/C++ code.  The present implementation follows ABI version 
-0.9.  There are four major parts to Cilk Plus language 
-extension: Array Notations, Cilk Keywords, SIMD annotations and elemental 
-functions.  Detailed information about Cilk Plus can be found at 
-@w{@uref{http://www.cilkplus.org}}. 
+When the option @option{-fcilkplus} is specified, enable the usage of
+the Cilk Plus Language extension features for C/C++.  The present
+implementation follows ABI version 0.9.  This is an experimental
+feature that is only partially complete, and whose interface may
+change in future versions of GCC, as the official specification
+changes.  Currently only the array notation feature of the language
+specification has been implemented.  More features will be implemented
+in subsequent release cycles.
+
+Detailed information about Cilk Plus can be found at
+@w{@uref{http://www.cilkplus.org}}.
 
 @item -fgnu-tm
 @opindex fgnu-tm


Re: [C++] DR1473 - let literal operators be defined with empty user-defined string literal

2013-06-26 Thread Ed Smith-Rowland

On 06/25/2013 08:50 AM, Jason Merrill wrote:

I had missed a few files in my patch anyway (I was doing too much at once).


On 06/25/2013 08:27 AM, Ed Smith-Rowland wrote:

+  else if (token->type == CPP_KEYWORD)
+{
+  error ("unexpected keyword;"
+ " Remove space between quotes and suffix identifier");
+  return error_mark_node;
+}


Lower-case 'r' after a semicolon.

Done.


After giving the error, let's try to handle it properly anyway to 
avoid cascading errors.



+if (TREE_STRING_LENGTH (string_tree) > 2)


Why 2?  I would expect TREE_STRING_LENGTH for "" to be 1 (the NUL).

The string length is the two quotes (and, as you'll see, the encoding 
prefix length).

+error ("expected empty string after % keyword");
+return error_mark_node;


And let's continue after the error here, too.


+  error ("invalid encoding prefix in literal operator");
   return error_mark_node;


And here.
I the patch I am sending you now, I don't return error mark node very 
often.  I go on, nonempty strings and bad encoding notwithstanding, and 
produce the correct operator ID which gets returned.  Correct?


Jason


I'm still testing and I might have to tweak the error lines and such.

OK in principal though?

Ed

libcpp:

2013-06-25  Ed Smith-Rowland  <3dw...@verizon.net>

* lex.c: Constrain suffixes treated as concatenated literal and macro
to just the patterns found in inttypes.h.


gcc/cp:

2013-06-25  Ed Smith-Rowland  <3dw...@verizon.net>

* cp-tree.h (UDLIT_OP_ANSI_PREFIX): Remove space.
* parser.c (cp_parser_operator()): Parse user-defined string
literal as literal operator.


gcc/testsuite:

2013-06-25  Ed Smith-Rowland  <3dw...@verizon.net>

* g++.dg/cpp0x/udlit-nospace-neg.C: Adjust.
* g++.dg/cpp1y/udlit-enc-prefix-neg.C: New.
* g++.dg/cpp1y/udlit-userdef-string.C: New.
* g++.dg/cpp1y/complex_literals.h: New.
Index: gcc/cp/cp-tree.h
===
--- gcc/cp/cp-tree.h(revision 200414)
+++ gcc/cp/cp-tree.h(working copy)
@@ -4404,7 +4404,7 @@
 #define LAMBDANAME_PREFIX "__lambda"
 #define LAMBDANAME_FORMAT LAMBDANAME_PREFIX "%d"
 
-#define UDLIT_OP_ANSI_PREFIX "operator\"\" "
+#define UDLIT_OP_ANSI_PREFIX "operator\"\""
 #define UDLIT_OP_ANSI_FORMAT UDLIT_OP_ANSI_PREFIX "%s"
 #define UDLIT_OP_MANGLED_PREFIX "li"
 #define UDLIT_OP_MANGLED_FORMAT UDLIT_OP_MANGLED_PREFIX "%s"
Index: libcpp/lex.c
===
--- libcpp/lex.c(revision 200414)
+++ libcpp/lex.c(working copy)
@@ -1556,22 +1556,21 @@
 
   if (CPP_OPTION (pfile, user_literals))
 {
-  /* According to C++11 [lex.ext]p10, a ud-suffix not starting with an
-underscore is ill-formed.  Since this breaks programs using macros
-from inttypes.h, we generate a warning and treat the ud-suffix as a
-separate preprocessing token.  This approach is under discussion by
-the standards committee, and has been adopted as a conforming
-extension by other front ends such as clang.
- A special exception is made for the suffix 's' which will be
-standardized as a user-defined literal suffix for strings.  */
-  if (ISALPHA (*cur) && *cur != 's')
+  /* If a string format macro, say from inttypes.h, is placed touching
+a string literal it could be parsed as a C++11 user-defined string
+literal thus breaking the program.
+Since all format macros in inttypes.h start with "PRI" or "SCN"
+suffixes beginning with these will be interpreted as macros and the
+string and the macro parsed as separate tokens. A warning is issued. */
+  if (ustrcmp (cur, (const unsigned char *) "PRI") == 0
+   || ustrcmp (cur, (const unsigned char *) "SCN") == 0)
{
  /* Raise a warning, but do not consume subsequent tokens.  */
  if (CPP_OPTION (pfile, warn_literal_suffix))
cpp_warning_with_line (pfile, CPP_W_LITERAL_SUFFIX,
   token->src_loc, 0,
   "invalid suffix on literal; C++11 requires "
-  "a space between literal and identifier");
+  "a space between literal and string macro");
}
   /* Grab user defined literal suffix.  */
   else if (ISIDST (*cur))
@@ -1689,22 +1688,21 @@
 
   if (CPP_OPTION (pfile, user_literals))
 {
-  /* According to C++11 [lex.ext]p10, a ud-suffix not starting with an
-underscore is ill-formed.  Since this breaks programs using macros
-from inttypes.h, we generate a warning and treat the ud-suffix as a
-separate preprocessing token.  This approach is under discussion by
-the standards committee, and has been adopted as a conforming
-extension by other front ends such as clang.
-  

Re: Document __builtin_isinf_sign more precisely

2013-06-26 Thread Marc Glisse

Ping http://gcc.gnu.org/ml/gcc-patches/2013-06/msg00475.html

On Sun, 9 Jun 2013, Marc Glisse wrote:


Hello,

this patch documents that __builtin_isinf_sign returns +-1 for +-Inf. This 
builtin was created so it could be used by a libc that has a stronger 
guarantee than the standard, and for glibc that means returning +-1, which is 
what the code already does.


2013-06-10  Marc Glisse  

PR middle-end/57219
* doc/extend.texi (__builtin_isinf_sign): Restrict the return
values to -1, 0 and 1.


--
Marc Glisse


Re: [C++] Fix __builtin_shuffle

2013-06-26 Thread Marc Glisse

Ping http://gcc.gnu.org/ml/gcc-patches/2013-06/msg00470.html

On Sun, 9 Jun 2013, Marc Glisse wrote:


Hello,

when porting __builtin_shuffle from C to C++, I ignored all the C++ 
specificities and added some extra bugs. This should improve things a bit.


Bootstrap+testsuite on x86_64-linux-gnu.


2013-06-10  Marc Glisse  

PR c++/57509

gcc/c-family/
* c-common.h (c_build_vec_perm_expr): New complain argument.
* c-common.c (c_build_vec_perm_expr): Likewise.
Use save_expr also in C++.

gcc/cp/
* typeck.c (cp_build_vec_perm_expr): New function.
* cp-tree.h: Declare it.
* parser.c (cp_parser_postfix_expression): Call it.
* pt.c (tsubst_copy): Handle VEC_PERM_EXPR.
(tsubst_copy_and_build): Likewise.

gcc/testsuite/
* g++.dg/ext/pr57509.C: New file.


--
Marc Glisse


Re: [x86] Remove 2 builtins

2013-06-26 Thread Marc Glisse

Ping http://gcc.gnu.org/ml/gcc-patches/2013-06/msg00478.html

On Sun, 9 Jun 2013, Marc Glisse wrote:


Hello,

this patch removes 2 builtins that are undocumented, unused, and have 
confusing semantics. Bootstrap+testsuite on x86_64-linux-gnu.



2013-06-10  Marc Glisse  

PR target/57224
* config/i386/i386.c (enum ix86_builtins, bdesc_args): Remove
IX86_BUILTIN_CMPNGTSS and IX86_BUILTIN_CMPNGESS.




--
Marc Glisse


Re: [omp4/cilkplus] jumps in/out-of #pragma simd for

2013-06-26 Thread Aldy Hernandez

This is a followup for the C++ changes (your pt.c suggested changes, etc).

Only a few minor changes are needed, since c_finish_cilk_simd_loop() is 
shared between C/C++ and it creates the appropriate CILK_SIMD tree node.


Is this what you had in mind?
commit db2127098137dea6c246041e0d763a57a174fa3c
Author: Aldy Hernandez 
Date:   Wed Jun 26 09:29:27 2013 -0500

Handle CILK_SIMD tree code in C++.

diff --git a/gcc/cp/ChangeLog.cilkplus b/gcc/cp/ChangeLog.cilkplus
index e7f7596..f0ee3ee 100644
--- a/gcc/cp/ChangeLog.cilkplus
+++ b/gcc/cp/ChangeLog.cilkplus
@@ -1,3 +1,10 @@
+2013-06-26  Aldy Hernandez  
+
+   * cp-gimplify.c (cp_gimplify_expr): Add case for CILK_SIMD.
+   (cp_genericize_r): Same.
+   * pt.c (tsubst_expr): Same.
+   * semantics.c (finish_omp_for): Same.
+
 2013-05-21  Balaji V. Iyer  
Aldy Hernandez  
 
diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index 0dfa4a2..52ce57b 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -670,6 +670,7 @@ cp_gimplify_expr (tree *expr_p, gimple_seq *pre_p, 
gimple_seq *post_p)
 
 case OMP_FOR:
 case OMP_SIMD:
+case CILK_SIMD:
 case OMP_DISTRIBUTE:
   ret = cp_gimplify_omp_for (expr_p, pre_p);
   break;
@@ -1120,6 +1121,7 @@ cp_genericize_r (tree *stmt_p, int *walk_subtrees, void 
*data)
 genericize_break_stmt (stmt_p);
   else if (TREE_CODE (stmt) == OMP_FOR
   || TREE_CODE (stmt) == OMP_SIMD
+  || TREE_CODE (stmt) == CILK_SIMD
   || TREE_CODE (stmt) == OMP_DISTRIBUTE)
 genericize_omp_for_stmt (stmt_p, walk_subtrees, data);
   else if (TREE_CODE (stmt) == SIZEOF_EXPR)
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 63d960d..d0fa491 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -13293,6 +13293,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t 
complain, tree in_decl,
 
 case OMP_FOR:
 case OMP_SIMD:
+case CILK_SIMD:
 case OMP_DISTRIBUTE:
   {
tree clauses, body, pre_body;
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index ee83462..722a996 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -5782,7 +5782,7 @@ finish_omp_for (location_t locus, enum tree_code code, 
tree declv, tree initv,
 
   if (CLASS_TYPE_P (TREE_TYPE (decl)))
{
- if (code == OMP_SIMD)
+ if (code == OMP_SIMD || code == CILK_SIMD)
{
  error_at (elocus, "%<#pragma omp simd%> used with class "
"iteration variable %qE", decl);


Re: Use unsigned(-1) for lshift

2013-06-26 Thread Marc Glisse

Ping (re-attaching the patch)

2013-06-26  Marc Glisse  

PR other/57324
* hwint.h (HOST_WIDE_INT_UC, HOST_WIDE_INT_1U, HOST_WIDE_INT_M1,
HOST_WIDE_INT_M1U): New macros.
* fold-const.c (sign_bit_p, build_range_check, fold_unary_loc,
fold_binary_loc, fold_ternary_loc): Use the new macros. Use an
unsigned -1 for lshift.
* cse.c (cse_insn): Likewise.
* double-int.c (rshift_double, lshift_double): Likewise.
* builtins.c (fold_builtin_bitop): Likewise.
* combine.c (force_to_mode): Likewise.
* tree.c (integer_pow2p, tree_log2, tree_floor_log2): Likewise.
* simplify-rtx.c (simplify_const_unary_operation,
simplify_const_binary_operation): Likewise.
* tree-stdarg.c (reachable_at_most_once, va_list_counter_bump,
va_list_ptr_read, check_va_list_escapes): Likewise.
* rtlanal.c (nonzero_bits1): Likewise.
* expmed.c (expand_smod_pow2): Likewise.
* tree-ssa-structalias.c (UNKNOWN_OFFSET): Use HOST_WIDE_INT_MIN.

--
Marc GlisseIndex: gcc/tree.c
===
--- gcc/tree.c  (revision 200422)
+++ gcc/tree.c  (working copy)
@@ -2044,26 +2044,26 @@ integer_pow2p (const_tree expr)
   prec = TYPE_PRECISION (TREE_TYPE (expr));
   high = TREE_INT_CST_HIGH (expr);
   low = TREE_INT_CST_LOW (expr);
 
   /* First clear all bits that are beyond the type's precision in case
  we've been sign extended.  */
 
   if (prec == HOST_BITS_PER_DOUBLE_INT)
 ;
   else if (prec > HOST_BITS_PER_WIDE_INT)
-high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
+high &= ~(HOST_WIDE_INT_M1U << (prec - HOST_BITS_PER_WIDE_INT));
   else
 {
   high = 0;
   if (prec < HOST_BITS_PER_WIDE_INT)
-   low &= ~((HOST_WIDE_INT) (-1) << prec);
+   low &= ~(HOST_WIDE_INT_M1U << prec);
 }
 
   if (high == 0 && low == 0)
 return 0;
 
   return ((high == 0 && (low & (low - 1)) == 0)
  || (low == 0 && (high & (high - 1)) == 0));
 }
 
 /* Return 1 if EXPR is an integer constant other than zero or a
@@ -2108,26 +2108,26 @@ tree_log2 (const_tree expr)
   prec = TYPE_PRECISION (TREE_TYPE (expr));
   high = TREE_INT_CST_HIGH (expr);
   low = TREE_INT_CST_LOW (expr);
 
   /* First clear all bits that are beyond the type's precision in case
  we've been sign extended.  */
 
   if (prec == HOST_BITS_PER_DOUBLE_INT)
 ;
   else if (prec > HOST_BITS_PER_WIDE_INT)
-high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
+high &= ~(HOST_WIDE_INT_M1U << (prec - HOST_BITS_PER_WIDE_INT));
   else
 {
   high = 0;
   if (prec < HOST_BITS_PER_WIDE_INT)
-   low &= ~((HOST_WIDE_INT) (-1) << prec);
+   low &= ~(HOST_WIDE_INT_M1U << prec);
 }
 
   return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high)
  : exact_log2 (low));
 }
 
 /* Similar, but return the largest integer Y such that 2 ** Y is less
than or equal to EXPR.  */
 
 int
@@ -2145,26 +2145,26 @@ tree_floor_log2 (const_tree expr)
   high = TREE_INT_CST_HIGH (expr);
   low = TREE_INT_CST_LOW (expr);
 
   /* First clear all bits that are beyond the type's precision in case
  we've been sign extended.  Ignore if type's precision hasn't been set
  since what we are doing is setting it.  */
 
   if (prec == HOST_BITS_PER_DOUBLE_INT || prec == 0)
 ;
   else if (prec > HOST_BITS_PER_WIDE_INT)
-high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
+high &= ~(HOST_WIDE_INT_M1U << (prec - HOST_BITS_PER_WIDE_INT));
   else
 {
   high = 0;
   if (prec < HOST_BITS_PER_WIDE_INT)
-   low &= ~((HOST_WIDE_INT) (-1) << prec);
+   low &= ~(HOST_WIDE_INT_M1U << prec);
 }
 
   return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high)
  : floor_log2 (low));
 }
 
 /* Return 1 if EXPR is the real constant zero.  Trailing zeroes matter for
decimal float constants, so don't return 1 for them.  */
 
 int
Index: gcc/simplify-rtx.c
===
--- gcc/simplify-rtx.c  (revision 200422)
+++ gcc/simplify-rtx.c  (working copy)
@@ -1988,28 +1988,27 @@ simplify_const_unary_operation (enum rtx
  if (REAL_VALUES_LESS (t, x))
{
  xh = th;
  xl = tl;
  break;
}
 
  /* Test against the signed lower bound.  */
  if (width > HOST_BITS_PER_WIDE_INT)
{
- th = (unsigned HOST_WIDE_INT) (-1)
-  << (width - HOST_BITS_PER_WIDE_INT - 1);
+ th = HOST_WIDE_INT_M1U << (width - HOST_BITS_PER_WIDE_INT - 1);
  tl = 0;
}
  else
{
  th = -1;
- tl = (unsigned HOST_WIDE_INT) (-1) << (width - 1);
+ tl = HOST_WIDE_INT_M1U << (width - 1);
}
  real_from_integer (&t, VOIDmode, tl, th, 0);
  if (R

Re: [Patch, Fortran] PR57721 - improve out-of-bounds error message for components

2013-06-26 Thread Thomas Koenig

Hi Tobias,


The patch changes the out-of-bounds message for "k==11"
   z(i)%y(j)%x(k)=0
from:
   Fortran runtime error: Index '11' of dimension 1 of array 'z' above
upper bound of 10
to
   Fortran runtime error: Index '11' of dimension 1 of array 'z%y%x'
above upper bound of 10

(For j out of bounds, it would show "z%y" and for i out of bounds "z".)

Build and regtested on x86-64-gnu-linux.
OK for the trunk?


OK.

Thanks a lot for the patch!

Thomas



Re: [omp4/cilkplus] jumps in/out-of #pragma simd for

2013-06-26 Thread Jakub Jelinek
On Wed, Jun 26, 2013 at 09:44:03AM -0500, Aldy Hernandez wrote:
> This is a followup for the C++ changes (your pt.c suggested changes, etc).
> 
> Only a few minor changes are needed, since c_finish_cilk_simd_loop()
> is shared between C/C++ and it creates the appropriate CILK_SIMD
> tree node.
> 
> Is this what you had in mind?

Yes.

Jakub


Go patch committed: Don't permit global variables named init

2013-06-26 Thread Ian Lance Taylor
The Go language does not permit global variables named init.  That name
is reserved for functions that run when the program starts.  This patch,
from Rémy Oudompheng, implements that restriction in gccgo.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline and 4.8 branch.

Ian

diff -r f250c0138323 go/gogo.cc
--- a/go/gogo.cc	Tue Jun 25 09:27:11 2013 -0700
+++ b/go/gogo.cc	Wed Jun 26 08:46:11 2013 -0700
@@ -1278,6 +1278,14 @@
 		   n.c_str());
 	  inform(pf->second, "%qs imported here", n.c_str());
 	}
+
+  // No package scope identifier may be named "init".
+  if (!p->second->is_function()
+	  && Gogo::unpack_hidden_name(p->second->name()) == "init")
+	{
+	  error_at(p->second->location(),
+	   "cannot declare init - must be func");
+	}
 }
 }
 


Re: [PATCH, PR 57208] Add ipa-cp created references to the symbol table

2013-06-26 Thread Martin Jambor
Hi,

On Tue, Jun 25, 2013 at 03:14:47PM +0200, Jan Hubicka wrote:
> > the patch reportedly fixes an issue when LTO building chromium.  It
> > adds references that are created by IPA-CP when propagating references
> > from aggregates (the scalar case is handled by the call graph
> > infrastructure).
> > 
> > Bootstrapped and tested on x86_64-linux.  OK for trunk?
> > 
> > Thanks,
> > 
> > Martin
> > 
> > 
> > 2013-06-24  Martin Jambor  
> > 
> > PR lto/57208
> > * ipa-cp.c (create_specialized_node): Add newly created references
> > to the symbol table.
> >

...
 
> >
> 
> There is identical code in cgraphclones.c doing the same for non-agg values.
> Can you commonize it to (perhaps ipa_maybe_record_reference that will take
> value as a parameter)?
> OK with that change.
> 

OK, so unless someone objects, I will commit the following tomorrow.
Tested and bootstrapped on x86_64-linux.

Thanks,

Martin


2013-06-26  Martin Jambor  

PR lto/57208
* ipa-ref.h (ipa_maybe_record_reference): Declare.
* ipa-ref.c (ipa_maybe_record_reference): New function.
* cgraphclones.c (cgraph_create_virtual_clone): Use it.
* ipa-cp.c (create_specialized_node): Record potential references from
aggvals.
* Makefile.in (ipa-ref.o): Add IPA_REF_H to dependencies.

Index: src/gcc/ipa-cp.c
===
--- src.orig/gcc/ipa-cp.c
+++ src/gcc/ipa-cp.c
@@ -2663,6 +2663,7 @@ create_specialized_node (struct cgraph_n
 {
   struct ipa_node_params *new_info, *info = IPA_NODE_REF (node);
   vec *replace_trees = NULL;
+  struct ipa_agg_replacement_value *av;
   struct cgraph_node *new_node;
   int i, count = ipa_get_param_count (info);
   bitmap args_to_skip;
@@ -2704,6 +2705,10 @@ create_specialized_node (struct cgraph_n
   new_node = cgraph_create_virtual_clone (node, callers, replace_trees,
  args_to_skip, "constprop");
   ipa_set_node_agg_value_chain (new_node, aggvals);
+  for (av = aggvals; av; av = av->next)
+ipa_maybe_record_reference ((symtab_node) new_node, av->value,
+   IPA_REF_ADDR, NULL);
+
   if (dump_file && (dump_flags & TDF_DETAILS))
 {
   fprintf (dump_file, " the new node is %s/%i.\n",
Index: src/gcc/Makefile.in
===
--- src.orig/gcc/Makefile.in
+++ src/gcc/Makefile.in
@@ -2933,7 +2933,8 @@ ipa-prop.o : ipa-prop.c $(CONFIG_H) $(SY
$(DATA_STREAMER_H) $(TREE_STREAMER_H) $(PARAMS_H)
 ipa-ref.o : ipa-ref.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
langhooks.h $(GGC_H) $(TARGET_H) $(CGRAPH_H)  $(TREE_H) $(TARGET_H) \
-   $(TREE_FLOW_H) $(TM_H) $(TREE_PASS_H) $(FLAGS_H) $(TREE_H) $(GGC_H) 
+   $(TREE_FLOW_H) $(TM_H) $(TREE_PASS_H) $(FLAGS_H) $(TREE_H) $(GGC_H) \
+   $(IPA_UTILS_H)
 ipa-cp.o : ipa-cp.c $(CONFIG_H) $(SYSTEM_H) coretypes.h  \
$(TREE_H) $(TARGET_H) $(GIMPLE_H) $(CGRAPH_H) $(IPA_PROP_H) $(TREE_FLOW_H) \
$(TREE_PASS_H) $(FLAGS_H) $(DIAGNOSTIC_H) \
Index: src/gcc/cgraphclones.c
===
--- src.orig/gcc/cgraphclones.c
+++ src/gcc/cgraphclones.c
@@ -341,27 +341,8 @@ cgraph_create_virtual_clone (struct cgra
   || in_lto_p)
 new_node->symbol.unique_name = true;
   FOR_EACH_VEC_SAFE_ELT (tree_map, i, map)
-{
-  tree var = map->new_tree;
-  symtab_node ref_node;
-
-  STRIP_NOPS (var);
-  if (TREE_CODE (var) != ADDR_EXPR)
-   continue;
-  var = get_base_var (var);
-  if (!var)
-   continue;
-  if (TREE_CODE (var) != FUNCTION_DECL
- && TREE_CODE (var) != VAR_DECL)
-   continue;
-
-  /* Record references of the future statement initializing the constant
-argument.  */
-  ref_node = symtab_get_node (var);
-  gcc_checking_assert (ref_node);
-  ipa_record_reference ((symtab_node)new_node, (symtab_node)ref_node,
-   IPA_REF_ADDR, NULL);
-}
+ipa_maybe_record_reference ((symtab_node) new_node, map->new_tree,
+   IPA_REF_ADDR, NULL);
   if (!args_to_skip)
 new_node->clone.combined_args_to_skip = 
old_node->clone.combined_args_to_skip;
   else if (old_node->clone.combined_args_to_skip)
Index: src/gcc/ipa-ref.c
===
--- src.orig/gcc/ipa-ref.c
+++ src/gcc/ipa-ref.c
@@ -25,6 +25,7 @@ along with GCC; see the file COPYING3.
 #include "ggc.h"
 #include "target.h"
 #include "cgraph.h"
+#include "ipa-utils.h"
 
 static const char *ipa_ref_use_name[] = {"read","write","addr","alias"};
 
@@ -67,6 +68,30 @@ ipa_record_reference (symtab_node referr
   return ref;
 }
 
+/* If VAL is a refeerence to a function or a variable, add a reference from
+   REFERRING_NODE to the corresponding symbol table node.  USE_TYPE specify
+   type of the use and STMT the statement (if it exists).  Return the new
+   reference or

Re: [PATCH][ARM][testsuite] Add 'dg-require-effective-target sync_*' to some atomic tests

2013-06-26 Thread Meador Inge
Ping.

On 06/12/2013 11:46 AM, Meador Inge wrote:
> Hi All,
> 
> This patch adds the needed 'dg-require-effective-target sync_*' lines to some
> of the atomic tests so that they will not be run if the appropriate atomic
> support is not available.
> 
> OK for trunk?
> 
> 2013-06-12  Meador Inge  
> 
>   * gcc.dg/atomic-flag.c: Add dg-require-effective-target sync_*.
>   * g++.dg/simulate-thread/atomics-2.C: Likewise.
>   * g++.dg/simulate-thread/atomics-1.C: Likewise.
> 


-- 
Meador Inge
CodeSourcery / Mentor Embedded


Re: [omp4/cilkplus] jumps in/out-of #pragma simd for

2013-06-26 Thread Aldy Hernandez

On 06/26/13 10:33, Jakub Jelinek wrote:

On Wed, Jun 26, 2013 at 09:44:03AM -0500, Aldy Hernandez wrote:

This is a followup for the C++ changes (your pt.c suggested changes, etc).

Only a few minor changes are needed, since c_finish_cilk_simd_loop()
is shared between C/C++ and it creates the appropriate CILK_SIMD
tree node.

Is this what you had in mind?


Yes.


Perfect.  I have pushed this to my aldyh/cilk-in-gomp branch.

This is pretty much all I have for the cilk patches sitting on top of 
your gomp4 branch.  Everything else should just depend on gomp-4_0-branch.


Thanks.



[PATCH] Fix vectorizable_store

2013-06-26 Thread Jakub Jelinek
Hi!

On the gomp4 branch I've noticed a miscompilation of the simd-3.C
testcase I'm adding there, but even say
int a[1024] __attribute__((aligned (32))) = { 1 };
int b[1024] __attribute__((aligned (32))) = { 1 };
unsigned short c[1024] __attribute__((aligned (32))) = { 1 };

__attribute__((noinline, noclone)) void
foo (int *p)
{
  int i;
  p = (int *) __builtin_assume_aligned (p, 32);
  for (i = 0; i < 512; i++)
{
  a[i] *= p[i];
  c[i]++;
}
}

int
main ()
{
  int i;
  for (i = 0; i < 512; i++)
{
  a[i] = i - 512;
  b[i] = (i - 51) % 39;
  c[i] = (unsigned short) i;
}
  foo (b);
  for (i = 0; i < 512; i++)
if (b[i] != (i - 51) % 39
|| a[i] != (i - 512) * b[i]
|| c[i] != (unsigned short) (i + 1))
  __builtin_abort ();
  return 0;
}
without -fopenmp, just -O3 -mavx.  The relevant change was just
that ptr_incr has been initialized to NULL in both vectorizable_store
and vectorizable_load, because vect_create_data_ref_ptr doesn't initialize
it if only_init is true.  Looking at it, we just trigger undefined behavior
and are just lucky that it works by accident on the trunk and branches.
The problem is that if ncopies > 1, vectorizable_store declares the variable
inside of the loop, for j == 0 it initializes it through
vect_create_data_ref_ptr, but then on the next iteration the variable is
uninitialized again (but just due to luck contains the value from the
previous iteration, but say if compiler unrolled the loop, it would already
misbehave) and then it is passed to bump_vector_ptr.  Fixed by moving the
var decl outside of the loop.  While not strictly necessary, I find it
cleaner to initialize it to NULL, though if you disagree with it, I can keep
that change local to gomp4 branch for now (i.e. remove " = NULL" from the
first hunk and the third hunk).

Ok for trunk/4.8?

2013-06-26  Jakub Jelinek  

* tree-vect-stmts.c (vectorizable_store): Move ptr_incr var
decl before the loop, initialize to NULL.
(vectorizable_load): Initialize ptr_incr to NULL.

--- gcc/tree-vect-stmts.c.jj2013-04-22 08:06:41.0 +0200
+++ gcc/tree-vect-stmts.c   2013-06-26 21:34:28.609654773 +0200
@@ -3796,6 +3796,7 @@ vectorizable_store (gimple stmt, gimple_
   enum vect_def_type dt;
   stmt_vec_info prev_stmt_info = NULL;
   tree dataref_ptr = NULL_TREE;
+  gimple ptr_incr = NULL;
   int nunits = TYPE_VECTOR_SUBPARTS (vectype);
   int ncopies;
   int j;
@@ -4041,7 +4042,6 @@ vectorizable_store (gimple stmt, gimple_
   for (j = 0; j < ncopies; j++)
 {
   gimple new_stmt;
-  gimple ptr_incr;
 
   if (j == 0)
{
@@ -4314,7 +4314,7 @@ vectorizable_load (gimple stmt, gimple_s
   tree dummy;
   enum dr_alignment_support alignment_support_scheme;
   tree dataref_ptr = NULL_TREE;
-  gimple ptr_incr;
+  gimple ptr_incr = NULL;
   int nunits = TYPE_VECTOR_SUBPARTS (vectype);
   int ncopies;
   int i, j, group_size, group_gap;


Jakub


Re: [PATCH] Cilk Plus Array Notation for C++

2013-06-26 Thread Jason Merrill

On 06/26/2013 01:31 PM, Iyer, Balaji V wrote:

Attached, please find a fixed patch and ChangeLog entries:


This patch seems to be missing some hunks that are described in the 
ChangeLog and were present in the previous patch, such as



* cp-array-notation.c (cp_length_mismatch_in_expr_p): Combined two
if statements into one and compared integers using tree_int_cst_equal.



Sorry about that, I accidentally missed this one. It is fixed now. I have also 
added the braced list capability into cp_array_notation.


Hmm, I seem to have been unclear.  I was expecting that the call to 
cp_parser_array_notation could come after the braced list case, so we 
don't need to duplicate the offsetof or braced list code inside 
cp_parser_array_notation.


And then if you'd like we could check for ':' before the ']' and give a 
helpful diagnostic.



+  /* If we hare here, then there are 2 possibilities:


"are"


+  if (processing_template_decl)
+array_ntn_expr = build_min_nt_loc (loc, ARRAY_NOTATION_REF, array,
+  start_index, length, stride, NULL_TREE);


If we know the type of the array, we should use it, rather than always 
leaving it null in a template.  That is, if !dependent_type_p (type), we 
should give the ARRAY_NOTATION_REF a real type.



+  if (TREE_CODE (array_type) == RECORD_TYPE
+ || TREE_CODE (array_type) == POINTER_TYPE)
 {
+ error_at (loc, "start-index and length fields necessary for "
+   "using array notation in pointers or records");


In a template, array_type might be NULL_TREE; this diagnostic should 
move into build_array_notation_ref.



+  array_type_domain = TYPE_DOMAIN (array_type);
+  if (!array_type_domain)
+   {
+ error_at (loc, "start-index and length fields necessary for "
+   "using array notation with array of unknown bound");
+ cp_parser_skip_to_end_of_statement (parser);
+ return error_mark_node;
+   }
+  start_index = TYPE_MINVAL (array_type_domain);
+  start_index = cp_fold_convert (ptrdiff_type_node, start_index);
+  length_index = size_binop
+   (PLUS_EXPR, TYPE_MAXVAL (array_type_domain), size_one_node);
+  length_index = cp_fold_convert (ptrdiff_type_node, length_index);
+  stride = build_int_cst (ptrdiff_type_node, 1);


As should all this code.  cp_parser_array_notation should only parse.


+  else
+   stride = build_one_cst (ptrdiff_type_node);


I would move this into build_array_notation_ref as well.

Jason



Re: [C++] Fix __builtin_shuffle

2013-06-26 Thread Jason Merrill

On 06/09/2013 07:09 AM, Marc Glisse wrote:

+  arg0 = build_non_dependent_expr (arg0);
+  arg1 = build_non_dependent_expr (arg1);
+  arg2 = build_non_dependent_expr (arg2);
+}
+  return c_build_vec_perm_expr (loc, arg0, arg1, arg2, complain & tf_error);


This is wrong; the places in the compiler that currently use 
build_non_dependent_expr only use the result temporarily for determining 
the type of the expression, but then use the original arguments for 
building the return value.


Jason



Re: [Patch, Fortran] Coarrays: Don't (free)/alloc LHS coarray components on assignment

2013-06-26 Thread Tobias Burnus

Tobias Burnus wrote:
With coarrays, allocation/deallocation of coarrays requires a 
synchronization with all other images. Thus, the standard restricts 
changing the allocation status to: ALLOCATE and DEALLOCATE statements 
plus end-of-scope deallocation.


In particular, with intrinsic assignment the allocation status does 
not change. Hence, there is no realloc on assignment. But also (this 
patch!) no deallocation/allocation of allocatable components during 
intrinsic assignment of derived types. [This implies that the LHS 
componet has to have the same allocation status, shape, 
type-parameters and actual type as the RHS.]


The patch additionally checks whether end-of-scope deallocation of 
coarrays properly calls the deregister function (it did/does).


Build and regtested on x86-64-gnu-linux.
OK for the trunk?


Update: I forgot to copy the back the address of the allocated CAF - 
which lead to an unwanted address sharing between the RHS and LHS.


Note: structure_alloc_comps also contains bits from 
http://gcc.gnu.org/ml/fortran/2013-06/msg00131.html


Build and regtested on x86-64-gnu-linux.
OK for the trunk?

Tobias
2013-06-26  Tobias Burnus  

	* trans-array.h (gfc_deallocate_alloc_comp_no_caf,
	gfc_reassign_alloc_comp_caf): New prototype.
	* trans-array.c (enum): Add DEALLOCATE_ALLOC_COMP_NO_CAF
	and COPY_ALLOC_COMP_CAF.
	(structure_alloc_comps): Handle it.
	(gfc_reassign_alloc_comp_caf,
	gfc_deallocate_alloc_comp_no_caf): New function.
	(gfc_alloc_allocatable_for_assignment): Call it.
	* trans-expr.c (gfc_trans_scalar_assign,
	gfc_trans_arrayfunc_assign, gfc_trans_assignment_1): Ditto.
	* parse.c (parse_derived): Correctly set coarray_comp.
	* resolve.c (resolve_symbol): Improve error wording.

2013-06-26  Tobias Burnus  

	* gfortran.dg/coarray_lib_realloc_1.f90: New.
	* gfortran.dg/coarray/lib_realloc_1.f90: New.
	* gfortran.dg/coarray_6.f90: Add dg-error.

diff --git a/gcc/fortran/parse.c b/gcc/fortran/parse.c
index f98a213..737f3d6 100644
--- a/gcc/fortran/parse.c
+++ b/gcc/fortran/parse.c
@@ -2228,11 +2228,11 @@ endType:
 	  sym->attr.coarray_comp = 1;
 	}
  
-  if (c->ts.type == BT_DERIVED && c->ts.u.derived->attr.coarray_comp)
+  if (c->ts.type == BT_DERIVED && c->ts.u.derived->attr.coarray_comp
+	  && !c->attr.pointer)
 	{
 	  coarray = true;
-	  if (!pointer && !allocatable)
-	sym->attr.coarray_comp = 1;
+	  sym->attr.coarray_comp = 1;
 	}
 
   /* Looking for lock_type components.  */
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index ce68401..0c0804b 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -13125,8 +13125,8 @@ resolve_symbol (gfc_symbol *sym)
   && (class_attr.codimension || class_attr.pointer || class_attr.dimension
 	  || class_attr.allocatable))
 {
-  gfc_error ("Variable '%s' at %L with coarray component "
-		 "shall be a nonpointer, nonallocatable scalar",
+  gfc_error ("Variable '%s' at %L with coarray component shall be a "
+		 "nonpointer, nonallocatable scalar, which is not a coarray",
 		 sym->name, &sym->declared_at);
   return;
 }
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 39bf0dd..452becf 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -7445,8 +7445,9 @@ gfc_copy_allocatable_data (tree dest, tree src, tree type, int rank)
deallocate, nullify or copy allocatable components.  This is the work horse
function for the functions named in this enum.  */
 
-enum {DEALLOCATE_ALLOC_COMP = 1, NULLIFY_ALLOC_COMP, COPY_ALLOC_COMP,
-  COPY_ONLY_ALLOC_COMP};
+enum {DEALLOCATE_ALLOC_COMP = 1, DEALLOCATE_ALLOC_COMP_NO_CAF,
+  NULLIFY_ALLOC_COMP, COPY_ALLOC_COMP, COPY_ONLY_ALLOC_COMP,
+  COPY_ALLOC_COMP_CAF};
 
 static tree
 structure_alloc_comps (gfc_symbol * der_type, tree decl,
@@ -7577,6 +7578,7 @@ structure_alloc_comps (gfc_symbol * der_type, tree decl,
   switch (purpose)
 	{
 	case DEALLOCATE_ALLOC_COMP:
+	case DEALLOCATE_ALLOC_COMP_NO_CAF:
 
 	  /* gfc_deallocate_scalar_with_status calls gfc_deallocate_alloc_comp
 	 (i.e. this function) so generate all the calls and suppress the
@@ -7584,19 +7586,37 @@ structure_alloc_comps (gfc_symbol * der_type, tree decl,
 	  called_dealloc_with_status = false;
 	  gfc_init_block (&tmpblock);
 
-	  if (c->attr.allocatable && (c->attr.dimension || c->attr.codimension)
-	  && !c->attr.proc_pointer)
+	  if ((c->ts.type == BT_DERIVED && !c->attr.pointer)
+	  || (c->ts.type == BT_CLASS && !CLASS_DATA (c)->attr.class_pointer))
 	{
 	  comp = fold_build3_loc (input_location, COMPONENT_REF, ctype,
   decl, cdecl, NULL_TREE);
+
+	  /* The finalizer frees allocatable components.  */
+	  called_dealloc_with_status
+		= gfc_add_comp_finalizer_call (&tmpblock, comp, c,
+	   purpose == DEALLOCATE_ALLOC_COMP);
+	}
+	  else
+	comp = NULL_TREE;
+
+	  if (c->attr.allocatable && !c->attr.proc_pointer
+	  && (c->attr.dimension
+		  || (c->attr.cod

Re: [C++] DR1473 - let literal operators be defined with empty user-defined string literal

2013-06-26 Thread Jason Merrill

On 06/26/2013 09:43 AM, Ed Smith-Rowland wrote:

+  if (bad_encoding_prefix)
+   error ("invalid encoding prefix in literal operator");
+  {
+   tree string_tree = USERDEF_LITERAL_VALUE (token->u.value);


No need to open a nested block for a declaration now that we're 
compiling as C++.


Otherwise, OK.

Jason



Re: GCC's -fsplit-stack disturbing Mach's vm_allocate

2013-06-26 Thread Thomas Schwinge
Hi!

On Sat, 22 Jun 2013 08:15:46 -0700, Ian Lance Taylor  wrote:
> Go can work without split stack.  In that case libgo will use much
> larger stacks for goroutines, to reduce the chance of running out of
> stack space (see StackMin in libgo/runtime/proc.c).  So the number of
> simultaneous goroutines that can be run will be limited.  This is
> usually OK on x86_64 but it does hamper Go programs running on 32-bit
> x86.

OK, but that's not the most pressing issue we're having right now.
Anyway, as it stands, the split-stack code doesn't work on Hurd, so I
disabled it in r200434 as follows:

gcc/
* config/i386/gnu.h [TARGET_LIBC_PROVIDES_SSP]
(TARGET_CAN_SPLIT_STACK, TARGET_THREAD_SPLIT_STACK_OFFSET):
Undefine.

diff --git gcc/config/i386/gnu.h gcc/config/i386/gnu.h
index 35063e6..4a91c84 100644
--- gcc/config/i386/gnu.h
+++ gcc/config/i386/gnu.h
@@ -36,6 +36,12 @@ along with GCC.  If not, see .
 #endif
 
 #ifdef TARGET_LIBC_PROVIDES_SSP
+
+/* Not supported yet.  */
+# undef TARGET_THREAD_SSP_OFFSET
+
 /* Not supported yet.  */
-#undef TARGET_THREAD_SSP_OFFSET
+# undef TARGET_CAN_SPLIT_STACK
+# undef TARGET_THREAD_SPLIT_STACK_OFFSET
+
 #endif


Grüße,
 Thomas


pgpNWArY8XEiV.pgp
Description: PGP signature


Re: Hurd port for GCC Go

2013-06-26 Thread Thomas Schwinge
Hi!

On Fri, 14 Jun 2013 16:42:06 +0200, I wrote:
> I have now pushed my working branch to tschwinge/t/hurd/go, and will
> update this from time to time, both for integrating further changes (my
> own as well as those that you send me), and merge in GCC trunk changes.
> On that branch, use something like »git diff :/refs/top-bases/baseline«
> to diff your working tree against the branch's base.  When reviewing the
> commit history on that branch, it may be helpful to exclude any bulk
> merges from trunk, so use something like »git log HEAD ^origin/trunk«.
> 
> Fotis and Svante, please base any futher work for the Hurd port for GCC
> Go on that branch.  Send patches by email, for now.
> 
> > I got as far as having GCC Go compiling with GCC trunk sources; more to
> > come later.

I have just updated tschwinge/t/hurd/go with some further patches, and we
now got a usable baseline, hooray:

$ grep -v ^PASS: < gcc/testsuite/go/go.sum 
Test Run By thomas on Wed Jun 26 15:40:55 2013
Native configuration is i686-unknown-gnu0.3

=== go tests ===

Schedule of variations:
unix

Running target unix
Running [...]/gcc/testsuite/go.dg/dg.exp ...
Running [...]/gcc/testsuite/go.go-torture/execute/execute.exp ...
Running [...]/gcc/testsuite/go.test/go-test.exp ...
FAIL: go.test/test/chan/doubleselect.go execution,  -O2 -g 
FAIL: go.test/test/chan/nonblock.go execution,  -O2 -g 
UNTESTED: go.test/test/chan/select2.go
FAIL: go.test/test/chan/select3.go execution,  -O2 -g 
FAIL: go.test/test/chan/select5.go execution
UNTESTED: go.test/test/closure.go
FAIL: go.test/test/fixedbugs/bug147.go execution,  -O2 -g 
FAIL: go.test/test/fixedbugs/bug347.go execution,  -O0 -g 
FAIL: go.test/test/fixedbugs/bug348.go execution,  -O0 -g 
XFAIL: bug429.go  -O2 -g  execution test
FAIL: go.test/test/goprint.go execution
UNTESTED: go.test/test/goprint.go compare
UNTESTED: go.test/test/init1.go
FAIL: go.test/test/mallocfin.go execution,  -O2 -g 
FAIL: go.test/test/nil.go execution,  -O2 -g 
FAIL: go.test/test/recover3.go execution,  -O2 -g 
UNTESTED: go.test/test/rotate.go
UNTESTED: go.test/test/stack.go

=== go Summary ===

# of expected passes5069
# of unexpected failures11
# of expected failures  1
# of untested testcases 6
[...]/gcc/testsuite/go/../../gccgo  version 4.9.0 20130606 (experimental) 
(GCC) 

The patches are:

  * Disable -fsplit-stack (as just pushed to GCC trunk, too).

  * Hack in support in libgo for requesting heap memory with alignment
requirements.  Any stack used on Hurd must currently have a 2 MiB
size, and also be aligned accordingly.  This patch is probably not
suitable/wanted for upstream.

  * Use the patch before to use accordingly-sized stacks on Hurd.  This
patch is probably not suitable/wanted for upstream.  The Hurd
eventually will support arbitrarily-sized and aligned stacks.

  * Revert a hack by Svante, which is now no longer needed, as the
autodetection now works fine.

  * Disable the sigchld.go test, which busy-loops on GNU/Hurd, causing
the test harness to hang.

  * Disable in libgo on Hurd the setup of an alternate signal stack.
This patch is probably not suitable/wanted for upstream.  The Hurd
eventually will support sigaltstack.

  * Disable in libgo on Hurd the use of SA_ONSTACK.  This looks like a
bug in Hurd's glibc: signal handling breaks down (SIGILL) if no
alternate signal stack has been set and SA_ONSTACK is used.  The
standard says about SA_ONSTACK: »If set *and an alternate signal
stack has been declared with sigaltstack()*, the signal shall be
delivered to the calling process on that stack.  Otherwise, the
signal shall be delivered on the current stack.«

  * Re-enable the sigchld.go test, which now passes.

commit 397bf49a65468084df39b3208971e53e0b166c65
Author: Thomas Schwinge 
AuthorDate: Tue Jun 25 16:32:02 2013 +0200
Commit: Thomas Schwinge 
CommitDate: Tue Jun 25 18:13:47 2013 +0200

gcc/
* config/i386/gnu.h [TARGET_LIBC_PROVIDES_SSP]
(TARGET_CAN_SPLIT_STACK, TARGET_THREAD_SPLIT_STACK_OFFSET):
Undefine.
---
 gcc/config/i386/gnu.h |6 ++
 1 file changed, 6 insertions(+)

diff --git gcc/config/i386/gnu.h gcc/config/i386/gnu.h
index 35063e6..4a91c84 100644
--- gcc/config/i386/gnu.h
+++ gcc/config/i386/gnu.h
@@ -36,6 +36,12 @@ along with GCC.  If not, see .
 #endif
 
 #ifdef TARGET_LIBC_PROVIDES_SSP
+
 /* Not supported yet.  */
 # undef TARGET_THREAD_SSP_OFFSET
+
+/* Not supported yet.  */
+# undef TARGET_CAN_SPLIT_STACK
+# undef TARGET_THREAD_SPLIT_STACK_OFFSET
+
 #endif

commit 540a787bfe48ad434c1e44d425e287b7ac91af2f
Author: Thomas Schwinge 
AuthorDate: Tue Jun 25 17:59:28 2013 +0200
Commit: Thomas Schwinge 
CommitDate: Wed J

[C++] Implement DR1164

2013-06-26 Thread Marc Glisse

Hello,

this patch tries to implement DR1164. It passes bootstrap+testsuite on 
x86_64-unknown-linux-gnu.


2013-06-27  Marc Glisse  

PR c++/57172
gcc/cp/
* pt.c (more_specialized_fn): If both arguments are references,
give priority to an lvalue.

gcc/testsuite/
* g++.dg/cpp0x/pr57172.C: New testcase.


--
Marc GlisseIndex: gcc/testsuite/g++.dg/cpp0x/pr57172.C
===
--- gcc/testsuite/g++.dg/cpp0x/pr57172.C(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/pr57172.C(revision 0)
@@ -0,0 +1,7 @@
+// PR c++/57172
+// { dg-do compile { target c++11 } }
+
+template  int f (T&) { }
+template  int f (T&&) = delete;
+int i;
+int j = f (i);

Property changes on: gcc/testsuite/g++.dg/cpp0x/pr57172.C
___
Added: svn:keywords
   + Author Date Id Revision URL
Added: svn:eol-style
   + native

Index: gcc/cp/pt.c
===
--- gcc/cp/pt.c (revision 200430)
+++ gcc/cp/pt.c (working copy)
@@ -17503,21 +17503,22 @@ check_undeduced_parms (tree targs, tree
 
The 1998 std underspecified function template partial ordering, and
DR214 addresses the issue.  We take pairs of arguments, one from
each of the templates, and deduce them against each other.  One of
the templates will be more specialized if all the *other*
template's arguments deduce against its arguments and at least one
of its arguments *does* *not* deduce against the other template's
corresponding argument.  Deduction is done as for class templates.
The arguments used in deduction have reference and top level cv
qualifiers removed.  Iff both arguments were originally reference
-   types *and* deduction succeeds in both directions, the template
+   types *and* deduction succeeds in both directions, an lvalue reference
+   wins against an rvalue reference and otherwise the template
with the more cv-qualified argument wins for that pairing (if
neither is more cv-qualified, they both are equal).  Unlike regular
deduction, after all the arguments have been deduced in this way,
we do *not* verify the deduced template argument values can be
substituted into non-deduced contexts.
 
The logic can be a bit confusing here, because we look at deduce1 and
targs1 to see if pat2 is at least as specialized, and vice versa; if we
can find template arguments for pat1 to make arg1 look like arg2, that
means that arg2 is at least as specialized as arg1.  */
@@ -17579,41 +17580,45 @@ more_specialized_fn (tree pat1, tree pat
 
   while (len--
 /* Stop when an ellipsis is seen.  */
 && args1 != NULL_TREE && args2 != NULL_TREE)
 {
   tree arg1 = TREE_VALUE (args1);
   tree arg2 = TREE_VALUE (args2);
   int deduce1, deduce2;
   int quals1 = -1;
   int quals2 = -1;
+  int ref1 = 0;
+  int ref2 = 0;
 
   if (TREE_CODE (arg1) == TYPE_PACK_EXPANSION
   && TREE_CODE (arg2) == TYPE_PACK_EXPANSION)
 {
   /* When both arguments are pack expansions, we need only
  unify the patterns themselves.  */
   arg1 = PACK_EXPANSION_PATTERN (arg1);
   arg2 = PACK_EXPANSION_PATTERN (arg2);
 
   /* This is the last comparison we need to do.  */
   len = 0;
 }
 
   if (TREE_CODE (arg1) == REFERENCE_TYPE)
{
+ ref1 = TYPE_REF_IS_RVALUE (arg1) + 1;
  arg1 = TREE_TYPE (arg1);
  quals1 = cp_type_quals (arg1);
}
 
   if (TREE_CODE (arg2) == REFERENCE_TYPE)
{
+ ref2 = TYPE_REF_IS_RVALUE (arg2) + 1;
  arg2 = TREE_TYPE (arg2);
  quals2 = cp_type_quals (arg2);
}
 
   arg1 = TYPE_MAIN_VARIANT (arg1);
   arg2 = TYPE_MAIN_VARIANT (arg2);
 
   if (TREE_CODE (arg1) == TYPE_PACK_EXPANSION)
 {
   int i, len2 = list_length (args2);
@@ -17677,33 +17682,47 @@ more_specialized_fn (tree pat1, tree pat
 
   /* If we couldn't deduce arguments for tparms1 to make arg1 match
 arg2, then arg2 is not as specialized as arg1.  */
   if (!deduce1)
lose2 = true;
   if (!deduce2)
lose1 = true;
 
   /* "If, for a given type, deduction succeeds in both directions
 (i.e., the types are identical after the transformations above)
-and if the type from the argument template is more cv-qualified
-than the type from the parameter template (as described above)
-that type is considered to be more specialized than the other. If
-neither type is more cv-qualified than the other then neither type
-is more specialized than the other."  */
+and both P and A were reference types (before being replaced with
+the type referred to above):
+- if the type from the argument template was an lvalue reference and
+the type

[Patch, AArch64, ILP32] 0/5 Add support for ILP32

2013-06-26 Thread Yufeng Zhang

Hi,

A set of five patches will be sent shortly as the gcc part of changes 
that add support for ILP32 in the AArch64 baremetal toolchain.


The five patches will be organized as the following:

1. Configury changes;

2. AArch64 backend changes that add necessary instruction patterns and 
update the backend macros and hooks to support ILP32;


3. Minor change to the generic part of the compiler to enable correct 
pass-by-reference parameter passing;


4. Changes to a number of tests for them to be ILP32-friendly;

5. Define _ILP32 and __ILP32__.

The patch set will enable the basic ILP32 support in the baremetal 
environment, with small absolute and small PIC as the supported 
addressing models.


Patches for binutils changes have been committed to the binutils trunk; 
they were previously posted here: 
http://sourceware.org/ml/binutils/2013-06/msg00176.html



Thanks,
Yufeng




[Patch, AArch64, ILP32] 1/5 Initial support - configury changes

2013-06-26 Thread Yufeng Zhang

This patch adds the configuration changes to the AArch64 GCC to support:

* -milp32 and -mlp64 options in the compiler and the driver
* multilib of ilp32 and/or lp64 libraries
* differentiation of basic types in the compiler backend

The patch enables --with-multilib-list configuration option for 
specifying the list of library flavors to enable; the default value is 
"mlp64" and can be overridden by --with-abi to "milp32".


It also enables --with-abi for setting the default model in the 
compiler.  Its default value is "mlp64" unless --with-multilib-list is 
explicitly specified with "milp32", in which case it defaults to "milp32".


In the backend, two target flags are introduced: TARGET_ILP32 and 
TARGET_LP64.  They are set by -milp32 and -mlp64 respectively, exclusive 
to each other.  The default setting is via the option variable 
aarch64_pmodel_flags, which defaults to TARGET_DEFAULT_PMODEL, which is 
further defined in biarchlp64.h or biarchilp32.h depending which header 
file is included.


  biarchlp64.h biarchilp32.h
TARGET_DEFAULT_PMODEL OPTION_MASK_LP64 OPTION_MASK_ILP32
TARGET_PMODEL 12

TARGET_ILP32 and TARGET_LP64 are implicitly defined as:

#define TARGET_ILP32 ((aarch64_pmodel_flags & OPTION_MASK_ILP32) != 0)
#define TARGET_LP64 ((aarch64_pmodel_flags & OPTION_MASK_LP64) != 0)

Note that the multilib support in the Linux toolchain is suppressed 
deliberately.


OK for the trunk?

Thanks,
Yufeng


gcc/
* config.gcc (aarch64*-*-*): Support --with-abi.
(aarch64*-*-elf): Support --with-multilib-list.
(aarch64*-*-linux*): Likewise.
(supported_defaults): Add abi to aarch64*-*-*.
* configure.ac: Mention AArch64 for --with-multilib-list.
* configure: Re-generated.
* config/aarch64/biarchilp32.h: New file.
* config/aarch64/biarchlp64.h: New file.
* config/aarch64/aarch64-elf.h (SPEC_LP64): New define.
(SPEC_ILP32): Ditto.
(ASM_SPEC): Update to SPEC_LP64 and SPEC_ILP32.
(MULTILIB_DEFAULTS): New define.
* config/aarch64/aarch64-elf-raw.h (EMUL_SUFFIX): New define.
(LINK_SPEC): Change to depend on SPEC_LP64 and SPEC_ILP32 and also
to use EMUL_SUFFIX.
* config/aarch64/aarch64.h (LONG_TYPE_SIZE): Change to depend on
TARGET_ILP32.
(POINTER_SIZE): New define.
(POINTERS_EXTEND_UNSIGNED): Ditto.
* config/aarch64/aarch64.c (initialize_aarch64_programming_model):
New declaration and definition.
(aarch64_override_options): Call the new function.
* config/aarch64/aarch64.opt (aarch64_pmodel_flags): New.
(milp32, mlp64): New.
* config/aarch64/t-aarch64 (comma): New define.
(MULTILIB_OPTIONS): Ditto.
(MULTILIB_DIRNAMES): Ditto.
* config/aarch64/t-aarch64-linux (MULTIARCH_DIRNAME): New define.

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 0ad7217..c8af44e 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -497,6 +497,26 @@ then
 fi
 
 case ${target} in
+aarch64*-*-*)
+	case ${with_abi} in
+	"")
+		if test "x$with_multilib_list" = xmilp32; then
+			tm_file="aarch64/biarchilp32.h ${tm_file}"
+		else
+			tm_file="aarch64/biarchlp64.h ${tm_file}"
+		fi
+		;;
+	lp64 | mlp64)
+		tm_file="aarch64/biarchlp64.h ${tm_file}"
+		;;
+	ilp32 | milp32)
+		tm_file="aarch64/biarchilp32.h ${tm_file}"
+		;;
+	*)
+		echo "Unknown ABI used in --with-abi=$with_abi"
+		exit 1
+	esac
+	;;
 i[34567]86-*-*)
 	if test "x$with_abi" != x; then
 		echo "This target does not support --with-abi."
@@ -827,6 +847,32 @@ aarch64*-*-elf)
 		tm_defines="${tm_defines} TARGET_BIG_ENDIAN_DEFAULT=1"
 		;;
 	esac
+	aarch64_multilibs="${with_multilib_list}"
+	if test "$aarch64_multilibs" = "default"; then
+		case ${with_abi} in
+		ilp32 | milp32)
+			aarch64_multilibs="milp32"
+			;;
+		*)
+			# TODO: Change to build both flavours by default when
+			# the ILP32 support is mature enough.
+			# aarch64_multilibs="mlp64,milp32"
+			aarch64_multilibs="mlp64"
+			;;
+		esac
+	fi
+	aarch64_multilibs=`echo $aarch64_multilibs | sed -e 's/,/ /g'`
+	for aarch64_multilib in ${aarch64_multilibs}; do
+		case ${aarch64_multilib} in
+		milp32 | mlp64 )
+			TM_MULTILIB_CONFIG="${TM_MULTILIB_CONFIG},${aarch64_multilib}"
+			;;
+		*)
+			echo "--with-multilib-list=${aarch64_multilib} not supported."
+			exit 1
+		esac
+	done
+	TM_MULTILIB_CONFIG=`echo $TM_MULTILIB_CONFIG | sed 's/^,//'`
 	;;
 aarch64*-*-linux*)
 	tm_file="${tm_file} dbxelf.h elfos.h gnu-user.h linux.h glibc-stdint.h"
@@ -837,6 +883,32 @@ aarch64*-*-linux*)
 		tm_defines="${tm_defines} TARGET_BIG_ENDIAN_DEFAULT=1"
 		;;
 	esac
+	aarch64_multilibs="${with_multilib_list}"
+	if test "$aarch64_multilibs" = "default"; then
+		case ${with_abi} in
+		ilp32 | milp32)
+			aarch64_multilibs="milp32"
+			;;
+		*)
+			# TODO: Change to build both flavours by default when
+			# the ILP32 support is mature enough.
+			# aa

[Patch, AArch64, ILP32] 2/5 More backend changes and support for small absolute and small PIC addressing models

2013-06-26 Thread Yufeng Zhang
This patch updates the AArch64 backend to support the small absolute and 
small PIC addressing models for ILP32; it also updates a number of other 
backend macros and hooks in order to support ILP32.


OK for the trunk?

Thanks,
Yufeng


gcc/

* config/aarch64/aarch64.c (POINTER_BYTES): New define.
(aarch64_load_symref_appropriately): In the case of
SYMBOL_SMALL_ABSOLUTE, use the mode of 'dest' instead of Pmode
to generate new rtx; likewise to the case of SYMBOL_SMALL_GOT.
(aarch64_expand_mov_immediate): In the case of SYMBOL_FORCE_TO_MEM,
change to pass 'ptr_mode' to force_const_mem and zero-extend 'mem'
if 'mode' doesn't equal to 'ptr_mode'.
(aarch64_output_mi_thunk): Add an assertion on the alignment of
'vcall_offset'; change to call aarch64_emit_move differently 
depending

on whether 'Pmode' equals to 'ptr_mode' or not; use 'POINTER_BYTES'
to calculate the upper bound of 'vcall_offset'.
(aarch64_cannot_force_const_mem): Change to also return true if
mode != ptr_mode.
(aarch64_legitimize_reload_address): In the case of large
displacements, add new local variable 'xmode' and an assertion
based on it; change to use 'xmode' to generate the new rtx and
reload.
(aarch64_asm_trampoline_template): Change to generate the template
differently depending on TARGET_ILP32 or not; change to use
'POINTER_BYTES' in the argument passed to assemble_aligned_integer.
(aarch64_trampoline_size): Removed.
(aarch64_trampoline_init): Add new local constant 'tramp_code_sz'
and replace immediate literals with it.  Change to use 'ptr_mode'
instead of 'DImode' and call convert_memory_address if the mode
of 'fnaddr' doesn't equal to 'ptr_mode'.
(aarch64_elf_asm_constructor): Change to use 
assemble_aligned_integer

to output symbol.
(aarch64_elf_asm_destructor): Likewise.
* config/aarch64/aarch64.h (TRAMPOLINE_SIZE): Change to be 
dependent

on TARGET_ILP32 instead of aarch64_trampoline_size.
* config/aarch64/aarch64.md (movsi_aarch64): Add new alternatives
of 'mov' between WSP and W registers as well as 'adr' and 'adrp'.
(loadwb_pair_): Rename to ...
(loadwb_pair_): ... this.  Replace PTR with P.
(storewb_pair_): Likewise; rename to ...
(storewb_pair_): ... this.
(add_losym): Change to 'define_expand' and call 
gen_add_losym_

depending on the value of 'mode'.
(add_losym_): New.
(ldr_got_small_): New, based on ldr_got_small.
(ldr_got_small): Remove.
(ldr_got_small_sidi): New.
* config/aarch64/iterators.md (P): New.
(PTR): Change to 'ptr_mode' in the condition.

diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index c16d55f..1117515 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -46,6 +46,9 @@
 #include "optabs.h"
 #include "dwarf2.h"
 
+/* Defined for convenience.  */
+#define POINTER_BYTES (POINTER_SIZE / BITS_PER_UNIT)
+
 /* Classifies an address.
 
ADDRESS_REG_IMM
@@ -519,13 +522,16 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm,
 {
 case SYMBOL_SMALL_ABSOLUTE:
   {
+	/* In ILP32, the mode of dest can be either SImode or DImode.  */
 	rtx tmp_reg = dest;
+	enum machine_mode mode = GET_MODE (dest);
+
+	gcc_assert (mode == Pmode || mode == ptr_mode);
+
 	if (can_create_pseudo_p ())
-	  {
-	tmp_reg =  gen_reg_rtx (Pmode);
-	  }
+	  tmp_reg = gen_reg_rtx (mode);
 
-	emit_move_insn (tmp_reg, gen_rtx_HIGH (Pmode, imm));
+	emit_move_insn (tmp_reg, gen_rtx_HIGH (mode, imm));
 	emit_insn (gen_add_losym (dest, tmp_reg, imm));
 	return;
   }
@@ -536,11 +542,33 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm,
 
 case SYMBOL_SMALL_GOT:
   {
+	/* In ILP32, the mode of dest can be either SImode or DImode,
+	   while the got entry is always of SImode size.  The mode of
+	   dest depends on how dest is used: if dest is assigned to a
+	   pointer (e.g. in the memory), it has SImode; it may have
+	   DImode if dest is dereferenced to access the memeory.
+	   This is why we have to handle three different ldr_got_small
+	   patterns here (two patterns for ILP32).  */
 	rtx tmp_reg = dest;
+	enum machine_mode mode = GET_MODE (dest);
+
 	if (can_create_pseudo_p ())
-	  tmp_reg =  gen_reg_rtx (Pmode);
-	emit_move_insn (tmp_reg, gen_rtx_HIGH (Pmode, imm));
-	emit_insn (gen_ldr_got_small (dest, tmp_reg, imm));
+	  tmp_reg = gen_reg_rtx (mode);
+
+	emit_move_insn (tmp_reg, gen_rtx_HIGH (mode, imm));
+	if (mode == ptr_mode)
+	  {
+	if (mode == DImode)
+	  emit_insn (gen_ldr_got_small_di (dest, tmp_reg, imm));
+	else
+	  emit_insn (gen_ldr_got_small_si (dest, tmp_reg, imm));
+	  }
+	else
+	  {
+	gcc_assert (mode == Pmode);
+	emit_insn (gen_ldr_got_small_sidi (dest, tmp_reg, imm));
+	

[Patch, AArch64, ILP32] 3/5 Minor change in function.c:assign_parm_find_data_types()

2013-06-26 Thread Yufeng Zhang
This patch updates assign_parm_find_data_types to assign passed_mode and 
nominal_mode with the mode of the built pointer type instead of the 
hard-coded Pmode in the case of pass-by-reference.  This is in line with 
the assignment to passed_mode and nominal_mode in other cases inside the 
function.


assign_parm_find_data_types generally uses TYPE_MODE to calculate 
passed_mode and nominal_mode:


  /* Find mode of arg as it is passed, and mode of arg as it should be
 during execution of this function.  */
  passed_mode = TYPE_MODE (passed_type);
  nominal_mode = TYPE_MODE (nominal_type);

this includes the case when the passed argument is a pointer by itself.

However there is a discrepancy when it deals with argument passed by 
invisible reference; it builds the argument's corresponding pointer 
type, but sets passed_mode and nominal_mode with Pmode directly.


This is OK for targets where Pmode == ptr_mode, but on AArch64 with 
ILP32 they are different with Pmode as DImode and ptr_mode as SImode. 
When such a reference is passed on stack, the reference is prepared by 
the caller in the lower 4 bytes of an 8-byte slot but is fetched by the 
callee as an 8-byte datum, of which the higher 4 bytes may contain junk. 
 It is probably the combination of Pmode != ptr_mode and the particular 
ABI specification that make the AArch64 ILP32 the first target on which 
the issue manifests itself.


Bootstrapped on x86_64-none-linux-gnu.

OK for the trunk?

Thanks,
Yufeng


gcc/
* function.c (assign_parm_find_data_types): Set passed_mode and
nominal_mode to the TYPE_MODE of nominal_type for the built
pointer type in case of the struct-pass-by-reference.diff --git a/gcc/function.c b/gcc/function.c
index 3e33fc7..6a0aaaf 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -2369,7 +2369,7 @@ assign_parm_find_data_types (struct assign_parm_data_all *all, tree parm,
 {
   passed_type = nominal_type = build_pointer_type (passed_type);
   data->passed_pointer = true;
-  passed_mode = nominal_mode = Pmode;
+  passed_mode = nominal_mode = TYPE_MODE (nominal_type);
 }
 
   /* Find mode as it is passed by the ABI.  */

[Patch, AArch64, ILP32] 4/5 Change tests to be ILP32-friendly

2013-06-26 Thread Yufeng Zhang

The attached patch fixes a few gcc test cases.


Thanks,
Yufeng


gcc/testsuite/

* gcc.dg/20020219-1.c: Skip the test on aarch64*-*-* in ilp32.
* gcc.target/aarch64/aapcs64/test_18.c (struct y): Change the field
type from long to long long.
* gcc.target/aarch64/atomic-op-long.c: Update dg-final directives
to have effective-target keywords of lp64 and ilp32.
* gcc.target/aarch64/fcvt_double_int.c: Likewise.
* gcc.target/aarch64/fcvt_double_long.c: Likewise.
* gcc.target/aarch64/fcvt_double_uint.c: Likewise.
* gcc.target/aarch64/fcvt_double_ulong.c: Likewise.
* gcc.target/aarch64/fcvt_float_int.c: Likewise.
* gcc.target/aarch64/fcvt_float_long.c: Likewise.
* gcc.target/aarch64/fcvt_float_uint.c: Likewise.
* gcc.target/aarch64/fcvt_float_ulong.c: Likewise.
* gcc.target/aarch64/vect_smlal_1.c: Replace 'long' with 'long long'.

diff --git a/gcc/testsuite/gcc.dg/20020219-1.c b/gcc/testsuite/gcc.dg/20020219-1.c
index ffdf19a..d2ba755 100644
--- a/gcc/testsuite/gcc.dg/20020219-1.c
+++ b/gcc/testsuite/gcc.dg/20020219-1.c
@@ -13,6 +13,7 @@
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 /* { dg-options "-O2 -mdisable-indexing" { target hppa*-*-hpux* } } */
+/* { dg-skip-if "" { aarch64*-*-* && ilp32 } { "*" } { "" } } */
 /* { dg-skip-if "" { "ia64-*-hpux*" } "*" "-mlp64" } */
 /* { dg-skip-if "" { { i?86-*-* x86_64-*-* } && x32 } { "*" } { "" } } */
 
diff --git a/gcc/testsuite/gcc.target/aarch64/aapcs64/test_18.c b/gcc/testsuite/gcc.target/aarch64/aapcs64/test_18.c
index b611e9b..2ebecee 100644
--- a/gcc/testsuite/gcc.target/aarch64/aapcs64/test_18.c
+++ b/gcc/testsuite/gcc.target/aarch64/aapcs64/test_18.c
@@ -9,10 +9,10 @@
 
 struct y
 {
-  long p;
-  long q;
-  long r;
-  long s;
+  long long p;
+  long long q;
+  long long r;
+  long long s;
 } v = { 1, 2, 3, 4 };
 
 struct z
diff --git a/gcc/testsuite/gcc.target/aarch64/atomic-op-long.c b/gcc/testsuite/gcc.target/aarch64/atomic-op-long.c
index 9468ef4..0672d48 100644
--- a/gcc/testsuite/gcc.target/aarch64/atomic-op-long.c
+++ b/gcc/testsuite/gcc.target/aarch64/atomic-op-long.c
@@ -39,5 +39,7 @@ atomic_fetch_or_RELAXED (long a)
   return __atomic_fetch_or (&v, a, __ATOMIC_RELAXED);
 }
 
-/* { dg-final { scan-assembler-times "ldxr\tx\[0-9\]+, \\\[x\[0-9\]+\\\]" 6 } } */
-/* { dg-final { scan-assembler-times "stxr\tw\[0-9\]+, x\[0-9\]+, \\\[x\[0-9\]+\\\]" 6 } } */
+/* { dg-final { scan-assembler-times "ldxr\tx\[0-9\]+, \\\[x\[0-9\]+\\\]" 6 {target lp64} } } */
+/* { dg-final { scan-assembler-times "ldxr\tw\[0-9\]+, \\\[x\[0-9\]+\\\]" 6 {target ilp32} } } */
+/* { dg-final { scan-assembler-times "stxr\tw\[0-9\]+, x\[0-9\]+, \\\[x\[0-9\]+\\\]" 6 {target lp64} } } */
+/* { dg-final { scan-assembler-times "stxr\tw\[0-9\]+, w\[0-9\]+, \\\[x\[0-9\]+\\\]" 6 {target ilp32} } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/fcvt_double_int.c b/gcc/testsuite/gcc.target/aarch64/fcvt_double_int.c
index 697aab1..e539909 100644
--- a/gcc/testsuite/gcc.target/aarch64/fcvt_double_int.c
+++ b/gcc/testsuite/gcc.target/aarch64/fcvt_double_int.c
@@ -8,8 +8,10 @@
 #include "fcvt.x"
 
 /* { dg-final { scan-assembler-times "fcvtzs\tw\[0-9\]+, *d\[0-9\]" 2 } } */
-/* { dg-final { scan-assembler-times "fcvtps\tx\[0-9\]+, *d\[0-9\]" 1 } } */
-/* { dg-final { scan-assembler-times "fcvtps\tw\[0-9\]+, *d\[0-9\]" 2 } } */
-/* { dg-final { scan-assembler-times "fcvtms\tx\[0-9\]+, *d\[0-9\]" 1 } } */
-/* { dg-final { scan-assembler-times "fcvtms\tw\[0-9\]+, *d\[0-9\]" 2 } } */
+/* { dg-final { scan-assembler-times "fcvtps\tx\[0-9\]+, *d\[0-9\]" 1 {target lp64} } } */
+/* { dg-final { scan-assembler-times "fcvtps\tw\[0-9\]+, *d\[0-9\]" 2 {target lp64} } } */
+/* { dg-final { scan-assembler-times "fcvtps\tw\[0-9\]+, *d\[0-9\]" 3 {target ilp32} } } */
+/* { dg-final { scan-assembler-times "fcvtms\tx\[0-9\]+, *d\[0-9\]" 1 {target lp64} } } */
+/* { dg-final { scan-assembler-times "fcvtms\tw\[0-9\]+, *d\[0-9\]" 2 {target lp64} } } */
+/* { dg-final { scan-assembler-times "fcvtms\tw\[0-9\]+, *d\[0-9\]" 3 {target ilp32} } } */
 /* { dg-final { scan-assembler-times "fcvtas\tw\[0-9\]+, *d\[0-9\]" 2 } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/fcvt_double_long.c b/gcc/testsuite/gcc.target/aarch64/fcvt_double_long.c
index edf640b..5eb36ff 100644
--- a/gcc/testsuite/gcc.target/aarch64/fcvt_double_long.c
+++ b/gcc/testsuite/gcc.target/aarch64/fcvt_double_long.c
@@ -7,7 +7,11 @@
 
 #include "fcvt.x"
 
-/* { dg-final { scan-assembler-times "fcvtzs\tx\[0-9\]+, *d\[0-9\]" 2 } } */
-/* { dg-final { scan-assembler-times "fcvtps\tx\[0-9\]+, *d\[0-9\]" 3 } } */
-/* { dg-final { scan-assembler-times "fcvtms\tx\[0-9\]+, *d\[0-9\]" 3 } } */
-/* { dg-final { scan-assembler-times "fcvtas\tx\[0-9\]+, *d\[0-9\]" 2 } } */
+/* { dg-final { scan-assembler-times "fcvtzs\tx\[0-9\]+, *d\[0-9\]" 2 {target lp64} } } */
+/* { dg-final { scan-assembler-times "fcvtzs\tw\[0-9\]+, *d\[0-9\]" 2 {target ilp32} } 

Go patch committed: Division by constant integer 0 is a compile error

2013-06-26 Thread Ian Lance Taylor
In Go 1 division by an integer constant 0 was changed from a runtime
error to a compile time error.  This patch from Rémy Oudompheng
implements that in gccgo.  This required updating a couple of tests to
new copies from the master sources.  Bootstrapped and ran Go testsuite
on x86_64-unknown-linux-gnu.  Committed to mainline and 4.8 branch.

Ian

Index: gcc/go/gofrontend/expressions.cc
===
--- gcc/go/gofrontend/expressions.cc	(revision 200398)
+++ gcc/go/gofrontend/expressions.cc	(working copy)
@@ -5848,6 +5848,20 @@ Binary_expression::do_check_types(Gogo*)
 	  this->set_is_error();
 	  return;
 	}
+  if (this->op_ == OPERATOR_DIV || this->op_ == OPERATOR_MOD)
+	{
+	  // Division by a zero integer constant is an error.
+	  Numeric_constant rconst;
+	  unsigned long rval;
+	  if (left_type->integer_type() != NULL
+	  && this->right_->numeric_constant_value(&rconst)
+	  && rconst.to_unsigned_long(&rval) == Numeric_constant::NC_UL_VALID
+	  && rval == 0)
+	{
+	  this->report_error(_("integer division by zero"));
+	  return;
+	}
+	}
 }
   else
 {
Index: gcc/testsuite/go.test/test/fixedbugs/bug410.go
===
--- gcc/testsuite/go.test/test/fixedbugs/bug410.go	(revision 200210)
+++ gcc/testsuite/go.test/test/fixedbugs/bug410.go	(working copy)
@@ -18,7 +18,7 @@ func zzz () {
 for s := range arr {
 x := make([]byte, 10)
 for i := 0; i < 100 ; i++ {
-x[i] ^= k[i-arr[s].num%0]
+x[i] ^= k[i-arr[s].num%3]
 }
 }
 }
Index: gcc/testsuite/go.test/test/64bit.go
===
--- gcc/testsuite/go.test/test/64bit.go	(revision 200210)
+++ gcc/testsuite/go.test/test/64bit.go	(working copy)
@@ -594,6 +594,19 @@ const binaryConstR = "func test%vBinaryR
 	"}\n" +
 	"\n"
 
+const binaryConstR0 = "func test%vBinaryR%v(a, add, sub, mul, div, mod, and, or, xor, andnot %v, dodiv bool) {\n" +
+	"	const b %v = %v;\n" +
+	"	const typ = `%s`;\n" +
+	"	if n, op, want := a + b, `+`, add; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" +
+	"	if n, op, want := a - b, `-`, sub; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" +
+	"	if n, op, want := a * b, `*`, mul; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" +
+	"	if n, op, want := a & b, `&`, and; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" +
+	"	if n, op, want := a | b, `|`, or; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" +
+	"	if n, op, want := a ^ b, `^`, xor; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" +
+	"	if n, op, want := a &^ b, `&^`, andnot; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" +
+	"}\n" +
+	"\n"
+
 const shiftConstL = "func test%vShiftL%v(b uint64, left, right %v) {\n" +
 	"	const a %v = %v;\n" +
 	"	const typ = `%s`;\n" +
@@ -621,12 +634,20 @@ const shiftConstR = "func test%vShiftR%v
 func constTests() {
 	for i, a := range int64Values {
 		fmt.Fprintf(bout, binaryConstL, "Int64", i, "int64", "int64", a, "int64")
-		fmt.Fprintf(bout, binaryConstR, "Int64", i, "int64", "int64", a, "int64")
+		if a.hi == 0 && a.lo == 0 {
+			fmt.Fprintf(bout, binaryConstR0, "Int64", i, "int64", "int64", a, "int64")
+		} else {
+			fmt.Fprintf(bout, binaryConstR, "Int64", i, "int64", "int64", a, "int64")
+		}
 		fmt.Fprintf(bout, shiftConstL, "Int64", i, "int64", "int64", a, "int64")
 	}
 	for i, a := range uint64Values {
 		fmt.Fprintf(bout, binaryConstL, "Uint64", i, "uint64", "uint64", a, "uint64")
-		fmt.Fprintf(bout, binaryConstR, "Uint64", i, "uint64", "uint64", a, "uint64")
+		if a.hi == 0 && a.lo == 0 {
+			fmt.Fprintf(bout, binaryConstR0, "Uint64", i, "uint64", "uint64", a, "uint64")
+		} else {
+			fmt.Fprintf(bout, binaryConstR, "Uint64", i, "uint64", "uint64", a, "uint64")
+		}
 		fmt.Fprintf(bout, shiftConstL, "Uint64", i, "uint64", "uint64", a, "uint64")
 	}
 	for i, a := range shiftValues {


[Patch, AArch64, ILP32] 5/5 Define _ILP32 and __ILP32__

2013-06-26 Thread Yufeng Zhang
This patch defines _ILP32 and __ILP32__ for the AArch64 port when the 
ILP32 ABI is in use.


This helps libraries, e.g. libgloss and glibc, recognize which model is 
being compiled.


OK for the trunk?

Thanks,
Yufeng


gcc/
* config/aarch64/aarch64.h (TARGET_CPU_CPP_BUILTINS): Define _ILP32
and __ILP32__ when the ILP32 model is in use.

diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
index d468dd8..e5dadb3 100644
--- a/gcc/config/aarch64/aarch64.h
+++ b/gcc/config/aarch64/aarch64.h
@@ -49,6 +49,11 @@
 	break;	\
 	}		\
 			\
+  if (TARGET_ILP32)	\
+	{		\
+	  cpp_define (parse_in, "_ILP32");		\
+	  cpp_define (parse_in, "__ILP32__");		\
+	}		\
 } while (0)
 
 

Go patch committed: Disallow fallthrough at end of switch

2013-06-26 Thread Ian Lance Taylor
In Go 1 the fallthrough statement is no longer permitted in the last
case of a switch, as there is no code to which to fall through.  This
patch from Rémy Oudompheng implements this restriction in gccgo.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline and 4.8 branch.

Ian

diff -r 133fcbfa33c6 go/parse.cc
--- a/go/parse.cc	Wed Jun 26 15:31:30 2013 -0700
+++ b/go/parse.cc	Wed Jun 26 15:44:23 2013 -0700
@@ -4523,9 +4523,12 @@
   bool is_fallthrough = false;
   if (this->peek_token()->is_keyword(KEYWORD_FALLTHROUGH))
 {
+  Location fallthrough_loc = this->location();
   is_fallthrough = true;
   if (this->advance_token()->is_op(OPERATOR_SEMICOLON))
 	this->advance_token();
+  if (this->peek_token()->is_op(OPERATOR_RCURLY))
+	error_at(fallthrough_loc, _("cannot fallthrough final case in switch"));
 }
 
   if (is_default)


Re: [Patch, AArch64, ILP32] 1/5 Initial support - configury changes

2013-06-26 Thread Andrew Pinski
On Wed, Jun 26, 2013 at 3:33 PM, Yufeng Zhang  wrote:
> This patch adds the configuration changes to the AArch64 GCC to support:
>
> * -milp32 and -mlp64 options in the compiler and the driver
> * multilib of ilp32 and/or lp64 libraries
> * differentiation of basic types in the compiler backend
>
> The patch enables --with-multilib-list configuration option for specifying
> the list of library flavors to enable; the default value is "mlp64" and can
> be overridden by --with-abi to "milp32".
>
> It also enables --with-abi for setting the default model in the compiler.
> Its default value is "mlp64" unless --with-multilib-list is explicitly
> specified with "milp32", in which case it defaults to "milp32".
>
> In the backend, two target flags are introduced: TARGET_ILP32 and
> TARGET_LP64.  They are set by -milp32 and -mlp64 respectively, exclusive to
> each other.  The default setting is via the option variable
> aarch64_pmodel_flags, which defaults to TARGET_DEFAULT_PMODEL, which is
> further defined in biarchlp64.h or biarchilp32.h depending which header file
> is included.
>
>   biarchlp64.h biarchilp32.h
> TARGET_DEFAULT_PMODEL OPTION_MASK_LP64 OPTION_MASK_ILP32
> TARGET_PMODEL 12
>
> TARGET_ILP32 and TARGET_LP64 are implicitly defined as:
>
> #define TARGET_ILP32 ((aarch64_pmodel_flags & OPTION_MASK_ILP32) != 0)
> #define TARGET_LP64 ((aarch64_pmodel_flags & OPTION_MASK_LP64) != 0)
>
> Note that the multilib support in the Linux toolchain is suppressed
> deliberately.
>
> OK for the trunk?


I think you should not support --with-multilib-list at all.  It should
just include ilp32 multilib no matter what.  Note the linux multilib
has to wait until the glibc/kernel side is done.

Also:
+#if TARGET_BIG_ENDIAN_DEFAULT == 1
+#define EMUL_SUFFIX "b"
+#else
+#define EMUL_SUFFIX ""
+#endif

is broken when you supply the opposite endian option.

Also you really should just use -mabi=ilp32 and -mabi=lp64 which
reduces the number of changes needed to be done to config.gcc.

You should use DRIVER_SELF_SPECS to simplify your LINKS_SPECS.
Something like:
#ifdef TARGET_BIG_ENDIAN_DEFAULT
#define ENDIAN_SPEC "-mbig-endian"
#else
#define ENDIAN_SPEC "-mlittle-endian"
#endif
/* Force the default endianness and ABI flags onto the command line
   in order to make the other specs easier to write.  */
#undef DRIVER_SELF_SPECS
#define DRIVER_SELF_SPECS \
  " %{!mbig-endian:%{!mlittle-endian:" ENDIAN_SPEC "}}" \
  " %{!milp32:%{!mlp64:-mlp64}}"

or rather:
" %{!mabi=*: -mabi=lp64}"



And then in aarch64-elf-raw.h:
#ifndef LINK_SPEC
#define LINK_SPEC "%{mbig-endian:-EB} %{mlittle-endian:-EL} -X \
-maarch64elf%{milp32:32}%{mbig-endian:b}"
#endif

Or using the -mabi=* way:
#ifndef LINK_SPEC
#define LINK_SPEC "%{mbig-endian:-EB} %{mlittle-endian:-EL} -X \
-maarch64elf%{mabi=ilp32:32}%{mbig-endian:b}"
#endif



Thanks,
Andrew Pinski


>
> Thanks,
> Yufeng
>
>
> gcc/
> * config.gcc (aarch64*-*-*): Support --with-abi.
> (aarch64*-*-elf): Support --with-multilib-list.
> (aarch64*-*-linux*): Likewise.
> (supported_defaults): Add abi to aarch64*-*-*.
> * configure.ac: Mention AArch64 for --with-multilib-list.
> * configure: Re-generated.
> * config/aarch64/biarchilp32.h: New file.
> * config/aarch64/biarchlp64.h: New file.
> * config/aarch64/aarch64-elf.h (SPEC_LP64): New define.
> (SPEC_ILP32): Ditto.
> (ASM_SPEC): Update to SPEC_LP64 and SPEC_ILP32.
> (MULTILIB_DEFAULTS): New define.
> * config/aarch64/aarch64-elf-raw.h (EMUL_SUFFIX): New define.
> (LINK_SPEC): Change to depend on SPEC_LP64 and SPEC_ILP32 and also
> to use EMUL_SUFFIX.
> * config/aarch64/aarch64.h (LONG_TYPE_SIZE): Change to depend on
> TARGET_ILP32.
> (POINTER_SIZE): New define.
> (POINTERS_EXTEND_UNSIGNED): Ditto.
> * config/aarch64/aarch64.c (initialize_aarch64_programming_model):
> New declaration and definition.
> (aarch64_override_options): Call the new function.
> * config/aarch64/aarch64.opt (aarch64_pmodel_flags): New.
> (milp32, mlp64): New.
> * config/aarch64/t-aarch64 (comma): New define.
> (MULTILIB_OPTIONS): Ditto.
> (MULTILIB_DIRNAMES): Ditto.
> * config/aarch64/t-aarch64-linux (MULTIARCH_DIRNAME): New define.
>


Re: [google/gcc-4_8] Port -Wreal-conversion warning

2013-06-26 Thread Xinliang David Li
The warn_type should also be guarded with float type check:

 warn_type = (warn_real_conversion
&& (FLOAT_TYPE_P (type) || FLOAT_TYPE_P (expr_type)))
? OPT_Wreal_conversion
: OPT_Wconversion;

Also why did you put the warn_type code inside the default?

David


On Mon, Jun 24, 2013 at 10:03 PM, Sharad Singhai  wrote:
> On Mon, Jun 24, 2013 at 9:14 PM, Xinliang David Li  wrote:
>> To avoid printing twice, can you just do
>>
>> opt_type = (warn_conversion ? OPT_Wconversion : OPT_Wreal_conversion);
>> warning_at (loc, opt_type, ...);
>
> Thanks for the suggestion. I have updated the enclosed patch and
> retested. Okay for google/gcc-4_8?
>
> Thanks,
> Sharad
>
> 2013-06-24
>
> * doc/invoke.texi: Document new option -Wreal-conversion.
> * c-family/c.opt: Handle new option.
> * c-family/c-opts.c (c_common_post_options): Ditto.
> * c-family/c-common.c (conversion_warning): Ditto.
>
> testsuite/ChangeLog:
>
> * testsuite/gcc.dg/Wreal-conversion-1.c: New test.
> * testsuite/g++.dg/warn/Wreal-conversion-1.C: Ditto.
>
> Index: doc/invoke.texi
> ===
> --- doc/invoke.texi (revision 200359)
> +++ doc/invoke.texi (working copy)
> @@ -237,7 +237,7 @@ Objective-C and Objective-C++ Dialects}.
>  -Wno-attributes -Wno-builtin-macro-redefined @gol
>  -Wc++-compat -Wc++11-compat -Wcast-align  -Wcast-qual  @gol
>  -Wchar-subscripts -Wclobbered  -Wcomment @gol
> --Wconversion  -Wcoverage-mismatch  -Wno-cpp  -Wno-deprecated  @gol
> +-Wconversion -Wreal-conversion -Wcoverage-mismatch  -Wno-cpp
> -Wno-deprecated  @gol
>  -Wno-deprecated-declarations -Wdisabled-optimization  @gol
>  -Wno-div-by-zero -Wdouble-promotion -Wempty-body  -Wenum-compare @gol
>  -Wno-endif-labels -Werror  -Werror=* @gol
> @@ -4452,6 +4452,12 @@ reference to them. Warnings about conversions betw
>  unsigned integers are disabled by default in C++ unless
>  @option{-Wsign-conversion} is explicitly enabled.
>
> +@item -Wreal-conversion
> +@opindex Wreal-conversion
> +@opindex Wno-real-conversion
> +Warn for implicit type conversions from real (@code{double} or @code{float})
> +to integral values.
> +
>  @item -Wno-conversion-null @r{(C++ and Objective-C++ only)}
>  @opindex Wconversion-null
>  @opindex Wno-conversion-null
> Index: testsuite/gcc.dg/Wreal-conversion-1.c
> ===
> --- testsuite/gcc.dg/Wreal-conversion-1.c (revision 0)
> +++ testsuite/gcc.dg/Wreal-conversion-1.c (revision 0)
> @@ -0,0 +1,23 @@
> +// { dg-do compile }
> +// { dg-options "-Wreal-conversion" }
> +
> +#include 
> +
> +int func1(int a) {
> +  double f = a;
> +  return f;   // { dg-warning "conversion to" }
> +}
> +
> +double func3();
> +
> +void func2() {
> +  double g = 3.2;
> +  float f;
> +  int t = g;  // { dg-warning "conversion to" }
> +  int p;
> +  p = f;  // { dg-warning "conversion to" }
> +  func1(g);   // { dg-warning "conversion to" }
> +  char c = f; // { dg-warning "conversion to" }
> +  int q;
> +  q = func3();// { dg-warning "conversion to" }
> +}
> Index: testsuite/g++.dg/warn/Wreal-conversion-1.C
> ===
> --- testsuite/g++.dg/warn/Wreal-conversion-1.C (revision 0)
> +++ testsuite/g++.dg/warn/Wreal-conversion-1.C (revision 0)
> @@ -0,0 +1,24 @@
> +// { dg-do compile }
> +// { dg-options "-Wreal-conversion" }
> +
> +#include 
> +
> +int func1(int a) {
> +  double f = a;
> +  return f;   // { dg-warning "conversion to" }
> +}
> +
> +double func3();
> +
> +void func2() {
> +  double g = 3.2;
> +  float f;
> +  int t = g;  // { dg-warning "conversion to" }
> +  bool b = g;
> +  int p;
> +  p = f;  // { dg-warning "conversion to" }
> +  func1(g);   // { dg-warning "conversion to" }
> +  char c = f; // { dg-warning "conversion to" }
> +  int q;
> +  q = func3();// { dg-warning "conversion to" }
> +}
> Index: c-family/c.opt
> ===
> --- c-family/c.opt (revision 200359)
> +++ c-family/c.opt (working copy)
> @@ -677,6 +677,10 @@ Wsign-compare
>  C ObjC C++ ObjC++ EnabledBy(Wextra)
>  ;
>
> +Wreal-conversion
> +C ObjC C++ ObjC++ Var(warn_real_conversion) Init(-1) Warning
> +Warn for implicit type conversions from real to integral values
> +
>  Wsign-conversion
>  C ObjC C++ ObjC++ Var(warn_sign_conversion) LangEnabledBy(C ObjC,Wconversion)
>  Warn for implicit type conversions between signed and unsigned integers
> Index: c-family/c-opts.c
> ===
> --- c-family/c-opts.c (revision 200359)
> +++ c-family/c-opts.c (working copy)
> @@ -876,6 +876,12 @@ c_common_post_options (const char **pfilename)
>if (warn_packed_bitfield_compat == -1)
>  warn_packed_bitfield_compat = 1;
>
> +  /* Enable warning for converting

Re: [Patch, AArch64, ILP32] 3/5 Minor change in function.c:assign_parm_find_data_types()

2013-06-26 Thread Andrew Pinski
On Wed, Jun 26, 2013 at 3:39 PM, Yufeng Zhang  wrote:
> This patch updates assign_parm_find_data_types to assign passed_mode and
> nominal_mode with the mode of the built pointer type instead of the
> hard-coded Pmode in the case of pass-by-reference.  This is in line with the
> assignment to passed_mode and nominal_mode in other cases inside the
> function.
>
> assign_parm_find_data_types generally uses TYPE_MODE to calculate
> passed_mode and nominal_mode:
>
>   /* Find mode of arg as it is passed, and mode of arg as it should be
>  during execution of this function.  */
>   passed_mode = TYPE_MODE (passed_type);
>   nominal_mode = TYPE_MODE (nominal_type);
>
> this includes the case when the passed argument is a pointer by itself.
>
> However there is a discrepancy when it deals with argument passed by
> invisible reference; it builds the argument's corresponding pointer type,
> but sets passed_mode and nominal_mode with Pmode directly.
>
> This is OK for targets where Pmode == ptr_mode, but on AArch64 with ILP32
> they are different with Pmode as DImode and ptr_mode as SImode. When such a
> reference is passed on stack, the reference is prepared by the caller in the
> lower 4 bytes of an 8-byte slot but is fetched by the callee as an 8-byte
> datum, of which the higher 4 bytes may contain junk.  It is probably the
> combination of Pmode != ptr_mode and the particular ABI specification that
> make the AArch64 ILP32 the first target on which the issue manifests itself.
>
> Bootstrapped on x86_64-none-linux-gnu.
>
> OK for the trunk?


IA64-hpux also uses Pmode != ptr_mode, can you provide the testcase
which fails without this change?
I used a powerpc64 target where Pmode != ptr_mode which did not hit
this bug either.

Thanks,
Andrew

>
> Thanks,
> Yufeng
>
>
> gcc/
> * function.c (assign_parm_find_data_types): Set passed_mode and
> nominal_mode to the TYPE_MODE of nominal_type for the built
> pointer type in case of the struct-pass-by-reference.


Re: [Patch, AArch64, ILP32] 3/5 Minor change in function.c:assign_parm_find_data_types()

2013-06-26 Thread Yufeng Zhang

On 06/27/13 00:04, Andrew Pinski wrote:

On Wed, Jun 26, 2013 at 3:39 PM, Yufeng Zhang  wrote:

This patch updates assign_parm_find_data_types to assign passed_mode and
nominal_mode with the mode of the built pointer type instead of the
hard-coded Pmode in the case of pass-by-reference.  This is in line with the
assignment to passed_mode and nominal_mode in other cases inside the
function.

assign_parm_find_data_types generally uses TYPE_MODE to calculate
passed_mode and nominal_mode:

   /* Find mode of arg as it is passed, and mode of arg as it should be
  during execution of this function.  */
   passed_mode = TYPE_MODE (passed_type);
   nominal_mode = TYPE_MODE (nominal_type);

this includes the case when the passed argument is a pointer by itself.

However there is a discrepancy when it deals with argument passed by
invisible reference; it builds the argument's corresponding pointer type,
but sets passed_mode and nominal_mode with Pmode directly.

This is OK for targets where Pmode == ptr_mode, but on AArch64 with ILP32
they are different with Pmode as DImode and ptr_mode as SImode. When such a
reference is passed on stack, the reference is prepared by the caller in the
lower 4 bytes of an 8-byte slot but is fetched by the callee as an 8-byte
datum, of which the higher 4 bytes may contain junk.  It is probably the
combination of Pmode != ptr_mode and the particular ABI specification that
make the AArch64 ILP32 the first target on which the issue manifests itself.

Bootstrapped on x86_64-none-linux-gnu.

OK for the trunk?



IA64-hpux also uses Pmode != ptr_mode, can you provide the testcase
which fails without this change?
I used a powerpc64 target where Pmode != ptr_mode which did not hit
this bug either.


The issue was firstly observed in one of the compat tests which passes a 
large number of non-small structures.  The following is a trimmed-down 
reproducible code snippet (although not runnable but shall be easy to be 
make runnable):


struct s5
{
  double a;
  double b;
  double c;
  double d;
  double e;
} gS;

double foo (struct s5 p1, struct s5 p2,struct s5 p3,struct s5 p4,struct 
s5 p5,struct s5 p6,struct s5 p7,struct s5 p8, struct s5 p9)

{
  return p9.c;
}
--- CUT ---

The code-gen (-O2) without the patch is:

.text
.align  2
.global foo
.type   foo, %function
foo:
ldr x0, [sp]<<=== here!
ldr d0, [x0,16]
ret
.size   foo, .-foo

Where the arrow points is the load of the pointer to 'p9' that is passed 
on stack.  The instruction really should be ldr w0, [sp], i.e. the 
pointer mode is SImode rather than DImode.


It needs a number of conditions for the issue to manifest:

1. pass-by-reference; on aarch64 one example is a struct that is larger 
than 16 bytes.
2. the reference is passed on stack; on aarch64, this usually only 
happens after registers x0 - x7 are used.
3. the size of stack slot for passing pointer is larger than the pointer 
size; on aarch64, it is 8-byte vs. 4-byte
4. the unused part of the stack slot is not zeroed out, i.e. undefined 
by the ABI

5. in the runtime, the unused part of such a stack slot contains junk.

The runtime segmentation fault may only be generated when all the above 
conditions are met.  I'm not familiar with IA64-hpux or powerpc64 
procedure call ABIs, but I guess those targets are just being lucky?


Thanks,
Yufeng



Re: [Patch, AArch64, ILP32] 3/5 Minor change in function.c:assign_parm_find_data_types()

2013-06-26 Thread Andrew Pinski
On Wed, Jun 26, 2013 at 4:41 PM, Yufeng Zhang  wrote:
> On 06/27/13 00:04, Andrew Pinski wrote:
>>
>> On Wed, Jun 26, 2013 at 3:39 PM, Yufeng Zhang
>> wrote:
>>>
>>> This patch updates assign_parm_find_data_types to assign passed_mode and
>>> nominal_mode with the mode of the built pointer type instead of the
>>> hard-coded Pmode in the case of pass-by-reference.  This is in line with
>>> the
>>> assignment to passed_mode and nominal_mode in other cases inside the
>>> function.
>>>
>>> assign_parm_find_data_types generally uses TYPE_MODE to calculate
>>> passed_mode and nominal_mode:
>>>
>>>/* Find mode of arg as it is passed, and mode of arg as it should be
>>>   during execution of this function.  */
>>>passed_mode = TYPE_MODE (passed_type);
>>>nominal_mode = TYPE_MODE (nominal_type);
>>>
>>> this includes the case when the passed argument is a pointer by itself.
>>>
>>> However there is a discrepancy when it deals with argument passed by
>>> invisible reference; it builds the argument's corresponding pointer type,
>>> but sets passed_mode and nominal_mode with Pmode directly.
>>>
>>> This is OK for targets where Pmode == ptr_mode, but on AArch64 with ILP32
>>> they are different with Pmode as DImode and ptr_mode as SImode. When such
>>> a
>>> reference is passed on stack, the reference is prepared by the caller in
>>> the
>>> lower 4 bytes of an 8-byte slot but is fetched by the callee as an 8-byte
>>> datum, of which the higher 4 bytes may contain junk.  It is probably the
>>> combination of Pmode != ptr_mode and the particular ABI specification
>>> that
>>> make the AArch64 ILP32 the first target on which the issue manifests
>>> itself.
>>>
>>> Bootstrapped on x86_64-none-linux-gnu.
>>>
>>> OK for the trunk?
>>
>>
>>
>> IA64-hpux also uses Pmode != ptr_mode, can you provide the testcase
>> which fails without this change?
>> I used a powerpc64 target where Pmode != ptr_mode which did not hit
>> this bug either.
>
>
> The issue was firstly observed in one of the compat tests which passes a
> large number of non-small structures.  The following is a trimmed-down
> reproducible code snippet (although not runnable but shall be easy to be
> make runnable):
>
> struct s5
> {
>   double a;
>   double b;
>   double c;
>   double d;
>   double e;
> } gS;
>
> double foo (struct s5 p1, struct s5 p2,struct s5 p3,struct s5 p4,struct s5
> p5,struct s5 p6,struct s5 p7,struct s5 p8, struct s5 p9)
> {
>   return p9.c;
> }
> --- CUT ---
>
> The code-gen (-O2) without the patch is:
>
> .text
> .align  2
> .global foo
> .type   foo, %function
> foo:
> ldr x0, [sp]<<=== here!
> ldr d0, [x0,16]
> ret
> .size   foo, .-foo
>
> Where the arrow points is the load of the pointer to 'p9' that is passed on
> stack.  The instruction really should be ldr w0, [sp], i.e. the pointer mode
> is SImode rather than DImode.
>
> It needs a number of conditions for the issue to manifest:
>
> 1. pass-by-reference; on aarch64 one example is a struct that is larger than
> 16 bytes.
> 2. the reference is passed on stack; on aarch64, this usually only happens
> after registers x0 - x7 are used.
> 3. the size of stack slot for passing pointer is larger than the pointer
> size; on aarch64, it is 8-byte vs. 4-byte
> 4. the unused part of the stack slot is not zeroed out, i.e. undefined by
> the ABI

This is the real issue.  I think it is better if we change the ABI to
say they are zero'd.  It really makes things like this a mess.

> 5. in the runtime, the unused part of such a stack slot contains junk.
>
> The runtime segmentation fault may only be generated when all the above
> conditions are met.  I'm not familiar with IA64-hpux or powerpc64 procedure
> call ABIs, but I guess those targets are just being lucky?

Or rather their ABIs all say are zero or sign extended for values less
than 8 byte wide.

Thanks,
Andrew Pinski


Re: [Patch, AArch64, ILP32] 3/5 Minor change in function.c:assign_parm_find_data_types()

2013-06-26 Thread Andrew Pinski
On Wed, Jun 26, 2013 at 4:51 PM, Andrew Pinski  wrote:
> On Wed, Jun 26, 2013 at 4:41 PM, Yufeng Zhang  wrote:
>> On 06/27/13 00:04, Andrew Pinski wrote:
>>>
>>> On Wed, Jun 26, 2013 at 3:39 PM, Yufeng Zhang
>>> wrote:

 This patch updates assign_parm_find_data_types to assign passed_mode and
 nominal_mode with the mode of the built pointer type instead of the
 hard-coded Pmode in the case of pass-by-reference.  This is in line with
 the
 assignment to passed_mode and nominal_mode in other cases inside the
 function.

 assign_parm_find_data_types generally uses TYPE_MODE to calculate
 passed_mode and nominal_mode:

/* Find mode of arg as it is passed, and mode of arg as it should be
   during execution of this function.  */
passed_mode = TYPE_MODE (passed_type);
nominal_mode = TYPE_MODE (nominal_type);

 this includes the case when the passed argument is a pointer by itself.

 However there is a discrepancy when it deals with argument passed by
 invisible reference; it builds the argument's corresponding pointer type,
 but sets passed_mode and nominal_mode with Pmode directly.

 This is OK for targets where Pmode == ptr_mode, but on AArch64 with ILP32
 they are different with Pmode as DImode and ptr_mode as SImode. When such
 a
 reference is passed on stack, the reference is prepared by the caller in
 the
 lower 4 bytes of an 8-byte slot but is fetched by the callee as an 8-byte
 datum, of which the higher 4 bytes may contain junk.  It is probably the
 combination of Pmode != ptr_mode and the particular ABI specification
 that
 make the AArch64 ILP32 the first target on which the issue manifests
 itself.

 Bootstrapped on x86_64-none-linux-gnu.

 OK for the trunk?
>>>
>>>
>>>
>>> IA64-hpux also uses Pmode != ptr_mode, can you provide the testcase
>>> which fails without this change?
>>> I used a powerpc64 target where Pmode != ptr_mode which did not hit
>>> this bug either.
>>
>>
>> The issue was firstly observed in one of the compat tests which passes a
>> large number of non-small structures.  The following is a trimmed-down
>> reproducible code snippet (although not runnable but shall be easy to be
>> make runnable):
>>
>> struct s5
>> {
>>   double a;
>>   double b;
>>   double c;
>>   double d;
>>   double e;
>> } gS;
>>
>> double foo (struct s5 p1, struct s5 p2,struct s5 p3,struct s5 p4,struct s5
>> p5,struct s5 p6,struct s5 p7,struct s5 p8, struct s5 p9)
>> {
>>   return p9.c;
>> }
>> --- CUT ---
>>
>> The code-gen (-O2) without the patch is:
>>
>> .text
>> .align  2
>> .global foo
>> .type   foo, %function
>> foo:
>> ldr x0, [sp]<<=== here!
>> ldr d0, [x0,16]
>> ret
>> .size   foo, .-foo
>>
>> Where the arrow points is the load of the pointer to 'p9' that is passed on
>> stack.  The instruction really should be ldr w0, [sp], i.e. the pointer mode
>> is SImode rather than DImode.
>>
>> It needs a number of conditions for the issue to manifest:
>>
>> 1. pass-by-reference; on aarch64 one example is a struct that is larger than
>> 16 bytes.
>> 2. the reference is passed on stack; on aarch64, this usually only happens
>> after registers x0 - x7 are used.
>> 3. the size of stack slot for passing pointer is larger than the pointer
>> size; on aarch64, it is 8-byte vs. 4-byte
>> 4. the unused part of the stack slot is not zeroed out, i.e. undefined by
>> the ABI
>
> This is the real issue.  I think it is better if we change the ABI to
> say they are zero'd.  It really makes things like this a mess.
>
>> 5. in the runtime, the unused part of such a stack slot contains junk.
>>
>> The runtime segmentation fault may only be generated when all the above
>> conditions are met.  I'm not familiar with IA64-hpux or powerpc64 procedure
>> call ABIs, but I guess those targets are just being lucky?
>
> Or rather their ABIs all say are zero or sign extended for values less
> than 8 byte wide.

One more thing, it looks like your change will not work correctly for
big-endian ILP32 AARCH64 either as the least significant word is
offsetted by 4.
Did you test big-endian ILP32 AARCH64?

Thanks,
Andrew Pinski


Re: [google/gcc-4_8] Port -Wreal-conversion warning

2013-06-26 Thread Sharad Singhai
Sorry, my port was bad. I am going to revert this patch and redo it.

Thanks,
Sharad

On Wed, Jun 26, 2013 at 4:03 PM, Xinliang David Li  wrote:
> The warn_type should also be guarded with float type check:
>
>  warn_type = (warn_real_conversion
> && (FLOAT_TYPE_P (type) || FLOAT_TYPE_P (expr_type)))
> ? OPT_Wreal_conversion
> : OPT_Wconversion;
>
> Also why did you put the warn_type code inside the default?
>
> David
>
>
> On Mon, Jun 24, 2013 at 10:03 PM, Sharad Singhai  wrote:
>> On Mon, Jun 24, 2013 at 9:14 PM, Xinliang David Li  
>> wrote:
>>> To avoid printing twice, can you just do
>>>
>>> opt_type = (warn_conversion ? OPT_Wconversion : OPT_Wreal_conversion);
>>> warning_at (loc, opt_type, ...);
>>
>> Thanks for the suggestion. I have updated the enclosed patch and
>> retested. Okay for google/gcc-4_8?
>>
>> Thanks,
>> Sharad
>>
>> 2013-06-24
>>
>> * doc/invoke.texi: Document new option -Wreal-conversion.
>> * c-family/c.opt: Handle new option.
>> * c-family/c-opts.c (c_common_post_options): Ditto.
>> * c-family/c-common.c (conversion_warning): Ditto.
>>
>> testsuite/ChangeLog:
>>
>> * testsuite/gcc.dg/Wreal-conversion-1.c: New test.
>> * testsuite/g++.dg/warn/Wreal-conversion-1.C: Ditto.
>>
>> Index: doc/invoke.texi
>> ===
>> --- doc/invoke.texi (revision 200359)
>> +++ doc/invoke.texi (working copy)
>> @@ -237,7 +237,7 @@ Objective-C and Objective-C++ Dialects}.
>>  -Wno-attributes -Wno-builtin-macro-redefined @gol
>>  -Wc++-compat -Wc++11-compat -Wcast-align  -Wcast-qual  @gol
>>  -Wchar-subscripts -Wclobbered  -Wcomment @gol
>> --Wconversion  -Wcoverage-mismatch  -Wno-cpp  -Wno-deprecated  @gol
>> +-Wconversion -Wreal-conversion -Wcoverage-mismatch  -Wno-cpp
>> -Wno-deprecated  @gol
>>  -Wno-deprecated-declarations -Wdisabled-optimization  @gol
>>  -Wno-div-by-zero -Wdouble-promotion -Wempty-body  -Wenum-compare @gol
>>  -Wno-endif-labels -Werror  -Werror=* @gol
>> @@ -4452,6 +4452,12 @@ reference to them. Warnings about conversions betw
>>  unsigned integers are disabled by default in C++ unless
>>  @option{-Wsign-conversion} is explicitly enabled.
>>
>> +@item -Wreal-conversion
>> +@opindex Wreal-conversion
>> +@opindex Wno-real-conversion
>> +Warn for implicit type conversions from real (@code{double} or @code{float})
>> +to integral values.
>> +
>>  @item -Wno-conversion-null @r{(C++ and Objective-C++ only)}
>>  @opindex Wconversion-null
>>  @opindex Wno-conversion-null
>> Index: testsuite/gcc.dg/Wreal-conversion-1.c
>> ===
>> --- testsuite/gcc.dg/Wreal-conversion-1.c (revision 0)
>> +++ testsuite/gcc.dg/Wreal-conversion-1.c (revision 0)
>> @@ -0,0 +1,23 @@
>> +// { dg-do compile }
>> +// { dg-options "-Wreal-conversion" }
>> +
>> +#include 
>> +
>> +int func1(int a) {
>> +  double f = a;
>> +  return f;   // { dg-warning "conversion to" }
>> +}
>> +
>> +double func3();
>> +
>> +void func2() {
>> +  double g = 3.2;
>> +  float f;
>> +  int t = g;  // { dg-warning "conversion to" }
>> +  int p;
>> +  p = f;  // { dg-warning "conversion to" }
>> +  func1(g);   // { dg-warning "conversion to" }
>> +  char c = f; // { dg-warning "conversion to" }
>> +  int q;
>> +  q = func3();// { dg-warning "conversion to" }
>> +}
>> Index: testsuite/g++.dg/warn/Wreal-conversion-1.C
>> ===
>> --- testsuite/g++.dg/warn/Wreal-conversion-1.C (revision 0)
>> +++ testsuite/g++.dg/warn/Wreal-conversion-1.C (revision 0)
>> @@ -0,0 +1,24 @@
>> +// { dg-do compile }
>> +// { dg-options "-Wreal-conversion" }
>> +
>> +#include 
>> +
>> +int func1(int a) {
>> +  double f = a;
>> +  return f;   // { dg-warning "conversion to" }
>> +}
>> +
>> +double func3();
>> +
>> +void func2() {
>> +  double g = 3.2;
>> +  float f;
>> +  int t = g;  // { dg-warning "conversion to" }
>> +  bool b = g;
>> +  int p;
>> +  p = f;  // { dg-warning "conversion to" }
>> +  func1(g);   // { dg-warning "conversion to" }
>> +  char c = f; // { dg-warning "conversion to" }
>> +  int q;
>> +  q = func3();// { dg-warning "conversion to" }
>> +}
>> Index: c-family/c.opt
>> ===
>> --- c-family/c.opt (revision 200359)
>> +++ c-family/c.opt (working copy)
>> @@ -677,6 +677,10 @@ Wsign-compare
>>  C ObjC C++ ObjC++ EnabledBy(Wextra)
>>  ;
>>
>> +Wreal-conversion
>> +C ObjC C++ ObjC++ Var(warn_real_conversion) Init(-1) Warning
>> +Warn for implicit type conversions from real to integral values
>> +
>>  Wsign-conversion
>>  C ObjC C++ ObjC++ Var(warn_sign_conversion) LangEnabledBy(C 
>> ObjC,Wconversion)
>>  Warn for implicit type conversions between signed and unsigned integers
>> Index: c-family/c-opts.c
>> ===

Re: [Patch, AArch64, ILP32] 3/5 Minor change in function.c:assign_parm_find_data_types()

2013-06-26 Thread Yufeng Zhang

On 06/27/13 00:51, Andrew Pinski wrote:

On Wed, Jun 26, 2013 at 4:41 PM, Yufeng Zhang  wrote:

On 06/27/13 00:04, Andrew Pinski wrote:


On Wed, Jun 26, 2013 at 3:39 PM, Yufeng Zhang
wrote:


This patch updates assign_parm_find_data_types to assign passed_mode and
nominal_mode with the mode of the built pointer type instead of the
hard-coded Pmode in the case of pass-by-reference.  This is in line with
the
assignment to passed_mode and nominal_mode in other cases inside the
function.

assign_parm_find_data_types generally uses TYPE_MODE to calculate
passed_mode and nominal_mode:

/* Find mode of arg as it is passed, and mode of arg as it should be
   during execution of this function.  */
passed_mode = TYPE_MODE (passed_type);
nominal_mode = TYPE_MODE (nominal_type);

this includes the case when the passed argument is a pointer by itself.

However there is a discrepancy when it deals with argument passed by
invisible reference; it builds the argument's corresponding pointer type,
but sets passed_mode and nominal_mode with Pmode directly.

This is OK for targets where Pmode == ptr_mode, but on AArch64 with ILP32
they are different with Pmode as DImode and ptr_mode as SImode. When such
a
reference is passed on stack, the reference is prepared by the caller in
the
lower 4 bytes of an 8-byte slot but is fetched by the callee as an 8-byte
datum, of which the higher 4 bytes may contain junk.  It is probably the
combination of Pmode != ptr_mode and the particular ABI specification
that
make the AArch64 ILP32 the first target on which the issue manifests
itself.

Bootstrapped on x86_64-none-linux-gnu.

OK for the trunk?




IA64-hpux also uses Pmode != ptr_mode, can you provide the testcase
which fails without this change?
I used a powerpc64 target where Pmode != ptr_mode which did not hit
this bug either.



The issue was firstly observed in one of the compat tests which passes a
large number of non-small structures.  The following is a trimmed-down
reproducible code snippet (although not runnable but shall be easy to be
make runnable):

struct s5
{
   double a;
   double b;
   double c;
   double d;
   double e;
} gS;

double foo (struct s5 p1, struct s5 p2,struct s5 p3,struct s5 p4,struct s5
p5,struct s5 p6,struct s5 p7,struct s5 p8, struct s5 p9)
{
   return p9.c;
}
--- CUT ---

The code-gen (-O2) without the patch is:

 .text
 .align  2
 .global foo
 .type   foo, %function
foo:
 ldr x0, [sp]<<=== here!
 ldr d0, [x0,16]
 ret
 .size   foo, .-foo

Where the arrow points is the load of the pointer to 'p9' that is passed on
stack.  The instruction really should be ldr w0, [sp], i.e. the pointer mode
is SImode rather than DImode.

It needs a number of conditions for the issue to manifest:

1. pass-by-reference; on aarch64 one example is a struct that is larger than
16 bytes.
2. the reference is passed on stack; on aarch64, this usually only happens
after registers x0 - x7 are used.
3. the size of stack slot for passing pointer is larger than the pointer
size; on aarch64, it is 8-byte vs. 4-byte
4. the unused part of the stack slot is not zeroed out, i.e. undefined by
the ABI


This is the real issue.  I think it is better if we change the ABI to
say they are zero'd.  It really makes things like this a mess.


I don't agree on this.  There is nothing wrong with the unused bits 
filled with unspecified values; there are sufficient number of 
load/store instruction variants on AArch64 that are able to load/store 
smaller-sized datum from/to memory; zeroing-unused bits on the stack may 
require extra instructions which add cost.


Nevertheless, assign_parm_find_data_types() shall not generate different 
modes for pass-by-reference argument and straight-forward pointer one. 
For instance in the following code snippet, the passed_mode and 
nominal_mode for '&p9' in foo and 'p9' in bar shall be the same; but 
'&p9' in foo gets DImode and 'p3' in bar get SImode, which is really 
wrong (by typing '&p9', I mean the pass-by-reference).


struct s5
{
  double a;
  double b;
  double c;
  double d;
  double e;
} gS;

double foo (struct s5 p1, struct s5 p2,struct s5 p3,struct s5 p4,struct 
s5 p5,struct s5 p6,struct s5 p7,struct s5 p8, struct s5 p9)

{
  return p9.c;
}

double bar (struct s5 *p1, struct s5 *p2,struct s5 *p3,struct s5 
*p4,struct s5 *p5,struct s5 *p6,struct s5 *p7,struct s5 *p8, struct s5 *p9)

{
  return p9->c;
}

Hope I have demonstrated the issue clearly.

Thanks,
Yufeng



Re: [Patch, AArch64, ILP32] 3/5 Minor change in function.c:assign_parm_find_data_types()

2013-06-26 Thread Yufeng Zhang

On 06/27/13 00:57, Andrew Pinski wrote:

On Wed, Jun 26, 2013 at 4:51 PM, Andrew Pinski  wrote:

On Wed, Jun 26, 2013 at 4:41 PM, Yufeng Zhang  wrote:

On 06/27/13 00:04, Andrew Pinski wrote:


On Wed, Jun 26, 2013 at 3:39 PM, Yufeng Zhang
wrote:


This patch updates assign_parm_find_data_types to assign passed_mode and
nominal_mode with the mode of the built pointer type instead of the
hard-coded Pmode in the case of pass-by-reference.  This is in line with
the
assignment to passed_mode and nominal_mode in other cases inside the
function.

assign_parm_find_data_types generally uses TYPE_MODE to calculate
passed_mode and nominal_mode:

/* Find mode of arg as it is passed, and mode of arg as it should be
   during execution of this function.  */
passed_mode = TYPE_MODE (passed_type);
nominal_mode = TYPE_MODE (nominal_type);

this includes the case when the passed argument is a pointer by itself.

However there is a discrepancy when it deals with argument passed by
invisible reference; it builds the argument's corresponding pointer type,
but sets passed_mode and nominal_mode with Pmode directly.

This is OK for targets where Pmode == ptr_mode, but on AArch64 with ILP32
they are different with Pmode as DImode and ptr_mode as SImode. When such
a
reference is passed on stack, the reference is prepared by the caller in
the
lower 4 bytes of an 8-byte slot but is fetched by the callee as an 8-byte
datum, of which the higher 4 bytes may contain junk.  It is probably the
combination of Pmode != ptr_mode and the particular ABI specification
that
make the AArch64 ILP32 the first target on which the issue manifests
itself.

Bootstrapped on x86_64-none-linux-gnu.

OK for the trunk?




IA64-hpux also uses Pmode != ptr_mode, can you provide the testcase
which fails without this change?
I used a powerpc64 target where Pmode != ptr_mode which did not hit
this bug either.



The issue was firstly observed in one of the compat tests which passes a
large number of non-small structures.  The following is a trimmed-down
reproducible code snippet (although not runnable but shall be easy to be
make runnable):

struct s5
{
   double a;
   double b;
   double c;
   double d;
   double e;
} gS;

double foo (struct s5 p1, struct s5 p2,struct s5 p3,struct s5 p4,struct s5
p5,struct s5 p6,struct s5 p7,struct s5 p8, struct s5 p9)
{
   return p9.c;
}
--- CUT ---

The code-gen (-O2) without the patch is:

 .text
 .align  2
 .global foo
 .type   foo, %function
foo:
 ldr x0, [sp]<<=== here!
 ldr d0, [x0,16]
 ret
 .size   foo, .-foo

Where the arrow points is the load of the pointer to 'p9' that is passed on
stack.  The instruction really should be ldr w0, [sp], i.e. the pointer mode
is SImode rather than DImode.

It needs a number of conditions for the issue to manifest:

1. pass-by-reference; on aarch64 one example is a struct that is larger than
16 bytes.
2. the reference is passed on stack; on aarch64, this usually only happens
after registers x0 - x7 are used.
3. the size of stack slot for passing pointer is larger than the pointer
size; on aarch64, it is 8-byte vs. 4-byte
4. the unused part of the stack slot is not zeroed out, i.e. undefined by
the ABI


This is the real issue.  I think it is better if we change the ABI to
say they are zero'd.  It really makes things like this a mess.


5. in the runtime, the unused part of such a stack slot contains junk.

The runtime segmentation fault may only be generated when all the above
conditions are met.  I'm not familiar with IA64-hpux or powerpc64 procedure
call ABIs, but I guess those targets are just being lucky?


Or rather their ABIs all say are zero or sign extended for values less
than 8 byte wide.


One more thing, it looks like your change will not work correctly for
big-endian ILP32 AARCH64 either as the least significant word is
offsetted by 4.


Ah, this is definitely a bug and I can confirm that it only happens on 
the 32-bit pointer-type parameter passed on stack.  I'll bring up a 
patch today to fix it.



Did you test big-endian ILP32 AARCH64?


I started the big-endian testing fairly recently, so there is limited 
testing done so far but I am still working on it and will prepare 
patches if more issues are found.


Thanks,
Yufeng



Re: [Patch, AArch64, ILP32] 5/5 Define _ILP32 and __ILP32__

2013-06-26 Thread Joseph S. Myers
On Wed, 26 Jun 2013, Yufeng Zhang wrote:

> This patch defines _ILP32 and __ILP32__ for the AArch64 port when the ILP32
> ABI is in use.
> 
> This helps libraries, e.g. libgloss and glibc, recognize which model is being
> compiled.

GCC already defines _LP64 and __LP64__ in architecture-independent code 
for LP64 systems.  Libraries can use those to distinguish the two models 
for AArch64, so I don't see any need to add architecture-specific macros 
with the opposite sense.

-- 
Joseph S. Myers
jos...@codesourcery.com


Re: [C++] Implement DR1164

2013-06-26 Thread Jason Merrill

OK.

Jason


C++ PATCH for c++/57408 (ICE with invalid VLA capture)

2013-06-26 Thread Jason Merrill
We already added a helpful error message for this case, but we should 
also avoid crashing.


Tested x86_64-pc-linux-gnu, applying to trunk.
commit b87fed16be1aad58770349909ab8045088ed28ff
Author: Jason Merrill 
Date:   Fri Jun 21 08:28:49 2013 -0400

	PR c++/57408
	* semantics.c (add_capture): Set type to error_mark_node after
	error.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 0a460a4..4c76b80 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -9521,6 +9521,7 @@ add_capture (tree lambda, tree id, tree initializer, bool by_reference_p,
 	  && variably_modified_type_p (TREE_TYPE (type), NULL_TREE))
 	inform (input_location, "because the array element type %qT has "
 		"variable size", TREE_TYPE (type));
+  type = error_mark_node;
 }
   else if (by_reference_p)
 {
diff --git a/gcc/testsuite/g++.dg/cpp1y/vla9.C b/gcc/testsuite/g++.dg/cpp1y/vla9.C
new file mode 100644
index 000..ea5c4d8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/vla9.C
@@ -0,0 +1,31 @@
+// PR c++/57408
+// { dg-options "-std=c++1y -pedantic-errors" }
+
+template
+  struct Impl
+  {
+Callable func;
+Impl(Callable f) : func(f) { }
+virtual void run() { func(); }
+  };
+
+template
+void call(Callable f)
+  {
+Impl(f).run();
+  }
+
+extern "C" int printf(const char*, ...);
+
+int main(){
+int y = 2;
+float fa[2][y];	// { dg-error "array of array of runtime bound" }
+fa[0][0]=0.8;
+fa[0][1]=1.8;
+auto fx=[&](){
+for(int c=0; c<2; c++){
+printf("use me", fa[0][c]);	// { dg-error "capture of variable-size type" }
+}
+};
+call(fx);
+}


C++ PATCH to handling of overflow in in-class static member initializers

2013-06-26 Thread Jason Merrill
A question from a student of a committee member led me to notice that we 
were handling overflow in a class model of Fibonacci numbers oddly: 
C++11 says that arithmetic overflow causes an expression to not be 
constant, but instead of enforcing that on the actual affected variable 
initialization, we were initializing it fine and then preventing other 
expressions using that variable from being constant.


Checking this directly in store_init_value means we don't need to check 
in cp_finish_decl anymore.


Tested x86_64-pc-linux-gnu, applying to trunk.
commit 0bc5f82462c2a625608de5a69dcc54dbc08699c2
Author: Jason Merrill 
Date:   Sun Jun 23 06:15:20 2013 -0400

	* typeck2.c (store_init_value): Diagnose a non-constant
	initializer for in-class static.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index f562546..047fd77 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -6346,25 +6346,6 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
 	  cleanups = make_tree_vector ();
 	  init = check_initializer (decl, init, flags, &cleanups);
 
-	  /* Check that the initializer for a static data member was a
-	 constant.  Although we check in the parser that the
-	 initializer is an integral constant expression, we do not
-	 simplify division-by-zero at the point at which it
-	 occurs.  Therefore, in:
-
-	   struct S { static const int i = 7 / 0; };
-
-	 we issue an error at this point.  It would
-	 probably be better to forbid division by zero in
-	 integral constant expressions.  */
-	  if (DECL_EXTERNAL (decl) && init)
-	{
-	  error ("%qD cannot be initialized by a non-constant expression"
-		 " when being declared", decl);
-	  DECL_INITIALIZED_IN_CLASS_P (decl) = 0;
-	  init = NULL_TREE;
-	}
-
 	  /* Handle:
 
 	 [dcl.init]
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index a447893..7932939 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -775,7 +775,8 @@ store_init_value (tree decl, tree init, vec** cleanups, int flags)
   bool const_init;
   value = fold_non_dependent_expr (value);
   value = maybe_constant_init (value);
-  if (DECL_DECLARED_CONSTEXPR_P (decl))
+  if (DECL_DECLARED_CONSTEXPR_P (decl)
+	  || DECL_IN_AGGR_P (decl))
 	{
 	  /* Diagnose a non-constant initializer for constexpr.  */
 	  if (processing_template_decl
diff --git a/gcc/testsuite/g++.dg/cpp0x/overflow1.C b/gcc/testsuite/g++.dg/cpp0x/overflow1.C
new file mode 100644
index 000..7033e9c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/overflow1.C
@@ -0,0 +1,23 @@
+template 
+struct Fib
+{
+static const long long value // { dg-error "overflow" }
+= Fib::value + Fib::value;
+};
+
+template <>
+struct Fib<0>
+{
+   static const long long value = 0;
+};
+
+template <>
+struct Fib<1>
+{
+   static const long long value = 1;
+};
+
+int main()
+{
+  return Fib<95>::value;
+}
diff --git a/libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow_neg.cc b/libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow_neg.cc
index f0dcdec..f2f2330 100644
--- a/libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow_neg.cc
@@ -46,5 +46,6 @@ test02()
 // { dg-error "overflow in multiplication" "" { target *-*-* } 97 }
 // { dg-error "overflow in multiplication" "" { target *-*-* } 99 }
 // { dg-error "overflow in multiplication" "" { target *-*-* } 101 }
+// { dg-error "overflow in constant expression" "" { target *-*-* } 108 }
 // { dg-prune-output "out of range" }
 // { dg-prune-output "not usable in a constant expression" }


[PATCH] Improve jump threading using VRP information

2013-06-26 Thread Jeff Law


Just something else I saw while analyzing dumps from an unrelated set of 
changes.


It's relatively common to see sequences like this:

  # parent_1 = PHI 
  _11 = single_tree_10(D) != 0;
  _12 = parent_1 == 0B;
  _13 = _11 & _12;
  if (_13 != 0)
goto ;
  else
goto ;

Where VRP can deduce that the value of parent_6 has a nonzero value on 
one (or more) of the paths reaching this block (because those paths 
dereference parent_6).


Obviously when VRP knows parent_6 is nonzero, then we know the current 
block will always transfer control to BB 7.


Or something like this:

 :
  # prephitmp_49 = PHI <1(4), pretmp_48(5)>
  prev_line.31_6 = prev_line;
  _8 = prev_line.31_6 != line_7(D);
  line_differs_9 = (unsigned char) _8;
  _10 = prephitmp_49 | line_differs_9;
  if (_10 != 0)
goto ;
  else
goto ;


We may not know the exact value of _10, but VRP can determine that when 
BB6 is reached from BB4 that BB6 will always transfer control to BB8.



I never coded up the bits to utilize VRP information to simplify 
statements for threading except for COND_EXPRs.  It wasn't clear how 
often it would be useful, thus I took the easy way out.  This picks up a 
hundred or so additional threading opportunities in my testfiles.  Not 
huge, but worth it IMHO.


Bootstrapped and regression tested on x86_64-unknown-linux-gnu.

OK for trunk?



* tree-vrp.c (simplify_stmt_for_jump_threading): Try to
simplify assignments too.  If the RHS collapses to a singleton
range, then return the value for the range.

* gcc.dg/tree-ssa/ssa-vrp-thread-1.c: New test.

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-vrp-thread-1.c 
b/gcc/testsuite/gcc.dg/tree-ssa/ssa-vrp-thread-1.c
new file mode 100644
index 000..9d9473e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-vrp-thread-1.c
@@ -0,0 +1,31 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-vrp1-details" } */
+
+
+struct basic_block_def;
+typedef struct basic_block_def *basic_block;
+enum gimple_code
+{
+  LAST_AND_UNUSED_GIMPLE_CODE
+};
+struct omp_region
+{
+  struct omp_region *outer;
+  basic_block cont;
+};
+void
+build_omp_regions_1 (basic_block bb, struct omp_region *parent,
+unsigned char single_tree, enum gimple_code code)
+{
+  if (code == 25)
+parent = parent->outer;
+  else if (code == 42)
+parent->cont = bb;
+  if (single_tree && !parent)
+return;
+  oof ();
+}
+
+/* { dg-final { scan-tree-dump-times "Threaded" 1 "vrp1" }  } */
+/* { dg-final { cleanup-tree-dump "vrp1" } } */
+
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index ec7ef8f..683a3db 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -9109,15 +9109,27 @@ static vec equiv_stack;
 static tree
 simplify_stmt_for_jump_threading (gimple stmt, gimple within_stmt)
 {
-  /* We only use VRP information to simplify conditionals.  This is
- overly conservative, but it's unclear if doing more would be
- worth the compile time cost.  */
-  if (gimple_code (stmt) != GIMPLE_COND)
-return NULL;
+  if (gimple_code (stmt) == GIMPLE_COND)
+return vrp_evaluate_conditional (gimple_cond_code (stmt),
+gimple_cond_lhs (stmt),
+gimple_cond_rhs (stmt), within_stmt);
+
+  if (gimple_code (stmt) == GIMPLE_ASSIGN)
+{
+  value_range_t new_vr = VR_INITIALIZER;
+  tree lhs = gimple_assign_lhs (stmt);
+
+  if (TREE_CODE (lhs) == SSA_NAME
+ && (INTEGRAL_TYPE_P (TREE_TYPE (lhs))
+ || POINTER_TYPE_P (TREE_TYPE (lhs
+   {
+ extract_range_from_assignment (&new_vr, stmt);
+ if (range_int_cst_singleton_p (&new_vr))
+   return new_vr.min;
+   }
+}
 
-  return vrp_evaluate_conditional (gimple_cond_code (stmt),
-  gimple_cond_lhs (stmt),
-  gimple_cond_rhs (stmt), within_stmt);
+  return NULL_TREE;
 }
 
 /* Blocks which have more than one predecessor and more than


Re: [google/gcc-4_8] Port -Wreal-conversion warning

2013-06-26 Thread Sharad Singhai
I reverted the earlier broken patch. I am including an updated patch
which warns only for real conversion, not for integral conversions. I
also updated the test case to include an integral conversion (int to
char) which doesn't emit the warning with the -Wreal-conversion flag.

Bootstrapped and tested on x86_64. Okay for google/gcc-4_8?

Thanks,
Sharad

2013-06-26

* doc/invoke.texi: Document new option -Wreal-conversion.
* c-family/c.opt: Handle new option.
* c-family/c-opts.c (c_common_post_options): Ditto.
* c-family/c-common.c (conversion_warning): Ditto.

testsuite/ChangeLog:

* testsuite/gcc.dg/Wreal-conversion-1.c: New test.
* testsuite/g++.dg/warn/Wreal-conversion-1.C: Ditto.

Index: doc/invoke.texi
===
--- doc/invoke.texi (revision 200448)
+++ doc/invoke.texi (working copy)
@@ -237,7 +237,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wno-attributes -Wno-builtin-macro-redefined @gol
 -Wc++-compat -Wc++11-compat -Wcast-align  -Wcast-qual  @gol
 -Wchar-subscripts -Wclobbered  -Wcomment @gol
--Wconversion  -Wcoverage-mismatch  -Wno-cpp  -Wno-deprecated  @gol
+-Wconversion -Wreal-conversion -Wcoverage-mismatch  -Wno-cpp
-Wno-deprecated  @gol
 -Wno-deprecated-declarations -Wdisabled-optimization  @gol
 -Wno-div-by-zero -Wdouble-promotion -Wempty-body  -Wenum-compare @gol
 -Wno-endif-labels -Werror  -Werror=* @gol
@@ -4452,6 +4452,12 @@ reference to them. Warnings about conversions betw
 unsigned integers are disabled by default in C++ unless
 @option{-Wsign-conversion} is explicitly enabled.

+@item -Wreal-conversion
+@opindex Wreal-conversion
+@opindex Wno-real-conversion
+Warn for implicit type conversions from real (@code{double} or @code{float})
+to integral values. This warning is also enabled by @option{-Wconversion}.
+
 @item -Wno-conversion-null @r{(C++ and Objective-C++ only)}
 @opindex Wconversion-null
 @opindex Wno-conversion-null
Index: c-family/c.opt
===
--- c-family/c.opt (revision 200448)
+++ c-family/c.opt (working copy)
@@ -677,6 +677,10 @@ Wsign-compare
 C ObjC C++ ObjC++ EnabledBy(Wextra)
 ;

+Wreal-conversion
+C ObjC C++ ObjC++ Var(warn_real_conversion) Init(-1) Warning
EnabledBy(Wconversion)
+Warn for implicit type conversions from real to integral values
+
 Wsign-conversion
 C ObjC C++ ObjC++ Var(warn_sign_conversion) LangEnabledBy(C ObjC,Wconversion)
 Warn for implicit type conversions between signed and unsigned integers
Index: c-family/c-opts.c
===
--- c-family/c-opts.c (revision 200448)
+++ c-family/c-opts.c (working copy)
@@ -876,6 +876,12 @@ c_common_post_options (const char **pfilename)
   if (warn_packed_bitfield_compat == -1)
 warn_packed_bitfield_compat = 1;

+  /* Enable warning for converting real values to integral values
+ when -Wconversion is specified (unless disabled through
+ -Wno-real-conversion).  */
+  if (warn_real_conversion == -1)
+warn_real_conversion = warn_conversion;
+
   /* Special format checking options don't work without -Wformat; warn if
  they are used.  */
   if (!warn_format)
Index: c-family/c-common.c
===
--- c-family/c-common.c (revision 200448)
+++ c-family/c-common.c (working copy)
@@ -2665,12 +2665,22 @@ unsafe_conversion_p (tree type, tree expr, bool pr
 static void
 conversion_warning (tree type, tree expr)
 {
+  int warn_option;
   tree expr_type = TREE_TYPE (expr);
   location_t loc = EXPR_LOC_OR_HERE (expr);

-  if (!warn_conversion && !warn_sign_conversion)
+  if (!warn_conversion && !warn_sign_conversion && !warn_real_conversion)
 return;

+  /* When either type is a floating point type, warn with
+ -Wreal-conversion instead of -Wconversion (-Wreal-conversion is a
+ subset of -Wconversion that only warns for conversions of real
+ types to integral types).  */
+  warn_option = (warn_real_conversion
+ && (FLOAT_TYPE_P (type) || FLOAT_TYPE_P (expr_type)))
+? OPT_Wreal_conversion
+: OPT_Wconversion;
+
   switch (TREE_CODE (expr))
 {
 case EQ_EXPR:
@@ -2689,14 +2699,14 @@ conversion_warning (tree type, tree expr)
  can hold the values 0 and -1) doesn't lose information - but
  it does change the value.  */
   if (TYPE_PRECISION (type) == 1 && !TYPE_UNSIGNED (type))
- warning_at (loc, OPT_Wconversion,
+ warning_at (loc, warn_option,
 "conversion to %qT from boolean expression", type);
   return;

 case REAL_CST:
 case INTEGER_CST:
   if (unsafe_conversion_p (type, expr, true))
- warning_at (loc, OPT_Wconversion,
+ warning_at (loc, warn_option,
 "conversion to %qT alters %qT constant value",
 type, expr_type);
   return;
@@ -2715,7 +2725,7 @@ conversion_warning (tree type, tree expr)

 default: /* 'expr' is not a constant.  */
   if (unsafe_co

Re: [google/gcc-4_8] Port -Wreal-conversion warning

2013-06-26 Thread Xinliang David Li
Ok.

David

On Wed, Jun 26, 2013 at 10:16 PM, Sharad Singhai  wrote:
> I reverted the earlier broken patch. I am including an updated patch
> which warns only for real conversion, not for integral conversions. I
> also updated the test case to include an integral conversion (int to
> char) which doesn't emit the warning with the -Wreal-conversion flag.
>
> Bootstrapped and tested on x86_64. Okay for google/gcc-4_8?
>
> Thanks,
> Sharad
>
> 2013-06-26
>
> * doc/invoke.texi: Document new option -Wreal-conversion.
> * c-family/c.opt: Handle new option.
> * c-family/c-opts.c (c_common_post_options): Ditto.
> * c-family/c-common.c (conversion_warning): Ditto.
>
> testsuite/ChangeLog:
>
> * testsuite/gcc.dg/Wreal-conversion-1.c: New test.
> * testsuite/g++.dg/warn/Wreal-conversion-1.C: Ditto.
>
> Index: doc/invoke.texi
> ===
> --- doc/invoke.texi (revision 200448)
> +++ doc/invoke.texi (working copy)
> @@ -237,7 +237,7 @@ Objective-C and Objective-C++ Dialects}.
>  -Wno-attributes -Wno-builtin-macro-redefined @gol
>  -Wc++-compat -Wc++11-compat -Wcast-align  -Wcast-qual  @gol
>  -Wchar-subscripts -Wclobbered  -Wcomment @gol
> --Wconversion  -Wcoverage-mismatch  -Wno-cpp  -Wno-deprecated  @gol
> +-Wconversion -Wreal-conversion -Wcoverage-mismatch  -Wno-cpp
> -Wno-deprecated  @gol
>  -Wno-deprecated-declarations -Wdisabled-optimization  @gol
>  -Wno-div-by-zero -Wdouble-promotion -Wempty-body  -Wenum-compare @gol
>  -Wno-endif-labels -Werror  -Werror=* @gol
> @@ -4452,6 +4452,12 @@ reference to them. Warnings about conversions betw
>  unsigned integers are disabled by default in C++ unless
>  @option{-Wsign-conversion} is explicitly enabled.
>
> +@item -Wreal-conversion
> +@opindex Wreal-conversion
> +@opindex Wno-real-conversion
> +Warn for implicit type conversions from real (@code{double} or @code{float})
> +to integral values. This warning is also enabled by @option{-Wconversion}.
> +
>  @item -Wno-conversion-null @r{(C++ and Objective-C++ only)}
>  @opindex Wconversion-null
>  @opindex Wno-conversion-null
> Index: c-family/c.opt
> ===
> --- c-family/c.opt (revision 200448)
> +++ c-family/c.opt (working copy)
> @@ -677,6 +677,10 @@ Wsign-compare
>  C ObjC C++ ObjC++ EnabledBy(Wextra)
>  ;
>
> +Wreal-conversion
> +C ObjC C++ ObjC++ Var(warn_real_conversion) Init(-1) Warning
> EnabledBy(Wconversion)
> +Warn for implicit type conversions from real to integral values
> +
>  Wsign-conversion
>  C ObjC C++ ObjC++ Var(warn_sign_conversion) LangEnabledBy(C ObjC,Wconversion)
>  Warn for implicit type conversions between signed and unsigned integers
> Index: c-family/c-opts.c
> ===
> --- c-family/c-opts.c (revision 200448)
> +++ c-family/c-opts.c (working copy)
> @@ -876,6 +876,12 @@ c_common_post_options (const char **pfilename)
>if (warn_packed_bitfield_compat == -1)
>  warn_packed_bitfield_compat = 1;
>
> +  /* Enable warning for converting real values to integral values
> + when -Wconversion is specified (unless disabled through
> + -Wno-real-conversion).  */
> +  if (warn_real_conversion == -1)
> +warn_real_conversion = warn_conversion;
> +
>/* Special format checking options don't work without -Wformat; warn if
>   they are used.  */
>if (!warn_format)
> Index: c-family/c-common.c
> ===
> --- c-family/c-common.c (revision 200448)
> +++ c-family/c-common.c (working copy)
> @@ -2665,12 +2665,22 @@ unsafe_conversion_p (tree type, tree expr, bool pr
>  static void
>  conversion_warning (tree type, tree expr)
>  {
> +  int warn_option;
>tree expr_type = TREE_TYPE (expr);
>location_t loc = EXPR_LOC_OR_HERE (expr);
>
> -  if (!warn_conversion && !warn_sign_conversion)
> +  if (!warn_conversion && !warn_sign_conversion && !warn_real_conversion)
>  return;
>
> +  /* When either type is a floating point type, warn with
> + -Wreal-conversion instead of -Wconversion (-Wreal-conversion is a
> + subset of -Wconversion that only warns for conversions of real
> + types to integral types).  */
> +  warn_option = (warn_real_conversion
> + && (FLOAT_TYPE_P (type) || FLOAT_TYPE_P (expr_type)))
> +? OPT_Wreal_conversion
> +: OPT_Wconversion;
> +
>switch (TREE_CODE (expr))
>  {
>  case EQ_EXPR:
> @@ -2689,14 +2699,14 @@ conversion_warning (tree type, tree expr)
>   can hold the values 0 and -1) doesn't lose information - but
>   it does change the value.  */
>if (TYPE_PRECISION (type) == 1 && !TYPE_UNSIGNED (type))
> - warning_at (loc, OPT_Wconversion,
> + warning_at (loc, warn_option,
>  "conversion to %qT from boolean expression", type);
>return;
>
>  case REAL_CST:
>  case INTEGER_CST:
>if (unsafe_conversion_p (type, exp