[PATCH] Fix PR rtl-optimization/pr60663

2014-03-25 Thread Zhenqiang Chen
Hi,

The patch checks the number of the expected operands in
ASM_OPERANDS_TEMPLATE with the same logic as it in output_asm_insn to
make sure the ASM_OPERANDS are legal.

Bootstrap and no make check regression on X86-64 and ARM chromebook.

OK for trunk?

Thanks!
-Zhenqiang

ChangeLog:
2014-03-26  Zhenqiang Chen  

PR rtl-optimization/pr60663
* recog.c (check_asm_operands): Check the number of expected operands.

testsuite/ChangeLog:
2014-03-26  Zhenqiang Chen  

* gcc.dg/pr60663: New testcase.

diff --git a/gcc/recog.c b/gcc/recog.c
index f9040dc..65078ad 100644
--- a/gcc/recog.c
+++ b/gcc/recog.c
@@ -135,8 +135,8 @@ check_asm_operands (rtx x)
 {
   int noperands;
   rtx *operands;
-  const char **constraints;
-  int i;
+  const char **constraints, *templ;
+  int i, c;

   if (!asm_labels_ok (x))
 return 0;
@@ -159,7 +159,29 @@ check_asm_operands (rtx x)
   operands = XALLOCAVEC (rtx, noperands);
   constraints = XALLOCAVEC (const char *, noperands);

-  decode_asm_operands (x, operands, NULL, constraints, NULL, NULL);
+  templ = decode_asm_operands (x, operands, NULL, constraints, NULL, NULL);
+  /* The following logic is similar with it in output_asm_insn (final.c).
+ It checks the number of expected operands in ASM_OPERANDS_TEMPLATE.  */
+  if (*templ)
+{
+  const char* p = templ;
+  while ((c = *p++))
+   {
+ if (c == '%')
+   if (ISDIGIT (*p))
+ {
+   int opnum;
+   char *endptr;
+
+   opnum = strtoul (p, &endptr, 10);
+   if (opnum >= noperands)
+ return 0;
+
+p = endptr;
+c = *p;
+ }
+   }
+}

   for (i = 0; i < noperands; i++)
 {

diff --git a/gcc/testsuite/gcc.dg/pr60663.c b/gcc/testsuite/gcc.dg/pr60663.c
new file mode 100644
index 000..6c01084
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lp.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options " -O2 " } */
+
+int g (void)
+{
+  unsigned i, j;
+  asm("// %0 %1" : "=r" (i), "=r"(j));
+  return i;
+}


Re: [4.8, PATCH 0/26] Backport Power8 and LE support

2014-03-25 Thread Chris Johns

On 21/03/2014 1:05 pm, Bill Schmidt wrote:

For convenience of those who have kindly agreed to test the patch
series, here is the entire series as a single compressed patch.  Note
that this does not include patch 15/26, which we've agreed to submit
separately.


I have tested the patch with RTEMS head and see no change with our test 
results.


Chris



Re: [PATCH, doc] Mention nds32*-*-elf in the target specific installation notes.

2014-03-25 Thread Chung-Ju Wu
2014-03-24 23:47 GMT+08:00 Gerald Pfeifer :
> On Mon, 24 Mar 2014, Chung-Ju Wu wrote:
>> +2014-03-24  Chung-Ju Wu  
>> +
>> +   * doc/install.texi: Document nds32le-*-elf and nds32be-*-elf.
>
> Looks good to me.  (The new patch avoids "elf" which I believe should
> have been "ELF", by the way.)
>
> Gerald

Thanks for the comment.
In the future, I will use uppercase "ELF" instead.

And thank you for the approval.  Now it is committed as Rev. 208833:
http://gcc.gnu.org/r208833

Best regards,
jasonwucj


Re: [PATCH, doc] Add myself as NDS32 port contributor in the documentation.

2014-03-25 Thread Chung-Ju Wu
2014-03-24 20:07 GMT+08:00 Gerald Pfeifer :
> On Mon, 24 Mar 2014, Chung-Ju Wu wrote:
>> I would like to add an item to describe myself as nds32 port contributor.
>> The plaintext ChangeLog and patch are as below.
>> Bootstrapped and the webpage can be successfully built via 'make html'.
>>
>> Is it OK for trunk?
>
>> +2014-03-24  Chung-Ju Wu  
>> +
>> +   * doc/contrib.texi: Add myself as Andes nds32 port contributor.
>
> Yep, absolutely.
>
> Gerald

Thanks you so much.  Now it is committed as Rev. 208832.
http://http://gcc.gnu.org/r208832

Best regards,
jasonwucj


Fix PR ipa/60315 (inliner explosion)

2014-03-25 Thread Jan Hubicka
Hi,
this patch fixes compile time issue in the testcase that is caused by fact that 
the inliner
is repeatedly inlining into an call it earlier proved to be unreachable.  The 
analysis part
knows that such calls are not accounted into overall function summaries, but 
the transform
part sees them merely as cold calls and thus it attempts to do inlining for 
size.
This patch makes analysis part to practively redirect all known to be 
unreachable
calls to BUILTIN_UNREAHABLE.

Doing so uncovered the bug in ipa-pure-const I fixed earlier and also another
but in set_cond_stmt_execution_predicate where invert_tree_comparison is
called and the condition is used further. The function returns ERROR_MARK for FP
comparsions in some cases (though I think it should not since there seems to
be no toher way to invert comparsion without this and we have the unordered 
codes).
This concide with ipa-inline-analysis.c internal use of ERROR_MARK and leads to
inconsistent predicates.

Bootstrapped/regtested x86_64-linux, comitted.

PR ipa/60315
* cif-code.def (UNREACHABLE) New code.
* ipa-inline.c (inline_small_functions): Skip edges to 
__builtlin_unreachable.
(estimate_edge_growth): Allow edges to __builtlin_unreachable.
* ipa-inline-analysis.c (edge_set_predicate): Redirect edges with false
predicate to __bulitin_unreachable.
(set_cond_stmt_execution_predicate): Fix issue when 
invert_tree_comparison
returns ERROR_MARK.
* ipa-pure-const.c (propagate_pure_const, propagate_nothrow): Do not
propagate to inline clones.
* cgraph.c (verify_edge_corresponds_to_fndecl): Allow redirection
to unreachable.
* ipa-cp.c (create_specialized_node): Be ready for new node to appear.
* cgraphclones.c (cgraph_clone_node): If call destination is already
ureachable, do not redirect it back.
* tree-inline.c (fold_marked_statements): Hanlde calls becoming
unreachable.

* testsuite/g++.dg/torture/pr60315.C: New testcase.
Index: cif-code.def
===
--- cif-code.def(revision 208829)
+++ cif-code.def(working copy)
@@ -127,3 +127,7 @@ DEFCIFCODE(USES_COMDAT_LOCAL, CIF_FINAL_
 /* We can't inline because of mismatched caller/callee attributes.  */
 DEFCIFCODE(ATTRIBUTE_MISMATCH, CIF_FINAL_NORMAL,
   N_("function attribute mismatch"))
+
+/* We proved that the call is unreachable.  */
+DEFCIFCODE(UNREACHABLE, CIF_FINAL_NORMAL,
+  N_("unreachable"))
Index: cgraphclones.c
===
--- cgraphclones.c  (revision 208829)
+++ cgraphclones.c  (working copy)
@@ -238,8 +238,12 @@ cgraph_clone_node (struct cgraph_node *n
   FOR_EACH_VEC_ELT (redirect_callers, i, e)
 {
   /* Redirect calls to the old version node to point to its new
-version.  */
-  cgraph_redirect_edge_callee (e, new_node);
+version.  The only exception is when the edge was proved to
+be unreachable during the clonning procedure.  */
+  if (!e->callee
+ || DECL_BUILT_IN_CLASS (e->callee->decl) != BUILT_IN_NORMAL
+ || DECL_FUNCTION_CODE (e->callee->decl) != BUILT_IN_UNREACHABLE)
+cgraph_redirect_edge_callee (e, new_node);
 }
 
 
Index: ipa-inline.c
===
--- ipa-inline.c(revision 208829)
+++ ipa-inline.c(working copy)
@@ -1685,7 +1685,7 @@ inline_small_functions (void)
   edge = (struct cgraph_edge *) fibheap_extract_min (edge_heap);
   gcc_assert (edge->aux);
   edge->aux = NULL;
-  if (!edge->inline_failed)
+  if (!edge->inline_failed || !edge->callee->analyzed)
continue;
 
   /* Be sure that caches are maintained consistent.  
Index: ipa-inline.h
===
--- ipa-inline.h(revision 208829)
+++ ipa-inline.h(working copy)
@@ -285,7 +285,8 @@ static inline int
 estimate_edge_growth (struct cgraph_edge *edge)
 {
 #ifdef ENABLE_CHECKING
-  gcc_checking_assert (inline_edge_summary (edge)->call_stmt_size);
+  gcc_checking_assert (inline_edge_summary (edge)->call_stmt_size
+  || !edge->callee->analyzed);
 #endif
   return (estimate_edge_size (edge)
  - inline_edge_summary (edge)->call_stmt_size);
Index: testsuite/g++.dg/torture/pr60315.C
===
--- testsuite/g++.dg/torture/pr60315.C  (revision 0)
+++ testsuite/g++.dg/torture/pr60315.C  (revision 0)
@@ -0,0 +1,32 @@
+// { dg-do compile }
+struct Base {
+virtual int f() = 0;
+};
+
+struct Derived : public Base {
+virtual int f() final override {
+return 42;
+}
+};
+
+extern Base* b;
+
+int main() {
+return (static_cast(b)->*(&Derived::f))();
+}
+// { dg-do compile }
+struct Base {
+virtual int f() 

Re: [PATCH] Update the overall summary after edge_summary is updated

2014-03-25 Thread Jan Hubicka
> On Sat, Mar 22, 2014 at 6:32 PM, Jan Hubicka  wrote:
> >> Hi,
> >>
> >> This patch updates node's inline summary after edge_summary is
> >> updated. Otherwise it could lead to incorrect inline summary.
> >>
> >> Bootstrapped and gcc regression test on-going.
> >>
> >> OK for trunk?
> >>
> >> Thanks,
> >> Dehao
> >>
> >> gcc/ChangeLog:
> >>
> >> 2014-03-21  Dehao Chen  
> >>
> >> *ipa-inline.c (early_inliner): updates overall summary.
> >
> > Looks resonable, do you have testcase where it would make a difference?
> 
> Sorry, no small test case because this depends on autofdo profile.
> 
> The problem actually does not manifest in trunk unless einline
> iterations is increased to >1
> 

Hmm, OK, then you can avoid the update when we are running the last iteration.

OK with that change.
Honza

> Thanks,
> Dehao
> 
> >
> > Honza
> >>
> >> Index: gcc/ipa-inline.c
> >> ===
> >> --- gcc/ipa-inline.c (revision 208755)
> >> +++ gcc/ipa-inline.c (working copy)
> >> @@ -2318,6 +2318,7 @@ early_inliner (void)
> >>edge->call_stmt, edge->callee->decl, false))
> >>   edge->call_stmt_cannot_inline_p = true;
> >>  }
> >> +  inline_update_overall_summary (node);
> >>timevar_pop (TV_INTEGRATION);
> >>iterations++;
> >>inlined = false;


Re: [PATCH] Fix --with-build-config=bootstrap-ubsan bootstrap of lto-plugin (PR sanitizer/56781)

2014-03-25 Thread H.J. Lu
On Tue, Mar 25, 2014 at 3:11 PM, Jakub Jelinek  wrote:
> On Tue, Mar 25, 2014 at 03:01:26PM -0700, H.J. Lu wrote:
>> I got
>>
>> /export/gnu/import/git/gcc/libiberty/configure: line 4977: syntax
>> error near unexpected token `-fsanitize=address'
>> /export/gnu/import/git/gcc/libiberty/configure: line 4977: `  *
>> -fsanitize=address *) NOASANFLAG=-fno-sanitize=address ;;'
>> checking fcntl.h usability... yes
>
> Oops, should have been
> case " ${CFLAGS} " in
>   *\ -fsanitize=address\ *) NOASANFLAG=-fno-sanitize=address ;;
> esac
> instead of
> case " ${CFLAGS} " in
>   * -fsanitize=address *) NOASANFLAG=-fno-sanitize=address ;;
> esac
> I guess.
>
> 2014-03-25  Jakub Jelinek  
>
> PR sanitizer/56781
> lto-plugin/
> * Makefile.am (CFLAGS, LDFLAGS): Filter out -fsanitize=address.
> (liblto_plugin_la_LIBADD, liblto_plugin_la_LDFLAGS,
> liblto_plugin_la_DEPENDENCIES): Prefer ../libiberty/noasan/libiberty.a
> over ../libiberty/pic/libiberty.a if the former exists.
> * Makefile.in: Regenerated.
> libiberty/
> * maint-tool: Also emit rule for noasan/ subdirectory.
> * configure.ac (NOASANFLAG): Set and substitute.
> * Makefile.in: Regenerated.
> (NOASANFLAG): Set.
> (all, $(TARGETLIB), mostlyclean): Handle noasan subdir like pic
> subdir.
> (stamp-noasandir): New goal.
> * configure: Regenerated.
>

Doesn't work:

libtool: link:
/export/build/gnu/gcc-asan/build-x86_64-linux/./prev-gcc/xgcc
-B/export/build/gnu/gcc-asan/build-x86_64-linux/./prev-gcc/
-B/usr/local/x86_64-unknown-linux-gnu/bin/
-B/usr/local/x86_64-unknown-linux-gnu/bin/
-B/usr/local/x86_64-unknown-linux-gnu/lib/ -isystem
/usr/local/x86_64-unknown-linux-gnu/include -isystem
/usr/local/x86_64-unknown-linux-gnu/sys-include-shared
.libs/lto-plugin.o-static-libgcc -static-libstdc++ -static-libgcc
-fsanitize=address -static-libasan
-B/export/build/gnu/gcc-asan/build-x86_64-linux/prev-x86_64-unknown-linux-gnu/libsanitizer/
-B/export/build/gnu/gcc-asan/build-x86_64-linux/prev-x86_64-unknown-linux-gnu/libsanitizer/asan/
-B/export/build/gnu/gcc-asan/build-x86_64-linux/prev-x86_64-unknown-linux-gnu/libsanitizer/asan/.libs
../libiberty/noasan/libiberty.a   -Wl,-soname -Wl,liblto_plugin.so.0
-o .libs/liblto_plugin.so.0.0.0
...

/usr/local/x86_64-unknown-linux-gnu/bin/ld:
/export/build/gnu/gcc-asan/build-x86_64-linux/./gcc/liblto_plugin.so:
error loading plugin:
/export/build/gnu/gcc-asan/build-x86_64-linux/./gcc/liblto_plugin.so:
undefined symbol: __asan_option_detect_stack_use_after_return
collect2: error: ld returned 1 exit status
make[5]: *** [libgcc_s.so] Error 1


-- 
H.J.


Re: [PATCH] Update the overall summary after edge_summary is updated

2014-03-25 Thread Dehao Chen
On Sat, Mar 22, 2014 at 6:32 PM, Jan Hubicka  wrote:
>> Hi,
>>
>> This patch updates node's inline summary after edge_summary is
>> updated. Otherwise it could lead to incorrect inline summary.
>>
>> Bootstrapped and gcc regression test on-going.
>>
>> OK for trunk?
>>
>> Thanks,
>> Dehao
>>
>> gcc/ChangeLog:
>>
>> 2014-03-21  Dehao Chen  
>>
>> *ipa-inline.c (early_inliner): updates overall summary.
>
> Looks resonable, do you have testcase where it would make a difference?

Sorry, no small test case because this depends on autofdo profile.

The problem actually does not manifest in trunk unless einline
iterations is increased to >1

Thanks,
Dehao

>
> Honza
>>
>> Index: gcc/ipa-inline.c
>> ===
>> --- gcc/ipa-inline.c (revision 208755)
>> +++ gcc/ipa-inline.c (working copy)
>> @@ -2318,6 +2318,7 @@ early_inliner (void)
>>edge->call_stmt, edge->callee->decl, false))
>>   edge->call_stmt_cannot_inline_p = true;
>>  }
>> +  inline_update_overall_summary (node);
>>timevar_pop (TV_INTEGRATION);
>>iterations++;
>>inlined = false;


Re: [Build, Driver] Add -lcilkrts for -fcilkplus

2014-03-25 Thread Tobias Burnus

Paolo Bonzini wrote:

Il 11/03/2014 07:42, Tobias Burnus ha scritto:

+XPCFLAGS=""
+CFLAGS="$CFLAGS -pthread"
+AC_LINK_IFELSE(
...
+ [XPCFLAGS=" -Wc,-pthread"],

XPCFLAGS is dead, I think?


Yes - contrary to libgomp, from which I have taken that code block. I 
have now removed it.



Also, should -pthread be included in the spec too?


Regarding -pthreads: That should already be included via gcc/gcc.c:

+#define CILK_SELF_SPECS "%{fcilkplus: -pthread}"

 static const char *const driver_self_specs[] = {
...
CILK_SELF_SPECS
 };

Updated patch below (nongenerated libcilkrts only).

Tobias

2014-03-24  Tobias Burnus  

	* libcilkrts.spec.in: New.
	* Makefile.am: Handle libcilkrts.spec.
	* configure.ac: Determine link options for libcilkrts.spec.
	* Makefile.in: Regenerate.
	* configure: Regenerate.

diff --git a/libcilkrts/Makefile.am b/libcilkrts/Makefile.am
index f2d13aa..84551c8 100644
--- a/libcilkrts/Makefile.am
+++ b/libcilkrts/Makefile.am
@@ -51,6 +51,7 @@ AM_LDFLAGS = -lpthread
 gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER)
 
 # Target list.
+nodist_toolexeclib_HEADERS = libcilkrts.spec
 toolexeclib_LTLIBRARIES = libcilkrts.la
 
 libcilkrts_la_SOURCES =\
diff --git a/libcilkrts/configure.ac b/libcilkrts/configure.ac
index 61b45b0..fb21505 100644
--- a/libcilkrts/configure.ac
+++ b/libcilkrts/configure.ac
@@ -49,7 +49,7 @@ AC_PROG_CC
 AC_PROG_CXX
 # AC_PROG_LIBTOOL
 # AC_CONFIG_MACRO_DIR([..])
-AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([Makefile libcilkrts.spec])
 AM_ENABLE_MULTILIB(, ..)
 AC_FUNC_ALLOCA
 
@@ -183,6 +183,32 @@ AC_LINK_IFELSE(
   AC_DEFINE(HAVE_PTHREAD_AFFINITY_NP, 1,
 [   Define if pthread_{,attr_}{g,s}etaffinity_np is supported.]))
 
+# Check to see if -pthread or -lpthread is needed.  Prefer the former.
+# Note that the CILK_SELF_SPEC in gcc.c may force -pthread.
+# In case the pthread.h system header is not found, this test will fail.
+CFLAGS="$CFLAGS -pthread"
+AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+  [#include 
+   void *g(void *d) { return NULL; }],
+  [pthread_t t; pthread_create(&t,NULL,g,NULL);])],
+ [],
+ [CFLAGS="$save_CFLAGS" LIBS="-lpthread $LIBS"
+  AC_LINK_IFELSE(
+   [AC_LANG_PROGRAM(
+[#include 
+ void *g(void *d) { return NULL; }],
+[pthread_t t; pthread_create(&t,NULL,g,NULL);])],
+   [],
+   [AC_MSG_ERROR([Pthreads are required to build libcilkrts])])])
+
+if test $enable_shared = yes; then
+  link_cilkrts="-lcilkrts %{static: $LIBS}"
+else
+  link_cilkrts="-lcilkrts $LIBS"
+fi
+AC_SUBST(link_cilkrts)
+
 
 # Must be last
 AC_OUTPUT
diff --git a/libcilkrts/libcilkrts.spec.in b/libcilkrts/libcilkrts.spec.in
new file mode 100644
index 000..b98cce9
--- /dev/null
+++ b/libcilkrts/libcilkrts.spec.in
@@ -0,0 +1,3 @@
+# This spec file is read by gcc when linking.  It is used to specify the
+# standard libraries we need in order to link with libcilkrts.
+*link_cilkrts: @link_cilkrts@


Re: Please revert the patches in bug #54040 and #59346 and special case x32

2014-03-25 Thread Eric Botcazou
> Should I file a bug to get feedback on this issue? I know Ada is not the
> most prioritized language for gcc, but anyway. The current
> implementation is not POSIX-compliant.

Can you post a complete patch doing the reversion?  Breaking POSIX and every 
Unix for the sake of x32 is definitely too much in my opinion.

-- 
Eric Botcazou


Re: [Fortran][PATCH][gomp4]: Transform OpenACC loop directive

2014-03-25 Thread Tobias Burnus

Hi Ilmir,

Ilmir Usmanov wrote:
For DO CONCURRENT, it is not. 

I always forget about this kind of loops.


And I tend to forget about the issues with mask as I don't use do 
concurrent with mask.



* And do concurrent also supports masks:

logical :: my_mask(3)
integer :: i, b(3)
b(i) = [5, 5, 2]
my_mask = [.true., .false., .true.]
do concurrent (i=1:3, b(i) == 5 .and. my_mask(i))
  b(i) = -42
end do
end
This is doable: generate mask conditions inside of the deepest for 
loop (see applied patch). So, GENERIC of your example will be like:

#pragma acc loop collapse(1)
for (i = 1; i < 3; i++)
  {
if (b[i-1] == 5 && my_mask[i-1])
  {
b[i-1] = -42;
  }
  }


That will work in the most common cases but not in general. At least it 
is my understanding that Fortran requires that one first evaluates the 
mask expression before one enters the loop. That's made explicit for 
FORALL and DO CONCURRENT uses a forall header and does some refs to 
FORALL (esp. 7.2.4.2.2 and 7.2.4.2.3), but it does not state so explicitly.


In particular, the following example shows a difference between creating 
a temporary array for the mask and putting the condition in the loop 
without a temporary. On my system, the example will give:

   1  -1 -20  -2 -30
 -10  -1 -20  -2 -30

I think you willl get the same result as on line 1 instead of the one of 
line two. Thus, one will need a temporary (cf. PR60661 for a 
missed-optimization tracking to avoid the temporary.)



Example:

implicit none
integer :: i, n
integer :: b(5)

n = 5

b = [1, -1, 2, -2, 3]
do i = 1, n
  if (.not. (b(i) > 0)) cycle
  b(n-i+1) = b(n-i+1)*(-10)
end do
print *, b

b = [1, -1, 2, -2, 3]
do concurrent (i = 1:n, b(i) > 0)
  b(n-i+1) = b(n-i+1)*(-10)
end do
print *, b
end

Otherwise, the patch looks good to me.

Tobias


Re: [GOOGLE] Refactor the LIPO fixup

2014-03-25 Thread Xinliang David Li
Add comment to the new function. init_node_map is better invoked after
the link step to avoid creating entries with for dead nodes.

Ok if large perf testing is fine.

David

On Tue, Mar 25, 2014 at 3:38 PM, Dehao Chen  wrote:
> This patch refactors LIPO fixup related code to move it into a
> standalone function. This makes sure that
> symtab_remove_unreachable_nodes is called right after the fixup so
> that there is not dangling cgraph nodes any time.
>
> Bootstrapped and regression test on-going.
>
> OK for google-4_8?
>
> Thanks,
> Dehao


Re: [PATCH] Fix undefined behavior in IRA

2014-03-25 Thread Vladimir Makarov

On 2014-03-25, 12:14 PM, Marek Polacek wrote:

This is a temporary fix for UB in IRA, where ubsan complains because
there's signed iteger overflow in the multiplication.  To shut this
error up, we can perform the multiplication in unsigned and only then
cast the result of the multiplication to int.

Regtested/bootstrapped on x86_64-linux, ok for trunk?



Ok. Thanks, Marek.


2014-03-25  Marek Polacek  

PR other/59545
* ira-color.c (update_conflict_hard_regno_costs): Perform the
multiplication in unsigned type.






[GOOGLE] Refactor the LIPO fixup

2014-03-25 Thread Dehao Chen
This patch refactors LIPO fixup related code to move it into a
standalone function. This makes sure that
symtab_remove_unreachable_nodes is called right after the fixup so
that there is not dangling cgraph nodes any time.

Bootstrapped and regression test on-going.

OK for google-4_8?

Thanks,
Dehao
Index: gcc/tree-profile.c
===
--- gcc/tree-profile.c  (revision 208818)
+++ gcc/tree-profile.c  (working copy)
@@ -1119,18 +1119,12 @@ tree_profiling (void)
  cgraphunit.c:ipa_passes().  */
   gcc_assert (cgraph_state == CGRAPH_STATE_IPA_SSA);
 
+  init_node_map ();
+
   /* After value profile transformation, artificial edges (that keep
  function body from being deleted) won't be needed.  */
+  lipo_link_and_fixup ();
 
-  cgraph_pre_profiling_inlining_done = true;
-  cgraph_process_module_scope_statics ();
-  /* Now perform link to allow cross module inlining.  */
-  cgraph_do_link ();
-  varpool_do_link ();
-  cgraph_unify_type_alias_sets ();
-
-  init_node_map();
-
   FOR_EACH_DEFINED_FUNCTION (node)
 {
   if (!gimple_has_body_p (node->symbol.decl))
@@ -1142,23 +1136,6 @@ tree_profiling (void)
 
   push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
 
-  if (L_IPO_COMP_MODE)
-{
-  basic_block bb;
-  FOR_EACH_BB (bb)
-{
-  gimple_stmt_iterator gsi;
-  for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
-{
-  gimple stmt = gsi_stmt (gsi);
-  if (is_gimple_call (stmt))
-lipo_fixup_cgraph_edge_call_target (stmt);
-}
-   }
-  update_ssa (TODO_update_ssa);
-   }
-
-
   /* Local pure-const may imply need to fixup the cfg.  */
   if (execute_fixup_cfg () & TODO_cleanup_cfg)
cleanup_tree_cfg ();
Index: gcc/l-ipo.h
===
--- gcc/l-ipo.h (revision 208818)
+++ gcc/l-ipo.h (working copy)
@@ -60,7 +60,7 @@ void add_decl_to_current_module_scope (tree decl,
 int lipo_cmp_type (tree t1, tree t2);
 tree get_type_or_decl_name (tree);
 int equivalent_struct_types_for_tbaa (const_tree t1, const_tree t2);
-void lipo_fixup_cgraph_edge_call_target (gimple);
+void lipo_link_and_fixup (void);
 extern void copy_defined_module_set (tree, tree);
 extern bool is_parsing_done_p (void);
 extern const char* get_module_name (unsigned int);
Index: gcc/auto-profile.c
===
--- gcc/auto-profile.c  (revision 208818)
+++ gcc/auto-profile.c  (working copy)
@@ -1535,14 +1535,8 @@ auto_profile (void)
 
   init_node_map ();
   profile_info = autofdo::afdo_profile_info;
+  lipo_link_and_fixup ();
 
-  cgraph_pre_profiling_inlining_done = true;
-  cgraph_process_module_scope_statics ();
-  /* Now perform link to allow cross module inlining.  */
-  cgraph_do_link ();
-  varpool_do_link ();
-  cgraph_unify_type_alias_sets ();
-
   FOR_EACH_FUNCTION (node)
 {
   if (!gimple_has_body_p (node->symbol.decl))
@@ -1554,35 +1548,6 @@ auto_profile (void)
 
   push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
 
-  if (L_IPO_COMP_MODE)
-   {
- basic_block bb;
- FOR_EACH_BB (bb)
-   {
- gimple_stmt_iterator gsi;
- for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
-   {
- gimple stmt = gsi_stmt (gsi);
- if (is_gimple_call (stmt))
-   lipo_fixup_cgraph_edge_call_target (stmt);
-   }
-   }
-   }
-  rebuild_cgraph_edges ();
-  pop_cfun ();
-}
-
-  FOR_EACH_FUNCTION (node)
-{
-  if (!gimple_has_body_p (node->symbol.decl))
-   continue;
-
-  /* Don't profile functions produced for builtin stuff.  */
-  if (DECL_SOURCE_LOCATION (node->symbol.decl) == BUILTINS_LOCATION)
-   continue;
-
-  push_cfun (DECL_STRUCT_FUNCTION (node->symbol.decl));
-
   /* First do indirect call promotion and early inline to make the
 IR match the profiled binary before actual annotation.
 
Index: gcc/cgraphbuild.c
===
--- gcc/cgraphbuild.c   (revision 208818)
+++ gcc/cgraphbuild.c   (working copy)
@@ -599,7 +599,7 @@ record_references_in_initializer (tree decl, bool
needs to be set to the resolved node so that ipa-inline
sees the definitions.  */
 #include "gimple-pretty-print.h"
-void
+static void
 lipo_fixup_cgraph_edge_call_target (gimple stmt)
 {
   tree decl;
@@ -625,6 +625,52 @@ lipo_fixup_cgraph_edge_call_target (gimple stmt)
 }
 }
 
+void
+lipo_link_and_fixup ()
+{
+  struct cgraph_node *node;
+
+  cgraph_pre_profiling_inlining_done = true;
+  cgraph_process_module_scope_statics ();
+  /* Now perform link to allow cross module inlining.  */
+  cgraph_do_link ();
+  varpool_do_link ();
+  cgraph

Re: [DOC PATCH] Amend designated inits doc (PR c/39525)

2014-03-25 Thread Joseph S. Myers
On Tue, 25 Mar 2014, Marek Polacek wrote:

> Apparently some users would like to see what happens to omitted field
> members when initializing a structure in GCC docs.
> 
> Ok for trunk?
> 
> 2014-03-25  Marek Polacek  
> 
>   PR c/39525
>   * doc/extend.texi (Designated Inits): Describe what happens to omitted
>   field members.

OK.

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


Re: [DOC PATCH] Describe VLAs in struct/union (PR c/37428)

2014-03-25 Thread Joseph S. Myers
On Tue, 25 Mar 2014, Marek Polacek wrote:

> We should mention this GNU C extension in the manual.
> 
> Ok?
> 
> 2014-03-25  Marek Polacek  
> 
>   PR c/37428
>   * doc/extend.texi (C Extensions): Mention variable-length arrays in
>   a structure/union.

OK.

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


Re: [PATCH] Fix --with-build-config=bootstrap-ubsan bootstrap of lto-plugin (PR sanitizer/56781)

2014-03-25 Thread H.J. Lu
On Tue, Mar 25, 2014 at 2:32 PM, Jakub Jelinek  wrote:
> On Tue, Mar 25, 2014 at 09:17:07PM +0100, Jakub Jelinek wrote:
>> On Tue, Mar 25, 2014 at 08:57:21PM +0100, Jakub Jelinek wrote:
>> > It works fine for ubsan, and your fix is not the right thing to do,
>> > e.g. bootstrap-ubsan reveals some bugs in libiberty which would be 
>> > otherwise
>> > unnoticed if you always filter away the sanitizing options from libiberty.
>> >
>> > So, I think my patch is the right thing to do for ubsan bootstraps, and for
>> > asan bootstraps we'll need something different (build libiberty twice, or
>> > build selected libiberty objects inside lto-plugin/ directory again, or
>> > something similar).  You do want the libiberty parts in cc1, cc1plus, xgcc
>> > etc. instrumented.
>>
>> Seems libiberty builds (optionally) everything also into pic/ subdirectory,
>> I think best would be if it in case it found -fsanitize=address in CFLAGS
>> also built everything into noasan/ subdirectory with additional
>> -fno-sanitize=address, and filter out -fsanitize=address just in lto-plugin
>> Makefile and use noasan/libiberty.a preferrably over pic/libiberty.a over
>> libiberty.a.
>> I guess I can cook up a patch tomorrow for that, though probably won't have
>> cycles to fully test that.
>
> Here is completely untested patch that should do that (on top of the two
> PR56781 patches I've posted earlier today).  Can you give them a shot?
>
> 2014-03-25  Jakub Jelinek  
>
> PR sanitizer/56781
> lto-plugin/
> * Makefile.am (CFLAGS, LDFLAGS): Filter out -fsanitize=address.
> (liblto_plugin_la_LIBADD, liblto_plugin_la_LDFLAGS,
> liblto_plugin_la_DEPENDENCIES): Prefer ../libiberty/noasan/libiberty.a
> over ../libiberty/pic/libiberty.a if the former exists.
> * Makefile.in: Regenerated.
> libiberty/
> * maint-tool: Also emit rule for noasan/ subdirectory.
> * configure.ac (NOASANFLAG): Set and substitute.
> * Makefile.in: Regenerated.
> (NOASANFLAG): Set.
> (all, $(TARGETLIB), mostlyclean): Handle noasan subdir like pic
> subdir.
> (stamp-noasandir): New goal.
> * configure: Regenerated.
>

I got

/export/gnu/import/git/gcc/libiberty/configure: line 4977: syntax
error near unexpected token `-fsanitize=address'
/export/gnu/import/git/gcc/libiberty/configure: line 4977: `  *
-fsanitize=address *) NOASANFLAG=-fno-sanitize=address ;;'
checking fcntl.h usability... yes

H.J.


[DOC PATCH] Amend designated inits doc (PR c/39525)

2014-03-25 Thread Marek Polacek
Apparently some users would like to see what happens to omitted field
members when initializing a structure in GCC docs.

Ok for trunk?

2014-03-25  Marek Polacek  

PR c/39525
* doc/extend.texi (Designated Inits): Describe what happens to omitted
field members.

diff --git gcc/doc/extend.texi gcc/doc/extend.texi
index c0da713..90bf6d8 100644
--- gcc/doc/extend.texi
+++ gcc/doc/extend.texi
@@ -1967,6 +1967,9 @@ Another syntax that has the same meaning, obsolete since 
GCC 2.5, is
 struct point p = @{ y: yvalue, x: xvalue @};
 @end smallexample
 
+Omitted field members are implicitly initialized the same as objects
+that have static storage duration.
+
 @cindex designators
 The @samp{[@var{index}]} or @samp{.@var{fieldname}} is known as a
 @dfn{designator}.  You can also use a designator (or the obsolete colon

Marek


Fix wrong code issue in ipa-pure-const

2014-03-25 Thread Jan Hubicka
Hi,
this patch fixes issue I run into while working on other fix. ipa-pure-const is 
happy
to make inline clone pure when it proves it is, but because decls are shared 
with master
clone, it actually makes offline copy and the master clone pure, too.
This may lead to wrong code issues if function contains indirect call and only 
in some
instances this call was resolved to call to a pure function.

Bootstrapped/regtested x86_64-linux, will commit it shortly.

Honza

* ipa-pure-const.c (propagate_pure_const, propagate_nothrow):
Do not modify inline clones.
Index: ipa-pure-const.c
===
--- ipa-pure-const.c(revision 208802)
+++ ipa-pure-const.c(working copy)
@@ -1327,35 +1327,39 @@ propagate_pure_const (void)
  w_l->pure_const_state = this_state;
  w_l->looping = this_looping;
 
- switch (this_state)
-   {
-   case IPA_CONST:
- if (!TREE_READONLY (w->decl))
-   {
- warn_function_const (w->decl, !this_looping);
- if (dump_file)
-   fprintf (dump_file, "Function found to be %sconst: %s\n",
-this_looping ? "looping " : "",
-w->name ());
-   }
- cgraph_set_const_flag (w, true, this_looping);
- break;
+ /* Inline clones share declaration with their offline copies;
+do not modify their declarations since the offline copy may
+be different.  */
+ if (!w->global.inlined_to)
+   switch (this_state)
+ {
+ case IPA_CONST:
+   if (!TREE_READONLY (w->decl))
+ {
+   warn_function_const (w->decl, !this_looping);
+   if (dump_file)
+ fprintf (dump_file, "Function found to be %sconst: %s\n",
+  this_looping ? "looping " : "",
+  w->name ());
+ }
+   cgraph_set_const_flag (w, true, this_looping);
+   break;
 
-   case IPA_PURE:
- if (!DECL_PURE_P (w->decl))
-   {
- warn_function_pure (w->decl, !this_looping);
- if (dump_file)
-   fprintf (dump_file, "Function found to be %spure: %s\n",
-this_looping ? "looping " : "",
-w->name ());
-   }
- cgraph_set_pure_flag (w, true, this_looping);
- break;
+ case IPA_PURE:
+   if (!DECL_PURE_P (w->decl))
+ {
+   warn_function_pure (w->decl, !this_looping);
+   if (dump_file)
+ fprintf (dump_file, "Function found to be %spure: %s\n",
+  this_looping ? "looping " : "",
+  w->name ());
+ }
+   cgraph_set_pure_flag (w, true, this_looping);
+   break;
 
-   default:
- break;
-   }
+ default:
+   break;
+ }
  w_info = (struct ipa_dfs_info *) w->aux;
  w = w_info->next_cycle;
}
@@ -1448,10 +1452,16 @@ propagate_nothrow (void)
  funct_state w_l = get_function_state (w);
  if (!can_throw && !TREE_NOTHROW (w->decl))
{
- cgraph_set_nothrow_flag (w, true);
- if (dump_file)
-   fprintf (dump_file, "Function found to be nothrow: %s\n",
-w->name ());
+ /* Inline clones share declaration with their offline copies;
+do not modify their declarations since the offline copy may
+be different.  */
+ if (!w->global.inlined_to)
+   {
+ cgraph_set_nothrow_flag (w, true);
+ if (dump_file)
+   fprintf (dump_file, "Function found to be nothrow: %s\n",
+w->name ());
+   }
}
  else if (can_throw && !TREE_NOTHROW (w->decl))
w_l->can_throw = true;


[PATCH] Perform ubsan instrumentation for x >= 0 ? x : -x (take 2)

2014-03-25 Thread Jakub Jelinek
On Tue, Mar 25, 2014 at 10:43:02AM +0100, Richard Biener wrote:
> Yes, all transforms in fold-const would be invalid if the result doesn't
> behave in the same way wrt overflow.  Thus you really should instrument
> ABS_EXPR - you can treat it as A > 0 ? A : -A if that simplifies it.
> 
> I don't like the conditions that disable stuff based on sanitization.
> 
> Instrumenting ABS_EXPR shouldn't be too difficult.

Ok, here is a patch that does that.  Tested on x86_64-linux and i686-linux.
Ok for trunk?

2014-03-25  Jakub Jelinek  

PR sanitizer/60636
* ubsan.c (instrument_si_overflow): Instrument ABS_EXPR.

* c-c++-common/ubsan/pr60636.c: New test.

--- gcc/ubsan.c.jj  2014-03-19 14:44:23.0 +0100
+++ gcc/ubsan.c 2014-03-25 13:00:35.052459078 +0100
@@ -737,6 +737,21 @@ instrument_si_overflow (gimple_stmt_iter
   gimple_call_set_lhs (g, lhs);
   gsi_replace (&gsi, g, false);
   break;
+case ABS_EXPR:
+  /* Transform i = ABS_EXPR;
+into
+_N = UBSAN_CHECK_SUB (0, u);
+i = ABS_EXPR<_N>;  */
+  a = build_int_cst (lhstype, 0);
+  b = gimple_assign_rhs1 (stmt);
+  g = gimple_build_call_internal (IFN_UBSAN_CHECK_SUB, 2, a, b);
+  a = make_ssa_name (lhstype, NULL);
+  gimple_call_set_lhs (g, a);
+  gimple_set_location (g, gimple_location (stmt));
+  gsi_insert_before (&gsi, g, GSI_SAME_STMT);
+  gimple_assign_set_rhs1 (stmt, a);
+  update_stmt (stmt);
+  break;
 default:
   break;
 }
--- gcc/testsuite/c-c++-common/ubsan/pr60636.c.jj   2014-03-25 
12:31:29.458629212 +0100
+++ gcc/testsuite/c-c++-common/ubsan/pr60636.c  2014-03-25 12:31:29.458629212 
+0100
@@ -0,0 +1,15 @@
+/* PR sanitizer/60636 */
+/* { dg-do run } */
+/* { dg-options "-fsanitize=undefined" } */
+
+volatile long long int a;
+
+int
+main ()
+{
+  long long int u = -__LONG_LONG_MAX__ - 1;
+  a = u > 0 ? u : -u;
+  return 0;
+}
+
+/* { dg-output "negation of -9223372036854775808 cannot be represented in type 
'long long int'" } */


Jakub


[DOC PATCH] Fix up __builtin_ffs* args (PR c/50347)

2014-03-25 Thread Marek Polacek
ffs builtins had wrong type of parameters.

2014-03-25  Marek Polacek  

PR c/50347
* doc/extend.texi (ffs Builtins): Change unsigned types to signed
types.

diff --git gcc/doc/extend.texi gcc/doc/extend.texi
index c0da713..cb28bc9 100644
--- gcc/doc/extend.texi
+++ gcc/doc/extend.texi
@@ -8963,7 +8963,7 @@ Similar to @code{__builtin_nans}, except the return type 
is @code{float}.
 Similar to @code{__builtin_nans}, except the return type is @code{long double}.
 @end deftypefn
 
-@deftypefn {Built-in Function} int __builtin_ffs (unsigned int x)
+@deftypefn {Built-in Function} int __builtin_ffs (int x)
 Returns one plus the index of the least significant 1-bit of @var{x}, or
 if @var{x} is zero, returns zero.
 @end deftypefn
@@ -8993,9 +8993,9 @@ Returns the parity of @var{x}, i.e.@: the number of 
1-bits in @var{x}
 modulo 2.
 @end deftypefn
 
-@deftypefn {Built-in Function} int __builtin_ffsl (unsigned long)
+@deftypefn {Built-in Function} int __builtin_ffsl (long)
 Similar to @code{__builtin_ffs}, except the argument type is
-@code{unsigned long}.
+@code{long}.
 @end deftypefn
 
 @deftypefn {Built-in Function} int __builtin_clzl (unsigned long)
@@ -9023,9 +9023,9 @@ Similar to @code{__builtin_parity}, except the argument 
type is
 @code{unsigned long}.
 @end deftypefn
 
-@deftypefn {Built-in Function} int __builtin_ffsll (unsigned long long)
+@deftypefn {Built-in Function} int __builtin_ffsll (long long)
 Similar to @code{__builtin_ffs}, except the argument type is
-@code{unsigned long long}.
+@code{long long}.
 @end deftypefn
 
 @deftypefn {Built-in Function} int __builtin_clzll (unsigned long long)

Marek


Re: [PATCH] Fix --with-build-config=bootstrap-ubsan bootstrap of lto-plugin (PR sanitizer/56781)

2014-03-25 Thread Jakub Jelinek
On Tue, Mar 25, 2014 at 08:57:21PM +0100, Jakub Jelinek wrote:
> It works fine for ubsan, and your fix is not the right thing to do,
> e.g. bootstrap-ubsan reveals some bugs in libiberty which would be otherwise
> unnoticed if you always filter away the sanitizing options from libiberty.
> 
> So, I think my patch is the right thing to do for ubsan bootstraps, and for
> asan bootstraps we'll need something different (build libiberty twice, or
> build selected libiberty objects inside lto-plugin/ directory again, or
> something similar).  You do want the libiberty parts in cc1, cc1plus, xgcc
> etc. instrumented.

Seems libiberty builds (optionally) everything also into pic/ subdirectory,
I think best would be if it in case it found -fsanitize=address in CFLAGS
also built everything into noasan/ subdirectory with additional
-fno-sanitize=address, and filter out -fsanitize=address just in lto-plugin
Makefile and use noasan/libiberty.a preferrably over pic/libiberty.a over
libiberty.a.
I guess I can cook up a patch tomorrow for that, though probably won't have
cycles to fully test that.

Jakub


Re: [PATCH] Fix folding of UBSAN_CHECK_SUB (x, 0) etc.

2014-03-25 Thread Jakub Jelinek
On Tue, Mar 25, 2014 at 10:15:37AM +0100, Richard Biener wrote:
> On Tue, 25 Mar 2014, Richard Biener wrote:
> 
> > On Tue, 25 Mar 2014, Jakub Jelinek wrote:
> > 
> > > Hi!
> > > 
> > > While working on previous patch, I've noticed a severe omission in the
> > > -fsanitize=signed-integer-overflow support.  Nothing ever
> > > folds addition/subtraction of 0 and multiplication by [0,1], none of these
> > > may ever overflow and thus we can fold them to normal operations and let
> > > those be folded as normal operations.
> > > 
> > > Bootstrapped/regtested on x86_64-linux and i686-linux, tested with
> > > --with-build-config=bootstrap-ubsan bootstrap on i686-linux, ok for trunk?
> > 
> > I think you only need to adjust gimple_fold_stmt_to_constant_1.
> 
> Actually there only for a * 0 and a - a, as others don't result in
> constants.  Still the other cases should be handled in fold_stmt,
> not only in VRP.

Ok, here is an updated patch that optimizes this in VRP,
gimple_fold_stmt_to_constant_1 and gimple_fold_call.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2014-03-25  Jakub Jelinek  

* tree-vrp.c (simplify_internal_call_using_ranges): If only
one range is range_int_cst_p, but not both, at least optimize
addition/subtraction of 0 and multiplication by 0 or 1.
* gimple-fold.c (gimple_fold_call): Fold
IFN_UBSAN_CHECK_{ADD,SUB,MUL}.
(gimple_fold_stmt_to_constant_1): If both op0 and op1 aren't
INTEGER_CSTs, try to fold at least x * 0 and y - y.

--- gcc/tree-vrp.c.jj   2014-03-25 09:22:01.352151925 +0100
+++ gcc/tree-vrp.c  2014-03-25 11:25:44.898562545 +0100
@@ -9336,31 +9336,58 @@ simplify_internal_call_using_ranges (gim
   else if (TREE_CODE (op0) == INTEGER_CST)
 set_value_range_to_value (&vr0, op0, NULL);
   else
-return false;
+set_value_range_to_varying (&vr0);
 
   if (TREE_CODE (op1) == SSA_NAME)
 vr1 = *get_value_range (op1);
   else if (TREE_CODE (op1) == INTEGER_CST)
 set_value_range_to_value (&vr1, op1, NULL);
   else
-return false;
+set_value_range_to_varying (&vr1);
 
-  if (!range_int_cst_p (&vr0) || !range_int_cst_p (&vr1))
-return false;
-
-  tree r1 = int_const_binop (subcode, vr0.min, vr1.min);
-  tree r2 = int_const_binop (subcode, vr0.max, vr1.max);
-  if (r1 == NULL_TREE || TREE_OVERFLOW (r1)
-  || r2 == NULL_TREE || TREE_OVERFLOW (r2))
-return false;
-  if (subcode == MULT_EXPR)
+  if (!range_int_cst_p (&vr0))
+{
+  /* If one range is VR_ANTI_RANGE, VR_VARYING etc.,
+optimize at least x = y + 0; x = y - 0; x = y * 0;
+and x = y * 1; which never overflow.  */
+  if (!range_int_cst_p (&vr1))
+   return false;
+  if (tree_int_cst_sgn (vr1.min) == -1)
+   return false;
+  if (compare_tree_int (vr1.max, subcode == MULT_EXPR) == 1)
+   return false;
+}
+  else if (!range_int_cst_p (&vr1))
+{
+  /* If one range is VR_ANTI_RANGE, VR_VARYING etc.,
+optimize at least x = 0 + y; x = 0 * y; and x = 1 * y;
+which never overflow.  */
+  if (subcode == MINUS_EXPR)
+   return false;
+  if (!range_int_cst_p (&vr0))
+   return false;
+  if (tree_int_cst_sgn (vr0.min) == -1)
+   return false;
+  if (compare_tree_int (vr0.max, subcode == MULT_EXPR) == 1)
+   return false;
+}
+  else
 {
-  tree r3 = int_const_binop (subcode, vr0.min, vr1.max);
-  tree r4 = int_const_binop (subcode, vr0.max, vr1.min);
-  if (r3 == NULL_TREE || TREE_OVERFLOW (r3)
- || r4 == NULL_TREE || TREE_OVERFLOW (r4))
+  tree r1 = int_const_binop (subcode, vr0.min, vr1.min);
+  tree r2 = int_const_binop (subcode, vr0.max, vr1.max);
+  if (r1 == NULL_TREE || TREE_OVERFLOW (r1)
+ || r2 == NULL_TREE || TREE_OVERFLOW (r2))
return false;
+  if (subcode == MULT_EXPR)
+   {
+ tree r3 = int_const_binop (subcode, vr0.min, vr1.max);
+ tree r4 = int_const_binop (subcode, vr0.max, vr1.min);
+ if (r3 == NULL_TREE || TREE_OVERFLOW (r3)
+ || r4 == NULL_TREE || TREE_OVERFLOW (r4))
+   return false;
+   }
 }
+
   gimple g = gimple_build_assign_with_ops (subcode, gimple_call_lhs (stmt),
   op0, op1);
   gsi_replace (gsi, g, false);
--- gcc/gimple-fold.c.jj2014-03-18 17:08:48.0 +0100
+++ gcc/gimple-fold.c   2014-03-25 12:04:07.277342445 +0100
@@ -1186,13 +1186,56 @@ gimple_fold_call (gimple_stmt_iterator *
   else if (gimple_call_builtin_p (stmt, BUILT_IN_MD))
changed |= targetm.gimple_fold_builtin (gsi);
 }
-  else if (gimple_call_internal_p (stmt)
-  && gimple_call_internal_fn (stmt) == IFN_BUILTIN_EXPECT)
+  else if (gimple_call_internal_p (stmt))
 {
-  tree result = fold_builtin_expect (gimple_location (stmt),
-gimple_call_arg (stmt, 0),
-gimp

Re: [PATCH] Fix ubsan i?86 {add,sub,mul}v4 patterns

2014-03-25 Thread Uros Bizjak
On Tue, Mar 25, 2014 at 8:18 PM, Jakub Jelinek  wrote:
> On Tue, Mar 25, 2014 at 04:06:40PM +0100, Jakub Jelinek wrote:
>> On Tue, Mar 25, 2014 at 12:39:18PM +0100, Uros Bizjak wrote:
>> > The patch is OK in principle, but we could follow established practice
>> > and use separate predicates - please see general_szext_operand mode
>> > attribute definition.
>>
>> So like this?  I've tried to use non-VOIDmode of the predicates that were
>> used previously (i.e. general_operand or x86_64_general_operand).
>>
>> 2014-03-25  Jakub Jelinek  
>>
>>   * config/i386/i386.md (general_sext_operand): New mode attr.
>>   (addv4, subv4, mulv4): If operands[2] is CONST_INT,
>>   don't generate (sign_extend (const_int)).
>>   (*addv4, *subv4, *mulv4): Disallow CONST_INT_P
>>   operands[2].  Use We constraint instead of  and 
>> 
>>   predicate instead of .
>>   (*addv4_1, *subv4_1, *mulv4_1): New insns.
>>   * config/i386/constraints.md (We): New constraint.
>>   * config/i386/predicates.md (x86_64_sext_operand,
>>   sext_operand): New predicates.
>
> Now successfully bootstrapped/regtested on x86_64-linux and i686-linux.

The patch is OK for mainline.

Thanks,
Uros.


Re: [PATCH] Fix --with-build-config=bootstrap-ubsan bootstrap of lto-plugin (PR sanitizer/56781)

2014-03-25 Thread Jakub Jelinek
On Tue, Mar 25, 2014 at 12:44:58PM -0700, H.J. Lu wrote:
> On Tue, Mar 25, 2014 at 12:28 PM, Jakub Jelinek  wrote:
> > lto-plugin is another problematic directory in asan/ubsan bootstraps.
> >
> > Unlike fixincludes, it is bootstrapped, and like fixincludes it is also
> > linked against host libiberty.  The problem for lto-plugin is that the
> > -static-libubsan -fsanitize=undefined -B/some/path/to/libsanitizer/ 
> > -B/some/path/to/libsanitizer/ubsan/.libs/
> > switches are eaten by libtool, which throws them away on the floor.
> >
> > We apparently have libtool-ldflags which is used by other libraries
> > to filter some options so that libtool doesn't eat them, but even after
> > applying the lto-plugin/Makefile.am changes I got failures, because
> > while -fsanitize=undefined now made it through, the rest of the options
> > didn't.  So, this patch also tweaks libtool-ldflags to handle some more
> > options.
> >
> 
> lto-plugin is dlopened by ld.  How does asan work in lto-plugin
> when ld isn't compiled with asan?

It works fine for ubsan, and your fix is not the right thing to do,
e.g. bootstrap-ubsan reveals some bugs in libiberty which would be otherwise
unnoticed if you always filter away the sanitizing options from libiberty.

So, I think my patch is the right thing to do for ubsan bootstraps, and for
asan bootstraps we'll need something different (build libiberty twice, or
build selected libiberty objects inside lto-plugin/ directory again, or
something similar).  You do want the libiberty parts in cc1, cc1plus, xgcc
etc. instrumented.

Jakub


Re: [PATCH] Fix PR c++/60573

2014-03-25 Thread Adam Butcher

On 2014-03-25 15:48, Jason Merrill wrote:

On 03/18/2014 10:46 PM, Adam Butcher wrote:

+ if (TYPE_BEING_DEFINED (scope->this_entity))
+   if (scope->level_chain == 0
+   || scope->this_entity != scope->level_chain->this_entity)
+ break;


I don't think this is an adequate test; if you have another class
wrapping B, you'll have two levels of context pushed for the
declarator, so the this_entities will compare unequal.  I think we
need some way to designate a scope that actually corresponds to a
class-specifier.


I don't follow.  Are you suggesting a case like the following?

  struct A
  {
struct X
{
  struct B
  {
void foo(auto);
  };
};

void X::B::foo(auto) {}  // { dg-error "cannot define" }
  };

If so, it is handled.  The code you are referring to is within a 
level_chain traversal loop so handles arbitrary levels of pushed 
context.  The end result is the same though; we arrive at an 'A::' scope 
that is not the defining class scope but has the same 'this_entity' as 
it (so TYPE_BEING_DEFINED returns true).  The scope chain is as if the 
following was used to declare it:


  struct A
  {
...
void A::X::B::foo(auto);
  };

It is the two levels of 'A' entity scopes that caused the ICE due the 
previous version of the loop stopping to inject the template parameter 
list between the 'A::' and the 'X::', rather than unwinding back to the 
scope defining 'A'.


Apologies if I've completely misunderstood your point here.  I've got a 
feeling that I may have.


Adam


Re: [PATCH] Fix --with-build-config=bootstrap-ubsan bootstrap of lto-plugin (PR sanitizer/56781)

2014-03-25 Thread H.J. Lu
On Tue, Mar 25, 2014 at 12:28 PM, Jakub Jelinek  wrote:
> Hi!
>
> lto-plugin is another problematic directory in asan/ubsan bootstraps.
>
> Unlike fixincludes, it is bootstrapped, and like fixincludes it is also
> linked against host libiberty.  The problem for lto-plugin is that the
> -static-libubsan -fsanitize=undefined -B/some/path/to/libsanitizer/ 
> -B/some/path/to/libsanitizer/ubsan/.libs/
> switches are eaten by libtool, which throws them away on the floor.
>
> We apparently have libtool-ldflags which is used by other libraries
> to filter some options so that libtool doesn't eat them, but even after
> applying the lto-plugin/Makefile.am changes I got failures, because
> while -fsanitize=undefined now made it through, the rest of the options
> didn't.  So, this patch also tweaks libtool-ldflags to handle some more
> options.
>

lto-plugin is dlopened by ld.  How does asan work in lto-plugin
when ld isn't compiled with asan?

-- 
H.J.


[patch] fix libstdc++/60658

2014-03-25 Thread Jonathan Wakely

This fixes a simple thinko in the atomic partial specialization
that uses sizeof(T) instead of sizeof(T*).

It's a regression since 4.6 so I'm committing it to trunk and the 4.7
and 4.8 branches.

Tested x86_64-linux.


commit cb68113312d9702bd17af760c775697d2d57f94a
Author: Jonathan Wakely 
Date:   Tue Mar 25 19:23:37 2014 +

PR libstdc++/60658
* include/bits/atomic_base.h (__atomic_base<_PTp*>::is_lock_free()):
Use sizeof pointer type not the element type.
* testsuite/29_atomics/atomic/60658.cc: New.

diff --git a/libstdc++-v3/include/bits/atomic_base.h 
b/libstdc++-v3/include/bits/atomic_base.h
index 7d2ba75..242459a 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -768,11 +768,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   bool
   is_lock_free() const noexcept
-  { return __atomic_is_lock_free(_M_type_size(1), nullptr); }
+  { return __atomic_is_lock_free(sizeof(__pointer_type), nullptr); }
 
   bool
   is_lock_free() const volatile noexcept
-  { return __atomic_is_lock_free(_M_type_size(1), nullptr); }
+  { return __atomic_is_lock_free(sizeof(__pointer_type), nullptr); }
 
   _GLIBCXX_ALWAYS_INLINE void
   store(__pointer_type __p,
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/60658.cc 
b/libstdc++-v3/testsuite/29_atomics/atomic/60658.cc
new file mode 100644
index 000..5634085
--- /dev/null
+++ b/libstdc++-v3/testsuite/29_atomics/atomic/60658.cc
@@ -0,0 +1,43 @@
+// { dg-require-atomic-builtins "" }
+// { dg-options "-std=gnu++11" }
+
+// Copyright (C) 2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+#include 
+#include 
+
+// libstdc++/60658
+
+struct Foo {
+  char buf[1];
+};
+
+struct Bar {
+  char buf[100];
+};
+
+int
+main ()
+{
+  bool test __attribute__((unused)) = true;
+
+  std::atomic a;
+  std::atomic b;
+
+  VERIFY (a.is_lock_free() == b.is_lock_free());
+}


Re: [PATCH] Fix ubsan i?86 {add,sub,mul}v4 patterns

2014-03-25 Thread Jakub Jelinek
On Tue, Mar 25, 2014 at 12:39:18PM +0100, Uros Bizjak wrote:
> The patch is OK in principle, but we could follow established practice
> and use separate predicates - please see general_szext_operand mode
> attribute definition.

So like this?  I've tried to use non-VOIDmode of the predicates that were
used previously (i.e. general_operand or x86_64_general_operand).

2014-03-25  Jakub Jelinek  

* config/i386/i386.md (general_sext_operand): New mode attr.
(addv4, subv4, mulv4): If operands[2] is CONST_INT,
don't generate (sign_extend (const_int)).
(*addv4, *subv4, *mulv4): Disallow CONST_INT_P
operands[2].  Use We constraint instead of  and 

predicate instead of .
(*addv4_1, *subv4_1, *mulv4_1): New insns.
* config/i386/constraints.md (We): New constraint.
* config/i386/predicates.md (x86_64_sext_operand,
sext_operand): New predicates.

--- gcc/config/i386/i386.md.jj  2014-03-25 09:22:01.796149575 +0100
+++ gcc/config/i386/i386.md 2014-03-25 16:03:38.730898166 +0100
@@ -971,6 +971,15 @@ (define_mode_attr general_operand
 (DI "x86_64_general_operand")
 (TI "x86_64_general_operand")])
 
+;; General sign extend operand predicate for integer modes,
+;; which disallows VOIDmode operands and thus it is suitable
+;; for use inside sign_extend.
+(define_mode_attr general_sext_operand
+   [(QI "sext_operand")
+(HI "sext_operand")
+(SI "x86_64_sext_operand")
+(DI "x86_64_sext_operand")])
+
 ;; General sign/zero extend operand predicate for integer modes.
 (define_mode_attr general_szext_operand
[(QI "general_operand")
@@ -5821,10 +5830,11 @@ (define_expand "addv4"
   (eq:CCO (plus:
  (sign_extend:
 (match_operand:SWI 1 "nonimmediate_operand"))
- (sign_extend:
-(match_operand:SWI 2 "")))
+ (match_dup 4))
   (sign_extend:
- (plus:SWI (match_dup 1) (match_dup 2)
+ (plus:SWI (match_dup 1)
+   (match_operand:SWI 2
+  "")
  (set (match_operand:SWI 0 "register_operand")
   (plus:SWI (match_dup 1) (match_dup 2)))])
(set (pc) (if_then_else
@@ -5832,7 +5842,13 @@ (define_expand "addv4"
   (label_ref (match_operand 3))
   (pc)))]
   ""
-  "ix86_fixup_binary_operands_no_copy (PLUS, mode, operands);")
+{
+  ix86_fixup_binary_operands_no_copy (PLUS, mode, operands);
+  if (CONST_INT_P (operands[2]))
+operands[4] = operands[2];
+  else
+operands[4] = gen_rtx_SIGN_EXTEND (mode, operands[2]);
+})
 
 (define_insn "*addv4"
   [(set (reg:CCO FLAGS_REG)
@@ -5840,7 +5856,8 @@ (define_insn "*addv4"
   (sign_extend:
  (match_operand:SWI 1 "nonimmediate_operand" "%0,0"))
   (sign_extend:
- (match_operand:SWI 2 "" ",")))
+ (match_operand:SWI 2 ""
+  "mWe,We")))
(sign_extend:
   (plus:SWI (match_dup 1) (match_dup 2)
(set (match_operand:SWI 0 "nonimmediate_operand" "=,m")
@@ -5850,6 +5867,31 @@ (define_insn "*addv4"
   [(set_attr "type" "alu")
(set_attr "mode" "")])
 
+(define_insn "*addv4_1"
+  [(set (reg:CCO FLAGS_REG)
+   (eq:CCO (plus:
+  (sign_extend:
+ (match_operand:SWI 1 "nonimmediate_operand" "0"))
+  (match_operand: 3 "const_int_operand" "i"))
+   (sign_extend:
+  (plus:SWI (match_dup 1)
+(match_operand:SWI 2 "x86_64_immediate_operand"
+ "")
+   (set (match_operand:SWI 0 "nonimmediate_operand" "=m")
+   (plus:SWI (match_dup 1) (match_dup 2)))]
+  "ix86_binary_operator_ok (PLUS, mode, operands)
+   && CONST_INT_P (operands[2])
+   && INTVAL (operands[2]) == INTVAL (operands[3])"
+  "add{}\t{%2, %0|%0, %2}"
+  [(set_attr "type" "alu")
+   (set_attr "mode" "")
+   (set (attr "length_immediate")
+   (cond [(match_test "IN_RANGE (INTVAL (operands[2]), -128, 127)")
+ (const_string "1")
+  (match_test " == 8")
+ (const_string "4")]
+ (const_string "")))])
+
 ;; The lea patterns for modes less than 32 bits need to be matched by
 ;; several insns converted to real lea by splitters.
 
@@ -6093,10 +6135,11 @@ (define_expand "subv4"
   (eq:CCO (minus:
  (sign_extend:
 (match_operand:SWI 1 "nonimmediate_operand"))
- (sign_extend:
-(match_operand:SWI 2 "")))
+ (match_dup 

[PATCH] Fix --with-build-config=bootstrap-ubsan bootstrap of lto-plugin (PR sanitizer/56781)

2014-03-25 Thread Jakub Jelinek
Hi!

lto-plugin is another problematic directory in asan/ubsan bootstraps.

Unlike fixincludes, it is bootstrapped, and like fixincludes it is also
linked against host libiberty.  The problem for lto-plugin is that the
-static-libubsan -fsanitize=undefined -B/some/path/to/libsanitizer/ 
-B/some/path/to/libsanitizer/ubsan/.libs/
switches are eaten by libtool, which throws them away on the floor.

We apparently have libtool-ldflags which is used by other libraries
to filter some options so that libtool doesn't eat them, but even after
applying the lto-plugin/Makefile.am changes I got failures, because
while -fsanitize=undefined now made it through, the rest of the options
didn't.  So, this patch also tweaks libtool-ldflags to handle some more
options.

Bootstrapped/regtested on x86_64-linux (normally) and i686-linux
(--with-build-config=bootstrap-ubsan).  Ok for trunk?

2014-03-25  Jakub Jelinek  

PR sanitizer/56781
* libtool-ldflags: Also prefix -static-lib*, -shared-lib*
and -B* options with -Xcompiler.
lto-plugin/
* Makefile.am (LTLDFLAGS, liblto_plugin_la_LINK): New variables.
* Makefile.in: Regenerated.

--- libtool-ldflags.jj  2008-09-05 12:59:51.0 +0200
+++ libtool-ldflags 2014-03-25 15:43:36.726185093 +0100
@@ -2,7 +2,7 @@
 
 # Script to translate LDFLAGS into a form suitable for use with libtool.
 
-# Copyright (C) 2005 Free Software Foundation, Inc.
+# Copyright (C) 2005-2014 Free Software Foundation, Inc.
 #
 # This file is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -36,14 +36,15 @@ prev_arg=
 for arg
 do
 case $arg in
-   -f*|--*)
+   -f*|--*|-static-lib*|-shared-lib*|-B*)
# Libtool does not ascribe any special meaning options
# that begin with -f or with a double-dash.  So, it will
# think these options are linker options, and prefix them
# with "-Wl,".  Then, the compiler driver will ignore the
# options.  So, we prefix these options with -Xcompiler to
# make clear to libtool that they are in fact compiler
-   # options.
+   # options.  Similarly for e.g. -static-libstdc++, or
+   # -B/some/path.
case $prev_arg in
-Xpreprocessor|-Xcompiler|-Xlinker)
# This option is already prefixed; don't prefix it again.
--- lto-plugin/Makefile.am.jj   2014-03-17 20:01:54.0 +0100
+++ lto-plugin/Makefile.am  2014-03-25 15:46:26.832294118 +0100
@@ -18,6 +18,7 @@ in_gcc_libs = $(foreach lib, $(libexecsu
 
 # Can be removed when libiberty becomes a normal convenience library
 Wc=-Wc,
+LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS))
 
 liblto_plugin_la_SOURCES = lto-plugin.c
 liblto_plugin_la_LIBADD = \
@@ -28,6 +29,9 @@ liblto_plugin_la_LDFLAGS = $(AM_LDFLAGS)
$(if $(wildcard 
../libiberty/pic/libiberty.a),,-Wc,../libiberty/libiberty.a)
 liblto_plugin_la_DEPENDENCIES = $(if $(wildcard \
../libiberty/pic/libiberty.a),../libiberty/pic/libiberty.a,)
+liblto_plugin_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+   $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+   $(liblto_plugin_la_LDFLAGS) $(LTLDFLAGS) -o $@
 
 all-local: $(in_gcc_libs)
 
--- lto-plugin/Makefile.in.jj   2014-03-17 20:01:54.0 +0100
+++ lto-plugin/Makefile.in  2014-03-25 15:47:10.059071353 +0100
@@ -84,9 +84,6 @@ am__installdirs = "$(DESTDIR)$(libexecsu
 LTLIBRARIES = $(libexecsub_LTLIBRARIES)
 am_liblto_plugin_la_OBJECTS = lto-plugin.lo
 liblto_plugin_la_OBJECTS = $(am_liblto_plugin_la_OBJECTS)
-liblto_plugin_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-   $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-   $(liblto_plugin_la_LDFLAGS) $(LDFLAGS) -o $@
 DEFAULT_INCLUDES = -I.@am__isrc@
 depcomp =
 am__depfiles_maybe =
@@ -239,6 +236,7 @@ in_gcc_libs = $(foreach lib, $(libexecsu
 
 # Can be removed when libiberty becomes a normal convenience library
 Wc = -Wc,
+LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS))
 liblto_plugin_la_SOURCES = lto-plugin.c
 liblto_plugin_la_LIBADD = \
$(if $(wildcard 
../libiberty/pic/libiberty.a),$(Wc)../libiberty/pic/libiberty.a,)
@@ -251,6 +249,10 @@ liblto_plugin_la_LDFLAGS = $(AM_LDFLAGS)
 liblto_plugin_la_DEPENDENCIES = $(if $(wildcard \
../libiberty/pic/libiberty.a),../libiberty/pic/libiberty.a,)
 
+liblto_plugin_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+   $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+   $(liblto_plugin_la_LDFLAGS) $(LTLDFLAGS) -o $@
+
 all: config.h
$(MAKE) $(AM_MAKEFLAGS) all-am
 


Jakub


Re: [PATCH] x86: _mm512_set1_p[sd]

2014-03-25 Thread Ulrich Drepper
On Mon, Mar 24, 2014 at 9:09 AM, Jakub Jelinek  wrote:
> The following is recognized well:
>
> typedef char v32qi __attribute__((vector_size (32)));
> v32qi foo (char a)
> {
>   return (v32qi) { a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, 
> a, a, a, a, a, a, a, a, a, a, a, a, a };
> }


Perhaps "well" but not optimal.  The created code is

vmovd   %edi, %xmm0
vpbroadcastb%xmm0, %xmm0
vinserti128   $1, %xmm0, %ymm0, %ymm0

It should generate for AVX2

vmovd   %edi, %xmm0
vpbroadcastb%xmm0, %ymm0


[PATCH] Fix --with-build-config=bootstrap-ubsan bootstrap of fixincludes (PR sanitizer/56781)

2014-03-25 Thread Jakub Jelinek
Hi!

This patch fixes a problem where build of host fixincludes fails
with --with-build-config=bootstrap-ubsan (and bootstrap-asan).
The problem is that fixincludes is linked against host libiberty
that is bootstrapped, but fixincludes is not bootstrapped.
Thus, libiberty uses post stage1 cflags/ldflags and is compiled
therefore in stage2/stage3 with -fsanitize=undefined, but fixincludes
is compiled/linked with normal cflags/ldflags and thus not linked
against libubsan.

Fixed by making fixincludes another host bootstrapped module
if doing asan/ubsan bootstrap (no need to waste build cycles otherwise).

Bootstrapped/regtested on x86_64-linux (normal bootstrap) and
on i686-linux (--with-build-config=bootstrap-ubsan).  Ok for trunk?

2014-03-25  Jakub Jelinek  

PR sanitizer/56781
* Makefile.def: Set bootstrap=true; for host fixincludes.
* configure.ac: Don't bootstrap host fixincludes unless
--with-build-config=bootstrap-{a,ub}san.
* Makefile.in: Regenerated.
* configure: Regenerated.

--- Makefile.def.jj 2013-11-21 09:26:57.0 +0100
+++ Makefile.def2014-03-25 13:55:23.805116854 +0100
@@ -39,7 +39,7 @@ host_modules= { module= cgen; };
 host_modules= { module= dejagnu; };
 host_modules= { module= etc; };
 host_modules= { module= fastjar; no_check_cross= true; };
-host_modules= { module= fixincludes;
+host_modules= { module= fixincludes; bootstrap=true;
missing= TAGS; };
 host_modules= { module= flex; no_check_cross= true; };
 host_modules= { module= gas; bootstrap=true; };
--- configure.ac.jj 2014-03-21 08:15:39.0 +0100
+++ configure.ac2014-03-25 17:11:35.819558369 +0100
@@ -2532,6 +2532,7 @@ AC_MSG_RESULT($enable_vtable_verify)
 # build configuration in Makefile.
 target_configdirs=`echo "${target_configdirs}" | sed -e 's/target-//g'`
 build_configdirs=`echo "${build_configdirs}" | sed -e 's/build-//g'`
+bootstrap_fixincludes=no
 
 # If we are building libgomp, bootstrap it.
 if echo " ${target_configdirs} " | grep " libgomp " > /dev/null 2>&1 ; then
@@ -2544,6 +2545,7 @@ if echo " ${target_configdirs} " | grep
   case "$BUILD_CONFIG" in
 *bootstrap-asan* | *bootstrap-ubsan* )
   bootstrap_target_libs=${bootstrap_target_libs}target-libsanitizer,
+  bootstrap_fixincludes=yes
   ;;
   esac
 fi
@@ -2626,11 +2628,15 @@ for module in ${configdirs} ; do
   fi
 done
   fi
+  case ${module},${bootstrap_fixincludes} in
+fixincludes,no) host_bootstrap_suffix=no-bootstrap ;;
+*) host_bootstrap_suffix=$bootstrap_suffix ;;
+  esac
   extrasub_host="$extrasub_host
 /^@if $module\$/d
 /^@endif $module\$/d
-/^@if $module-$bootstrap_suffix\$/d
-/^@endif $module-$bootstrap_suffix\$/d"
+/^@if $module-$host_bootstrap_suffix\$/d
+/^@endif $module-$host_bootstrap_suffix\$/d"
 done
 extrasub_target=
 for module in ${target_configdirs} ; do
--- Makefile.in.jj  2014-03-07 13:58:01.0 +0100
+++ Makefile.in 2014-03-25 13:55:32.0 +0100
@@ -1003,7 +1003,9 @@ all-host: maybe-all-cgen
 all-host: maybe-all-dejagnu
 all-host: maybe-all-etc
 all-host: maybe-all-fastjar
+@if fixincludes-no-bootstrap
 all-host: maybe-all-fixincludes
+@endif fixincludes-no-bootstrap
 all-host: maybe-all-flex
 @if gas-no-bootstrap
 all-host: maybe-all-gas
@@ -7807,7 +7809,6 @@ configure-fixincludes: stage_current
 @if fixincludes
 maybe-configure-fixincludes: configure-fixincludes
 configure-fixincludes: 
-   @: $(MAKE); $(unstage)
@r=`${PWD_COMMAND}`; export r; \
s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
test ! -f $(HOST_SUBDIR)/fixincludes/Makefile || exit 0; \
@@ -7830,6 +7831,204 @@ configure-fixincludes:
 
 
 
+.PHONY: configure-stage1-fixincludes maybe-configure-stage1-fixincludes
+maybe-configure-stage1-fixincludes:
+@if fixincludes-bootstrap
+maybe-configure-stage1-fixincludes: configure-stage1-fixincludes
+configure-stage1-fixincludes:
+   @[ $(current_stage) = stage1 ] || $(MAKE) stage1-start
+   @$(SHELL) $(srcdir)/mkinstalldirs $(HOST_SUBDIR)/fixincludes
+   @r=`${PWD_COMMAND}`; export r; \
+   s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
+   TFLAGS="$(STAGE1_TFLAGS)"; \
+   test ! -f $(HOST_SUBDIR)/fixincludes/Makefile || exit 0; \
+   $(HOST_EXPORTS) \
+   CFLAGS="$(STAGE1_CFLAGS)"; export CFLAGS; \
+   CXXFLAGS="$(STAGE1_CXXFLAGS)"; export CXXFLAGS; \
+   LIBCFLAGS="$(LIBCFLAGS)"; export LIBCFLAGS;  \
+   echo Configuring stage 1 in $(HOST_SUBDIR)/fixincludes ; \
+   $(SHELL) $(srcdir)/mkinstalldirs $(HOST_SUBDIR)/fixincludes ; \
+   cd $(HOST_SUBDIR)/fixincludes || exit 1; \
+   case $(srcdir) in \
+ /* | [A-Za-z]:[\\/]*) topdir=$(srcdir) ;; \
+ *) topdir=`echo $(HOST_SUBDIR)/fixincludes/ | \
+   sed -e 's,\./,,g' -e 's,[^/]*/,../,g' `$(srcdir) ;; \
+   esac; \
+   srcdiroption="--srcdir=$${topdir}/fixincludes"; \
+   libsrcdir="$$s/fixincludes"; \
+   $(SHELL) $$

Re: [PATCH] Fix ubsan i?86 {add,sub,mul}v4 patterns

2014-03-25 Thread Jakub Jelinek
On Tue, Mar 25, 2014 at 04:06:40PM +0100, Jakub Jelinek wrote:
> On Tue, Mar 25, 2014 at 12:39:18PM +0100, Uros Bizjak wrote:
> > The patch is OK in principle, but we could follow established practice
> > and use separate predicates - please see general_szext_operand mode
> > attribute definition.
> 
> So like this?  I've tried to use non-VOIDmode of the predicates that were
> used previously (i.e. general_operand or x86_64_general_operand).
> 
> 2014-03-25  Jakub Jelinek  
> 
>   * config/i386/i386.md (general_sext_operand): New mode attr.
>   (addv4, subv4, mulv4): If operands[2] is CONST_INT,
>   don't generate (sign_extend (const_int)).
>   (*addv4, *subv4, *mulv4): Disallow CONST_INT_P
>   operands[2].  Use We constraint instead of  and 
> 
>   predicate instead of .
>   (*addv4_1, *subv4_1, *mulv4_1): New insns.
>   * config/i386/constraints.md (We): New constraint.
>   * config/i386/predicates.md (x86_64_sext_operand,
>   sext_operand): New predicates.

Now successfully bootstrapped/regtested on x86_64-linux and i686-linux.

Jakub


Re: [PATCH] Don't bootstrap libsanitizer or libvtv unless needed

2014-03-25 Thread Jakub Jelinek
On Tue, Mar 25, 2014 at 05:36:54PM +0100, Paolo Bonzini wrote:
> Il 20/03/2014 13:24, Jakub Jelinek ha scritto:
> >We currently bootstrap both libsanitizer and libvtv, the former
> >just in case somebody decides to --with-build-config=bootstrap-asan
> >(or --with-build-config=bootstrap-ubsan), the latter if somebody decides
> >to --enable-vtable-verify.
> >
> >This patch changes it so that we only bootstrap libsanitizer if
> >bootstrap-asan or bootstrap-ubsan is in BOOT_CONFIG, and only bootstrap
> >libvtv if --enable-vtable-verify.
> >
> >Bootstrapped/regtested on x86_64-linux and i686-linux, on x86_64 it
> >saved a few minutes of build time, neither libsanitizer nor libvtv
> >has been bootstrapped, only built in stage3.
> >Currently also bootstrapping on i686-linux with
> >--enable-vtable-verify --with-build-config=bootstrap-asan
> >but already got into stage2 and verified that both libsanitizer and libvtv
> >are being bootstrapped in that case.
> >
> >Ok for trunk?
> >
> >2014-03-20  Jakub Jelinek  
> >
> > * configure.ac: Move BUILD_CONFIG set up earlier.  Add
> > --enable-vtable-verify option parsing.  Don't add
> > target-libsanitizer to bootstrap_target_libs unless
> > --with-build-config=bootstrap-asan or
> > --with-build-config=bootstrap-ubsan.  Don't add target-libvtv
> > to bootstrap_target_libs unless --enable-vtable-verify.
> > * configure: Regenerated.
> 
> Is the extra complication really worth saving a few minutes of compile time?

IMHO yes, saving around 5-10 minutes of x86_64 bootstraps that you perform
several times a day is worth it.

Jakub


Re: [PATCH] Fix PR59626, _FORTIFY_SOURCE wrappers and LTO

2014-03-25 Thread Jan Hubicka
> > >   PR lto/59626
> > >   * passes.c (ipa_write_summaries): Drop function bodies of
> > >   extern always-inline functions.
> > > 
> > >   * gcc.dg/lto/pr59626_0.c: New testcase.
> > >   * gcc.dg/lto/pr59626_1.c: Likewise.
> > > 
> > Hi,
> > do you see some problem with this approach? Unlike in dropping for 
> > ipa_write_summaries
> > it drops just after early optimizations and it is done unconditonally.
> > I see it kills every cross module inlining of extern inlines, but so does 
> > your patch.
> > This may make difference for C++ implicit extern inlines (keyed functions) 
> > where I can
> > imagine users both to declare them always inline and then call indirectly...
> > I do it unconditionally because I do not like much of idea of making the 
> > LTO and non-LTO
> > pipelines diverging even more.
> 
> Well - it doesn't fix the testcase for me.

A fair complaint ;) I just check that it removes the body of always_inline.  I 
will check
why it doesn't help.  We probably also need to drop the attribute as you do in 
ipa-profile.

Honza


[committed][DOC PATCH] Fix typo in example (PR c/35449)

2014-03-25 Thread Marek Polacek
I'm applying this as obvious.

2014-03-25  Marek Polacek  

PR c/35449
* doc/extend.texi (Example of asm with clobbered asm reg): Fix typo.

diff --git gcc/doc/extend.texi gcc/doc/extend.texi
index 986cc94..c0da713 100644
--- gcc/doc/extend.texi
+++ gcc/doc/extend.texi
@@ -6343,7 +6343,7 @@ int foo ()
   int *y = &x;
   int result;
   asm ("magic stuff accessing an 'int' pointed to by '%1'"
-   : "=&d" (r) : "a" (y), "m" (*y));
+   : "=&d" (result) : "a" (y), "m" (*y));
   return result;
 @}
 @end smallexample

Marek


[PATCH, PR 60600] Handle inconsistent devirtualizations gracefully

2014-03-25 Thread Martin Jambor
Hi,

the following patch converting an assert to a test fixes PR 60600.  If
we determine that a devirtualization cannot happen, we can now convert
the call to builtin_unreachable.

Bootstrapped and tested on x86_64-linux.  I have also sucessfully LTO
built Firefox with the change.  Pre-approved by Honza in bugzilla and
thus I will commit it shortly.

Thanks,

Martin


2014-03-25  Martin Jambor  

PR ipa/60600
* ipa-cp.c (ipa_get_indirect_edge_target_1): Redirect type
inconsistent devirtualizations to __builtin_unreachable.

testsuite/
* g++.dg/ipa/pr60600.C: New test.

diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index b71048a..74042ad 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -1639,11 +1639,18 @@ ipa_get_indirect_edge_target_1 (struct cgraph_edge *ie,
return NULL_TREE;
   target = gimple_get_virt_method_for_binfo (token, binfo);
 }
-#ifdef ENABLE_CHECKING
-  if (target)
-gcc_assert (possible_polymorphic_call_target_p
-(ie, cgraph_get_node (target)));
-#endif
+
+  if (target && !possible_polymorphic_call_target_p (ie,
+cgraph_get_node (target)))
+{
+  if (dump_file)
+   fprintf (dump_file,
+"Type inconsident devirtualization: %s/%i->%s\n",
+ie->caller->name (), ie->caller->order,
+IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (target)));
+  target = builtin_decl_implicit (BUILT_IN_UNREACHABLE);
+  cgraph_get_create_node (target);
+}
 
   return target;
 }
diff --git a/gcc/testsuite/g++.dg/ipa/pr60600.C 
b/gcc/testsuite/g++.dg/ipa/pr60600.C
new file mode 100644
index 000..00c368e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ipa/pr60600.C
@@ -0,0 +1,34 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -fdump-ipa-cp" } */
+
+struct data {
+data(int);
+};
+
+struct top {
+virtual int topf();
+};
+
+struct intermediate: top {
+int topf() /* override */ { return 0; }
+};
+
+struct child1: top {
+void childf()
+{
+data d(topf());
+}
+};
+
+struct child2: intermediate {};
+
+void test(top& t)
+{
+child1& c = static_cast(t);
+c.childf();
+child2 d;
+test(d);
+}
+
+/* { dg-final { scan-ipa-dump "Type inconsident devirtualization" "cp" } } */
+/* { dg-final { cleanup-ipa-dump "cp" } } */


C++ PATCH for c++/60375 (unevaluated lambda)

2014-03-25 Thread Jason Merrill
The parser was getting confused by trying to process the body of the 
lambda in an unevaluated context, so let's just skip the body.  The 
second patch avoids repeated errors about the issue, but isn't necessary 
to fix the ICE, so I'm saving it for after 4.9.


Tested x86_64-pc-linux-gnu, applying to trunk.
commit 276e736980d133f032633eeb69d9edb1be6070eb
Author: Jason Merrill 
Date:   Mon Mar 24 16:11:02 2014 -0400

	PR c++/60375
	* parser.c (cp_parser_lambda_expression): Don't parse the body of
	a lambda in unevaluated context.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 4ca08a1..2e117a5 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -8718,14 +8718,17 @@ cp_parser_lambda_expression (cp_parser* parser)
 {
   tree lambda_expr = build_lambda_expr ();
   tree type;
-  bool ok;
+  bool ok = true;
 
   LAMBDA_EXPR_LOCATION (lambda_expr)
 = cp_lexer_peek_token (parser->lexer)->location;
 
   if (cp_unevaluated_operand)
-error_at (LAMBDA_EXPR_LOCATION (lambda_expr),
-	  "lambda-expression in unevaluated context");
+{
+  error_at (LAMBDA_EXPR_LOCATION (lambda_expr),
+		"lambda-expression in unevaluated context");
+  ok = false;
+}
 
   /* We may be in the middle of deferred access check.  Disable
  it now.  */
@@ -8770,12 +8773,15 @@ cp_parser_lambda_expression (cp_parser* parser)
 /* By virtue of defining a local class, a lambda expression has access to
the private variables of enclosing classes.  */
 
-ok = cp_parser_lambda_declarator_opt (parser, lambda_expr);
+ok &= cp_parser_lambda_declarator_opt (parser, lambda_expr);
 
 if (ok)
   cp_parser_lambda_body (parser, lambda_expr);
 else if (cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE))
-  cp_parser_skip_to_end_of_block_or_statement (parser);
+  {
+	if (cp_parser_skip_to_closing_brace (parser))
+	  cp_lexer_consume_token (parser->lexer);
+  }
 
 /* The capture list was built up in reverse order; fix that now.  */
 LAMBDA_EXPR_CAPTURE_LIST (lambda_expr)
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-uneval.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-uneval.C
index 898f685..dcea169 100644
--- a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-uneval.C
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-uneval.C
@@ -5,3 +5,5 @@ template 
 struct A { };
 A a; // { dg-error "lambda.*unevaluated context" }
 
+// { dg-prune-output "template argument" }
+// { dg-prune-output "invalid type" }
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-uneval2.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-uneval2.C
new file mode 100644
index 000..14cb298
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-uneval2.C
@@ -0,0 +1,7 @@
+// PR c++/60375
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+  decltype( [](){ return this; }() ) x; // { dg-error "unevaluated" }
+};

commit d0dd16c1e91b1d394c659e608d86a93e82f24fb4
Author: Jason Merrill 
Date:   Mon Mar 24 16:11:02 2014 -0400

	* parser.h (struct cp_token): Rename ambiguous_p to error_reported.
	* parser.c: Adjust.
	(cp_lexer_get_preprocessor_token): Always clear it.
	(cp_parser_lambda_expression): Use it to avoid duplicate diagnostics.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 2e117a5..fa3e111 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -762,6 +762,7 @@ cp_lexer_get_preprocessor_token (cp_lexer *lexer, cp_token *token)
   token->keyword = RID_MAX;
   token->pragma_kind = PRAGMA_NONE;
   token->purged_p = false;
+  token->error_reported = false;
 
   /* On some systems, some header files are surrounded by an
  implicit extern "C" block.  Set a flag in the token if it
@@ -797,7 +798,6 @@ cp_lexer_get_preprocessor_token (cp_lexer *lexer, cp_token *token)
   C_SET_RID_CODE (token->u.value, RID_MAX);
 }
 
-	  token->ambiguous_p = false;
 	  token->keyword = RID_MAX;
 	}
 }
@@ -3011,7 +3011,7 @@ cp_parser_parse_and_diagnose_invalid_type_name (cp_parser *parser)
   if (token->type == CPP_NESTED_NAME_SPECIFIER)
 {
   cp_token *next = cp_lexer_peek_nth_token (parser->lexer, 2);
-  if (next->type == CPP_NAME && next->ambiguous_p)
+  if (next->type == CPP_NAME && next->error_reported)
 	goto out;
 }
 
@@ -4535,7 +4535,7 @@ cp_parser_primary_expression (cp_parser *parser,
 	   we've already issued an error message; there's no reason
 	   to check again.  */
 	if (id_expr_token->type == CPP_NAME
-		&& id_expr_token->ambiguous_p)
+		&& id_expr_token->error_reported)
 	  {
 		cp_parser_simulate_error (parser);
 		return error_mark_node;
@@ -5313,7 +5313,7 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser,
 	  token = cp_lexer_consume_token (parser->lexer);
 	  if (!error_p)
 		{
-		  if (!token->ambiguous_p)
+		  if (!token->error_reported)
 		{
 		  tree decl;
 		  tree ambiguous_decls;
@@ -8719,14 +8719,18 @@ cp_parser_lambda_expression (cp_parser* parser)
   tree lambda_

C++ PATCH for c++/60628 (auto array)

2014-03-25 Thread Jason Merrill
We got confused tsubsting the VLA type because tsubst doesn't expect to 
see a SAVE_EXPR.  Simple to fix by enforcing the rule against auto arrays.


Tested x86_64-pc-linux-gnu, applying to trunk.
commit f2fbd4a8a0152e2d9d6c0b9d6ccfb1639183ed0c
Author: Jason Merrill 
Date:   Mon Mar 24 14:58:58 2014 -0400

	PR c++/60628
	* decl.c (create_array_type_for_decl): Complain about array of auto.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index c912ffc..f3a081b 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -8534,6 +8534,14 @@ create_array_type_for_decl (tree name, tree type, tree size)
   && (flag_iso || warn_vla > 0))
 pedwarn (input_location, OPT_Wvla, "array of array of runtime bound");
 
+  /* 8.3.4p1: ...if the type of the identifier of D contains the auto
+ type-specifier, the program is ill-formed.  */
+  if (type_uses_auto (type))
+{
+  error ("%qD declared as array of %qT", name, type);
+  return error_mark_node;
+}
+
   /* Figure out the index type for the array.  */
   if (size)
 itype = compute_array_index_type (name, size, tf_warning_or_error);
diff --git a/gcc/testsuite/g++.dg/cpp0x/auto42.C b/gcc/testsuite/g++.dg/cpp0x/auto42.C
new file mode 100644
index 000..fea4c28
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/auto42.C
@@ -0,0 +1,9 @@
+// PR c++/60628
+// { dg-do compile { target c++11 } }
+
+#include 
+
+void foo(int i)
+{
+  auto x[1] = { 0 };		// { dg-error "array of .auto" }
+}


Re: std::rethrow_exception is broken

2014-03-25 Thread Jonathan Wakely

On 24/03/14 19:19 +, Jonathan Wakely wrote:

There is a lot of code in libsupc++/eh_* that relies on
__cxa_exception and __cxa_dependent_exception having similar layouts,
so tricks like this work:

static inline void*
__gxx_caught_object(_Unwind_Exception* eo)
{
 // Bad as it looks, this actually works for dependent exceptions too.
 __cxa_exception* header = __get_exception_header_from_ue (eo);
 return header->adjustedPtr;
}

The idea is that although the eo might be a pointer to the
unwindHeader member  of either __cxa_exception or
__cxa_dependent_exception, the adjustedPtr member will be always be at
the same location relative to the unwindHeader member, so it Just
Works.

Except it doesn't.

offsetof(__cxa_exception, unwindHeader) == 80
offsetof(__cxa_dependent_exception, unwindHeader) == 80
offsetof(__cxa_exception, adjustedPtr) == 72
offsetof(__cxa_dependent_exception, adjustedPtr) == 64


Here's the output of GDB's pahole on __cxa_exception

(gdb) pahole struct __cxxabiv1::__cxa_exception
   struct __cxxabiv1::__cxa_exception {
 /*   0   8 */std::type_info * exceptionType
 /*   8   8 */void (*)(void *) exceptionDestructor
 /*  16   8 */void (*)(void) unexpectedHandler
 /*  24   8 */void (*)(void) terminateHandler
 /*  32   8 */__cxxabiv1::__cxa_exception * nextException
 /*  40   4 */int handlerCount
 /*  44   4 */int handlerSwitchValue
 /*  48   8 */const unsigned char * actionRecord
 /*  56   8 */const unsigned char * languageSpecificData
 /*  64   8 */unsigned long catchTemp
 /*  72   8 */void * adjustedPtr
 /*  80  32 */   struct _Unwind_Exception {
 /*   0   8 */  unsigned long exception_class
 /*   8   8 */  void (*)(_Unwind_Reason_Code, _Unwind_Exception *) 
exception_cleanup
 /*  16   8 */  unsigned long private_1
 /*  24   8 */  unsigned long private_2
 } unwindHeader
   } 
 
And here's the current definition of __cxa_dependent_exception:


(gdb) pahole struct __cxxabiv1::__cxa_dependent_exception 
   struct __cxxabiv1::__cxa_dependent_exception {

 /*   0   8 */void * primaryException
 /*   8   8 */void (*)(void) unexpectedHandler
 /*  16   8 */void (*)(void) terminateHandler
 /*  24   8 */__cxxabiv1::__cxa_exception * nextException
 /*  32   4 */int handlerCount
 /*  36   4 */int handlerSwitchValue
 /*  40   8 */const unsigned char * actionRecord
 /*  48   8 */const unsigned char * languageSpecificData
 /*  56   8 */unsigned long catchTemp
 /*  64   8 */void * adjustedPtr
  /* XXX 64 bit hole, try to pack */
 /*  80  32 */   struct _Unwind_Exception {
 /*   0   8 */  unsigned long exception_class
 /*   8   8 */  void (*)(_Unwind_Reason_Code, _Unwind_Exception *) 
exception_cleanup
 /*  16   8 */  unsigned long private_1
 /*  24   8 */  unsigned long private_2
 } unwindHeader
   } 


Notice the hole right before the unwindHeader member which is not
there in __cxa_exception. All the member which are supposed to be at
the same offsets as in __cxa_exception are 8 bytes earlier.

The attached patch adds a __padding member near the start so changes
that to:

(gdb) pahole struct __cxxabiv1::__cxa_dependent_exception 
   struct __cxxabiv1::__cxa_dependent_exception {

 /*   0   8 */void * primaryException
 /*   8   8 */void (*)(void *) __padding
 /*  16   8 */void (*)(void) unexpectedHandler
 /*  24   8 */void (*)(void) terminateHandler
 /*  32   8 */__cxxabiv1::__cxa_exception * nextException
 /*  40   4 */int handlerCount
 /*  44   4 */int handlerSwitchValue
 /*  48   8 */const unsigned char * actionRecord
 /*  56   8 */const unsigned char * languageSpecificData
 /*  64   8 */unsigned long catchTemp
 /*  72   8 */void * adjustedPtr
 /*  80  32 */   struct _Unwind_Exception {
 /*   0   8 */  unsigned long exception_class
 /*   8   8 */  void (*)(_Unwind_Reason_Code, _Unwind_Exception *) 
exception_cleanup
 /*  16   8 */  unsigned long private_1
 /*  24   8 */  unsigned long private_2
 } unwindHeader
   } 


That change allows all the pointer tricks in libsupc++/eh_*.cc to
continue working.  It's a change to the layout of a low-level type,
which is not visible to users linking to libsupc++.so, but anyone
linking statically will not be able to mix code using GCC 4.9's
libsupc++.a with the libsupc++.a from previous versions if they use
std::rethrow_exception() anywhere.

Tested x86_64-linux, I plan to commit this to trunk soon.

commit 06a845f80204947afd6866109db58cc85dc87117
Author: Jonathan Wakely 
Date:   Tue Mar 25 14:42:45 2014 +

PR libstdc++/60612
* libsupc++/eh_ptr.cc: Assert __cxa_dependent_exception layout is
compatible with __cxa_exception.
* libsupc++/unwind-cxx.h (__cxa_dependent_exception): Add padding.
Fix typos in comments.
* testsuite/1

Re: C++ PATCHes to run testsuite in C++14 mode

2014-03-25 Thread Jason Merrill

On 03/25/2014 12:32 PM, Smith-Rowland, Edward M wrote:

I noticed while converting some of my test cases to use the new targets that 
gnu targets don't seem to work.


Right.  To get -std=gnu* you specify the standard level and then use 
dg-options "".


Jason




Re: [Patch, AArch64] Fix shuffle for big-endian.

2014-03-25 Thread Tejas Belagod

Richard Henderson wrote:

On 02/21/2014 08:30 AM, Tejas Belagod wrote:

+  /* If two vectors, we end up with a wierd mixed-endian mode on NEON.  */
+  if (BYTES_BIG_ENDIAN)
+   {
+ if (!d->one_vector_p && d->perm[i] & nunits)
+   {
+ /* Extract the offset.  */
+ elt = d->perm[i] & (nunits - 1);
+ /* Reverse the top half.  */
+ elt = nunits - 1 - elt;
+ /* Offset it by the bottom half.  */
+ elt += nunits;
+   }
+ else
+   elt = nunits - 1 - d->perm[i];
+   }


Isn't this just

  elt = d->perm[i] ^ (nunits - 1);

all the time?  I.e. invert the index within the word,
but leave the word index (nunits) unchanged.



Yes, I think that works. Thanks!

Tejas.



Re: [Patch, AArch64] Fix shuffle for big-endian.

2014-03-25 Thread Tejas Belagod

Alan Lawrence wrote:
Further to that - all looks good after one-liner 
http://gcc.gnu.org/ml/gcc-patches/2014-03/msg01142.html has gone in. (Without 
that, enabling the code in Tejas' patch causes a regression in 
gcc.dg/torture/vshuf-v4hi.c as loading a vector constant goes wrong).




Thanks for your fix.

Tejas.


I'll send a patch to enable this and fix up the testsuite shortly...

Cheers, Alan

Alan Lawrence wrote:
I've been doing some local testing using this patch as a basis for some of my 
own work on NEON intrinsics, and it seems good to me. A couple of points:


(1) Re. the comment that "If two vectors, we end up with a wierd mixed-endian 
mode on NEON": firstly "wierd" should be spelt "weird";

secondly, if I understand right, this comment belongs with the next "if
(!d->one_vector_p...)" rather than the "if (BYTES_BIG_ENDIAN)" before which it's
written.

(2) as you say, this code is not exercised, unless you do something to remove 
the 'if (BYTES_BIG_ENDIAN) return false;' earlier in that same function. Can I 
politely suggest you do that here in this patch?


(3) In my own regression testing, with const_vec_perm enabled on big_endian, I 
see 2*PASS->FAIL, namely


gcc.dg/vect/vect-114.c scan-tree-dump-times vect "vectorized 0 loops" 1

gcc.dg/vect/vect-114.c -flto -ffat-lto-objects  scan-tree-dump-times
vect "vectorized 0 loops" 1

These are essentially noise, but the noise is removed and I see no other 
problems, if (after this patch) I re-enable the testsuite's "vect_perm" target 
selector for aarch64 big-endian (testsuite/lib/target-supports.exp). Would you 
like a separate patch for that or roll it in here?


Cheers, Alan

Tejas Belagod wrote:

Hi,

When a shuffle of more than one input happens, on NEON we end up with a 
'mixed-endian' format in the register list which TBL operates on. We don't make 
this correction in RTL and therefore the shuffle operation gets it incorrect. 
Here is a patch that fixes-up the index table in the selector rtx in RTL to also 
be mixed-endian to reflect what's happening on NEON.


As trunk stands, this patch will not be exercised as constant vector permute for 
Big-endian is disabled. I've tested this by locally enabling const vec_perm and 
it fixes the some regressions we have on big-endian:


aarch64_be-none-elf:
FAIL->PASS: gcc.c-torture/execute/loop-11.c execution,  -O3 -fomit-frame-pointer
FAIL->PASS: gcc.c-torture/execute/loop-11.c execution,  -O3 -fomit-frame-pointer 
-funroll-all-loops -finline-functions
FAIL->PASS: gcc.c-torture/execute/loop-11.c execution,  -O3 -fomit-frame-pointer 
-funroll-loops

FAIL->PASS: gcc.c-torture/execute/loop-11.c execution,  -O3 -g
FAIL->PASS: gcc.dg/torture/vector-shuffle1.c  -O0  execution test
FAIL->PASS: gcc.dg/torture/vshuf-v16qi.c  -O2  execution test
FAIL->PASS: gcc.dg/torture/vshuf-v2df.c  -O2  execution test
FAIL->PASS: gcc.dg/torture/vshuf-v2di.c  -O2  execution test
FAIL->PASS: gcc.dg/torture/vshuf-v2sf.c  -O2  execution test
FAIL->PASS: gcc.dg/torture/vshuf-v2si.c  -O2  execution test
FAIL->PASS: gcc.dg/torture/vshuf-v4sf.c  -O2  execution test
FAIL->PASS: gcc.dg/torture/vshuf-v4si.c  -O2  execution test
FAIL->PASS: gcc.dg/torture/vshuf-v8hi.c  -O2  execution test
FAIL->PASS: gcc.dg/torture/vshuf-v8qi.c  -O2  execution test
FAIL->PASS: gcc.dg/vect/vect-114.c -flto -ffat-lto-objects execution test
FAIL->PASS: gcc.dg/vect/vect-114.c execution test
FAIL->PASS: gcc.dg/vect/vect-15.c -flto -ffat-lto-objects execution test
FAIL->PASS: gcc.dg/vect/vect-15.c execution test

Also regressed on aarch64-none-elf.

OK for stage-1?

Thanks,
Tejas.

2014-02-21  Tejas Belagod  

gcc/
* config/aarch64/aarch64.c (aarch64_evpc_tbl): Fix index vector for
big-endian when dealing with more than one input shuffle vector.










Re: [PATCH] Don't bootstrap libsanitizer or libvtv unless needed

2014-03-25 Thread Paolo Bonzini

Il 20/03/2014 13:24, Jakub Jelinek ha scritto:

Hi!

We currently bootstrap both libsanitizer and libvtv, the former
just in case somebody decides to --with-build-config=bootstrap-asan
(or --with-build-config=bootstrap-ubsan), the latter if somebody decides
to --enable-vtable-verify.

This patch changes it so that we only bootstrap libsanitizer if
bootstrap-asan or bootstrap-ubsan is in BOOT_CONFIG, and only bootstrap
libvtv if --enable-vtable-verify.

Bootstrapped/regtested on x86_64-linux and i686-linux, on x86_64 it
saved a few minutes of build time, neither libsanitizer nor libvtv
has been bootstrapped, only built in stage3.
Currently also bootstrapping on i686-linux with
--enable-vtable-verify --with-build-config=bootstrap-asan
but already got into stage2 and verified that both libsanitizer and libvtv
are being bootstrapped in that case.

Ok for trunk?

2014-03-20  Jakub Jelinek  

* configure.ac: Move BUILD_CONFIG set up earlier.  Add
--enable-vtable-verify option parsing.  Don't add
target-libsanitizer to bootstrap_target_libs unless
--with-build-config=bootstrap-asan or
--with-build-config=bootstrap-ubsan.  Don't add target-libvtv
to bootstrap_target_libs unless --enable-vtable-verify.
* configure: Regenerated.


Is the extra complication really worth saving a few minutes of compile time?

Paolo


Re: C++ PATCHes to run testsuite in C++14 mode

2014-03-25 Thread Smith-Rowland, Edward M
Jason,
I noticed while converting some of my test cases to use the new targets that 
gnu targets don't seem to work.
It doesn't matter for the test cases at hand but we might want to consider
target gnu++11
target gnu++11_only
target gnu++1y
target gnu++1y_only



[PATCH, rs6000] Improve atomic_load/store code gen for Power8 TI mode

2014-03-25 Thread Pat Haugen
Power8 can use lq/stq instructions for TI mode atomic_load/store. 
Bootstrap/regtest with no new failures. Ok for trunk and 4.8 (once 
bootstrap/regtest finishes)?


-Pat


2014-03-25  Pat Haugen  

* config/rs6000/sync.md (AINT mode_iterator): Move definition.
(loadsync_): Change mode.
(atomic_load, atomic_store): Add support for TI mode.
(load_quadpti, store_quadpti): New.
* config/rs6000/rs6000.md (unspec enum): Add UNSPEC_LSQ.

gcc/testsuite:
* gcc.target/powerpc/atomic_load_store-p8.c: New.


Index: testsuite/gcc.target/powerpc/atomic_load_store-p8.c
===
--- testsuite/gcc.target/powerpc/atomic_load_store-p8.c	(revision 0)
+++ testsuite/gcc.target/powerpc/atomic_load_store-p8.c	(revision 0)
@@ -0,0 +1,22 @@
+/* { dg-do compile { target { powerpc*-*-* && lp64 } } } */
+/* { dg-skip-if "" { powerpc*-*-darwin* } { "*" } { "" } } */
+/* { dg-require-effective-target powerpc_p8vector_ok } */
+/* { dg-options "-mcpu=power8 -O2" } */
+/* { dg-final { scan-assembler-times "lq" 1 } } */
+/* { dg-final { scan-assembler-times "stq" 1 } } */
+/* { dg-final { scan-assembler-not "bl __atomic" } } */
+/* { dg-final { scan-assembler-not "lqarx" } } */
+/* { dg-final { scan-assembler-not "stqcx" } } */
+
+__int128
+atomic_load_128_relaxed (__int128 *ptr)
+{
+	return __atomic_load_n (ptr, __ATOMIC_RELAXED);
+}
+
+void
+atomic_store_128_relaxed (__int128 *ptr, __int128 val)
+{
+	__atomic_store_n (ptr, val, __ATOMIC_RELAXED);
+}
+
Index: config/rs6000/sync.md
===
--- config/rs6000/sync.md	(revision 208798)
+++ config/rs6000/sync.md	(working copy)
@@ -107,10 +107,17 @@ (define_insn "isync"
   "isync"
   [(set_attr "type" "isync")])
 
+;; Types that we should provide atomic instructions for.
+(define_mode_iterator AINT [QI
+			HI
+			SI
+			(DI "TARGET_POWERPC64")
+			(TI "TARGET_SYNC_TI")])
+
 ;; The control dependency used for load dependency described
 ;; in B.2.3 of the Power ISA 2.06B.
 (define_insn "loadsync_"
-  [(unspec_volatile:BLK [(match_operand:INT1 0 "register_operand" "r")]
+  [(unspec_volatile:BLK [(match_operand:AINT 0 "register_operand" "r")]
 			UNSPECV_ISYNC)
(clobber (match_scratch:CC 1 "=y"))]
   ""
@@ -119,17 +126,39 @@ (define_insn "loadsync_"
(set_attr "length" "12")])
 
 (define_expand "atomic_load"
-  [(set (match_operand:INT1 0 "register_operand" "")		;; output
-	(match_operand:INT1 1 "memory_operand" ""))		;; memory
+  [(set (match_operand:AINT 0 "register_operand" "")		;; output
+	(match_operand:AINT 1 "memory_operand" ""))		;; memory
(use (match_operand:SI 2 "const_int_operand" ""))]		;; model
   ""
 {
+  if (mode == TImode && !TARGET_QUAD_MEMORY)
+FAIL;
+
   enum memmodel model = (enum memmodel) INTVAL (operands[2]);
 
   if (model == MEMMODEL_SEQ_CST)
 emit_insn (gen_hwsync ());
 
-  emit_move_insn (operands[0], operands[1]);
+  if (mode != TImode)
+emit_move_insn (operands[0], operands[1]);
+  else
+{
+  rtx op0 = operands[0];
+  rtx op1 = operands[1];
+  rtx pti_reg = gen_reg_rtx (PTImode);
+
+  // Can't have indexed address for 'lq'
+  if (indexed_address (XEXP (op1, 0), TImode))
+	{
+	  rtx old_addr = XEXP (op1, 0);
+	  rtx new_addr = force_reg (Pmode, old_addr);
+	  operands[1] = op1 = replace_equiv_address (op1, new_addr);
+	}
+
+  emit_insn (gen_load_quadpti (pti_reg, op1));
+
+  emit_move_insn (op0, gen_lowpart (TImode, pti_reg));
+}
 
   switch (model)
 {
@@ -146,12 +175,25 @@ (define_expand "atomic_load"
   DONE;
 })
 
+(define_insn "load_quadpti"
+  [(set (match_operand:PTI 0 "quad_int_reg_operand" "=&r")
+	(unspec:PTI
+ [(match_operand:TI 1 "quad_memory_operand" "wQ")] UNSPEC_LSQ))]
+  "TARGET_QUAD_MEMORY
+   && !reg_mentioned_p (operands[0], operands[1])"
+  "lq %0,%1"
+  [(set_attr "type" "load")
+   (set_attr "length" "4")])
+
 (define_expand "atomic_store"
-  [(set (match_operand:INT1 0 "memory_operand" "")		;; memory
-	(match_operand:INT1 1 "register_operand" ""))		;; input
-   (use (match_operand:SI 2 "const_int_operand" ""))]		;; model
+  [(set (match_operand:AINT 0 "memory_operand" "")  ;; memory
+(match_operand:AINT 1 "register_operand" ""))   ;; input
+   (use (match_operand:SI 2 "const_int_operand" ""))]   ;; model
   ""
 {
+  if (mode == TImode && !TARGET_QUAD_MEMORY)
+FAIL;
+
   enum memmodel model = (enum memmodel) INTVAL (operands[2]);
   switch (model)
 {
@@ -166,10 +208,38 @@ (define_expand "atomic_store"
 default:
   gcc_unreachable ();
 }
-  emit_move_insn (operands[0], operands[1]);
+  if (mode != TImode)
+emit_move_insn (operands[0], operands[1]);
+  else
+{
+  rtx op0 = operands[0];
+  rtx op1 = operands[1];
+  rtx pti_reg = gen_reg_rtx (PTImode);
+
+  // Can't have indexed address for 'stq'
+  if (indexed_address (XE

[PATCH] Fix undefined behavior in IRA

2014-03-25 Thread Marek Polacek
This is a temporary fix for UB in IRA, where ubsan complains because
there's signed iteger overflow in the multiplication.  To shut this 
error up, we can perform the multiplication in unsigned and only then
cast the result of the multiplication to int.

Regtested/bootstrapped on x86_64-linux, ok for trunk?

2014-03-25  Marek Polacek  

PR other/59545
* ira-color.c (update_conflict_hard_regno_costs): Perform the
multiplication in unsigned type.

diff --git gcc/ira-color.c gcc/ira-color.c
index c20aaf7..1f4c96e 100644
--- gcc/ira-color.c
+++ gcc/ira-color.c
@@ -1505,7 +1505,7 @@ update_conflict_hard_regno_costs (int *costs, enum 
reg_class aclass,
index = ira_class_hard_reg_index[aclass][hard_regno];
if (index < 0)
  continue;
-   cost = conflict_costs [i] * mult / div;
+   cost = (int) ((unsigned) conflict_costs [i] * mult) / div;
if (cost == 0)
  continue;
cont_p = true;

Marek


[DOC PATCH] Describe VLAs in struct/union (PR c/37428)

2014-03-25 Thread Marek Polacek
We should mention this GNU C extension in the manual.

Ok?

2014-03-25  Marek Polacek  

PR c/37428
* doc/extend.texi (C Extensions): Mention variable-length arrays in
a structure/union.

diff --git gcc/doc/extend.texi gcc/doc/extend.texi
index 986cc94..b564ade 100644
--- gcc/doc/extend.texi
+++ gcc/doc/extend.texi
@@ -1592,6 +1592,18 @@ Jumping or breaking out of the scope of the array name 
deallocates the
 storage.  Jumping into the scope is not allowed; you get an error
 message for it.
 
+@cindex variable-length array in a structure
+As an extension, GCC accepts variable-length arrays as a member of
+a structure or a union.  For example:
+
+@smallexample
+void
+foo (int n)
+@{
+  struct S @{ int x[n]; @};
+@}
+@end smallexample
+
 @cindex @code{alloca} vs variable-length arrays
 You can use the function @code{alloca} to get an effect much like
 variable-length arrays.  The function @code{alloca} is available in

Marek


RFA: Fix PR rtl-optimization/60651

2014-03-25 Thread Joern Rennecke
As described in the PR, this patch fixes a wrong-code bug by making the order of
emitted mode switching instructions more consistet & predictable.

Bootstrapped / regtested on i686-pc-linux-gnu.


tmp
Description: Binary data


Re: [PATCH AArch64] Fix aarch64_simd_valid_immediate for Bigendian

2014-03-25 Thread James Greenhalgh
On Mon, Mar 24, 2014 at 11:32:39AM +, Marcus Shawcroft wrote:
> On 21 March 2014 14:55, Alan Lawrence  wrote:
> > This patch fixes a bug whereby a vector like V8QImode {1,0,1,0,1,0,1,0} can
> > result in an instruction like
> >
> > movi v1.4h, 0x1
> >
> > whereas on bigendian this should be
> >
> > movi v1.4h, 0x1, lsl 8
> >
> > Regression tested on aarch64_be-none-elf: no changes in libstdc++, newlib;
> > no regressions in gcc or g++ and FAIL->PASS as listed below.
> >
> > Ok for trunk (stage 4) ?
> 
> 
> > Cheers, Alan
> >
> > gcc/ChangeLog:
> >
> > 2014-03-21  Alan Lawrence  alan.lawre...@arm.com
> >
> > * config/aarch64/aarch64.c (aarch64_simd_valid_immediate): reverse
> > order
> > of elements for bigendian.
> 
> s/reverse/Reverse/
> 
> This should be fixed now in stage-4, the fix looks straight forward.
> If there are no objections from RM's in the next 24 hours go ahead and
> commit it.
> 

I've committed this on Alan's behalf as revision 208814, with the
ChangeLog below.

Thanks,
James

gcc/

2014-03-25  Alan Lawrence  

* config/aarch64/aarch64.c (aarch64_simd_valid_immediate): Reverse
order of elements for big-endian.



Re: [Build, Driver] Add -lcilkrts for -fcilkplus

2014-03-25 Thread Paolo Bonzini

Il 11/03/2014 07:42, Tobias Burnus ha scritto:


+# Check to see if -pthread or -lpthread is needed.  Prefer the former.
+# In case the pthread.h system header is not found, this test will fail.
+XPCFLAGS=""
+CFLAGS="$CFLAGS -pthread"
+AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+  [#include 
+   void *g(void *d) { return NULL; }],
+  [pthread_t t; pthread_create(&t,NULL,g,NULL);])],
+ [XPCFLAGS=" -Wc,-pthread"],
+ [CFLAGS="$save_CFLAGS" LIBS="-lpthread $LIBS"
+  AC_LINK_IFELSE(
+   [AC_LANG_PROGRAM(
+[#include 
+ void *g(void *d) { return NULL; }],
+[pthread_t t; pthread_create(&t,NULL,g,NULL);])],
+   [],
+   [AC_MSG_ERROR([Pthreads are required to build libcilkrts])])])
+


XPCFLAGS is dead, I think?

Also, should -pthread be included in the spec too?

Paolo


[PATCH][ARM/AArch64][1/2] Crypto intrinsics tuning for Cortex-A53 - "type" Attribute restructuring

2014-03-25 Thread Kyrill Tkachov

Hi all,

This two-patch series adds scheduling information for the ARMv8-A Crypto 
instructions on the Cortex-A53.
This first patch does some preliminary restructuring to allow the arm and 
aarch64 backends to share the is_neon_type attribute.


It also splits the crypto_aes type into crypto_aese and crypto_aesmc since the 
aese/aesd and aesmc/aesimc instructions will be treated differently (in patch 2/2).


This patch touches both arm and aarch64 backends since there's no clean way to 
split it into per-backend patches without breaking each one.


Tested and bootstrapped on arm-none-linux-gnueabihf and on 
aarch64-none-linux-gnu.

This patch is fairly uncontroversial and doesn't change functionality or code 
generation by itself.


I'll leave it to the maintainers to decide when this should go in...

Thanks,
Kyrill

2014-03-25  Kyrylo Tkachov  

* config/aarch64/aarch64-simd.md (aarch64_crypto_aesv16qi):
Use crypto_aese type.
(aarch64_crypto_aesv16qi): Use crypto_aesmc type.
* config/arm/arm.md (is_neon_type): Replace crypto_aes with
crypto_aese, crypto_aesmc.  Move to types.md.
* config/arm/types.md (crypto_aes): Split into crypto_aese,
crypto_aesmc.
* config/arm/iterators.md (crypto_type): Likewise.commit 267f7406f6c343872e783e5ae74a55cb49387218
Author: Kyrylo Tkachov 
Date:   Mon Jan 27 11:29:44 2014 +

 Crypto scheduling for A53

diff --git a/gcc/config/aarch64/aarch64-simd.md b/gcc/config/aarch64/aarch64-simd.md
index 4dffb59..18eec8d 100644
--- a/gcc/config/aarch64/aarch64-simd.md
+++ b/gcc/config/aarch64/aarch64-simd.md
@@ -4225,7 +4225,7 @@
  CRYPTO_AES))]
   "TARGET_SIMD && TARGET_CRYPTO"
   "aes\\t%0.16b, %2.16b"
-  [(set_attr "type" "crypto_aes")]
+  [(set_attr "type" "crypto_aese")]
 )
 
 (define_insn "aarch64_crypto_aesv16qi"
@@ -4234,7 +4234,7 @@
 	 CRYPTO_AESMC))]
   "TARGET_SIMD && TARGET_CRYPTO"
   "aes\\t%0.16b, %1.16b"
-  [(set_attr "type" "crypto_aes")]
+  [(set_attr "type" "crypto_aesmc")]
 )
 
 ;; sha1
diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md
index 2ddda02..4df24a2 100644
--- a/gcc/config/arm/arm.md
+++ b/gcc/config/arm/arm.md
@@ -262,105 +262,6 @@
 ; initialized by arm_option_override()
 (define_attr "ldsched" "no,yes" (const (symbol_ref "arm_ld_sched")))
 
-; YES if the "type" attribute assigned to the insn denotes an
-; Advanced SIMD instruction, NO otherwise.
-(define_attr "is_neon_type" "yes,no"
-	 (if_then_else (eq_attr "type"
-	 "neon_add, neon_add_q, neon_add_widen, neon_add_long,\
-  neon_qadd, neon_qadd_q, neon_add_halve, neon_add_halve_q,\
-  neon_add_halve_narrow_q,\
-  neon_sub, neon_sub_q, neon_sub_widen, neon_sub_long, neon_qsub,\
-  neon_qsub_q, neon_sub_halve, neon_sub_halve_q,\
-  neon_sub_halve_narrow_q,\
-  neon_abs, neon_abs_q, neon_neg, neon_neg_q, neon_qneg,\
-  neon_qneg_q, neon_qabs, neon_qabs_q, neon_abd, neon_abd_q,\
-  neon_abd_long, neon_minmax, neon_minmax_q, neon_compare,\
-  neon_compare_q, neon_compare_zero, neon_compare_zero_q,\
-  neon_arith_acc, neon_arith_acc_q, neon_reduc_add,\
-  neon_reduc_add_q, neon_reduc_add_long, neon_reduc_add_acc,\
-  neon_reduc_add_acc_q, neon_reduc_minmax, neon_reduc_minmax_q,\
-  neon_logic, neon_logic_q, neon_tst, neon_tst_q,\
-  neon_shift_imm, neon_shift_imm_q, neon_shift_imm_narrow_q,\
-  neon_shift_imm_long, neon_shift_reg, neon_shift_reg_q,\
-  neon_shift_acc, neon_shift_acc_q, neon_sat_shift_imm,\
-  neon_sat_shift_imm_q, neon_sat_shift_imm_narrow_q,\
-  neon_sat_shift_reg, neon_sat_shift_reg_q,\
-  neon_ins, neon_ins_q, neon_move, neon_move_q, neon_move_narrow_q,\
-  neon_permute, neon_permute_q, neon_zip, neon_zip_q, neon_tbl1,\
-  neon_tbl1_q, neon_tbl2, neon_tbl2_q, neon_tbl3, neon_tbl3_q,\
-  neon_tbl4, neon_tbl4_q, neon_bsl, neon_bsl_q, neon_cls,\
-  neon_cls_q, neon_cnt, neon_cnt_q, neon_dup, neon_dup_q,\
-  neon_ext, neon_ext_q, neon_rbit, neon_rbit_q,\
-  neon_rev, neon_rev_q, neon_mul_b, neon_mul_b_q, neon_mul_h,\
-  neon_mul_h_q, neon_mul_s, neon_mul_s_q, neon_mul_b_long,\
-  neon_mul_h_long, neon_mul_s_long, neon_mul_d_long, neon_mul_h_scalar,\
-  neon_mul_h_scalar_q, neon_mul_s_scalar, neon_mul_s_scalar_q,\
-  neon_mul_h_scalar_long, neon_mul_s_scalar_long, neon_sat_mul_b,\
-  neon_sat_mul_b_q, neon_sat_mul_h, neon_sat_mul_h_q,\
-  neon_sat_mul_s, neon_sat_mul_s_q, neon_sat_mul_b_long,\
-  neon_sat_mul_h_long, neon_sat_mul_s_long, neon_sat_mul_h_scalar,\
-  neon_sat_mul_h_scalar_q, neon_sat_mul_s_scalar,\
-  neon_sat_mul_s_scalar_q, neon_sat_mul_h_scalar_long,\
-  neon_sat_mul_s_scalar_long, neon_mla_b, neon_mla_b_q, neon_mla_h,\
-  neon_mla_h_q, neon_mla_s, neon_mla_s_q, neon_mla_b_long,\
-  neon_mla_h_long, neon_mla_s_long, neon_mla_h_scalar

[PATCH][ARM/AArch64][2/2] Crypto intrinsics tuning for Cortex-A53 - pipeline description

2014-03-25 Thread Kyrill Tkachov

Hi all,

In ARMv8-A there's a general expectation that AESE/AESMC and AESD/AESIMC 
sequences of the form:


AESE Vn, _
AESMC Vn, Vn

will issue both instructions in a single cycle on super-scalar implementations. 
It would be nice to model that in our pipeline descriptions. This patch defines 
a function to detect such pairs and uses it in the pipeline description for 
these instructions for the Cortex-A53.


The patch also adds some missed AdvancedSIMD information to the pipeline 
description for the Cortex-A53.


Bootstrapped and tested on arm-none-linux-gnueabihf and aarch64-none-linux-gnu.

Cortex-A53 scheduling is the default scheduling description on aarch64 so this 
patch can change default behaviour. That's an argument for taking this in stage1 
or maybe backporting it into 4.9.1 once the release is made.


What do people think?

Thanks,
Kyrill


2014-03-25  Kyrylo Tkachov  

* config/arm/aarch-common.c (aarch_crypto_can_dual_issue): New function.
* config/arm/aarch-common-protos.h (aarch_crypto_can_dual_issue): Declare
extern.
* config/arm/cortex-a53.md: Add reservations and bypass for crypto
instructions as well as AdvancedSIMD loads.
commit b89802221229e8ca7fac5fcd6d552392301edde0
Author: Kyrylo Tkachov 
Date:   Mon Jan 27 11:29:44 2014 +

 Crypto scheduling for A53

diff --git a/gcc/config/arm/aarch-common-protos.h b/gcc/config/arm/aarch-common-protos.h
index 056fe56..2b33626 100644
--- a/gcc/config/arm/aarch-common-protos.h
+++ b/gcc/config/arm/aarch-common-protos.h
@@ -23,6 +23,7 @@
 #ifndef GCC_AARCH_COMMON_PROTOS_H
 #define GCC_AARCH_COMMON_PROTOS_H
 
+extern int aarch_crypto_can_dual_issue (rtx, rtx);
 extern int arm_early_load_addr_dep (rtx, rtx);
 extern int arm_early_store_addr_dep (rtx, rtx);
 extern int arm_mac_accumulator_is_mul_result (rtx, rtx);
diff --git a/gcc/config/arm/aarch-common.c b/gcc/config/arm/aarch-common.c
index c11f7e9..17c4924 100644
--- a/gcc/config/arm/aarch-common.c
+++ b/gcc/config/arm/aarch-common.c
@@ -31,6 +31,42 @@
 #include "c-family/c-common.h"
 #include "rtl.h"
 
+/* In ARMv8-A there's a general expectation that AESE/AESMC
+   and AESD/AESIMC sequences of the form:
+
+   AESE Vn, _
+   AESMC Vn, Vn
+
+   will issue both instructions in a single cycle on super-scalar
+   implementations.  This function identifies such pairs.  */
+
+int
+aarch_crypto_can_dual_issue (rtx producer, rtx consumer)
+{
+  rtx producer_src, consumer_src;
+
+  producer = single_set (producer);
+  consumer = single_set (consumer);
+
+  producer_src = producer ? SET_SRC (producer) : NULL;
+  consumer_src = consumer ? SET_SRC (consumer) : NULL;
+
+  if (producer_src && consumer_src
+  && GET_CODE (producer_src) == UNSPEC && GET_CODE (consumer_src) == UNSPEC
+  && ((XINT (producer_src, 1) == UNSPEC_AESE
+   && XINT (consumer_src, 1) == UNSPEC_AESMC)
+  || (XINT (producer_src, 1) == UNSPEC_AESD
+  && XINT (consumer_src, 1) == UNSPEC_AESIMC)))
+  {
+unsigned int regno = REGNO (SET_DEST (producer));
+
+return REGNO (SET_DEST (consumer)) == regno
+   && REGNO (XVECEXP (consumer_src, 0, 0)) == regno;
+  }
+
+  return 0;
+}
+
 typedef struct
 {
   rtx_code search_code;
diff --git a/gcc/config/arm/cortex-a53.md b/gcc/config/arm/cortex-a53.md
index deae8eb..b131c81 100644
--- a/gcc/config/arm/cortex-a53.md
+++ b/gcc/config/arm/cortex-a53.md
@@ -61,6 +61,11 @@
 
 (define_cpu_unit "cortex_a53_fp_div_sqrt" "cortex_a53")
 
+;; The Advanced SIMD pipelines.
+
+(define_cpu_unit "cortex_a53_simd0" "cortex_a53")
+(define_cpu_unit "cortex_a53_simd1" "cortex_a53")
+
 
 ;; ALU instructions.
 
@@ -248,6 +253,39 @@
   "cortex_a53_slot0, cortex_a53_fp_div_sqrt * 28")
 
 
+;; ARMv8-A Cryptographic extensions.
+
+
+(define_insn_reservation "cortex_a53_crypto_aese" 2
+  (and (eq_attr "tune" "cortexa53")
+   (eq_attr "type" "crypto_aese"))
+  "cortex_a53_simd0")
+
+(define_insn_reservation "cortex_a53_crypto_aesmc" 2
+  (and (eq_attr "tune" "cortexa53")
+   (eq_attr "type" "crypto_aesmc"))
+  "cortex_a53_simd0 | cortex_a53_simd1")
+
+(define_insn_reservation "cortex_a53_crypto_sha1_fast" 2
+  (and (eq_attr "tune" "cortexa53")
+   (eq_attr "type" "crypto_sha1_fast, crypto_sha256_fast"))
+  "cortex_a53_simd0")
+
+(define_insn_reservation "cortex_a53_crypto_sha1_xor" 3
+  (and (eq_attr "tune" "cortexa53")
+   (eq_attr "type" "crypto_sha1_xor"))
+  "cortex_a53_simd0")
+
+(define_insn_reservation "cortex_a53_crypto_sha_slow" 5
+  (and (eq_attr "tune" "cortexa53")
+   (eq_attr "type" "crypto_sha1_slow, crypto_sha256_slow"))
+  "cortex_a53_simd0")
+
+(define_bypass 0 "cortex_a53_crypto_aese"
+ "cortex_a53_crypto_aesmc"
+  

Re: [PATCH][ARM] Handle FMA code in rtx costs.

2014-03-25 Thread Richard Earnshaw
On 24/03/14 17:15, Kyrill Tkachov wrote:
> Hi all,
> 
> This patch adds proper rtx costing logic for floating point fma operations on 
> arm. It also handles the fma+neg combinations that can be expressed with 
> vfms,vfnma or vfnms instructions.
> Not much else to say here...
> 
> Tested and boostrapped on arm-none-linux-gnueabihf.
> 
> Ok for next stage1?
> 
> Thanks,
> Kyrill
> 
> 2014-03-24  Kyrylo Tkachov  
> 
>  * config/arm/arm.c (arm_new_rtx_costs): Handle FMA.
> 
> 
> arm-fma-costs.patch
> 
> 
> commit 9cebc525c432e4a87ead5b513b70c99dff6628c8
> Author: Kyrylo Tkachov 
> Date:   Thu Mar 20 09:13:06 2014 +
> 
> [ARM] Cost FMA operations properly.
> 
> diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
> index 5619ebd..e7a0530 100644
> --- a/gcc/config/arm/arm.c
> +++ b/gcc/config/arm/arm.c
> @@ -10673,6 +10673,36 @@ arm_new_rtx_costs (rtx x, enum rtx_code code, enum 
> rtx_code outer_code,
>*cost = LIBCALL_COST (1);
>return false;
>  
> +case FMA:
> +  if (TARGET_32BIT && TARGET_HARD_FLOAT && TARGET_FMA)
> +{
> +  rtx op0 = XEXP (x, 0);
> +  rtx op1 = XEXP (x, 1);
> +  rtx op2 = XEXP (x, 2);
> +
> +  *cost = COSTS_N_INSNS (1);
> +
> +  /* vfms or vfnma.  */
> +  if (GET_CODE (op0) == NEG)
> +op0 = XEXP (op0, 0);
> +
> +  /* vfnms or vfnma.  */
> +  if (GET_CODE (op2) == NEG)
> +op2 = XEXP (op2, 0);
> +
> +  *cost += rtx_cost (op0, FMA, 0, speed_p);
> +  *cost += rtx_cost (op1, FMA, 1, speed_p);
> +  *cost += rtx_cost (op2, FMA, 2, speed_p);
> +
> +  if (speed_p)
> +*cost += extra_cost->fp[mode ==DFmode].fma;
> +
> +  return true;
> +}
> +
> +  *cost = LIBCALL_COST (1);

This should be LIBCALL_COST (3) (there are 3 arguments to the operation).

Otherwise OK.

R.




Re: [PATCH, ARM] Enable tail call optimization for long call

2014-03-25 Thread Marcus Shawcroft
On 24 March 2014 11:26, Jiong Wang  wrote:

> gcc/
>   * config/arm/predicates.md (call_insn_operand): Add long_call check.
>   * config/arm/arm.md (sibcall, sibcall_value): Force the address to reg for
> long_call.
>   * config/aarch64/aarch64.c (arm_function_ok_for_sibcall): Remove long_call
> restriction.

aarch64 -> arm

/Marcus


Re: [PATCH] Fix PR c++/60573

2014-03-25 Thread Jason Merrill

On 03/18/2014 10:46 PM, Adam Butcher wrote:

+ if (TYPE_BEING_DEFINED (scope->this_entity))
+   if (scope->level_chain == 0
+   || scope->this_entity != scope->level_chain->this_entity)
+ break;


I don't think this is an adequate test; if you have another class 
wrapping B, you'll have two levels of context pushed for the declarator, 
so the this_entities will compare unequal.  I think we need some way to 
designate a scope that actually corresponds to a class-specifier.


Jason



Re: [PATCH][ARM] Cortex-A8 rtx cost table

2014-03-25 Thread Richard Earnshaw
On 25/03/14 11:36, Kyrill Tkachov wrote:
> Hi all,
> 
> This patch adds the rtx cost table for the Cortex-A8 core. It's an ARMv7 
> core, 
> so it goes into arm.c instead of aarch-cost-tables.h.
> 
> Bootstrapped and tested on a Cortex-A8 Linux system and benchmarked to make 
> sure 
> no performance regressions. There are various small improvements here and 
> there.
> 
> Ok for next stage 1?
> 
> Thanks,
> Kyrill
> 
> 2013-03-25  Kyrylo Tkachov  
> 
>  * config/arm/arm.c (cortexa8_extra_costs): New table.
>  (arm_cortex_a8_tune): New tuning struct.
>  * config/arm/arm-cores.def (cortex-a8): Use cortex_a8 tuning struct.
> 
> 

OK.

R.




Re: [PATCH, ARM] Enable tail call optimization for long call

2014-03-25 Thread Richard Earnshaw
On 24/03/14 11:26, Jiong Wang wrote:
> This patch enables tail call optimization for long call on arm.
> 
> Previously we have too strict check on arm_function_ok_for_sibcall and
> be lack of the support on sibcall/sibcall_value expand that long call tail 
> oppportunities are lost.
> 
> OK for next next stage 1?
> 

I think this is OK for EABI targets (since we can rely on the linker
generating the right form of interworking veneer), but I'm less certain
about other systems (do we still support COFF).

I think I'd prefer the patch to factor in TARGET_AAPCS_BASED and to
assume that if that is true then arbitrary tail-calls are safe.

R.

> thanks.
> 
> 
> tail-long-call.patch
> 
> 
> diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
> index d5f9ff3..8dcdfa8 100644
> --- a/gcc/config/arm/arm.c
> +++ b/gcc/config/arm/arm.c
> @@ -6087,11 +6087,6 @@ arm_function_ok_for_sibcall (tree decl, tree exp)
>if (TARGET_VXWORKS_RTP && flag_pic && !targetm.binds_local_p (decl))
>  return false;
>  
> -  /* Cannot tail-call to long calls, since these are out of range of
> - a branch instruction.  */
> -  if (decl && arm_is_long_call_p (decl))
> -return false;
> -
>/* If we are interworking and the function is not declared static
>   then we can't tail-call it unless we know that it exists in this
>   compilation unit (since it might be a Thumb routine).  */
> diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md
> index 2ddda02..fe285f0 100644
> --- a/gcc/config/arm/arm.md
> +++ b/gcc/config/arm/arm.md
> @@ -9444,8 +9444,10 @@
>"TARGET_32BIT"
>"
>{
> -if (!REG_P (XEXP (operands[0], 0))
> -   && (GET_CODE (XEXP (operands[0], 0)) != SYMBOL_REF))
> +if ((!REG_P (XEXP (operands[0], 0))
> +  && GET_CODE (XEXP (operands[0], 0)) != SYMBOL_REF)
> + || (GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF
> + && arm_is_long_call_p (SYMBOL_REF_DECL (XEXP (operands[0], 0)
>   XEXP (operands[0], 0) = force_reg (SImode, XEXP (operands[0], 0));
>  
>  if (operands[2] == NULL_RTX)
> @@ -9462,8 +9464,10 @@
>"TARGET_32BIT"
>"
>{
> -if (!REG_P (XEXP (operands[1], 0)) &&
> -   (GET_CODE (XEXP (operands[1],0)) != SYMBOL_REF))
> +if ((!REG_P (XEXP (operands[1], 0))
> +  && GET_CODE (XEXP (operands[1], 0)) != SYMBOL_REF)
> + || (GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
> + && arm_is_long_call_p (SYMBOL_REF_DECL (XEXP (operands[1], 0)
>   XEXP (operands[1], 0) = force_reg (SImode, XEXP (operands[1], 0));
>  
>  if (operands[3] == NULL_RTX)
> diff --git a/gcc/config/arm/predicates.md b/gcc/config/arm/predicates.md
> index ce5c9a8..3673343 100644
> --- a/gcc/config/arm/predicates.md
> +++ b/gcc/config/arm/predicates.md
> @@ -673,5 +673,6 @@
> (match_code "reg" "0")))
>  
>  (define_predicate "call_insn_operand"
> -  (ior (match_code "symbol_ref")
> +  (ior (and (match_code "symbol_ref")
> + (match_test "!arm_is_long_call_p (SYMBOL_REF_DECL (op))"))
> (match_operand 0 "s_register_operand")))
> diff --git a/gcc/testsuite/gcc.target/arm/tail-long-call.c 
> b/gcc/testsuite/gcc.target/arm/tail-long-call.c
> new file mode 100644
> index 000..9b27468
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/arm/tail-long-call.c
> @@ -0,0 +1,12 @@
> +/* { dg-skip-if "need at least armv5te" { *-*-* } { "-march=armv[234]*" 
> "-mthumb" } { "" } } */
> +/* { dg-options "-O2 -march=armv5te -marm" } */
> +/* { dg-final { scan-assembler "bx" } } */
> +/* { dg-final { scan-assembler-not "blx" } } */
> +
> +int lcal (int) __attribute__ ((long_call));
> +
> +int
> +dec (int a)
> +{
> +  return lcal (a);
> +}
> 




Re: Please revert the patches in bug #54040 and #59346 and special case x32

2014-03-25 Thread Svante Signell
Hi, 

Should I file a bug to get feedback on this issue? I know Ada is not the
most prioritized language for gcc, but anyway. The current
implementation is not POSIX-compliant.

On Mon, 2014-03-24 at 14:37 +0100, Svante Signell wrote:
> In reply to the thread ending with:
> http://gcc.gnu.org/ml/gcc-patches/2013-11/msg02069.html
> 
> and bugs:
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54040
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59346
> 
> Changing s-osinte-posix.adb
> 
> -  tv_nsec => long (Long_Long_Integer (F * 10#1#E9)));
> +  tv_nsec => time_t (Long_Long_Integer (F * 10#1#E9)));
> 
> breaks the build for kFreeBSD and Hurd too (in addition to hpux and solaris).
> 
> Note that POSIX specified tv_nsec to be long (i.e. 64 bit), see:
> http://pubs.opengroup.org/onlinepubs/009695299/basedefs/time.h.html
> The  header shall declare the structure timespec, which has at
> least the following members:
> time_t  tv_secSeconds. 
> longtv_nsec   Nanoseconds.
> 
> Additionally Linux/kFreeBSD/Hurd all defines struct timespec in time.h as 
> follows:
> /* POSIX.1b structure for a time value.  This is like a `struct timeval'
> but
>has nanoseconds instead of microseconds.  */
> struct timespec
>   {
> __time_t tv_sec;/* Seconds.  */
> __syscall_slong_t tv_nsec;  /* Nanoseconds.  */
>   };
> 
> So defining tv_nsec to be time_t is completely wrong. The problem seems
> to be present only for the x32 architecture, so why not make a special-case
> solution for that arch. Obviously x32 is non-POSIX compliant since long
> is 32 bits, resulting in tv_nsec being 32 bits where it needs to be 64
> bits. Isn't it possible to handle the differences for x32 with a
> s-osinte-linux-x32.ads file, even with s-osinte-posix.adb stays intact?
> 
> Then ther changes would be limited to:
> * s-linux-x32.ads: New file.
> * s-osprim-x32.adb: Likewise.
> * gcc-interface/Makefile.in (LIBGNAT_TARGET_PAIRS): Replace
> s-linux.ads with s-linux-x32.ads, s-osprim-posix.adb with
> s-osprim-x32.adb for x32.
> and the rest would be obsolete:
> * s-linux.ads (time_t): New type.
> * s-linux-alpha.ads (time_t):  Likewise.
> * s-linux-hppa.ads (time_t):  Likewise.
> * s-linux-mipsel.ads (time_t):  Likewise.
> * s-linux-sparc.ads (time_t):  Likewise.
> * s-osinte-linux.ads (time_t): Mark it private.  Replace long
> with System.Linux.time_t.
> (timespec): Replace long with time_t.
> * s-osinte-posix.adb (To_Timespec): Likewise.
> * s-taprop-linux.adb (timeval): Replace C.long with
> System.OS_Interface.time_t.
> and
>* s-osinte-hpux.ads (timespec): Change type of tv_nsec field to time_t.
>* s-osinte-kfreebsd-gnu.ads (timespec): Likewise.
>* s-osinte-solaris-posix.ads (timespec): Likewise.
> 
> Possible content in s-osinte-linux-x32.ads would be:
>type tv_nsec_t is private;
>type tv_nsec_t is new Long_Long_Integer;
>type timespec is record
>   tv_sec  : time_t;
>   tv_nsec : tv_nsec_t;
>end record;
>pragma Convention (C, timespec);
> 
> 




Re: [PATCH] Fix %K for LTO

2014-03-25 Thread Richard Biener
On Tue, 25 Mar 2014, Jakub Jelinek wrote:

> On Tue, Mar 25, 2014 at 03:35:29PM +0100, Richard Biener wrote:
> > The following implements a special-case for LTO when doing %K
> > formatting.  LTO currently only keeps FUNCTION_DECL abstract
> > origins (for BLOCKs satisfying inlined_function_outer_scope_p)
> > which means the existing %K formatting usually bails out immediately.
> > This severely complicates the search for warnings like
> > 
> > /usr/include/bits/stdio2.h: In function ‘main’:
> > /usr/include/bits/stdio2.h:293:2: warning: call to ‘__fread_chk_warn’ 
> > declared with attribute warning: fread called with bigger size * nmemb 
> > than length of destination buffer
> >   return __fread_chk_warn (__ptr, __bos0 (__ptr), __size, __n, __stream);
> >   ^
> > 
> > because you only have an outermost function context to work on
> > and the inline stack can include functions from any translation
> > unit with LTO.  The following patch improves this to
> > 
> > In function 'fread',
> > inlined from 'main' at t.c:7:10:
> > /usr/include/bits/stdio2.h:293:2: warning: call to '__fread_chk_warn' 
> > declared with attribute warning: fread called with bigger size * nmemb 
> > than length of destination buffer
> >   return __fread_chk_warn (__ptr, __bos0 (__ptr), __size, __n, __stream);
> >   ^
> > 
> > which matches non-LTO behavior.
> > 
> > Bootstrap/regtest pending on x86_64-unknown-linux-gnu, ok for trunk?
> 
> If it works, ok.  I'd of course prefer if it preserved the abstract origins
> properly, otherwise it can't emit proper debug info.  But for now it is fine
> I guess.

Yeah, but we'd ICE here because the abstract BLOCKs cannot be
partitioned, etc. properly.  The debug info "works" at least
for the purpose of handling inlines.

Richard.

[PATCH] Fix %K for LTO

2014-03-25 Thread Richard Biener

The following implements a special-case for LTO when doing %K
formatting.  LTO currently only keeps FUNCTION_DECL abstract
origins (for BLOCKs satisfying inlined_function_outer_scope_p)
which means the existing %K formatting usually bails out immediately.
This severely complicates the search for warnings like

/usr/include/bits/stdio2.h: In function ‘main’:
/usr/include/bits/stdio2.h:293:2: warning: call to ‘__fread_chk_warn’ 
declared with attribute warning: fread called with bigger size * nmemb 
than length of destination buffer
  return __fread_chk_warn (__ptr, __bos0 (__ptr), __size, __n, __stream);
  ^

because you only have an outermost function context to work on
and the inline stack can include functions from any translation
unit with LTO.  The following patch improves this to

In function 'fread',
inlined from 'main' at t.c:7:10:
/usr/include/bits/stdio2.h:293:2: warning: call to '__fread_chk_warn' 
declared with attribute warning: fread called with bigger size * nmemb 
than length of destination buffer
  return __fread_chk_warn (__ptr, __bos0 (__ptr), __size, __n, __stream);
  ^

which matches non-LTO behavior.

Bootstrap/regtest pending on x86_64-unknown-linux-gnu, ok for trunk?

(unfortunately I can't make a testcase working, I have no idea why
dejagnu thinks that dg-message is not supported with lto.exp - it
does include gcc-dg.exp)

Thanks,
Richard.

2014-03-25  Richard Biener  

* tree-pretty-print.c (percent_K_format): Implement special
case for LTO and its stripped down BLOCK tree.

Index: gcc/tree-pretty-print.c
===
*** gcc/tree-pretty-print.c (revision 208812)
--- gcc/tree-pretty-print.c (working copy)
*** percent_K_format (text_info *text)
*** 3365,3370 
--- 3367,3391 
gcc_assert (pp_ti_abstract_origin (text) != NULL);
block = TREE_BLOCK (t);
*pp_ti_abstract_origin (text) = NULL;
+ 
+   if (in_lto_p)
+ {
+   /* ???  LTO drops all BLOCK_ABSTRACT_ORIGINs apart from those
+  representing the outermost block of an inlined function.
+So walk the BLOCK tree until we hit such a scope.  */
+   while (block
+&& TREE_CODE (block) == BLOCK)
+   {
+ if (inlined_function_outer_scope_p (block))
+   {
+ *pp_ti_abstract_origin (text) = block;
+ break;
+   }
+ block = BLOCK_SUPERCONTEXT (block);
+   }
+   return;
+ }
+ 
while (block
 && TREE_CODE (block) == BLOCK
 && BLOCK_ABSTRACT_ORIGIN (block))

Re: [PATCH] Environment variables forwarding

2014-03-25 Thread Yury Gribov
Cc-ing Jakub cause he's the author of original set-target-env-var 
support in GCC testsuite.


On 03/24/2014 01:46 PM, Maxim Ostapenko wrote:

Adding Dejagnu list this time.

On 03/24/2014 12:28 PM, Maxim Ostapenko wrote:

Hi all,

When porting Lsan on arm, I ran into problem with testing, because
almost all lsan tests require environment variables forwarding for
remote targets. Unfortunately, this feature isn't implemented yet
neither in Dejagnu nor in GCC. These two small patches seem to resolve
this issue.

Tested on arm with asan.exp and ubsan.exp.

I've cross-posted this message in Dejagnu too.

Do these changes make sense? If not - what's the proper way to forward
env vars on remote targets?

-Maxim


-Y
2014-03-24  Max Ostapenko  

	* config/unix.exp: Parse incoming string in environment variables
	and program name itself.

diff --git a/config/unix.exp b/config/unix.exp
index 4b244ca..fa0327a 100644
--- a/config/unix.exp
+++ b/config/unix.exp
@@ -50,6 +50,9 @@ proc unix_load { dest prog args } {
 	set inp ""
 }
 
+	regsub "^ *((\[^ \]+=\[^ \]* *)*).*" $prog "\\1" environ
+	regsub "^ *((\[^ \]+=\[^ \]* *)*)" $prog "" prog
+
 if {![file exists $prog]} then {
 	# We call both here because this should never happen.
 	perror "$prog does not exist in unix_load."
@@ -114,7 +117,7 @@ proc unix_load { dest prog args } {
 		return [list "unresolved" ""]
 	}
 	}
-	set status [remote_exec $dest "$remotefile" $parg $inp]
+	set status [remote_exec $dest "$environ $remotefile" $parg $inp]
 	remote_file $dest delete $remotefile.o $remotefile
 	if { [lindex $status 0] < 0 } {
 	verbose -log "Couldn't execute $prog, [lindex $status 1]" 3
2014-03-24  Max Ostapenko  

	* lib/gcc-dg.exp: Add check if Dejagnu supports environment
	variables forwarding for remote targets.
	* lib/target-supports.exp
	(check_runtime_env_vars_forwarding_nocache): New function.
	(check_runtime_env_vars_forwarding): New function.

diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp
index f9d52bc..05eab99 100644
--- a/gcc/testsuite/lib/gcc-dg.exp
+++ b/gcc/testsuite/lib/gcc-dg.exp
@@ -80,6 +80,9 @@ set LTO_TORTURE_OPTIONS ""
 global gcc_force_conventional_output
 set gcc_force_conventional_output ""
 
+global target_env_vars_available
+set target_env_vars_available ""
+
 if [check_effective_target_lto] {
 # When having plugin test both slim and fat LTO and plugin/nonplugin
 # path.
@@ -258,11 +261,21 @@ if { [info procs ${tool}_load] != [list] \
 	set saved_target_env_var [list]
 	if { [info exists set_target_env_var] \
 	 && [llength $set_target_env_var] != 0 } {
-	if { [is_remote target] } {
-		return [list "unsupported" ""]
-	}
-	set-target-env-var
-	}
+if { [is_remote target] } {
+if [check_runtime_env_vars_forwarding] {
+foreach env_var $set_target_env_var {
+set var [lindex $env_var 0]
+set value [lindex $env_var 1]
+set program "$var=$value $program"
+}
+} else {
+return [list "unsupported" ""]
+}
+} else {
+set-target-env-var
+}
+}
+
 	set result [eval [list saved_${tool}_load $program] $args]
 	if { [info exists set_target_env_var] \
 	 && [llength $set_target_env_var] != 0 } {
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index bee8471..3a3224f 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -5731,3 +5731,57 @@ proc force_conventional_output_for { test } {
 }
 }
 
+# This procedure is the same the check_runtime_nocache one. The only
+# difference is that executable will run with TEST=1 environment
+# variable. If Dejagnu supports environment variables forwarding
+# for remote targets, it will return 1, otherwise it will return 0.
+
+proc check_runtime_env_vars_forwarding_nocache {} {
+global tool
+global target_env_vars_available
+set basename env_forwarding_works
+set contents {
+#ifdef __cplusplus
+extern "C"
+#endif
+char *getenv(const char *name);
+
+#ifdef __cplusplus
+extern "C"
+#endif
+int strcmp(const char *s1, const char *s2);
+
+int main () { return strcmp(getenv("TEST"), "1"); }
+}
+
+set args ""
+
+set result [eval [list check_compile $basename executable $contents] $args]
+set lines [lindex $result 0]
+set output [lindex $result 1]
+
+set ok 0
+if { [string match "" $lines] } {
+# No error messages, everything is OK.
+set result [remote_load target "TEST=1 ./$output" "" ""]
+set status [lindex $result 0]
+verbose "check_runtime_nocache $basename: status is <$status>" 2
+if { $status == "pass" } {
+set ok 1
+}
+}
+remote_file build delete $output
+return $ok
+}
+
+proc check_runtime_e

Re: [PATCH] Fix %K for LTO

2014-03-25 Thread Jakub Jelinek
On Tue, Mar 25, 2014 at 03:35:29PM +0100, Richard Biener wrote:
> The following implements a special-case for LTO when doing %K
> formatting.  LTO currently only keeps FUNCTION_DECL abstract
> origins (for BLOCKs satisfying inlined_function_outer_scope_p)
> which means the existing %K formatting usually bails out immediately.
> This severely complicates the search for warnings like
> 
> /usr/include/bits/stdio2.h: In function ‘main’:
> /usr/include/bits/stdio2.h:293:2: warning: call to ‘__fread_chk_warn’ 
> declared with attribute warning: fread called with bigger size * nmemb 
> than length of destination buffer
>   return __fread_chk_warn (__ptr, __bos0 (__ptr), __size, __n, __stream);
>   ^
> 
> because you only have an outermost function context to work on
> and the inline stack can include functions from any translation
> unit with LTO.  The following patch improves this to
> 
> In function 'fread',
> inlined from 'main' at t.c:7:10:
> /usr/include/bits/stdio2.h:293:2: warning: call to '__fread_chk_warn' 
> declared with attribute warning: fread called with bigger size * nmemb 
> than length of destination buffer
>   return __fread_chk_warn (__ptr, __bos0 (__ptr), __size, __n, __stream);
>   ^
> 
> which matches non-LTO behavior.
> 
> Bootstrap/regtest pending on x86_64-unknown-linux-gnu, ok for trunk?

If it works, ok.  I'd of course prefer if it preserved the abstract origins
properly, otherwise it can't emit proper debug info.  But for now it is fine
I guess.

Jakub


Re: [RFC] Remove PUSH_ARGS_REVERSED from the RTL expander.

2014-03-25 Thread Michael Matz
Hi,

On Mon, 24 Mar 2014, Richard Henderson wrote:

> See
> 
>   http://en.wikipedia.org/wiki/X86_calling_conventions#pascal
> 
> Since we don't actually support this anymore, we can certainly tidy this 
> up.

Yeah, I thought about that, but I couldn't see how that could have used 
PUSH_ARGS_REVERSED.  The above calling convention would be a language 
setting while the macro is a target setting, and for interoperability even 
the Pascal compiler would have to be able to create some calls with 
reversed arguments.  So I thought that Pascal never was the purpose for 
the macro.  (I didn't check to make sure, though)


Ciao,
Michael.


Re: [patch] Shorten Windows path

2014-03-25 Thread Ian Lance Taylor
On Tue, Mar 25, 2014 at 1:58 AM, Joey Ye  wrote:
> Ping

This code looks different on mainline.

Writing "if ( do_canonical )" is not GCC style.

This patch does not respect the configure option
--disable-canonical-system-headers.

Also I personally don't actually know what the consequences would be.
Are there any downsides to canonicalizing header names?

Ian


>> -Original Message-
>> From: Joey Ye [mailto:joey...@arm.com]
>> Sent: 19 February 2014 15:45
>> To: gcc-patches@gcc.gnu.org; Ian Lance Taylor (i...@google.com)
>> Subject: [patch] Shorten Windows path
>>
>> Max length of path on Windows is 255, which is easy to exceed in a
>> complicated project. Ultimate solution may be complex but canonizing the
>> path and skipping the ".."s in path is helpful.
>>
>> Relative discussion in gcc-patches:
>> http://gcc.gnu.org/ml/gcc-patches/2013-11/msg00582.html
>>
>> OK to trunk stage 1?
>>
>> ChangeLog.libcpp:
>> * files.c (find_file_in_dir): Always try to shorten for DOS.
>>
>> diff --git a/libcpp/files.c b/libcpp/files.c index 7e88778..9dcc71f 100644
>> --- a/libcpp/files.c
>> +++ b/libcpp/files.c
>> @@ -386,9 +386,18 @@ find_file_in_dir (cpp_reader *pfile, _cpp_file *file,
>> bool *invalid_pch)
>>hashval_t hv;
>>char *copy;
>>void **pp;
>> +  bool do_canonical;
>>
>> +#ifdef HAVE_DOS_BASED_FILE_SYSTEM
>> +  /* For DOS based file system, we always try to shorten file path
>> +   * to as it has a shorter constraint on max path length.  */
>> +  do_canonical = true;
>> +#else
>>/* We try to canonicalize system headers.  */
>> -  if (CPP_OPTION (pfile, canonical_system_headers) &&
> file->dir->sysp)
>> +  do_canonical = (CPP_OPTION (pfile, canonical_system_headers)
>> +  && file->dir->sysp); #endif
>> +  if ( do_canonical )
>>   {
>> char * canonical_path = maybe_shorter_path (path);
>> if (canonical_path)
>
>


Re: [PATCH] [C++ RFC] Support named type capture for generic lambdas and generic functions as proposed by N3878

2014-03-25 Thread Andrew Sutton
It's not clear that this feature will be part of concepts. It will not
be included in the initial working paper, so the proposal will need to
be re-evaluated.

Andrew


On Tue, Mar 25, 2014 at 3:03 AM, Adam Butcher  wrote:
> * parser.c (cp_parser_simple_type_specifier): Lookahead for a braced
> identifier after a generic type ('auto') parameter and, if present, 
> use
> that as the type identifier name.  Otherwise generate one with
> make_generic_type_name.  Pass the resulting identifier as the new 
> second
> parameter ...
> (synthesize_implicit_template_parm): ... here.  Synthesize the 
> template
> type parm with the provided name rather than generating one.
>
> * g++.dg/cpp1y/generic-fn-typeid.C: New testcase.
> ---
>  gcc/cp/parser.c| 55 
> +-
>  gcc/testsuite/g++.dg/cpp1y/generic-fn-typeid.C | 42 
>  2 files changed, 88 insertions(+), 9 deletions(-)
>  create mode 100644 gcc/testsuite/g++.dg/cpp1y/generic-fn-typeid.C
>
> diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
> index 49fb731..4d6f8fe 100644
> --- a/gcc/cp/parser.c
> +++ b/gcc/cp/parser.c
> @@ -2128,8 +2128,10 @@ static tree cp_parser_late_parsing_omp_declare_simd
>  static tree cp_parser_late_parsing_cilk_simd_fn_info
>(cp_parser *, tree);
>
> +static tree make_generic_type_name
> +  ();
>  static tree synthesize_implicit_template_parm
> -  (cp_parser *);
> +  (cp_parser *, tree);
>  static tree finish_fully_implicit_template
>(cp_parser *, tree);
>
> @@ -14530,23 +14532,58 @@ cp_parser_simple_type_specifier (cp_parser* parser,
>maybe_warn_cpp0x (CPP0X_AUTO);
>if (parser->auto_is_implicit_function_template_parm_p)
> {
> - type = synthesize_implicit_template_parm (parser);
> + /* Synthesize an implicit template parameter named as specified by
> +the IDENTIFIER_NODE of a braced identifier (as proposed by 
> section
> +2.2 of N3878).  If no braced identifier is present then a name is
> +generated a via make_generic_type_name.  */
> +
> + if (cp_lexer_peek_nth_token
> + (parser->lexer, 2)->type == CPP_OPEN_BRACE)
> +   {
> + /* The 'auto' has only been peeked and is expected to be 
> consumed
> +later; parse the braced identifier leaving the closing brace 
> as
> +the next token.  */
> +
> + cp_lexer_consume_token (parser->lexer); /* RID_AUTO */
> + cp_lexer_consume_token (parser->lexer); /* CPP_OPEN_BRACE */
> +
> + tree synth_id = cp_parser_identifier (parser);
> + if (synth_id != error_mark_node)
> +   type = synthesize_implicit_template_parm (parser, synth_id);
> +
> + if (cp_parser_require
> + (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE) == 0
> + || synth_id == error_mark_node)
> +   {
> + error_at (input_location,
> +"expected braced identifier for generic type capture");
> + return error_mark_node;
> +   }
> +
> + /* Roll-back one token to allow for consume below.  */
> + cp_lexer_set_token_position (parser->lexer,
> +  cp_lexer_previous_token_position
> +  (parser->lexer));
> +   }
> + else
> +   type = synthesize_implicit_template_parm
> + (parser, make_generic_type_name ());
>
>   if (current_class_type && LAMBDA_TYPE_P (current_class_type))
> {
>   if (cxx_dialect < cxx1y)
> -   pedwarn (location_of (type), 0,
> +   pedwarn (token->location, 0,
>  "use of % in lambda parameter declaration "
>  "only available with "
>  "-std=c++1y or -std=gnu++1y");
> }
>   else if (cxx_dialect < cxx1y)
> -   pedwarn (location_of (type), 0,
> +   pedwarn (token->location, 0,
>  "use of % in parameter declaration "
>  "only available with "
>  "-std=c++1y or -std=gnu++1y");
>   else
> -   pedwarn (location_of (type), OPT_Wpedantic,
> +   pedwarn (token->location, OPT_Wpedantic,
>  "ISO C++ forbids use of % in parameter "
>  "declaration");
> }
> @@ -31957,11 +31994,12 @@ tree_type_is_auto_or_concept (const_tree t)
>  }
>
>  /* Add an implicit template type parameter to the CURRENT_TEMPLATE_PARMS
> -   (creating a new template parameter list if necessary).  Returns the newly
> -   created template type parm.  */
> +   (creating a new template parameter list if necessary).  The template type
> +   parameter is given the id SYNTH_ID.  Returns the newly created temp

[ARM] Fix PR target/60504

2014-03-25 Thread Eric Botcazou
Hi,

because of popular demand we switched the Ada compiler to ZCX, i.e. table-
driven EH scheme, on ARM/Linux, only to discover that GCC doesn't generate 
correct EH tables, which means that the Ada compiler cannot catch exceptions.

See also the earlier message posted by Tristan:
  http://gcc.gnu.org/ml/gcc/2013-12/msg00157.html

The problem is the discrepancy between the declared encoding and the actual 
encoding of the TType.  The latter is specified by the EABI: symbols must be 
relocated with an R_ARM_TARGET2 relocation, as visible in the assembly:

.LLSDACSE0:
.byte   0x1 @ Action record table
.byte   0
.align  2
.word   _ZTIi(TARGET2)

R_ARM_TARGET2 means DW_EH_PE_pcrel | DW_EH_PE_indirect in DWARF parlance on 
Linux, but the declared TType encoding is different:

.LLSDA0:
.byte   0xff@ @LPStart format (omit)
.byte   0   @ @TType format (absolute)
.uleb128 .LLSDATT0-.LLSDATTD0   @ @TType base offset

i.e. it's the DW_EH_PE_absptr default.

This works in C++ because of the _GLIBCXX_OVERRIDE_TTYPE_ENCODING kludge, 
which overrides the declared encoding during the parsing of the EH table:

  // Find @TType, the base of the handler and exception spec type data.
  info->ttype_encoding = *p++;
  if (info->ttype_encoding != DW_EH_PE_omit)
{
#if _GLIBCXX_OVERRIDE_TTYPE_ENCODING
  /* Older ARM EABI toolchains set this value incorrectly, so use a
 hardcoded OS-specific format.  */
  info->ttype_encoding = _GLIBCXX_OVERRIDE_TTYPE_ENCODING;
#endif
  p = read_uleb128 (p, &tmp);
  info->TType = p + tmp;
}
  else
info->TType = 0;

This comes from http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00765.html

Note that the above comment suggests that Paul's intent was to fix the bogus 
declared encoding in newer toolchains, but he didn't because of a misplaced 
#endif as spotted by Tristan.  Hence the attached patch, which aligns the 
declared encoding with the actual encoding and yields the correct:

.LLSDA0:
.byte   0xff@ @LPStart format (omit)
.byte   0x90@ @TType format (indirect pcrel)
.uleb128 .LLSDATT0-.LLSDATTD0   @ @TType base offset

which fixes the Ada failures in the process.  It was kindly tested by Bernd 
Edlinger on armv7l-unknown-linux-gnueabihf (all languages) with no regressions 
so we would like to have it for 4.9.x.


2014-04-25  Douglas B Rupp  

PR target/60504
* config/arm/arm.h (ASM_PREFERRED_EH_DATA_FORMAT): Expose from
ARM_TARGET2_DWARF_FORMAT.



2014-04-25  Eric Botcazou  

* gnat.dg/test_raise_from_pure.adb: UnXFAIL for ARM.


-- 
Eric Botcazouextern void foo ();

int bar ()
{
  try {
foo ();
  }
  catch (int) {
return 1;
  }

  return 0;
}Index: config/arm/arm.h
===
--- config/arm/arm.h	(revision 208763)
+++ config/arm/arm.h	(working copy)
@@ -937,13 +937,13 @@ extern int arm_arch_crc;
 
 #ifndef ARM_TARGET2_DWARF_FORMAT
 #define ARM_TARGET2_DWARF_FORMAT DW_EH_PE_pcrel
+#endif
 
 /* ttype entries (the only interesting data references used)
use TARGET2 relocations.  */
 #define ASM_PREFERRED_EH_DATA_FORMAT(code, data) \
   (((code) == 0 && (data) == 1 && ARM_UNWIND_INFO) ? ARM_TARGET2_DWARF_FORMAT \
 			   : DW_EH_PE_absptr)
-#endif
 
 /* The native (Norcroft) Pascal compiler for the ARM passes the static chain
as an invisible last argument (possible since varargs don't exist in
Index: testsuite/gnat.dg/test_raise_from_pure.adb
===
--- testsuite/gnat.dg/test_raise_from_pure.adb	(revision 208763)
+++ testsuite/gnat.dg/test_raise_from_pure.adb	(working copy)
@@ -1,4 +1,4 @@
--- { dg-do run { xfail arm*-*-* } }
+-- { dg-do run }
 -- { dg-options "-O2" }
 
 -- This is an optimization test and its failure is only a missed optimization.


[PATCH] PR debug/57519 - Emit DW_TAG_imported_declaration under the right class for 'using' statements in a class

2014-03-25 Thread Siva Chandra
Hello,

This is a re-posting of the patch I had posted 2 weeks back. I could
locate a PR for it, hence I am posting it now with the PR annotations.
Though the bug is in the 'debug' component, because of the nature of
the fix, I think it should be treated as a bug in the 'c++' component.
The patch is attached.

Link to the previous posting:
http://gcc.gnu.org/ml/gcc-patches/2014-03/msg00587.html

ChangeLog:
2014-03-25  Siva Chandra Reddy  

Fix PR debug/57519

/cp

PR debug/57519
* class.c (handle_using_decl): Pass the correct scope to
cp_emit_debug_info_for_using.

testsuite/

PR debug/57519
* g++.dg/debug/dwarf2/imported-decl-2.C: New testcase.

Thanks,
Siva Chandra
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index b46391b..6ad82d7 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -1299,7 +1299,7 @@ handle_using_decl (tree using_decl, tree t)
old_value = NULL_TREE;
 }
 
-  cp_emit_debug_info_for_using (decl, USING_DECL_SCOPE (using_decl));
+  cp_emit_debug_info_for_using (decl, t);
 
   if (is_overloaded_fn (decl))
 flist = decl;
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/imported-decl-2.C 
b/gcc/testsuite/g++.dg/debug/dwarf2/imported-decl-2.C
new file mode 100644
index 000..70200ec
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/dwarf2/imported-decl-2.C
@@ -0,0 +1,32 @@
+// { dg-do compile }
+// { dg-options "-gdwarf-2 -dA -O0 -fno-merge-debug-strings" }
+
+class 
+{
+ public:
+  int method (void);
+  int a;
+};
+
+int
+::method (void)
+{
+  return a;
+}
+
+class  : public 
+{
+ public:
+  using ::method;
+
+  int method (int b);
+};
+
+int
+::method (int b)
+{
+  return a + b;
+}
+
+// { dg-final { scan-assembler-not "ascii \"0\".*ascii 
\"0\".*DW_TAG_imported_declaration" } }
+// { dg-final { scan-assembler-times "ascii \"0\".*ascii 
\"0\".*DW_TAG_imported_declaration" 1 } }


Re: [PATCH] Fix ubsan i?86 {add,sub,mul}v4 patterns

2014-03-25 Thread Uros Bizjak
On Tue, Mar 25, 2014 at 11:17 AM, Jakub Jelinek  wrote:
> On Tue, Mar 25, 2014 at 09:12:14AM +0100, Uros Bizjak wrote:
>> > The bootstrap-ubsan bootstrap revealed a problem with the
>> > {add,sub,mul}v4 patterns.  The problem is that they
>> > accept CONST_INT operands (because the instructions do accept immediates),
>> > but to model what the instruction actually does, we need to have both
>> > the value of the operand itself and it's sign extended value to
>> > 2x wider mode, but say (sign_extend:DI (const_int 5)) in the pattern is
>> > invalid RTL (found about this because e.g. num_sign_bit_copies returns
>> > bogus return values on (sign_extend:DI (const_int 0)) ).
>> > The following patch attempts to fix this by using two different 
>> > define_insns
>> > for each, one that accepts everything but VOIDmode operands (i.e. usually
>> > register, memory, some SYMBOL_REFs/LABEL_REFs/CONSTs where we do have 
>> > mode),
>> > one that accepts only CONST_INTs.  Hopefully at least the combiner will
>> > canonicalize the potential (sign_extend:DI (const_int N)) into
>> > just (const_int N) and thus the *v4_1 insns would match (plus the
>> > expander expands it that way too).
>> >
>> > Bootstrapped/regtested on x86_64-linux and i686-linux, tested with
>> > i686-linux --with-build-config=bootstrap-ubsan bootstrap.  Ok for trunk?
>>
>> It looks to me that you will also need a corresponding predicate,
>> similar to x86_64_zext_operand that rejects sign-extended VOIDmode
>> operands where We constraint is used. That will also solve the problem
>> with combiner, which will be prohibited from combining VOIDmode
>> operands.
>>
>> Also, please use curly braces in multi-line preparation statements.
>
> Like this?  Or do you prefer a different name for the predicate?
> And, is it ok to use just one predicate for both {QI,HI}mode and
> {SI,DI}mode, or should I add separate predicates for "general_operand
> where GET_MODE (op) != VOIDmode" and "x86_64_general_operand where
> GET_MODE (op) != VOIDmode" and add a mode attribute for that?
> If so, what would be your preferred names for the 2 predicates and for the
> mode attribute?

The patch is OK in principle, but we could follow established practice
and use separate predicates - please see general_szext_operand mode
attribute definition.

I propose to use new "general_sext_operand" mode attribute that would
expand to "sext_operand" in QI/HImode case and "x86_64_sext_operand"
in SI/DImode case.

"sext_operand" should be defined similar to IOR part of
x86_64_zext_operand (using "immediate_operand" instead of
x86_64_zext_immediate_operand").

"x86_64_sext_operand" should be defined as "sext_operand", but should
use "x86_64_immediate_operand" in place of "immediate_operand".

(Looking at these definitions, it looks to me that other sign/zero
extend predicates also need to reject VOIDmode immediates, but let's
leave this to 4.9+).

Uros.


[PATCH][ARM] Cortex-A8 rtx cost table

2014-03-25 Thread Kyrill Tkachov

Hi all,

This patch adds the rtx cost table for the Cortex-A8 core. It's an ARMv7 core, 
so it goes into arm.c instead of aarch-cost-tables.h.


Bootstrapped and tested on a Cortex-A8 Linux system and benchmarked to make sure 
no performance regressions. There are various small improvements here and there.


Ok for next stage 1?

Thanks,
Kyrill

2013-03-25  Kyrylo Tkachov  

* config/arm/arm.c (cortexa8_extra_costs): New table.
(arm_cortex_a8_tune): New tuning struct.
* config/arm/arm-cores.def (cortex-a8): Use cortex_a8 tuning struct.commit 82b5eadc7978c90f3a5f1daf2223ae83f3bc10f6
Author: Kyrylo Tkachov 
Date:   Wed Feb 12 17:29:53 2014 +

Cortex-A8 costs

diff --git a/gcc/config/arm/arm-cores.def b/gcc/config/arm/arm-cores.def
index 3d9dfcd..6269338 100644
--- a/gcc/config/arm/arm-cores.def
+++ b/gcc/config/arm/arm-cores.def
@@ -136,7 +136,7 @@ ARM_CORE("cortex-m0plus",	cortexm0plus, cortexm0plus,	6M, FL_LDSCHED, v6m)
 ARM_CORE("generic-armv7-a",	genericv7a, genericv7a,		7A,  FL_LDSCHED, cortex)
 ARM_CORE("cortex-a5",		cortexa5, cortexa5,		7A,  FL_LDSCHED, cortex_a5)
 ARM_CORE("cortex-a7",		cortexa7, cortexa7,		7A,  FL_LDSCHED | FL_THUMB_DIV | FL_ARM_DIV, cortex_a7)
-ARM_CORE("cortex-a8",		cortexa8, cortexa8,		7A,  FL_LDSCHED, cortex)
+ARM_CORE("cortex-a8",		cortexa8, cortexa8,		7A,  FL_LDSCHED, cortex_a8)
 ARM_CORE("cortex-a9",		cortexa9, cortexa9,		7A,  FL_LDSCHED, cortex_a9)
 ARM_CORE("cortex-a12",	  	cortexa12, cortexa12,		7A,  FL_LDSCHED | FL_THUMB_DIV | FL_ARM_DIV, cortex_a12)
 ARM_CORE("cortex-a15",		cortexa15, cortexa15,		7A,  FL_LDSCHED | FL_THUMB_DIV | FL_ARM_DIV, cortex_a15)
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index c65d84b..d01ecce 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -1066,6 +1066,107 @@ const struct cpu_cost_table cortexa9_extra_costs =
   }
 };
 
+const struct cpu_cost_table cortexa8_extra_costs =
+{
+  /* ALU */
+  {
+0,			/* arith.  */
+0,			/* logical.  */
+COSTS_N_INSNS (1),	/* shift.  */
+0,			/* shift_reg.  */
+COSTS_N_INSNS (1),	/* arith_shift.  */
+0,			/* arith_shift_reg.  */
+COSTS_N_INSNS (1),	/* log_shift.  */
+0,			/* log_shift_reg.  */
+0,			/* extend.  */
+0,			/* extend_arith.  */
+0,			/* bfi.  */
+0,			/* bfx.  */
+0,			/* clz.  */
+0,			/* non_exec.  */
+true		/* non_exec_costs_exec.  */
+  },
+  {
+/* MULT SImode */
+{
+  COSTS_N_INSNS (1),	/* simple.  */
+  COSTS_N_INSNS (1),	/* flag_setting.  */
+  COSTS_N_INSNS (1),	/* extend.  */
+  COSTS_N_INSNS (1),	/* add.  */
+  COSTS_N_INSNS (1),	/* extend_add.  */
+  COSTS_N_INSNS (30)	/* idiv.  No HW div on Cortex A8.  */
+},
+/* MULT DImode */
+{
+  0,			/* simple (N/A).  */
+  0,			/* flag_setting (N/A).  */
+  COSTS_N_INSNS (2),	/* extend.  */
+  0,			/* add (N/A).  */
+  COSTS_N_INSNS (2),	/* extend_add.  */
+  0/* idiv (N/A).  */
+}
+  },
+  /* LD/ST */
+  {
+COSTS_N_INSNS (1),	/* load.  */
+COSTS_N_INSNS (1),	/* load_sign_extend.  */
+COSTS_N_INSNS (1),	/* ldrd.  */
+COSTS_N_INSNS (1),	/* ldm_1st.  */
+1,			/* ldm_regs_per_insn_1st.  */
+2,			/* ldm_regs_per_insn_subsequent.  */
+COSTS_N_INSNS (1),	/* loadf.  */
+COSTS_N_INSNS (1),	/* loadd.  */
+COSTS_N_INSNS (1),  /* load_unaligned.  */
+COSTS_N_INSNS (1),	/* store.  */
+COSTS_N_INSNS (1),	/* strd.  */
+COSTS_N_INSNS (1),	/* stm_1st.  */
+1,			/* stm_regs_per_insn_1st.  */
+2,			/* stm_regs_per_insn_subsequent.  */
+COSTS_N_INSNS (1),	/* storef.  */
+COSTS_N_INSNS (1),	/* stored.  */
+COSTS_N_INSNS (1)	/* store_unaligned.  */
+  },
+  {
+/* FP SFmode */
+{
+  COSTS_N_INSNS (36),	/* div.  */
+  COSTS_N_INSNS (11),	/* mult.  */
+  COSTS_N_INSNS (20),	/* mult_addsub. */
+  COSTS_N_INSNS (30),	/* fma.  */
+  COSTS_N_INSNS (9),	/* addsub.  */
+  COSTS_N_INSNS (3),	/* fpconst.  */
+  COSTS_N_INSNS (3),	/* neg.  */
+  COSTS_N_INSNS (6),	/* compare.  */
+  COSTS_N_INSNS (4),	/* widen.  */
+  COSTS_N_INSNS (4),	/* narrow.  */
+  COSTS_N_INSNS (8),	/* toint.  */
+  COSTS_N_INSNS (8),	/* fromint.  */
+  COSTS_N_INSNS (8)		/* roundint.  */
+},
+/* FP DFmode */
+{
+  COSTS_N_INSNS (64),	/* div.  */
+  COSTS_N_INSNS (16),	/* mult.  */
+  COSTS_N_INSNS (25),	/* mult_addsub.  */
+  COSTS_N_INSNS (30),	/* fma.  */
+  COSTS_N_INSNS (9),	/* addsub.  */
+  COSTS_N_INSNS (3),	/* fpconst.  */
+  COSTS_N_INSNS (3),	/* neg.  */
+  COSTS_N_INSNS (6),	/* compare.  */
+  COSTS_N_INSNS (6),	/* widen.  */
+  COSTS_N_INSNS (6),	/* narrow.  */
+  COSTS_N_INSNS (8),	/* toint.  */
+  COSTS_N_INSNS (8),	/* fromint.  */
+  COSTS_N_INSNS (8)		/* roundint.  */
+}
+  },
+  /* Vector */
+  {
+COSTS_N_INSNS (1)	/* alu.  */
+  }
+};
+
+
 
 const struct cpu_cost_table cortexa7_extra_costs =
 {
@@ -1584,6 +1685,2

[PATCH] Fix PR60635

2014-03-25 Thread Richard Biener

The following fixes PR60635 - we fail to update re-gimplified stmts
in gimple_regimplify_operands (or anywhere near its callers AFAIK).
It seems coverage is quite low as this must otherwise have been
noticed earlier ...

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Richard.

2014-03-25  Richard Biener  

PR middle-end/60635
* gimplify-me.c (gimple_regimplify_operands): Update the
re-gimplifed stmt.

* gfortran.dg/lto/pr60635_0.f90: New testcase.
* gfortran.dg/lto/pr60635_1.c: Likewise.

Index: gcc/gimplify-me.c
===
*** gcc/gimplify-me.c   (revision 208789)
--- gcc/gimplify-me.c   (working copy)
*** gimple_regimplify_operands (gimple stmt,
*** 315,320 
--- 315,322 
  gsi_insert_after (gsi_p, post_stmt, GSI_NEW_STMT);
  
pop_gimplify_context (NULL);
+ 
+   update_stmt (stmt);
  }
  
  
Index: gcc/testsuite/gfortran.dg/lto/pr60635_1.c
===
*** gcc/testsuite/gfortran.dg/lto/pr60635_1.c   (revision 0)
--- gcc/testsuite/gfortran.dg/lto/pr60635_1.c   (working copy)
***
*** 0 
--- 1,14 
+ #include 
+ #include 
+ 
+ static bool littleendian=true;
+ 
+ uint16_t bigendc16(union{uint16_t * n;uint8_t* b;}x){
+ 
+ if (!littleendian) return *x.n;
+ 
+ uint16_t res = ((uint16_t)(x.b[1])<<0) |
+   ((uint16_t)(x.b[0])<<8);
+ return res;
+ }
+ 
Index: gcc/testsuite/gfortran.dg/lto/pr60635_0.f90
===
*** gcc/testsuite/gfortran.dg/lto/pr60635_0.f90 (revision 0)
--- gcc/testsuite/gfortran.dg/lto/pr60635_0.f90 (working copy)
***
*** 0 
--- 1,16 
+ ! { dg-lto-do link }
+ program test
+   use iso_fortran_env
+ 
+   interface
+ integer(int16) function bigendc16(x) bind(C)
+   import
+   integer(int16), intent(in) :: x
+ end function
+   end interface
+   
+   integer(int16) :: x16 = 12345
+   x16 = bigendc16(x16)
+   print *,x16
+ end program
+ 


Re: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.

2014-03-25 Thread Mark Wielaard
On Mon, 2014-03-24 at 09:57 -0700, Cary Coutant wrote:
> > gcc/cp/
> > * dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if
> > enum_underlying_base_type defined and DWARF version > 3.
> > * langhooks.h (struct lang_hooks_for_types): Add
> > enum_underlying_base_type.
> > * langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New 
> > define.
> > (LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.
> 
> This should be the ChangeLog entry for cp/cp-lang.c.

Yes, you are right. Sorry for the copy/paste error.
Attached is the updated commit message and patch.

Thanks,

Mark
>From b92c7933ebf8a09a97ca2419d253a0ac1acdca6f Mon Sep 17 00:00:00 2001
From: Mark Wielaard 
Date: Sun, 23 Mar 2014 12:05:16 +0100
Subject: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.

Add a new lang-hook that provides the underlying base type of an
ENUMERAL_TYPE. Including implementations for C and C++. Use this
enum_underlying_base_type lang-hook in dwarf2out.c to add a DW_AT_type
base type reference to a DW_TAG_enumeration.

gcc/
	* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if
	enum_underlying_base_type defined and DWARF version > 3.
	* langhooks.h (struct lang_hooks_for_types): Add
	enum_underlying_base_type.
	* langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.

gcc/c-family/
	* c-common.c (c_enum_underlying_base_type): New function.
	* c-common.h (c_enum_underlying_base_type): Add declaration.

gcc/c/
	* c-objc-common.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.

gcc/cp/
	* cp-lang.c (cxx_enum_underlying_base_type): New function.
	(LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.
---
 gcc/ChangeLog   |   10 ++
 gcc/c-family/ChangeLog  |6 ++
 gcc/c-family/c-common.c |8 
 gcc/c-family/c-common.h |1 +
 gcc/c/ChangeLog |5 +
 gcc/c/c-objc-common.h   |2 ++
 gcc/cp/ChangeLog|6 ++
 gcc/cp/cp-lang.c|   18 ++
 gcc/dwarf2out.c |7 +++
 gcc/langhooks-def.h |4 +++-
 gcc/langhooks.h |2 ++
 11 files changed, 68 insertions(+), 1 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index b456eff..7bce951 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,15 @@
 2014-03-21  Mark Wielaard  
 
+	PR debug/16063
+	* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if
+	enum_underlying_base_type defined and DWARF version > 3.
+	* langhooks.h (struct lang_hooks_for_types): Add
+	enum_underlying_base_type.
+	* langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
+	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.
+
+2014-03-21  Mark Wielaard  
+
 	* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_const_value
 	as unsigned or int depending on type and value used.
 
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 536b4fc..94d779d 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-21  Mark Wielaard  
+
+	PR debug/16063
+	* c-common.c (c_enum_underlying_base_type): New function.
+	* c-common.h (c_enum_underlying_base_type): Add declaration.
+
 2014-03-22  Jakub Jelinek  
 
 	PR debug/60603
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index abd96fb..55ebbcc 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -3902,6 +3902,14 @@ c_register_builtin_type (tree type, const char* name)
 
   registered_builtin_types = tree_cons (0, type, registered_builtin_types);
 }
+
+/* The C version of the enum_underlying_base_type langhook.  */
+tree
+c_enum_underlying_base_type (const_tree type)
+{
+  return c_common_type_for_size (TYPE_PRECISION (type), TYPE_UNSIGNED (type));
+}
+
 
 /* Print an error message for invalid operands to arith operation
CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 1099b10..e378b44 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -832,6 +832,7 @@ extern void c_common_finish (void);
 extern void c_common_parse_file (void);
 extern alias_set_type c_common_get_alias_set (tree);
 extern void c_register_builtin_type (tree, const char*);
+extern tree c_enum_underlying_base_type (const_tree);
 extern bool c_promoting_integer_type_p (const_tree);
 extern int self_promoting_args_p (const_tree);
 extern tree strip_pointer_operator (tree);
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index b39b7d6..9ab6eab 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,8 @@
+2014-03-21  Mark Wielaard  
+
+	PR debug/16063
+	* c-objc-common.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.
+
 2014-03-18  Manuel López-Ibáñez  
 
 	PR c/55383
diff --git a/gcc/c/c-objc-common.h b/gcc/c/c-objc-common.h
index 92cf60f..0651db7 100644
--- a/gcc/c/c-objc-common.h
+++ b/gcc/c/c-objc-common.h
@@ -84,6 +84,8 @@ along with GCC; see the file COPY

Re: [PATCH] Fix ubsan i?86 {add,sub,mul}v4 patterns

2014-03-25 Thread Jakub Jelinek
On Tue, Mar 25, 2014 at 09:12:14AM +0100, Uros Bizjak wrote:
> > The bootstrap-ubsan bootstrap revealed a problem with the
> > {add,sub,mul}v4 patterns.  The problem is that they
> > accept CONST_INT operands (because the instructions do accept immediates),
> > but to model what the instruction actually does, we need to have both
> > the value of the operand itself and it's sign extended value to
> > 2x wider mode, but say (sign_extend:DI (const_int 5)) in the pattern is
> > invalid RTL (found about this because e.g. num_sign_bit_copies returns
> > bogus return values on (sign_extend:DI (const_int 0)) ).
> > The following patch attempts to fix this by using two different define_insns
> > for each, one that accepts everything but VOIDmode operands (i.e. usually
> > register, memory, some SYMBOL_REFs/LABEL_REFs/CONSTs where we do have mode),
> > one that accepts only CONST_INTs.  Hopefully at least the combiner will
> > canonicalize the potential (sign_extend:DI (const_int N)) into
> > just (const_int N) and thus the *v4_1 insns would match (plus the
> > expander expands it that way too).
> >
> > Bootstrapped/regtested on x86_64-linux and i686-linux, tested with
> > i686-linux --with-build-config=bootstrap-ubsan bootstrap.  Ok for trunk?
> 
> It looks to me that you will also need a corresponding predicate,
> similar to x86_64_zext_operand that rejects sign-extended VOIDmode
> operands where We constraint is used. That will also solve the problem
> with combiner, which will be prohibited from combining VOIDmode
> operands.
> 
> Also, please use curly braces in multi-line preparation statements.

Like this?  Or do you prefer a different name for the predicate?
And, is it ok to use just one predicate for both {QI,HI}mode and
{SI,DI}mode, or should I add separate predicates for "general_operand
where GET_MODE (op) != VOIDmode" and "x86_64_general_operand where
GET_MODE (op) != VOIDmode" and add a mode attribute for that?
If so, what would be your preferred names for the 2 predicates and for the
mode attribute?

2014-03-25  Jakub Jelinek  

* config/i386/i386.md (addv4, subv4, mulv4): If
operands[2] is CONST_INT, don't generate (sign_extend (const_int)).
(*addv4, *subv4, *mulv4): Disallow CONST_INT_P
operands[2].  Use We constraint instead of  and x86_64_sext_operand
predicate instead of .
(*addv4_1, *subv4_1, *mulv4_1): New insns.
* config/i386/constraints.md (We): New constraint.
* config/i386/predicates.md (x86_64_sext_operand): New predicate.

--- gcc/config/i386/i386.md.jj  2014-03-25 09:22:01.796149575 +0100
+++ gcc/config/i386/i386.md 2014-03-25 11:02:55.194817717 +0100
@@ -5821,10 +5821,11 @@ (define_expand "addv4"
   (eq:CCO (plus:
  (sign_extend:
 (match_operand:SWI 1 "nonimmediate_operand"))
- (sign_extend:
-(match_operand:SWI 2 "")))
+ (match_dup 4))
   (sign_extend:
- (plus:SWI (match_dup 1) (match_dup 2)
+ (plus:SWI (match_dup 1)
+   (match_operand:SWI 2
+  "")
  (set (match_operand:SWI 0 "register_operand")
   (plus:SWI (match_dup 1) (match_dup 2)))])
(set (pc) (if_then_else
@@ -5832,7 +5833,13 @@ (define_expand "addv4"
   (label_ref (match_operand 3))
   (pc)))]
   ""
-  "ix86_fixup_binary_operands_no_copy (PLUS, mode, operands);")
+{
+  ix86_fixup_binary_operands_no_copy (PLUS, mode, operands);
+  if (CONST_INT_P (operands[2]))
+operands[4] = operands[2];
+  else
+operands[4] = gen_rtx_SIGN_EXTEND (mode, operands[2]);
+})
 
 (define_insn "*addv4"
   [(set (reg:CCO FLAGS_REG)
@@ -5840,7 +5847,8 @@ (define_insn "*addv4"
   (sign_extend:
  (match_operand:SWI 1 "nonimmediate_operand" "%0,0"))
   (sign_extend:
- (match_operand:SWI 2 "" ",")))
+ (match_operand:SWI 2 "x86_64_sext_operand"
+  "mWe,We")))
(sign_extend:
   (plus:SWI (match_dup 1) (match_dup 2)
(set (match_operand:SWI 0 "nonimmediate_operand" "=,m")
@@ -5850,6 +5858,31 @@ (define_insn "*addv4"
   [(set_attr "type" "alu")
(set_attr "mode" "")])
 
+(define_insn "*addv4_1"
+  [(set (reg:CCO FLAGS_REG)
+   (eq:CCO (plus:
+  (sign_extend:
+ (match_operand:SWI 1 "nonimmediate_operand" "0"))
+  (match_operand: 3 "const_int_operand" "i"))
+   (sign_extend:
+  (plus:SWI (match_dup 1)
+(match_operand:SWI 2 "x86_64_immediate_operand"
+ "")
+   (set (match_operand:SW

Re: [PATCH, ARM] Enable tail call optimization for long call

2014-03-25 Thread Ramana Radhakrishnan
>
>
> gcc/
>   * config/arm/predicates.md (call_insn_operand): Add long_call check.
>   * config/arm/arm.md (sibcall, sibcall_value): Force the address to reg for
> long_call.
>   * config/aarch64/aarch64.c (arm_function_ok_for_sibcall): Remove long_call
> restriction.

config/arm/arm.c :)

The ARM parts are ok for stage1 if no regressions.


regards
Ramana

>
> gcc/testsuite
>   gcc.target/arm/tail-long-call.c: New test.


[PATCH] Fix -fPIE non-handling in lto-wrapper

2014-03-25 Thread Richard Biener

We handle -fpie but not -fPIE - obviously an oversight.

Committed as obvious.

Richard.

2014-03-25  Richard Biener  

* lto-wrapper.c (merge_and_complain): Handle OPT_fPIE like
OPT_fpie.
(run_gcc): Likewise.

Index: gcc/lto-wrapper.c
===
*** gcc/lto-wrapper.c   (revision 208789)
--- gcc/lto-wrapper.c   (working copy)
*** merge_and_complain (struct cl_decoded_op
*** 406,411 
--- 406,412 
  /* Fallthru.  */
case OPT_fPIC:
case OPT_fpic:
+   case OPT_fPIE:
case OPT_fpie:
case OPT_fcommon:
case OPT_fexceptions:
*** run_gcc (unsigned argc, char *argv[])
*** 671,676 
--- 672,678 
{
case OPT_fPIC:
case OPT_fpic:
+   case OPT_fPIE:
case OPT_fpie:
case OPT_fcommon:
case OPT_fexceptions:


Re: [PATCH] Fix folding of UBSAN_CHECK_SUB (x, 0) etc.

2014-03-25 Thread Jakub Jelinek
On Tue, Mar 25, 2014 at 10:15:37AM +0100, Richard Biener wrote:
> On Tue, 25 Mar 2014, Richard Biener wrote:
> > > While working on previous patch, I've noticed a severe omission in the
> > > -fsanitize=signed-integer-overflow support.  Nothing ever
> > > folds addition/subtraction of 0 and multiplication by [0,1], none of these
> > > may ever overflow and thus we can fold them to normal operations and let
> > > those be folded as normal operations.
> > > 
> > > Bootstrapped/regtested on x86_64-linux and i686-linux, tested with
> > > --with-build-config=bootstrap-ubsan bootstrap on i686-linux, ok for trunk?
> > 
> > I think you only need to adjust gimple_fold_stmt_to_constant_1.
> 
> Actually there only for a * 0 and a - a, as others don't result in
> constants.  Still the other cases should be handled in fold_stmt,
> not only in VRP.

IMHO we need even the VRP case, at least for multiplication, otherwise
we wouldn't optimize say:
int
baz (int x, int y)
{
  if (y < 32 || y > 33)
return 6;
  return x * (y - 32);
}
where y - 32 is not known to be a constant, but [0, 1], which is still
ok to optimize into just normal multiplication, because it never overflows.

Anyway, I'll look into handling it also in gimple-fold.c.

Jakub


Re: [PATCH] Perform ubsan instrumentation for x >= 0 ? x : -x

2014-03-25 Thread Richard Biener
On Tue, 25 Mar 2014, Jakub Jelinek wrote:

> On Tue, Mar 25, 2014 at 10:09:26AM +0100, Richard Biener wrote:
> > On Tue, 25 Mar 2014, Jakub Jelinek wrote:
> > 
> > > Hi!
> > > 
> > > While Marek has been debugging while some perl test fails when perl is 
> > > built
> > > with GCC 4.9, we've discovered that it is because of undefined behavior in
> > > it:
> > > ...
> > >   && (((UV)1 << NV_PRESERVES_UV_BITS) >
> > >   (UV)(SvIVX(sv) > 0 ? SvIVX(sv) : -SvIVX(sv)))
> > > where SvIVX(sv) can be LONG_MIN, at which point there is undefined 
> > > behavior
> > > on the negation, but -fsanitize=undefined did detect only other issues in
> > > the same source file and not this one, because fold-const.c folded it into
> > > ABS_EXPR early.
> > > 
> > > This patch disables such folding, because all the A op 0 ? A : -A
> > > operations this if is trying to optimize will need instrumentation with
> > > -fsanitize=signed-integer-overflow.
> > > 
> > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> > 
> > Can't one form a valid constant expression using this?  Also isn't
> > ABS_EXPR undefined for LONG_MIN as well?  So why is ubsan not
> > instrumenting that instead?
> 
> Well, for a constant expression A would need to fold to a constant, but then
> A op 0 would fold to a constant too and so would the whole A op 0 ? A : -A.
> 
> Instrumenting ABS_EXPR is certainly possible, but definitely more code than
> this patch.  I could revert this patch and implement it for 5.0 as ABS_EXPR
> instrumentation.  Of course, if you think we should do the instrumentation
> of ABS_EXPR, I can hack it up now.
> 
> I was afraid of also the other transformations in:
>  A == 0? A : -Asame as -A
>  A != 0? A : -Asame as A
>  A >= 0? A : -Asame as abs (A)
>  A > 0?  A : -Asame as abs (A)
>  A <= 0? A : -Asame as -abs (A)
>  A < 0?  A : -Asame as -abs (A)
> but only the second one doesn't add ABS_EXPR and removes the negation, but
> in that case the negation would happen only for 0, thus it would be fine.

Yes, all transforms in fold-const would be invalid if the result doesn't
behave in the same way wrt overflow.  Thus you really should instrument
ABS_EXPR - you can treat it as A > 0 ? A : -A if that simplifies it.

I don't like the conditions that disable stuff based on sanitization.

Instrumenting ABS_EXPR shouldn't be too difficult.

Richard.


Re: [PATCH] Perform ubsan instrumentation for x >= 0 ? x : -x

2014-03-25 Thread Jakub Jelinek
On Tue, Mar 25, 2014 at 10:09:26AM +0100, Richard Biener wrote:
> On Tue, 25 Mar 2014, Jakub Jelinek wrote:
> 
> > Hi!
> > 
> > While Marek has been debugging while some perl test fails when perl is built
> > with GCC 4.9, we've discovered that it is because of undefined behavior in
> > it:
> > ...
> >   && (((UV)1 << NV_PRESERVES_UV_BITS) >
> >   (UV)(SvIVX(sv) > 0 ? SvIVX(sv) : -SvIVX(sv)))
> > where SvIVX(sv) can be LONG_MIN, at which point there is undefined behavior
> > on the negation, but -fsanitize=undefined did detect only other issues in
> > the same source file and not this one, because fold-const.c folded it into
> > ABS_EXPR early.
> > 
> > This patch disables such folding, because all the A op 0 ? A : -A
> > operations this if is trying to optimize will need instrumentation with
> > -fsanitize=signed-integer-overflow.
> > 
> > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> Can't one form a valid constant expression using this?  Also isn't
> ABS_EXPR undefined for LONG_MIN as well?  So why is ubsan not
> instrumenting that instead?

Well, for a constant expression A would need to fold to a constant, but then
A op 0 would fold to a constant too and so would the whole A op 0 ? A : -A.

Instrumenting ABS_EXPR is certainly possible, but definitely more code than
this patch.  I could revert this patch and implement it for 5.0 as ABS_EXPR
instrumentation.  Of course, if you think we should do the instrumentation
of ABS_EXPR, I can hack it up now.

I was afraid of also the other transformations in:
 A == 0? A : -Asame as -A
 A != 0? A : -Asame as A
 A >= 0? A : -Asame as abs (A)
 A > 0?  A : -Asame as abs (A)
 A <= 0? A : -Asame as -abs (A)
 A < 0?  A : -Asame as -abs (A)
but only the second one doesn't add ABS_EXPR and removes the negation, but
in that case the negation would happen only for 0, thus it would be fine.

Jakub


Re: [C++ PATCH] Fix -std=c++11 OpenMP UDR handling (PR c++/60331)

2014-03-25 Thread Jakub Jelinek
On Mon, Mar 24, 2014 at 02:02:27PM -0400, Jason Merrill wrote:
> On 03/18/2014 11:16 AM, Jakub Jelinek wrote:
> >Jason, do you have better ideas how to fix this?
> 
> Better would be to return false from potential_constant_expression_1
> for DECL_EXPR; just add another case to the various _STMT tree
> codes.

Thanks, here is what I've checked in after another bootstrap/regtest:

2014-03-25  Jakub Jelinek  

PR c++/60331
* semantics.c (potential_constant_expression_1): Handle
DECL_EXPR.

* testsuite/libgomp.c++/udr-11.C: New test.
* testsuite/libgomp.c++/udr-12.C: New test.
* testsuite/libgomp.c++/udr-13.C: New test.
* testsuite/libgomp.c++/udr-14.C: New test.
* testsuite/libgomp.c++/udr-15.C: New test.
* testsuite/libgomp.c++/udr-16.C: New test.
* testsuite/libgomp.c++/udr-17.C: New test.
* testsuite/libgomp.c++/udr-18.C: New test.
* testsuite/libgomp.c++/udr-19.C: New test.

--- gcc/cp/semantics.c.jj   2014-03-13 19:01:19.0 +0100
+++ gcc/cp/semantics.c  2014-03-24 20:51:24.912546906 +0100
@@ -10253,6 +10253,7 @@ potential_constant_expression_1 (tree t,
 case DO_STMT:
 case FOR_STMT:
 case WHILE_STMT:
+case DECL_EXPR:
   if (flags & tf_error)
 error ("expression %qE is not a constant-expression", t);
   return false;
--- libgomp/testsuite/libgomp.c++/udr-11.C.jj   2014-03-18 11:47:43.326846415 
+0100
+++ libgomp/testsuite/libgomp.c++/udr-11.C  2014-03-18 11:47:43.329846576 
+0100
@@ -0,0 +1,4 @@
+// { dg-do run }
+// { dg-options "-fopenmp -std=c++11" }
+
+#include "udr-1.C"
--- libgomp/testsuite/libgomp.c++/udr-12.C.jj   2014-03-18 11:47:43.330846623 
+0100
+++ libgomp/testsuite/libgomp.c++/udr-12.C  2014-03-18 11:47:43.33184 
+0100
@@ -0,0 +1,4 @@
+// { dg-do run }
+// { dg-options "-fopenmp -std=c++11" }
+
+#include "udr-2.C"
--- libgomp/testsuite/libgomp.c++/udr-13.C.jj   2014-03-18 11:47:43.332846707 
+0100
+++ libgomp/testsuite/libgomp.c++/udr-13.C  2014-03-18 11:47:43.332846707 
+0100
@@ -0,0 +1,4 @@
+// { dg-do run }
+// { dg-options "-fopenmp -std=c++11" }
+
+#include "udr-3.C"
--- libgomp/testsuite/libgomp.c++/udr-14.C.jj   2014-03-18 11:47:43.333846744 
+0100
+++ libgomp/testsuite/libgomp.c++/udr-14.C  2014-03-18 11:47:43.334846777 
+0100
@@ -0,0 +1,4 @@
+// { dg-do run }
+// { dg-options "-fopenmp -std=c++11" }
+
+#include "udr-4.C"
--- libgomp/testsuite/libgomp.c++/udr-15.C.jj   2014-03-18 11:47:43.334846777 
+0100
+++ libgomp/testsuite/libgomp.c++/udr-15.C  2014-03-18 11:47:43.335846809 
+0100
@@ -0,0 +1,4 @@
+// { dg-do run }
+// { dg-options "-fopenmp -std=c++11" }
+
+#include "udr-5.C"
--- libgomp/testsuite/libgomp.c++/udr-16.C.jj   2014-03-18 11:47:43.336846840 
+0100
+++ libgomp/testsuite/libgomp.c++/udr-16.C  2014-03-18 11:47:43.336846840 
+0100
@@ -0,0 +1,4 @@
+// { dg-do run }
+// { dg-options "-fopenmp -std=c++11" }
+
+#include "udr-6.C"
--- libgomp/testsuite/libgomp.c++/udr-17.C.jj   2014-03-18 11:47:43.337846867 
+0100
+++ libgomp/testsuite/libgomp.c++/udr-17.C  2014-03-18 11:47:43.337846867 
+0100
@@ -0,0 +1,4 @@
+// { dg-do run }
+// { dg-options "-fopenmp -std=c++11" }
+
+#include "udr-7.C"
--- libgomp/testsuite/libgomp.c++/udr-18.C.jj   2014-03-18 11:47:43.338846892 
+0100
+++ libgomp/testsuite/libgomp.c++/udr-18.C  2014-03-18 11:47:43.338846892 
+0100
@@ -0,0 +1,4 @@
+// { dg-do run }
+// { dg-options "-fopenmp -std=c++11" }
+
+#include "udr-8.C"
--- libgomp/testsuite/libgomp.c++/udr-19.C.jj   2014-03-18 11:47:43.339846916 
+0100
+++ libgomp/testsuite/libgomp.c++/udr-19.C  2014-03-18 11:47:43.339846916 
+0100
@@ -0,0 +1,4 @@
+// { dg-do run }
+// { dg-options "-fopenmp -std=c++11" }
+
+#include "udr-9.C"


Jakub


Re: [PATCH] Fix folding of UBSAN_CHECK_SUB (x, 0) etc.

2014-03-25 Thread Richard Biener
On Tue, 25 Mar 2014, Richard Biener wrote:

> On Tue, 25 Mar 2014, Jakub Jelinek wrote:
> 
> > Hi!
> > 
> > While working on previous patch, I've noticed a severe omission in the
> > -fsanitize=signed-integer-overflow support.  Nothing ever
> > folds addition/subtraction of 0 and multiplication by [0,1], none of these
> > may ever overflow and thus we can fold them to normal operations and let
> > those be folded as normal operations.
> > 
> > Bootstrapped/regtested on x86_64-linux and i686-linux, tested with
> > --with-build-config=bootstrap-ubsan bootstrap on i686-linux, ok for trunk?
> 
> I think you only need to adjust gimple_fold_stmt_to_constant_1.

Actually there only for a * 0 and a - a, as others don't result in
constants.  Still the other cases should be handled in fold_stmt,
not only in VRP.

Richard.

> Richard.
> 
> > 2014-03-25  Jakub Jelinek  
> > 
> > * tree-vrp.c (simplify_internal_call_using_ranges): If only
> > one range is range_int_cst_p, but not both, at least optimize
> > addition/subtraction of 0 and multiplication by 0 or 1.
> > 
> > --- gcc/tree-vrp.c.jj   2014-03-12 10:14:18.0 +0100
> > +++ gcc/tree-vrp.c  2014-03-24 16:14:50.822674164 +0100
> > @@ -9336,31 +9336,58 @@ simplify_internal_call_using_ranges (gim
> >else if (TREE_CODE (op0) == INTEGER_CST)
> >  set_value_range_to_value (&vr0, op0, NULL);
> >else
> > -return false;
> > +set_value_range_to_varying (&vr0);
> >  
> >if (TREE_CODE (op1) == SSA_NAME)
> >  vr1 = *get_value_range (op1);
> >else if (TREE_CODE (op1) == INTEGER_CST)
> >  set_value_range_to_value (&vr1, op1, NULL);
> >else
> > -return false;
> > +set_value_range_to_varying (&vr1);
> >  
> > -  if (!range_int_cst_p (&vr0) || !range_int_cst_p (&vr1))
> > -return false;
> > -
> > -  tree r1 = int_const_binop (subcode, vr0.min, vr1.min);
> > -  tree r2 = int_const_binop (subcode, vr0.max, vr1.max);
> > -  if (r1 == NULL_TREE || TREE_OVERFLOW (r1)
> > -  || r2 == NULL_TREE || TREE_OVERFLOW (r2))
> > -return false;
> > -  if (subcode == MULT_EXPR)
> > +  if (!range_int_cst_p (&vr0))
> > +{
> > +  /* If one range is VR_ANTI_RANGE, VR_VARYING etc.,
> > +optimize at least x = y + 0; x = y - 0; x = y * 0;
> > +and x = y * 1; which never overflow.  */
> > +  if (!range_int_cst_p (&vr1))
> > +   return false;
> > +  if (tree_int_cst_sgn (vr1.min) == -1)
> > +   return false;
> > +  if (compare_tree_int (vr1.max, subcode == MULT_EXPR) == 1)
> > +   return false;
> > +}
> > +  else if (!range_int_cst_p (&vr1))
> > +{
> > +  /* If one range is VR_ANTI_RANGE, VR_VARYING etc.,
> > +optimize at least x = 0 + y; x = 0 * y; and x = 1 * y;
> > +which never overflow.  */
> > +  if (subcode == MINUS_EXPR)
> > +   return false;
> > +  if (!range_int_cst_p (&vr0))
> > +   return false;
> > +  if (tree_int_cst_sgn (vr0.min) == -1)
> > +   return false;
> > +  if (compare_tree_int (vr0.max, subcode == MULT_EXPR) == 1)
> > +   return false;
> > +}
> > +  else
> >  {
> > -  tree r3 = int_const_binop (subcode, vr0.min, vr1.max);
> > -  tree r4 = int_const_binop (subcode, vr0.max, vr1.min);
> > -  if (r3 == NULL_TREE || TREE_OVERFLOW (r3)
> > - || r4 == NULL_TREE || TREE_OVERFLOW (r4))
> > +  tree r1 = int_const_binop (subcode, vr0.min, vr1.min);
> > +  tree r2 = int_const_binop (subcode, vr0.max, vr1.max);
> > +  if (r1 == NULL_TREE || TREE_OVERFLOW (r1)
> > + || r2 == NULL_TREE || TREE_OVERFLOW (r2))
> > return false;
> > +  if (subcode == MULT_EXPR)
> > +   {
> > + tree r3 = int_const_binop (subcode, vr0.min, vr1.max);
> > + tree r4 = int_const_binop (subcode, vr0.max, vr1.min);
> > + if (r3 == NULL_TREE || TREE_OVERFLOW (r3)
> > + || r4 == NULL_TREE || TREE_OVERFLOW (r4))
> > +   return false;
> > +   }
> >  }
> > +
> >gimple g = gimple_build_assign_with_ops (subcode, gimple_call_lhs (stmt),
> >op0, op1);
> >gsi_replace (gsi, g, false);
> > 
> > Jakub
> > 
> > 
> 
> 

-- 
Richard Biener 
SUSE / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746
GF: Jeff Hawn, Jennifer Guild, Felix Imend"orffer


Re: [PATCH] Correct typos in gccint.texi.

2014-03-25 Thread Andreas Krebbel
On Thu, Mar 20, 2014 at 06:52:13AM +0100, Dominik Vogt wrote:
> 2014-03-20  Dominik Vogt  
> 
>   * doc/generic.texi: Correct typos.

Applied. Thanks!

-Andreas-



Re: [PATCH][AARCH64]PR60034

2014-03-25 Thread Marcus Shawcroft
On 25 March 2014 04:55, Kugan  wrote:

> gcc/
>
> 2014-03-25  Kugan Vivekanandarajah  
>
> PR target/60034
> * aarch64/aarch64.c (aarch64_classify_address): Fix alignment for
> section anchor.
>
> gcc/testsuite/
>
> 2014-03-25  Kugan Vivekanandarajah  
>
> PR target/60034
> * gcc.target/aarch64/pr60034.c: New file.

Thanks Kugan, leave 24h before committing to give the RM's chance to object.
/Marcus


Re: [PATCH] Fix folding of UBSAN_CHECK_SUB (x, 0) etc.

2014-03-25 Thread Richard Biener
On Tue, 25 Mar 2014, Jakub Jelinek wrote:

> Hi!
> 
> While working on previous patch, I've noticed a severe omission in the
> -fsanitize=signed-integer-overflow support.  Nothing ever
> folds addition/subtraction of 0 and multiplication by [0,1], none of these
> may ever overflow and thus we can fold them to normal operations and let
> those be folded as normal operations.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, tested with
> --with-build-config=bootstrap-ubsan bootstrap on i686-linux, ok for trunk?

I think you only need to adjust gimple_fold_stmt_to_constant_1.

Richard.

> 2014-03-25  Jakub Jelinek  
> 
>   * tree-vrp.c (simplify_internal_call_using_ranges): If only
>   one range is range_int_cst_p, but not both, at least optimize
>   addition/subtraction of 0 and multiplication by 0 or 1.
> 
> --- gcc/tree-vrp.c.jj 2014-03-12 10:14:18.0 +0100
> +++ gcc/tree-vrp.c2014-03-24 16:14:50.822674164 +0100
> @@ -9336,31 +9336,58 @@ simplify_internal_call_using_ranges (gim
>else if (TREE_CODE (op0) == INTEGER_CST)
>  set_value_range_to_value (&vr0, op0, NULL);
>else
> -return false;
> +set_value_range_to_varying (&vr0);
>  
>if (TREE_CODE (op1) == SSA_NAME)
>  vr1 = *get_value_range (op1);
>else if (TREE_CODE (op1) == INTEGER_CST)
>  set_value_range_to_value (&vr1, op1, NULL);
>else
> -return false;
> +set_value_range_to_varying (&vr1);
>  
> -  if (!range_int_cst_p (&vr0) || !range_int_cst_p (&vr1))
> -return false;
> -
> -  tree r1 = int_const_binop (subcode, vr0.min, vr1.min);
> -  tree r2 = int_const_binop (subcode, vr0.max, vr1.max);
> -  if (r1 == NULL_TREE || TREE_OVERFLOW (r1)
> -  || r2 == NULL_TREE || TREE_OVERFLOW (r2))
> -return false;
> -  if (subcode == MULT_EXPR)
> +  if (!range_int_cst_p (&vr0))
> +{
> +  /* If one range is VR_ANTI_RANGE, VR_VARYING etc.,
> +  optimize at least x = y + 0; x = y - 0; x = y * 0;
> +  and x = y * 1; which never overflow.  */
> +  if (!range_int_cst_p (&vr1))
> + return false;
> +  if (tree_int_cst_sgn (vr1.min) == -1)
> + return false;
> +  if (compare_tree_int (vr1.max, subcode == MULT_EXPR) == 1)
> + return false;
> +}
> +  else if (!range_int_cst_p (&vr1))
> +{
> +  /* If one range is VR_ANTI_RANGE, VR_VARYING etc.,
> +  optimize at least x = 0 + y; x = 0 * y; and x = 1 * y;
> +  which never overflow.  */
> +  if (subcode == MINUS_EXPR)
> + return false;
> +  if (!range_int_cst_p (&vr0))
> + return false;
> +  if (tree_int_cst_sgn (vr0.min) == -1)
> + return false;
> +  if (compare_tree_int (vr0.max, subcode == MULT_EXPR) == 1)
> + return false;
> +}
> +  else
>  {
> -  tree r3 = int_const_binop (subcode, vr0.min, vr1.max);
> -  tree r4 = int_const_binop (subcode, vr0.max, vr1.min);
> -  if (r3 == NULL_TREE || TREE_OVERFLOW (r3)
> -   || r4 == NULL_TREE || TREE_OVERFLOW (r4))
> +  tree r1 = int_const_binop (subcode, vr0.min, vr1.min);
> +  tree r2 = int_const_binop (subcode, vr0.max, vr1.max);
> +  if (r1 == NULL_TREE || TREE_OVERFLOW (r1)
> +   || r2 == NULL_TREE || TREE_OVERFLOW (r2))
>   return false;
> +  if (subcode == MULT_EXPR)
> + {
> +   tree r3 = int_const_binop (subcode, vr0.min, vr1.max);
> +   tree r4 = int_const_binop (subcode, vr0.max, vr1.min);
> +   if (r3 == NULL_TREE || TREE_OVERFLOW (r3)
> +   || r4 == NULL_TREE || TREE_OVERFLOW (r4))
> + return false;
> + }
>  }
> +
>gimple g = gimple_build_assign_with_ops (subcode, gimple_call_lhs (stmt),
>  op0, op1);
>gsi_replace (gsi, g, false);
> 
>   Jakub
> 
> 

-- 
Richard Biener 
SUSE / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746
GF: Jeff Hawn, Jennifer Guild, Felix Imend"orffer


Re: [PATCH] Perform ubsan instrumentation for x >= 0 ? x : -x

2014-03-25 Thread Richard Biener
On Tue, 25 Mar 2014, Jakub Jelinek wrote:

> Hi!
> 
> While Marek has been debugging while some perl test fails when perl is built
> with GCC 4.9, we've discovered that it is because of undefined behavior in
> it:
> ...
>   && (((UV)1 << NV_PRESERVES_UV_BITS) >
>   (UV)(SvIVX(sv) > 0 ? SvIVX(sv) : -SvIVX(sv)))
> where SvIVX(sv) can be LONG_MIN, at which point there is undefined behavior
> on the negation, but -fsanitize=undefined did detect only other issues in
> the same source file and not this one, because fold-const.c folded it into
> ABS_EXPR early.
> 
> This patch disables such folding, because all the A op 0 ? A : -A
> operations this if is trying to optimize will need instrumentation with
> -fsanitize=signed-integer-overflow.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Can't one form a valid constant expression using this?  Also isn't
ABS_EXPR undefined for LONG_MIN as well?  So why is ubsan not
instrumenting that instead?

Thanks,
Richard.
 
> 2014-03-25  Jakub Jelinek  
> 
>   PR sanitizer/60636
>   * fold-const.c (fold_cond_expr_with_comparison): Don't
>   fold A op 0 ? A : -A if -fsanitize=undefined.
> 
>   * c-c++-common/ubsan/pr60636.c: New test.
> 
> --- gcc/fold-const.c.jj   2014-01-03 11:40:35.0 +0100
> +++ gcc/fold-const.c  2014-03-24 17:59:45.395445617 +0100
> @@ -4718,7 +4718,13 @@ fold_cond_expr_with_comparison (location
> && operand_equal_p (TREE_OPERAND (arg1, 0),
> TREE_OPERAND (arg2, 1), 0)
> && operand_equal_p (TREE_OPERAND (arg1, 1),
> -   TREE_OPERAND (arg2, 0), 0
> +   TREE_OPERAND (arg2, 0), 0)))
> +  /* Don't fold this if sanitizing undefined behavior,
> +  -A or Y-X might overflow and after folding this we wouldn't
> +  be able to detect that.  */
> +  && ((flag_sanitize & SANITIZE_SI_OVERFLOW) == 0
> +   || !INTEGRAL_TYPE_P (TREE_TYPE (arg01))
> +   || TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg01
>  switch (comp_code)
>{
>case EQ_EXPR:
> --- gcc/testsuite/c-c++-common/ubsan/pr60636.c.jj 2014-03-24 
> 18:04:33.875925324 +0100
> +++ gcc/testsuite/c-c++-common/ubsan/pr60636.c2014-03-24 
> 18:09:18.696419079 +0100
> @@ -0,0 +1,15 @@
> +/* PR sanitizer/60636 */
> +/* { dg-do run } */
> +/* { dg-options "-fsanitize=undefined" } */
> +
> +volatile long long int a;
> +
> +int
> +main ()
> +{
> +  long long int u = -__LONG_LONG_MAX__ - 1;
> +  a = u > 0 ? u : -u;
> +  return 0;
> +}
> +
> +/* { dg-output "negation of -9223372036854775808 cannot be represented in 
> type 'long long int'" } */
> 
>   Jakub
> 
> 

-- 
Richard Biener 
SUSE / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746
GF: Jeff Hawn, Jennifer Guild, Felix Imend"orffer


Re: [PATCH] Fix undefined behavior in the combiner

2014-03-25 Thread Richard Biener
On Tue, 25 Mar 2014, Jakub Jelinek wrote:

> Hi!
> 
> simplify_compare_const is sometimes called with two CONST_INTs,
> which means mode is VOIDmode and mode_width is 0, but then it
> happily verifies that mode_width is <= HOST_BITS_PER_WIDE_INT
> and shits stuff by mode_width - 1 (i.e. -1).
> From what I can understand, some optimizations can be still
> performed even when we don't know the mode width, and sometimes
> the caller knows the mode of op0, so it makes sense to pass it down
> to let the function take it into account.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, tested also
> with --with-build-config=bootstrap-ubsan bootstrap.
> Ok for trunk?

Ok.

Thanks,
Richard.

> 2014-03-25  Jakub Jelinek  
> 
>   * combine.c (simplify_compare_const): Add MODE argument.
>   Handle mode_width 0 as very large mode_width.
>   (try_combine, simplify_comparison): Adjust callers.
> 
> --- gcc/combine.c.jj  2014-03-03 08:24:33.0 +0100
> +++ gcc/combine.c 2014-03-24 11:31:13.390695208 +0100
> @@ -446,7 +446,8 @@ static rtx simplify_shift_const (rtx, en
>int);
>  static int recog_for_combine (rtx *, rtx, rtx *);
>  static rtx gen_lowpart_for_combine (enum machine_mode, rtx);
> -static enum rtx_code simplify_compare_const (enum rtx_code, rtx, rtx *);
> +static enum rtx_code simplify_compare_const (enum rtx_code, enum 
> machine_mode,
> +  rtx, rtx *);
>  static enum rtx_code simplify_comparison (enum rtx_code, rtx *, rtx *);
>  static void update_table_tick (rtx);
>  static void record_value_for_reg (rtx, rtx, rtx);
> @@ -2949,7 +2950,7 @@ try_combine (rtx i3, rtx i2, rtx i1, rtx
>   {
> compare_code = orig_compare_code = GET_CODE (*cc_use_loc);
> compare_code = simplify_compare_const (compare_code,
> -  op0, &op1);
> +  GET_MODE (i2dest), op0, &op1);
> target_canonicalize_comparison (&compare_code, &op0, &op1, 1);
>   }
>  
> @@ -10817,9 +10818,9 @@ gen_lowpart_for_combine (enum machine_mo
> *POP1 may be updated.  */
>  
>  static enum rtx_code
> -simplify_compare_const (enum rtx_code code, rtx op0, rtx *pop1)
> +simplify_compare_const (enum rtx_code code, enum machine_mode mode,
> + rtx op0, rtx *pop1)
>  {
> -  enum machine_mode mode = GET_MODE (op0);
>unsigned int mode_width = GET_MODE_PRECISION (mode);
>HOST_WIDE_INT const_op = INTVAL (*pop1);
>  
> @@ -10835,7 +10836,7 @@ simplify_compare_const (enum rtx_code co
>if (const_op
>&& (code == EQ || code == NE || code == GE || code == GEU
> || code == LT || code == LTU)
> -  && mode_width <= HOST_BITS_PER_WIDE_INT
> +  && mode_width - 1 < HOST_BITS_PER_WIDE_INT
>&& exact_log2 (const_op & GET_MODE_MASK (mode)) >= 0
>&& (nonzero_bits (op0, mode)
> == (unsigned HOST_WIDE_INT) (const_op & GET_MODE_MASK (mode
> @@ -10882,7 +10883,7 @@ simplify_compare_const (enum rtx_code co
>/* If we are doing a <= 0 comparison on a value known to have
>a zero sign bit, we can replace this with == 0.  */
>else if (const_op == 0
> -&& mode_width <= HOST_BITS_PER_WIDE_INT
> +&& mode_width - 1 < HOST_BITS_PER_WIDE_INT
>  && (nonzero_bits (op0, mode)
>  & ((unsigned HOST_WIDE_INT) 1 << (mode_width - 1)))
>  == 0)
> @@ -10911,7 +10912,7 @@ simplify_compare_const (enum rtx_code co
>/* If we are doing a > 0 comparison on a value known to have
>a zero sign bit, we can replace this with != 0.  */
>else if (const_op == 0
> -&& mode_width <= HOST_BITS_PER_WIDE_INT
> +&& mode_width - 1 < HOST_BITS_PER_WIDE_INT
>  && (nonzero_bits (op0, mode)
>  & ((unsigned HOST_WIDE_INT) 1 << (mode_width - 1)))
>  == 0)
> @@ -10927,7 +10928,7 @@ simplify_compare_const (enum rtx_code co
> /* ... fall through ...  */
>   }
>/* (unsigned) < 0x8000 is equivalent to >= 0.  */
> -  else if (mode_width <= HOST_BITS_PER_WIDE_INT
> +  else if (mode_width - 1 < HOST_BITS_PER_WIDE_INT
>  && (unsigned HOST_WIDE_INT) const_op
>  == (unsigned HOST_WIDE_INT) 1 << (mode_width - 1))
>   {
> @@ -10943,7 +10944,7 @@ simplify_compare_const (enum rtx_code co
>if (const_op == 0)
>   code = EQ;
>/* (unsigned) <= 0x7fff is equivalent to >= 0.  */
> -  else if (mode_width <= HOST_BITS_PER_WIDE_INT
> +  else if (mode_width - 1 < HOST_BITS_PER_WIDE_INT
>  && (unsigned HOST_WIDE_INT) const_op
>  == ((unsigned HOST_WIDE_INT) 1 << (mode_width - 1)) - 1)
>   {
> @@ -10962,7 +10963,7 @@ simplify_compare_const (enum rtx_code co
>   }
>  
>/* (unsigned) >= 0x8000 is equivalent to < 0.  */
> -  else if (mode_width <= HOST_BIT

Re: [PATCH] Fix two spots with undefined behavior

2014-03-25 Thread Richard Biener
On Tue, 25 Mar 2014, Jakub Jelinek wrote:

> Hi!
> 
> These two spots were determined by --with-build-config=bootstrap-ubsan
> as having undefined signed integer overflow.
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
> ok for trunk?

Ok.

Thanks,
Richard.

> 2014-03-25  Jakub Jelinek  
> 
>   * cselib.c (cselib_hash_rtx): Perform addition in unsigned
>   type to avoid signed integer overflow.
>   * explow.c (plus_constant): Likewise.
> 
> --- gcc/cselib.c.jj   2014-03-12 10:13:41.0 +0100
> +++ gcc/cselib.c  2014-03-22 08:30:21.622829993 +0100
> @@ -1137,7 +1137,7 @@ cselib_hash_rtx (rtx x, int create, enum
>return hash ? hash : (unsigned int) ENTRY_VALUE;
>  
>  case CONST_INT:
> -  hash += ((unsigned) CONST_INT << 7) + INTVAL (x);
> +  hash += ((unsigned) CONST_INT << 7) + UINTVAL (x);
>return hash ? hash : (unsigned int) CONST_INT;
>  
>  case CONST_DOUBLE:
> --- gcc/explow.c.jj   2014-01-03 11:40:57.0 +0100
> +++ gcc/explow.c  2014-03-22 08:31:42.379409989 +0100
> @@ -110,7 +110,7 @@ plus_constant (enum machine_mode mode, r
> return immed_double_int_const (v, mode);
>   }
>  
> -  return gen_int_mode (INTVAL (x) + c, mode);
> +  return gen_int_mode (UINTVAL (x) + c, mode);
>  
>  case CONST_DOUBLE:
>{
> 
>   Jakub
> 
> 

-- 
Richard Biener 
SUSE / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746
GF: Jeff Hawn, Jennifer Guild, Felix Imend"orffer


RE: [patch] Shorten Windows path

2014-03-25 Thread Joey Ye
Ping

> -Original Message-
> From: Joey Ye [mailto:joey...@arm.com]
> Sent: 19 February 2014 15:45
> To: gcc-patches@gcc.gnu.org; Ian Lance Taylor (i...@google.com)
> Subject: [patch] Shorten Windows path
> 
> Max length of path on Windows is 255, which is easy to exceed in a
> complicated project. Ultimate solution may be complex but canonizing the
> path and skipping the ".."s in path is helpful.
> 
> Relative discussion in gcc-patches:
> http://gcc.gnu.org/ml/gcc-patches/2013-11/msg00582.html
> 
> OK to trunk stage 1?
> 
> ChangeLog.libcpp:
> * files.c (find_file_in_dir): Always try to shorten for DOS.
> 
> diff --git a/libcpp/files.c b/libcpp/files.c index 7e88778..9dcc71f 100644
> --- a/libcpp/files.c
> +++ b/libcpp/files.c
> @@ -386,9 +386,18 @@ find_file_in_dir (cpp_reader *pfile, _cpp_file *file,
> bool *invalid_pch)
>hashval_t hv;
>char *copy;
>void **pp;
> +  bool do_canonical;
> 
> +#ifdef HAVE_DOS_BASED_FILE_SYSTEM
> +  /* For DOS based file system, we always try to shorten file path
> +   * to as it has a shorter constraint on max path length.  */
> +  do_canonical = true;
> +#else
>/* We try to canonicalize system headers.  */
> -  if (CPP_OPTION (pfile, canonical_system_headers) &&
file->dir->sysp)
> +  do_canonical = (CPP_OPTION (pfile, canonical_system_headers)
> +  && file->dir->sysp); #endif
> +  if ( do_canonical )
>   {
> char * canonical_path = maybe_shorter_path (path);
> if (canonical_path)




Re: [PATCH] Fix PR59626, _FORTIFY_SOURCE wrappers and LTO

2014-03-25 Thread Richard Biener
On Tue, 25 Mar 2014, Jan Hubicka wrote:

> > 
> > Currently a _lot_ of packages fail to build with LTO because LTO
> > messes up fortify wrappers by replacing the call to the alias with
> > the symbol itself, making the wrapper look like infinitely
> > recursing.
> > 
> > The following patch fixes this by dropping the bodies of
> > DECL_EXTERN always-inline functions on the floor before IPA
> > (and when doing LTO).  IMHO we should at some point do this
> > unconditional on LTO as the early inliner is supposed to
> > remove all references to always-inline functions.
> > 
> > I'm not 100% sure about the cgraph API use to drop the function
> > body, but at least it seems to work ;)  I'm not sure if we want
> > to restrict the set of functions to apply this even more than
> > just those with always-inline and DECL_EXTERNAL set?
> > 
> > Now double-checking with a fortified LTO bootstrap.
> > 
> > Ok for trunk?
> > 
> > Thanks,
> > Richard.
> > 
> > 2014-03-24  Richard Biener  
> > 
> > PR lto/59626
> > * passes.c (ipa_write_summaries): Drop function bodies of
> > extern always-inline functions.
> > 
> > * gcc.dg/lto/pr59626_0.c: New testcase.
> > * gcc.dg/lto/pr59626_1.c: Likewise.
> > 
> Hi,
> do you see some problem with this approach? Unlike in dropping for 
> ipa_write_summaries
> it drops just after early optimizations and it is done unconditonally.
> I see it kills every cross module inlining of extern inlines, but so does 
> your patch.
> This may make difference for C++ implicit extern inlines (keyed functions) 
> where I can
> imagine users both to declare them always inline and then call indirectly...
> I do it unconditionally because I do not like much of idea of making the LTO 
> and non-LTO
> pipelines diverging even more.

Well - it doesn't fix the testcase for me.

Richard.

> Honza
> 
> Index: ipa.c
> ===
> --- ipa.c (revision 208798)
> +++ ipa.c (working copy)
> @@ -139,7 +139,10 @@ process_references (struct ipa_ref_list
>  
>if (node->definition && !node->in_other_partition
> && ((!DECL_EXTERNAL (node->decl) || node->alias)
> -   || (before_inlining_p
> +   || (((before_inlining_p
> + && (cgraph_state < CGRAPH_STATE_IPA_SSA
> + || !lookup_attribute ("always_inline",
> +   DECL_ATTRIBUTES (node->decl)
> /* We use variable constructors during late complation for
>constant folding.  Keep references alive so partitioning
>knows about potential references.  */
> @@ -191,7 +194,10 @@ walk_polymorphic_call_targets (pointer_s
> /* Prior inlining, keep alive bodies of possible targets for
>devirtualization.  */
>  if (n->definition
> -&& before_inlining_p)
> +&& (before_inlining_p
> +&& (cgraph_state < CGRAPH_STATE_IPA_SSA
> +|| !lookup_attribute ("always_inline",
> +  DECL_ATTRIBUTES (n->decl)
>pointer_set_insert (reachable, n);
>  
> /* Even after inlining we want to keep the possible targets in the
> 
> 


[PATCH, PR 60580, AArch64] Fix __attribute__ ((optimize("no-omit-frame-pointer")))

2014-03-25 Thread Marcus Shawcroft

Hi,

The implementation of -m[no-]omit-leaf-frame-pointer and 
-f[no-]omit-frame-pointer in the AArch64 target does not behave 
correctly in the presence of __attribute__ optimize.


This patch adjusts the implementation to work in a similar fashion to 
the same functionality in the i386 target.


The problem occurs because the current implementation uses a global 
'faked_omit_frame_pointer' to retain the original value of 
flag_omit_frame_pointer.  The global does not form part of the 
optimization save state.


This solution removes the global and instead tracks required behaviour 
using only flag_omit_frame_pointer and flag_omit_leaf_frame_pointer. 
These two form part of the optimziation save state and target save state 
respectively.


The additional complication for AArch64 is that the PCS requires that 
given -fno-omit-frame-pointer -momit-leave-frame-pointer, a leaf 
function that kills LR must create a frame record.  This is readily 
handled in aarch64_frame_pointer_required().  I've dropped logic in 
aarch64_can_eliminate() that attempts to detect this scenario since it 
appears to me to be superflous.


I'll leave this on the list for 24h for folks to comment and to give the 
RM's the chance to object before committing.


Cheers
/Marcus

2014-03-25  Marcus Shawcroft  

PR target/60580
* config/aarch64/aarch64.c (faked_omit_frame_pointer): Remove.
(aarch64_frame_pointer_required): Adjust logic.
(aarch64_can_eliminate): Adjust logic.
(aarch64_override_options_after_change): Adjust logic.diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index d59ecf7..7bd608c 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2014-03-21  Marcus Shawcroft  
+
+   PR target/60580
+   * config/aarch64/aarch64.c (faked_omit_frame_pointer): Remove.
+   (aarch64_frame_pointer_required): Adjust logic.
+   (aarch64_can_eliminate): Adjust logic.
+   (aarch64_override_options_after_change): Adjust logic.
+
 2014-03-19 Venkataramanan Kumar  
 
* config/aarch64/aarch64.md (stack_protect_set, stack_protect_test)
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index a0b20b67..c360289 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -315,10 +315,6 @@ static GTY(()) int gty_dummy;
 #define AARCH64_NUM_BITMASKS  5334
 static unsigned HOST_WIDE_INT aarch64_bitmasks[AARCH64_NUM_BITMASKS];
 
-/* Did we set flag_omit_frame_pointer just so
-   aarch64_frame_pointer_required would be called? */
-static bool faked_omit_frame_pointer;
-
 typedef enum aarch64_cond_code
 {
   AARCH64_EQ = 0, AARCH64_NE, AARCH64_CS, AARCH64_CC, AARCH64_MI, AARCH64_PL,
@@ -1730,17 +1726,15 @@ aarch64_frame_pointer_required (void)
   if (cfun->calls_alloca)
 return true;
 
-  /* We may have turned flag_omit_frame_pointer on in order to have this
- function called; if we did, we also set the 'faked_omit_frame_pointer' 
flag
- and we'll check it here.
- If we really did set flag_omit_frame_pointer normally, then we return 
false
- (no frame pointer required) in all cases.  */
+  /* In aarch64_override_options_after_change
+ flag_omit_leaf_frame_pointer turns off the frame pointer by
+ default.  Turn it back on now if we've not got a leaf
+ function.  */
+  if (flag_omit_leaf_frame_pointer
+  && (!crtl->is_leaf || df_regs_ever_live_p (LR_REGNUM)))
+return true;
 
-  if (flag_omit_frame_pointer && !faked_omit_frame_pointer)
-return false;
-  else if (flag_omit_leaf_frame_pointer)
-return !crtl->is_leaf || df_regs_ever_live_p (LR_REGNUM);
-  return true;
+  return false;
 }
 
 /* Mark the registers that need to be saved by the callee and calculate
@@ -4168,23 +4162,8 @@ aarch64_can_eliminate (const int from, const int to)
return true;
   if (from == FRAME_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
return true;
-return false;
-}
-  else
-{
-  /* If we decided that we didn't need a leaf frame pointer but then used
-LR in the function, then we'll want a frame pointer after all, so
-prevent this elimination to ensure a frame pointer is used.
-
-NOTE: the original value of flag_omit_frame_pointer gets trashed
-IFF flag_omit_leaf_frame_pointer is true, so we check the value
-of faked_omit_frame_pointer here (which is true when we always
-wish to keep non-leaf frame pointers but only wish to keep leaf frame
-pointers when LR is clobbered).  */
-  if (to == STACK_POINTER_REGNUM
- && df_regs_ever_live_p (LR_REGNUM)
- && faked_omit_frame_pointer)
-   return false;
+
+  return false;
 }
 
   return true;
@@ -5314,17 +5293,10 @@ aarch64_override_options (void)
 static void
 aarch64_override_options_after_change (void)
 {
-  faked_omit_frame_pointer = false;
-
-  /* To omit leaf frame pointers, we need to turn flag_omit_frame_pointer on so
- that aarch64_frame_pointer_

Re: [PATCH] Fix PR59626, _FORTIFY_SOURCE wrappers and LTO

2014-03-25 Thread Richard Biener
On Mon, 24 Mar 2014, Jan Hubicka wrote:

> > 
> > Currently a _lot_ of packages fail to build with LTO because LTO
> > messes up fortify wrappers by replacing the call to the alias with
> > the symbol itself, making the wrapper look like infinitely
> > recursing.
> > 
> > The following patch fixes this by dropping the bodies of
> > DECL_EXTERN always-inline functions on the floor before IPA
> > (and when doing LTO).  IMHO we should at some point do this
> > unconditional on LTO as the early inliner is supposed to
> > remove all references to always-inline functions.
> > 
> > I'm not 100% sure about the cgraph API use to drop the function
> > body, but at least it seems to work ;)  I'm not sure if we want
> > to restrict the set of functions to apply this even more than
> > just those with always-inline and DECL_EXTERNAL set?
> > 
> > Now double-checking with a fortified LTO bootstrap.
> > 
> > Ok for trunk?
> > 
> > Thanks,
> > Richard.
> > 
> > 2014-03-24  Richard Biener  
> > 
> > PR lto/59626
> > * passes.c (ipa_write_summaries): Drop function bodies of
> > extern always-inline functions.
> 
> I think it is probably better to drop these during unreachable function 
> removal same way as we drop extern inlines after inlining (just use 
> cgraph_state check to see if we are past early inlining). I will make 
> patch this afternoon.

Ah, I didn't know we do that already.  But note that these inlines
are extern inlines as well, so it doesn't seem to work ... though
I can't identify the code doing that in symtab_remove_unreachable_nodes.

> Why do you need to remove the always_inline attribute? And how do I do 
> fortified LTO bootstrap? :)

If I don't remove the always_inline attribute I still get errors from
tree-inline.c:4154 (there _is_ a caller to the function, it's just
an indirect one discvered during LTO only).

Ideally we'd have the address of an always-inline function resolve
to an offline body _not_ marked always-inline.  The same way as we'd
ideally for

int __atoi  (const char *) __asm__("atoi");
extern inline __attribute__((always_inline,gnu_inline))
int atoi (const char *x)
{
  return __atoi (x);
}

have the cgraph edge(!) from atoi to __atoi _not_ marked as
to always inline.  The alias decl after all does _not_ have
the always-inline attribute.

Thus the problems that arise with LTO are solely due to us
smashing all aliases to a single prevailing node.

Getting rid of the inline body before LTO out is the easiest way
out for this common use (and we should be able to throw away all
always-inline bodies after early inlining anyway).

To do a fortified LTO bootstrap you set BOOT_CFLAGS="-O2 -g 
-D_FORTIFY_SOURCE=2".

Richard.

> Honza
> > 
> > * gcc.dg/lto/pr59626_0.c: New testcase.
> > * gcc.dg/lto/pr59626_1.c: Likewise.
> > 
> > Index: gcc/passes.c
> > ===
> > *** gcc/passes.c(revision 208745)
> > --- gcc/passes.c(working copy)
> > *** ipa_write_summaries (void)
> > *** 2390,2404 
> >   
> > if (cgraph_function_with_gimple_body_p (node))
> > {
> > ! /* When streaming out references to statements as part of some IPA
> > !pass summary, the statements need to have uids assigned and the
> > !following does that for all the IPA passes here. Naturally, this
> > !ordering then matches the one IPA-passes get in their stmt_fixup
> > !hooks.  */
> > ! 
> > ! push_cfun (DECL_STRUCT_FUNCTION (node->decl));
> > ! renumber_gimple_stmt_uids ();
> > ! pop_cfun ();
> > }
> > if (node->definition)
> >   lto_set_symtab_encoder_in_partition (encoder, node);
> > --- 2396,2427 
> >   
> > if (cgraph_function_with_gimple_body_p (node))
> > {
> > ! if (DECL_EXTERNAL (node->decl)
> > ! && lookup_attribute ("always_inline",
> > !  DECL_ATTRIBUTES (node->decl)) != NULL)
> > !   {
> > ! /* We mess up uses of extern always-inline wrappers that
> > !end up calling an alias to itself like glibc _FORTIFY_SOURCE
> > !wrappers.  Simply drop the bodies of the extern inlines
> > !here to avoid that.  */
> > ! cgraph_release_function_body (node);
> > ! node->analyzed = false;
> > ! node->definition = false;
> > ! DECL_ATTRIBUTES (node->decl)
> > !   = remove_attribute ("always_inline",
> > !   DECL_ATTRIBUTES (node->decl));
> > !   }
> > ! else
> > !   {
> > ! /* When streaming out references to statements as part of some
> > !IPA pass summary, the statements need to have uids assigned
> > !and the following does that for all the IPA passes here.
> > !Naturally, this ordering then matches the one IPA-passes get
> > !in their stmt_fixup hooks.  */
> > ! push_cfun (DECL_STRUCT_FUNCTION (node->decl));
> >

[PATCH, ARM] Enable shrink-wrap for apcs frame

2014-03-25 Thread Zhenqiang Chen
Hi

The patch enables shrink-wrap for apcs frame.

Bootstrap and no make check regression in ARM, THUMB1 and THUMB2 modes.
No make check regression with "-g/-mapcs/-marm".
Build linux-3.14-rc7 without error.

Is it OK for next stage1?

Thanks!
-Zhenqiang

ChangeLog:
2014-03-25  Zhenqiang Chen  

* config/arm/arm.c (arm_option_override): Enable shrink-wrap for
TARGET_APCS_FRAME.
(arm_emit_multi_reg_pop): Set correct dwarf info.
(arm_expand_epilogue_apcs_frame): Add more dwarf info.

testsuite/ChangeLog:
2014-03-25  Zhenqiang Chen  

* gcc.target/arm/shrink-wrap-alloca.c: New test case.
* gcc.target/arm/shrink-wrap-sibcall.c: New test case.

diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 0240cc7..fa86942 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -2811,9 +2811,6 @@ arm_option_override (void)
  generate additional returns.  */
   if (optimize_function_for_size_p (cfun) && TARGET_THUMB2)
 flag_shrink_wrap = false;
-  /* TBD: Dwarf info for apcs frame is not handled yet.  */
-  if (TARGET_APCS_FRAME)
-flag_shrink_wrap = false;

   /* We only support -mslow-flash-data on armv7-m targets.  */
   if (target_slow_flash_data
@@ -19840,7 +19837,14 @@ arm_emit_multi_reg_pop (unsigned long saved_regs_mask)
 par = emit_insn (par);

   REG_NOTES (par) = dwarf;
-  if (!return_in_pc)
+
+  if (!emit_update)
+{
+  /* SP is restored from stack.  So reset the frame info.  */
+  RTX_FRAME_RELATED_P (par) = 1;
+  add_reg_note (par, REG_CFA_DEF_CFA, stack_pointer_rtx);
+}
+  else if (!return_in_pc)
 arm_add_cfa_adjust_cfa_note (par, UNITS_PER_WORD * num_regs,
  stack_pointer_rtx, stack_pointer_rtx);
 }
@@ -27226,6 +27230,9 @@ arm_expand_epilogue_apcs_frame (bool really_return)
   REG_NOTES (insn) = alloc_reg_note (REG_CFA_RESTORE,
  gen_rtx_REG (SImode, IP_REGNUM),
  NULL_RTX);
+  arm_add_cfa_adjust_cfa_note (insn, UNITS_PER_WORD,
+   stack_pointer_rtx,
+   stack_pointer_rtx);
 }

   if (!really_return || (saved_regs_mask & (1 << PC_REGNUM)))
diff --git a/gcc/testsuite/gcc.target/arm/shrink-wrap-alloca.c
b/gcc/testsuite/gcc.target/arm/shrink-wrap-alloca.c
new file mode 100644
index 000..318240b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/shrink-wrap-alloca.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -g -mapcs " } */
+
+int *p;
+
+void
+test (int a)
+{
+  if (a > 0)
+p = __builtin_alloca (4);
+}
diff --git a/gcc/testsuite/gcc.target/arm/shrink-wrap-sibcall.c
b/gcc/testsuite/gcc.target/arm/shrink-wrap-sibcall.c
new file mode 100644
index 000..2efe5d0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/shrink-wrap-sibcall.c
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -g -mapcs " } */
+
+unsigned char a, b, d, f, g;
+
+int test (void);
+
+int
+baz (int c)
+{
+  if (c == 0) return test ();
+  if (b & 1)
+{
+  g = 0;
+  int e = (a & 0x0f) - (g & 0x0f);
+
+  if (!a)  b |= 0x80;
+  a = e + test ();
+ f = g/5 + a*3879 + b *2985;
+}
+   else
+   {
+ f = g + a*39879 + b *25;
+   }
+  return test ();
+}


Re: [PATCH] Fix ubsan i?86 {add,sub,mul}v4 patterns

2014-03-25 Thread Uros Bizjak
On Tue, Mar 25, 2014 at 8:24 AM, Jakub Jelinek  wrote:
> Hi!
>
> The bootstrap-ubsan bootstrap revealed a problem with the
> {add,sub,mul}v4 patterns.  The problem is that they
> accept CONST_INT operands (because the instructions do accept immediates),
> but to model what the instruction actually does, we need to have both
> the value of the operand itself and it's sign extended value to
> 2x wider mode, but say (sign_extend:DI (const_int 5)) in the pattern is
> invalid RTL (found about this because e.g. num_sign_bit_copies returns
> bogus return values on (sign_extend:DI (const_int 0)) ).
> The following patch attempts to fix this by using two different define_insns
> for each, one that accepts everything but VOIDmode operands (i.e. usually
> register, memory, some SYMBOL_REFs/LABEL_REFs/CONSTs where we do have mode),
> one that accepts only CONST_INTs.  Hopefully at least the combiner will
> canonicalize the potential (sign_extend:DI (const_int N)) into
> just (const_int N) and thus the *v4_1 insns would match (plus the
> expander expands it that way too).
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, tested with
> i686-linux --with-build-config=bootstrap-ubsan bootstrap.  Ok for trunk?

It looks to me that you will also need a corresponding predicate,
similar to x86_64_zext_operand that rejects sign-extended VOIDmode
operands where We constraint is used. That will also solve the problem
with combiner, which will be prohibited from combining VOIDmode
operands.

Also, please use curly braces in multi-line preparation statements.

Uros,.


[patch, Fortran] Fix PR 60522

2014-03-25 Thread Thomas Koenig
Hello world,

the attached patch fixes the regression (after some thought
of what might still be optimized, which isn't much :-)

Regression-tested.  OK for trunk?

Thomas


2014-04-25  Thomas Koenig  

PR fortran/60522
* frontend-passes.c (cfe_code):  Do not walk subtrees
for WHERE.

2014-04-25  Thomas Koenig  

PR fortran/60522
* gfortran.dg/where_4.f90:  New test case.
Index: frontend-passes.c
===
--- frontend-passes.c	(Revision 208592)
+++ frontend-passes.c	(Arbeitskopie)
@@ -627,12 +627,35 @@ cfe_expr_0 (gfc_expr **e, int *walk_subtrees,
to insert statements as needed.  */
 
 static int
-cfe_code (gfc_code **c, int *walk_subtrees ATTRIBUTE_UNUSED,
-	  void *data ATTRIBUTE_UNUSED)
+cfe_code (gfc_code **c, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
 {
   current_code = c;
   inserted_block = NULL;
   changed_statement = NULL;
+
+  /* Do not do anything inside a WHERE statement; scalar assignments, BLOCKs
+ and allocation on assigment are prohibited inside WHERE, and finally
+ masking an expression would lead to wrong-code when replacing
+
+ WHERE (a>0)
+   b = sum(foo(a) + foo(a))
+ END WHERE
+
+ with
+
+ WHERE (a > 0)
+   tmp = foo(a)
+   b = sum(tmp + tmp)
+ END WHERE
+*/
+
+  if ((*c)->op == EXEC_WHERE)
+{
+  *walk_subtrees = 0;
+  return 0;
+}
+  
+
   return 0;
 }
 
! { dg-do compile }
! PR 60522 - this used to ICE.
! Original test case Roger Ferrer Ibanez
subroutine foo(a, b)
   implicit none
   integer, dimension(:), intent(inout) :: a
   integer, dimension(:), intent(in) :: b

   where (b(:) > 0)
  where (b(:) > 100)
 a(lbound(a, 1):ubound(a, 1)) = b(lbound(b, 1):ubound(b, 1)) * b(lbound(b, 1):ubound(b, 1)) - 100
  elsewhere
 a(lbound(a, 1):ubound(a, 1)) = b(lbound(b, 1):ubound(b, 1)) * b(lbound(b, 1):ubound(b, 1))
  end where
   elsewhere
  a(lbound(a, 1):ubound(a, 1)) = - b(lbound(b, 1):ubound(b, 1)) * b(lbound(b, 1):ubound(b, 1))
   end where
end subroutine foo


Re: [RFC] Do not consider volatile asms as optimization barriers #1

2014-03-25 Thread Yury Gribov

Jakub Jelinek wrote:

Richard Sandiford wrote:

OK, how about this?  It looks like the builtins.c and stmt.c stuff wasn't
merged until 4.9, and at this stage it seemed safer to just add the same
use/clobber sequence to both places.


Please wait a little bit, the patch has been committed to the trunk only
very recently, we want to see if it has any fallout.


It has been two weeks since Richard commited this to trunk. Perhaps it's 
ok to backport to 4.8 branch now?


-Y


[PATCH] Fix folding of UBSAN_CHECK_SUB (x, 0) etc.

2014-03-25 Thread Jakub Jelinek
Hi!

While working on previous patch, I've noticed a severe omission in the
-fsanitize=signed-integer-overflow support.  Nothing ever
folds addition/subtraction of 0 and multiplication by [0,1], none of these
may ever overflow and thus we can fold them to normal operations and let
those be folded as normal operations.

Bootstrapped/regtested on x86_64-linux and i686-linux, tested with
--with-build-config=bootstrap-ubsan bootstrap on i686-linux, ok for trunk?

2014-03-25  Jakub Jelinek  

* tree-vrp.c (simplify_internal_call_using_ranges): If only
one range is range_int_cst_p, but not both, at least optimize
addition/subtraction of 0 and multiplication by 0 or 1.

--- gcc/tree-vrp.c.jj   2014-03-12 10:14:18.0 +0100
+++ gcc/tree-vrp.c  2014-03-24 16:14:50.822674164 +0100
@@ -9336,31 +9336,58 @@ simplify_internal_call_using_ranges (gim
   else if (TREE_CODE (op0) == INTEGER_CST)
 set_value_range_to_value (&vr0, op0, NULL);
   else
-return false;
+set_value_range_to_varying (&vr0);
 
   if (TREE_CODE (op1) == SSA_NAME)
 vr1 = *get_value_range (op1);
   else if (TREE_CODE (op1) == INTEGER_CST)
 set_value_range_to_value (&vr1, op1, NULL);
   else
-return false;
+set_value_range_to_varying (&vr1);
 
-  if (!range_int_cst_p (&vr0) || !range_int_cst_p (&vr1))
-return false;
-
-  tree r1 = int_const_binop (subcode, vr0.min, vr1.min);
-  tree r2 = int_const_binop (subcode, vr0.max, vr1.max);
-  if (r1 == NULL_TREE || TREE_OVERFLOW (r1)
-  || r2 == NULL_TREE || TREE_OVERFLOW (r2))
-return false;
-  if (subcode == MULT_EXPR)
+  if (!range_int_cst_p (&vr0))
+{
+  /* If one range is VR_ANTI_RANGE, VR_VARYING etc.,
+optimize at least x = y + 0; x = y - 0; x = y * 0;
+and x = y * 1; which never overflow.  */
+  if (!range_int_cst_p (&vr1))
+   return false;
+  if (tree_int_cst_sgn (vr1.min) == -1)
+   return false;
+  if (compare_tree_int (vr1.max, subcode == MULT_EXPR) == 1)
+   return false;
+}
+  else if (!range_int_cst_p (&vr1))
+{
+  /* If one range is VR_ANTI_RANGE, VR_VARYING etc.,
+optimize at least x = 0 + y; x = 0 * y; and x = 1 * y;
+which never overflow.  */
+  if (subcode == MINUS_EXPR)
+   return false;
+  if (!range_int_cst_p (&vr0))
+   return false;
+  if (tree_int_cst_sgn (vr0.min) == -1)
+   return false;
+  if (compare_tree_int (vr0.max, subcode == MULT_EXPR) == 1)
+   return false;
+}
+  else
 {
-  tree r3 = int_const_binop (subcode, vr0.min, vr1.max);
-  tree r4 = int_const_binop (subcode, vr0.max, vr1.min);
-  if (r3 == NULL_TREE || TREE_OVERFLOW (r3)
- || r4 == NULL_TREE || TREE_OVERFLOW (r4))
+  tree r1 = int_const_binop (subcode, vr0.min, vr1.min);
+  tree r2 = int_const_binop (subcode, vr0.max, vr1.max);
+  if (r1 == NULL_TREE || TREE_OVERFLOW (r1)
+ || r2 == NULL_TREE || TREE_OVERFLOW (r2))
return false;
+  if (subcode == MULT_EXPR)
+   {
+ tree r3 = int_const_binop (subcode, vr0.min, vr1.max);
+ tree r4 = int_const_binop (subcode, vr0.max, vr1.min);
+ if (r3 == NULL_TREE || TREE_OVERFLOW (r3)
+ || r4 == NULL_TREE || TREE_OVERFLOW (r4))
+   return false;
+   }
 }
+
   gimple g = gimple_build_assign_with_ops (subcode, gimple_call_lhs (stmt),
   op0, op1);
   gsi_replace (gsi, g, false);

Jakub


[PATCH] Fix ubsan i?86 {add,sub,mul}v4 patterns

2014-03-25 Thread Jakub Jelinek
Hi!

The bootstrap-ubsan bootstrap revealed a problem with the
{add,sub,mul}v4 patterns.  The problem is that they
accept CONST_INT operands (because the instructions do accept immediates),
but to model what the instruction actually does, we need to have both
the value of the operand itself and it's sign extended value to
2x wider mode, but say (sign_extend:DI (const_int 5)) in the pattern is
invalid RTL (found about this because e.g. num_sign_bit_copies returns
bogus return values on (sign_extend:DI (const_int 0)) ).
The following patch attempts to fix this by using two different define_insns
for each, one that accepts everything but VOIDmode operands (i.e. usually
register, memory, some SYMBOL_REFs/LABEL_REFs/CONSTs where we do have mode),
one that accepts only CONST_INTs.  Hopefully at least the combiner will
canonicalize the potential (sign_extend:DI (const_int N)) into
just (const_int N) and thus the *v4_1 insns would match (plus the
expander expands it that way too).

Bootstrapped/regtested on x86_64-linux and i686-linux, tested with
i686-linux --with-build-config=bootstrap-ubsan bootstrap.  Ok for trunk?

2014-03-25  Jakub Jelinek  

* config/i386/i386.md (addv4, subv4, mulv4): If
operands[2] is CONST_INT, don't generate (sign_extend (const_int)).
(*addv4, *subv4, *mulv4): Disallow CONST_INT_P
operands[2].  Use We constraint instead of .
(*addv4_1, *subv4_1, *mulv4_1): New insns.
* config/i386/constraints.md (We): New constraint.

--- gcc/config/i386/i386.md.jj  2014-03-19 08:14:37.0 +0100
+++ gcc/config/i386/i386.md 2014-03-24 15:03:24.899354663 +0100
@@ -5821,10 +5821,11 @@ (define_expand "addv4"
   (eq:CCO (plus:
  (sign_extend:
 (match_operand:SWI 1 "nonimmediate_operand"))
- (sign_extend:
-(match_operand:SWI 2 "")))
+ (match_dup 4))
   (sign_extend:
- (plus:SWI (match_dup 1) (match_dup 2)
+ (plus:SWI (match_dup 1)
+   (match_operand:SWI 2
+  "")
  (set (match_operand:SWI 0 "register_operand")
   (plus:SWI (match_dup 1) (match_dup 2)))])
(set (pc) (if_then_else
@@ -5832,7 +5833,11 @@ (define_expand "addv4"
   (label_ref (match_operand 3))
   (pc)))]
   ""
-  "ix86_fixup_binary_operands_no_copy (PLUS, mode, operands);")
+  "ix86_fixup_binary_operands_no_copy (PLUS, mode, operands);
+   if (CONST_INT_P (operands[2]))
+ operands[4] = operands[2];
+   else
+ operands[4] = gen_rtx_SIGN_EXTEND (mode, operands[2]);")
 
 (define_insn "*addv4"
   [(set (reg:CCO FLAGS_REG)
@@ -5840,16 +5845,42 @@ (define_insn "*addv4"
   (sign_extend:
  (match_operand:SWI 1 "nonimmediate_operand" "%0,0"))
   (sign_extend:
- (match_operand:SWI 2 "" ",")))
+ (match_operand:SWI 2 "" "mWe,We")))
(sign_extend:
   (plus:SWI (match_dup 1) (match_dup 2)
(set (match_operand:SWI 0 "nonimmediate_operand" "=,m")
(plus:SWI (match_dup 1) (match_dup 2)))]
-  "ix86_binary_operator_ok (PLUS, mode, operands)"
+  "ix86_binary_operator_ok (PLUS, mode, operands)
+   && !CONST_INT_P (operands[2])"
   "add{}\t{%2, %0|%0, %2}"
   [(set_attr "type" "alu")
(set_attr "mode" "")])
 
+(define_insn "*addv4_1"
+  [(set (reg:CCO FLAGS_REG)
+   (eq:CCO (plus:
+  (sign_extend:
+ (match_operand:SWI 1 "nonimmediate_operand" "0"))
+  (match_operand: 3 "const_int_operand" "i"))
+   (sign_extend:
+  (plus:SWI (match_dup 1)
+(match_operand:SWI 2 "x86_64_immediate_operand"
+ "")
+   (set (match_operand:SWI 0 "nonimmediate_operand" "=m")
+   (plus:SWI (match_dup 1) (match_dup 2)))]
+  "ix86_binary_operator_ok (PLUS, mode, operands)
+   && CONST_INT_P (operands[2])
+   && INTVAL (operands[2]) == INTVAL (operands[3])"
+  "add{}\t{%2, %0|%0, %2}"
+  [(set_attr "type" "alu")
+   (set_attr "mode" "")
+   (set (attr "length_immediate")
+   (cond [(match_test "IN_RANGE (INTVAL (operands[2]), -128, 127)")
+ (const_string "1")
+  (match_test " == 8")
+ (const_string "4")]
+ (const_string "")))])
+
 ;; The lea patterns for modes less than 32 bits need to be matched by
 ;; several insns converted to real lea by splitters.
 
@@ -6093,10 +6124,11 @@ (define_expand "subv4"
   (eq:CCO (minus:
  (sign_extend:
 (match_operand:SWI 1 "nonimmediate_operand"))
- (sign_exten

[PATCH] Perform ubsan instrumentation for x >= 0 ? x : -x

2014-03-25 Thread Jakub Jelinek
Hi!

While Marek has been debugging while some perl test fails when perl is built
with GCC 4.9, we've discovered that it is because of undefined behavior in
it:
...
  && (((UV)1 << NV_PRESERVES_UV_BITS) >
  (UV)(SvIVX(sv) > 0 ? SvIVX(sv) : -SvIVX(sv)))
where SvIVX(sv) can be LONG_MIN, at which point there is undefined behavior
on the negation, but -fsanitize=undefined did detect only other issues in
the same source file and not this one, because fold-const.c folded it into
ABS_EXPR early.

This patch disables such folding, because all the A op 0 ? A : -A
operations this if is trying to optimize will need instrumentation with
-fsanitize=signed-integer-overflow.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2014-03-25  Jakub Jelinek  

PR sanitizer/60636
* fold-const.c (fold_cond_expr_with_comparison): Don't
fold A op 0 ? A : -A if -fsanitize=undefined.

* c-c++-common/ubsan/pr60636.c: New test.

--- gcc/fold-const.c.jj 2014-01-03 11:40:35.0 +0100
+++ gcc/fold-const.c2014-03-24 17:59:45.395445617 +0100
@@ -4718,7 +4718,13 @@ fold_cond_expr_with_comparison (location
  && operand_equal_p (TREE_OPERAND (arg1, 0),
  TREE_OPERAND (arg2, 1), 0)
  && operand_equal_p (TREE_OPERAND (arg1, 1),
- TREE_OPERAND (arg2, 0), 0
+ TREE_OPERAND (arg2, 0), 0)))
+  /* Don't fold this if sanitizing undefined behavior,
+-A or Y-X might overflow and after folding this we wouldn't
+be able to detect that.  */
+  && ((flag_sanitize & SANITIZE_SI_OVERFLOW) == 0
+ || !INTEGRAL_TYPE_P (TREE_TYPE (arg01))
+ || TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg01
 switch (comp_code)
   {
   case EQ_EXPR:
--- gcc/testsuite/c-c++-common/ubsan/pr60636.c.jj   2014-03-24 
18:04:33.875925324 +0100
+++ gcc/testsuite/c-c++-common/ubsan/pr60636.c  2014-03-24 18:09:18.696419079 
+0100
@@ -0,0 +1,15 @@
+/* PR sanitizer/60636 */
+/* { dg-do run } */
+/* { dg-options "-fsanitize=undefined" } */
+
+volatile long long int a;
+
+int
+main ()
+{
+  long long int u = -__LONG_LONG_MAX__ - 1;
+  a = u > 0 ? u : -u;
+  return 0;
+}
+
+/* { dg-output "negation of -9223372036854775808 cannot be represented in type 
'long long int'" } */

Jakub


[PATCH] Fix undefined behavior in the combiner

2014-03-25 Thread Jakub Jelinek
Hi!

simplify_compare_const is sometimes called with two CONST_INTs,
which means mode is VOIDmode and mode_width is 0, but then it
happily verifies that mode_width is <= HOST_BITS_PER_WIDE_INT
and shits stuff by mode_width - 1 (i.e. -1).
>From what I can understand, some optimizations can be still
performed even when we don't know the mode width, and sometimes
the caller knows the mode of op0, so it makes sense to pass it down
to let the function take it into account.

Bootstrapped/regtested on x86_64-linux and i686-linux, tested also
with --with-build-config=bootstrap-ubsan bootstrap.
Ok for trunk?

2014-03-25  Jakub Jelinek  

* combine.c (simplify_compare_const): Add MODE argument.
Handle mode_width 0 as very large mode_width.
(try_combine, simplify_comparison): Adjust callers.

--- gcc/combine.c.jj2014-03-03 08:24:33.0 +0100
+++ gcc/combine.c   2014-03-24 11:31:13.390695208 +0100
@@ -446,7 +446,8 @@ static rtx simplify_shift_const (rtx, en
 int);
 static int recog_for_combine (rtx *, rtx, rtx *);
 static rtx gen_lowpart_for_combine (enum machine_mode, rtx);
-static enum rtx_code simplify_compare_const (enum rtx_code, rtx, rtx *);
+static enum rtx_code simplify_compare_const (enum rtx_code, enum machine_mode,
+rtx, rtx *);
 static enum rtx_code simplify_comparison (enum rtx_code, rtx *, rtx *);
 static void update_table_tick (rtx);
 static void record_value_for_reg (rtx, rtx, rtx);
@@ -2949,7 +2950,7 @@ try_combine (rtx i3, rtx i2, rtx i1, rtx
{
  compare_code = orig_compare_code = GET_CODE (*cc_use_loc);
  compare_code = simplify_compare_const (compare_code,
-op0, &op1);
+GET_MODE (i2dest), op0, &op1);
  target_canonicalize_comparison (&compare_code, &op0, &op1, 1);
}
 
@@ -10817,9 +10818,9 @@ gen_lowpart_for_combine (enum machine_mo
*POP1 may be updated.  */
 
 static enum rtx_code
-simplify_compare_const (enum rtx_code code, rtx op0, rtx *pop1)
+simplify_compare_const (enum rtx_code code, enum machine_mode mode,
+   rtx op0, rtx *pop1)
 {
-  enum machine_mode mode = GET_MODE (op0);
   unsigned int mode_width = GET_MODE_PRECISION (mode);
   HOST_WIDE_INT const_op = INTVAL (*pop1);
 
@@ -10835,7 +10836,7 @@ simplify_compare_const (enum rtx_code co
   if (const_op
   && (code == EQ || code == NE || code == GE || code == GEU
  || code == LT || code == LTU)
-  && mode_width <= HOST_BITS_PER_WIDE_INT
+  && mode_width - 1 < HOST_BITS_PER_WIDE_INT
   && exact_log2 (const_op & GET_MODE_MASK (mode)) >= 0
   && (nonzero_bits (op0, mode)
  == (unsigned HOST_WIDE_INT) (const_op & GET_MODE_MASK (mode
@@ -10882,7 +10883,7 @@ simplify_compare_const (enum rtx_code co
   /* If we are doing a <= 0 comparison on a value known to have
 a zero sign bit, we can replace this with == 0.  */
   else if (const_op == 0
-  && mode_width <= HOST_BITS_PER_WIDE_INT
+  && mode_width - 1 < HOST_BITS_PER_WIDE_INT
   && (nonzero_bits (op0, mode)
   & ((unsigned HOST_WIDE_INT) 1 << (mode_width - 1)))
   == 0)
@@ -10911,7 +10912,7 @@ simplify_compare_const (enum rtx_code co
   /* If we are doing a > 0 comparison on a value known to have
 a zero sign bit, we can replace this with != 0.  */
   else if (const_op == 0
-  && mode_width <= HOST_BITS_PER_WIDE_INT
+  && mode_width - 1 < HOST_BITS_PER_WIDE_INT
   && (nonzero_bits (op0, mode)
   & ((unsigned HOST_WIDE_INT) 1 << (mode_width - 1)))
   == 0)
@@ -10927,7 +10928,7 @@ simplify_compare_const (enum rtx_code co
  /* ... fall through ...  */
}
   /* (unsigned) < 0x8000 is equivalent to >= 0.  */
-  else if (mode_width <= HOST_BITS_PER_WIDE_INT
+  else if (mode_width - 1 < HOST_BITS_PER_WIDE_INT
   && (unsigned HOST_WIDE_INT) const_op
   == (unsigned HOST_WIDE_INT) 1 << (mode_width - 1))
{
@@ -10943,7 +10944,7 @@ simplify_compare_const (enum rtx_code co
   if (const_op == 0)
code = EQ;
   /* (unsigned) <= 0x7fff is equivalent to >= 0.  */
-  else if (mode_width <= HOST_BITS_PER_WIDE_INT
+  else if (mode_width - 1 < HOST_BITS_PER_WIDE_INT
   && (unsigned HOST_WIDE_INT) const_op
   == ((unsigned HOST_WIDE_INT) 1 << (mode_width - 1)) - 1)
{
@@ -10962,7 +10963,7 @@ simplify_compare_const (enum rtx_code co
}
 
   /* (unsigned) >= 0x8000 is equivalent to < 0.  */
-  else if (mode_width <= HOST_BITS_PER_WIDE_INT
+  else if (mode_width - 1 < HOST_BITS_PER_WIDE_INT
   && (unsigned HOST_WIDE_INT) const_op
   == (unsigned HOST_WIDE_INT) 1 << (mode_width - 1))
   

[PATCH] Fix two spots with undefined behavior

2014-03-25 Thread Jakub Jelinek
Hi!

These two spots were determined by --with-build-config=bootstrap-ubsan
as having undefined signed integer overflow.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
ok for trunk?

2014-03-25  Jakub Jelinek  

* cselib.c (cselib_hash_rtx): Perform addition in unsigned
type to avoid signed integer overflow.
* explow.c (plus_constant): Likewise.

--- gcc/cselib.c.jj 2014-03-12 10:13:41.0 +0100
+++ gcc/cselib.c2014-03-22 08:30:21.622829993 +0100
@@ -1137,7 +1137,7 @@ cselib_hash_rtx (rtx x, int create, enum
   return hash ? hash : (unsigned int) ENTRY_VALUE;
 
 case CONST_INT:
-  hash += ((unsigned) CONST_INT << 7) + INTVAL (x);
+  hash += ((unsigned) CONST_INT << 7) + UINTVAL (x);
   return hash ? hash : (unsigned int) CONST_INT;
 
 case CONST_DOUBLE:
--- gcc/explow.c.jj 2014-01-03 11:40:57.0 +0100
+++ gcc/explow.c2014-03-22 08:31:42.379409989 +0100
@@ -110,7 +110,7 @@ plus_constant (enum machine_mode mode, r
  return immed_double_int_const (v, mode);
}
 
-  return gen_int_mode (INTVAL (x) + c, mode);
+  return gen_int_mode (UINTVAL (x) + c, mode);
 
 case CONST_DOUBLE:
   {

Jakub


[PATCH] [C++ RFC] Support named type capture for generic lambdas and generic functions as proposed by N3878

2014-03-25 Thread Adam Butcher
* parser.c (cp_parser_simple_type_specifier): Lookahead for a braced
identifier after a generic type ('auto') parameter and, if present, use
that as the type identifier name.  Otherwise generate one with
make_generic_type_name.  Pass the resulting identifier as the new second
parameter ...
(synthesize_implicit_template_parm): ... here.  Synthesize the template
type parm with the provided name rather than generating one.

* g++.dg/cpp1y/generic-fn-typeid.C: New testcase.
---
 gcc/cp/parser.c| 55 +-
 gcc/testsuite/g++.dg/cpp1y/generic-fn-typeid.C | 42 
 2 files changed, 88 insertions(+), 9 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/generic-fn-typeid.C

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 49fb731..4d6f8fe 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -2128,8 +2128,10 @@ static tree cp_parser_late_parsing_omp_declare_simd
 static tree cp_parser_late_parsing_cilk_simd_fn_info
   (cp_parser *, tree);
 
+static tree make_generic_type_name
+  ();
 static tree synthesize_implicit_template_parm
-  (cp_parser *);
+  (cp_parser *, tree);
 static tree finish_fully_implicit_template
   (cp_parser *, tree);
 
@@ -14530,23 +14532,58 @@ cp_parser_simple_type_specifier (cp_parser* parser,
   maybe_warn_cpp0x (CPP0X_AUTO);
   if (parser->auto_is_implicit_function_template_parm_p)
{
- type = synthesize_implicit_template_parm (parser);
+ /* Synthesize an implicit template parameter named as specified by
+the IDENTIFIER_NODE of a braced identifier (as proposed by section
+2.2 of N3878).  If no braced identifier is present then a name is
+generated a via make_generic_type_name.  */
+
+ if (cp_lexer_peek_nth_token
+ (parser->lexer, 2)->type == CPP_OPEN_BRACE)
+   {
+ /* The 'auto' has only been peeked and is expected to be consumed
+later; parse the braced identifier leaving the closing brace as
+the next token.  */
+
+ cp_lexer_consume_token (parser->lexer); /* RID_AUTO */
+ cp_lexer_consume_token (parser->lexer); /* CPP_OPEN_BRACE */
+
+ tree synth_id = cp_parser_identifier (parser);
+ if (synth_id != error_mark_node)
+   type = synthesize_implicit_template_parm (parser, synth_id);
+
+ if (cp_parser_require
+ (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE) == 0
+ || synth_id == error_mark_node)
+   {
+ error_at (input_location,
+"expected braced identifier for generic type capture");
+ return error_mark_node;
+   }
+
+ /* Roll-back one token to allow for consume below.  */
+ cp_lexer_set_token_position (parser->lexer,
+  cp_lexer_previous_token_position
+  (parser->lexer));
+   }
+ else
+   type = synthesize_implicit_template_parm
+ (parser, make_generic_type_name ());
 
  if (current_class_type && LAMBDA_TYPE_P (current_class_type))
{
  if (cxx_dialect < cxx1y)
-   pedwarn (location_of (type), 0,
+   pedwarn (token->location, 0,
 "use of % in lambda parameter declaration "
 "only available with "
 "-std=c++1y or -std=gnu++1y");
}
  else if (cxx_dialect < cxx1y)
-   pedwarn (location_of (type), 0,
+   pedwarn (token->location, 0,
 "use of % in parameter declaration "
 "only available with "
 "-std=c++1y or -std=gnu++1y");
  else
-   pedwarn (location_of (type), OPT_Wpedantic,
+   pedwarn (token->location, OPT_Wpedantic,
 "ISO C++ forbids use of % in parameter "
 "declaration");
}
@@ -31957,11 +31994,12 @@ tree_type_is_auto_or_concept (const_tree t)
 }
 
 /* Add an implicit template type parameter to the CURRENT_TEMPLATE_PARMS
-   (creating a new template parameter list if necessary).  Returns the newly
-   created template type parm.  */
+   (creating a new template parameter list if necessary).  The template type
+   parameter is given the id SYNTH_ID.  Returns the newly created template type
+   parm.  */
 
 tree
-synthesize_implicit_template_parm  (cp_parser *parser)
+synthesize_implicit_template_parm  (cp_parser *parser, tree synth_id)
 {
   gcc_assert (current_binding_level->kind == sk_function_parms);
 
@@ -32073,7 +32111,6 @@ synthesize_implicit_template_parm  (cp_parser *parser)
   /* Synthesize a new template parameter and track the current template
  parameter chain with implicit_template_parms.  */

  1   2   >