Re: [PATCH] Include tm_p.h in asan.c

2012-11-12 Thread Jakub Jelinek
On Mon, Nov 12, 2012 at 10:13:08PM -0500, David Edelsohn wrote:
> gcc/asan.c probably should have been split into two files because it
> works at multiple levels.  But given that it invokes
> ASM_GENERATE_INTERNAL_LABEL, it needs to include tm_p.h to include
> -protos.h.
> 
> Committed as obvious to allow AIX bootstrap to proceed.
> 
> * asan.c: Include tm_p.h

Thanks, but Makefile.in needs to be adjusted accordingly too.  Committed
as obvious.

2012-11-13  Jakub Jelinek  

* Makefile.in (asan.o): Depend on $(TM_P_H).

--- gcc/Makefile.in.jj  2012-11-12 16:58:42.0 +0100
+++ gcc/Makefile.in 2012-11-13 08:36:41.470663811 +0100
@@ -2211,7 +2211,7 @@ stor-layout.o : stor-layout.c $(CONFIG_H
 asan.o : asan.c asan.h $(CONFIG_H) $(SYSTEM_H) $(GIMPLE_H) \
output.h coretypes.h $(GIMPLE_PRETTY_PRINT_H) \
tree-iterator.h $(TREE_FLOW_H) $(TREE_PASS_H) \
-   $(TARGET_H) $(EXPR_H) $(OPTABS_H)
+   $(TARGET_H) $(EXPR_H) $(OPTABS_H) $(TM_P_H)
 tree-ssa-tail-merge.o: tree-ssa-tail-merge.c \
$(SYSTEM_H) $(CONFIG_H) coretypes.h $(TM_H) $(BITMAP_H) \
$(FLAGS_H) $(TM_P_H) $(BASIC_BLOCK_H) \


Jakub


Re: Patch: Print SImode register names to force addr32 prefix

2012-11-12 Thread Uros Bizjak
On Tue, Nov 13, 2012 at 8:15 AM, H.J. Lu  wrote:

 Since x32 runs in 64-bit mode, for address -0x4300(%rax), hardware
 sign-extends displacement from 32-bits to 64-bits and adds it to %rax.
 But x32 wants 32-bit -0x4300, not 64-bit -0x4300.  This patch
 uses 32-bit registers instead of 64-bit registers when displacement
 < -16*1024*1024.  -16*1024*1024 is used instead of 0 so that we will
 still generate -16(%rsp) instead of -16(%esp).

 Tested it on Linux/x32.  OK to install?
>>>
>>> This problem uncovers a bug in the middle-end, so I guess it would be
>>> better to fix it there.
>>>
>>> Uros.
>>
>> The problem is it isn't safe to transform
>>
>> (zero_extend:DI (plus:SI (FOO:SI) (const_int Y)))
>>
>> to
>>
>> (plus:DI (zero_extend:DI (FOO:SI)) (const_int Y))
>>
>> when Y is negative and its absolute value is greater than FOO.  However,
>> we have to do this transformation since other parts of GCC depend on
>> it.  If we revert the fix for
>>
>> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49721
>>
>> we will get
>>
>> FAIL: gcc.c-torture/compile/990523-1.c  -O3 -g  (internal compiler error)
>> FAIL: gcc.c-torture/compile/990523-1.c  -O3 -g  (test for excess errors)
>> FAIL: gcc.c-torture/compile/pr41634.c  -O3 -fomit-frame-pointer 
>> -funroll-all-loo
>> ps -finline-functions  (internal compiler error)
>> FAIL: gcc.c-torture/compile/pr41634.c  -O3 -fomit-frame-pointer 
>> -funroll-all-loo
>> ps -finline-functions  (test for excess errors)
>> FAIL: gcc.c-torture/compile/pr41634.c  -O3 -fomit-frame-pointer 
>> -funroll-loops
>> (internal compiler error)
>> FAIL: gcc.c-torture/compile/pr41634.c  -O3 -fomit-frame-pointer 
>> -funroll-loops
>> (test for excess errors)
>> FAIL: gcc.c-torture/compile/pr41634.c  -O3 -fomit-frame-pointer  (internal 
>> compi
>> ler error)
>> FAIL: gcc.c-torture/compile/pr41634.c  -O3 -fomit-frame-pointer  (test for 
>> exces
>> s errors)
>> FAIL: gcc.c-torture/compile/pr41634.c  -O3 -g  (internal compiler error)
>> FAIL: gcc.c-torture/compile/pr41634.c  -O3 -g  (test for excess errors)
>> FAIL: gcc.dg/Warray-bounds.c (internal compiler error)
>> FAIL: gcc.dg/Warray-bounds.c (test for excess errors)
>>
>> since we generate pseudo registers to convert SImode to DImode
>> after reload.  Fixing it requires significant changes.
>>
>> This is only a problem for 64-bit register address since the symbolic
>> address is 32-bit.  Using 32-bit base/index registers will work around
>> this issue.
>
> This address
>
> (plus:DI (zero_extend:DI (FOO:SI)) (const_int Y))
>
> is OK for x32 as long as Y, which is encoded as 32-bit immediate,
> is zero-extend from 32-bit to 64-bit.  SImode address does it.
> My patch optimizes it a little bit by using SImode address only
> for Y < -16*1024*1024.

I was wondering, why we operate with constant -16*1024*1024? Should we
use 0x7FF instead? Since the MSB is always zero, we are safe.

Please add a fat ??? comment, why we paper-over this issue and repost
the latest patch. I got lost in all the versions :(

Uros.


Re: Patch: Print SImode register names to force addr32 prefix

2012-11-12 Thread H.J. Lu
On Sun, Nov 11, 2012 at 1:37 PM, H.J. Lu  wrote:
> On Fri, Nov 9, 2012 at 9:23 AM, Uros Bizjak  wrote:
>> On Fri, Nov 9, 2012 at 10:17 AM, H.J. Lu  wrote:
>>
>>> Since x32 runs in 64-bit mode, for address -0x4300(%rax), hardware
>>> sign-extends displacement from 32-bits to 64-bits and adds it to %rax.
>>> But x32 wants 32-bit -0x4300, not 64-bit -0x4300.  This patch
>>> uses 32-bit registers instead of 64-bit registers when displacement
>>> < -16*1024*1024.  -16*1024*1024 is used instead of 0 so that we will
>>> still generate -16(%rsp) instead of -16(%esp).
>>>
>>> Tested it on Linux/x32.  OK to install?
>>
>> This problem uncovers a bug in the middle-end, so I guess it would be
>> better to fix it there.
>>
>> Uros.
>
> The problem is it isn't safe to transform
>
> (zero_extend:DI (plus:SI (FOO:SI) (const_int Y)))
>
> to
>
> (plus:DI (zero_extend:DI (FOO:SI)) (const_int Y))
>
> when Y is negative and its absolute value is greater than FOO.  However,
> we have to do this transformation since other parts of GCC depend on
> it.  If we revert the fix for
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49721
>
> we will get
>
> FAIL: gcc.c-torture/compile/990523-1.c  -O3 -g  (internal compiler error)
> FAIL: gcc.c-torture/compile/990523-1.c  -O3 -g  (test for excess errors)
> FAIL: gcc.c-torture/compile/pr41634.c  -O3 -fomit-frame-pointer 
> -funroll-all-loo
> ps -finline-functions  (internal compiler error)
> FAIL: gcc.c-torture/compile/pr41634.c  -O3 -fomit-frame-pointer 
> -funroll-all-loo
> ps -finline-functions  (test for excess errors)
> FAIL: gcc.c-torture/compile/pr41634.c  -O3 -fomit-frame-pointer -funroll-loops
> (internal compiler error)
> FAIL: gcc.c-torture/compile/pr41634.c  -O3 -fomit-frame-pointer -funroll-loops
> (test for excess errors)
> FAIL: gcc.c-torture/compile/pr41634.c  -O3 -fomit-frame-pointer  (internal 
> compi
> ler error)
> FAIL: gcc.c-torture/compile/pr41634.c  -O3 -fomit-frame-pointer  (test for 
> exces
> s errors)
> FAIL: gcc.c-torture/compile/pr41634.c  -O3 -g  (internal compiler error)
> FAIL: gcc.c-torture/compile/pr41634.c  -O3 -g  (test for excess errors)
> FAIL: gcc.dg/Warray-bounds.c (internal compiler error)
> FAIL: gcc.dg/Warray-bounds.c (test for excess errors)
>
> since we generate pseudo registers to convert SImode to DImode
> after reload.  Fixing it requires significant changes.
>
> This is only a problem for 64-bit register address since the symbolic
> address is 32-bit.  Using 32-bit base/index registers will work around
> this issue.

This address

(plus:DI (zero_extend:DI (FOO:SI)) (const_int Y))

is OK for x32 as long as Y, which is encoded as 32-bit immediate,
is zero-extend from 32-bit to 64-bit.  SImode address does it.
My patch optimizes it a little bit by using SImode address only
for Y < -16*1024*1024.

-- 
H.J.


Re: PATCH: PR other/55292: libsanitizer doesn't support x32

2012-11-12 Thread H.J. Lu
On Mon, Nov 12, 2012 at 6:59 PM, Andrew Pinski  wrote:
> On Mon, Nov 12, 2012 at 6:02 PM, Diego Novillo  wrote:
>> On Mon, Nov 12, 2012 at 6:36 PM, H.J. Lu  wrote:
>>> Hi,
>>>
>>> Linux/x32 doesn't have __NR_mmap2/__NR_fstat64 and uses
>>> __NR_mmap/__NR_fstat, just like Linux/x86-64.  Tested on Linux/x32.
>>> OK to install?
>>
>> Patches to libsanitizer should be sent upstream.  We should only
>> contain a copy of the master in the LLVM repository.  There should be
>> instructions in libsanitizer/README.gcc (Jakub, Dodji, are they there?
>>  I can't check ATM).
>
> I rather hate having to submit changes like this in two different
> places.  Why can't the people who added the target library like this
> take responsibility for doing the merges from the GCC source to the
> upstream?  Like libffi is handled.
>

Agreed.  I created a git branch, hjl/asan, to address those issues.
It compiles/installs fine on Linux/x32 with lib, lib64 and libx32:

[hjl@gnu-tools-1 gcc-4.8.0-x32]$ file  */libasan*.0.0.0
lib64/libasan.so.0.0.0:  ELF 64-bit LSB shared object, x86-64, version
1 (GNU/Linux), dynamically linked,
BuildID[sha1]=0xd397454af874d82e45bffde03c18870588e9d901, not stripped
lib/libasan.so.0.0.0:ELF 32-bit LSB shared object, Intel 80386,
version 1 (GNU/Linux), dynamically linked,
BuildID[sha1]=0x7b0c7b7793d3284cfad63f1a11bff1b814c3ac9a, not stripped
libx32/libasan.so.0.0.0: ELF 32-bit LSB shared object, x86-64, version
1 (GNU/Linux), dynamically linked,
BuildID[sha1]=0x699fa9a47f7cc24f9ff82c8663ecdf935b0f43a4, not stripped
[hjl@gnu-tools-1 gcc-4.8.0-x32]$

I am afraid that configure.ac change is very much specific to
compiling libsanitizer as a GCC target library.  Could someone
submit those changes upstream on behalf of GCC project?

Thanks.


-- 
H.J.


[PATCH] Get sparc building again after ASAN merge.

2012-11-12 Thread David Miller

libsanitizer/

* asan/asan_linux.cc (GetPcSpBp): Add sparc support.
---
 libsanitizer/ChangeLog.asan |  4 
 libsanitizer/asan/asan_linux.cc | 14 ++
 2 files changed, 18 insertions(+)

diff --git a/libsanitizer/ChangeLog.asan b/libsanitizer/ChangeLog.asan
index 7fe3c0c..5592092 100644
--- a/libsanitizer/ChangeLog.asan
+++ b/libsanitizer/ChangeLog.asan
@@ -1,3 +1,7 @@
+2012-11-12  David S. Miller  
+
+   * asan/asan_linux.cc (GetPcSpBp): Add sparc support.
+
 2012-10-29  Wei Mi  
 
Initial checkin: migrate asan runtime from llvm.
diff --git a/libsanitizer/asan/asan_linux.cc b/libsanitizer/asan/asan_linux.cc
index 2922740..ea7ee9e 100644
--- a/libsanitizer/asan/asan_linux.cc
+++ b/libsanitizer/asan/asan_linux.cc
@@ -66,6 +66,20 @@ void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {
   *pc = ucontext->uc_mcontext.gregs[REG_EIP];
   *bp = ucontext->uc_mcontext.gregs[REG_EBP];
   *sp = ucontext->uc_mcontext.gregs[REG_ESP];
+# elif defined(__sparc__)
+  ucontext_t *ucontext = (ucontext_t*)context;
+  uptr *stk_ptr;
+# if defined (__arch64__)
+  *pc = ucontext->uc_mcontext.mc_gregs[MC_PC];
+  *sp = ucontext->uc_mcontext.mc_gregs[MC_O6];
+  stk_ptr = (uptr *) (*sp + 2047);
+  *bp = stk_ptr[15];
+# else
+  *pc = ucontext->uc_mcontext.gregs[REG_PC];
+  *sp = ucontext->uc_mcontext.gregs[REG_O6];
+  stk_ptr = (uptr *) *sp;
+  *bp = stk_ptr[15];
+# endif
 #else
 # error "Unsupported arch"
 #endif
-- 
1.7.12.2.dirty



Committed: Fix PR55257: g++.dg/debug/dwarf2/non-virtual-thunk.C and heads-up target maintainers

2012-11-12 Thread Hans-Peter Nilsson
...those of you who don't have the equivalent of the patch
below in your ports, that is.  You'll likely only notice through
a slightly reduced debugging experience and
g++.dg/debug/dwarf2/non-virtual-thunk.C failing.  Yes, the docs
should mention these functions need to be called IMHO obviously,
but not by me not now maybe later.  Tested cris-elf, committed.

gcc:
PR target/55257
* config/cris/cris.c (cris_asm_output_mi_thunk): Call
final_start_function and final_end_function.

Index: gcc/config/cris/cris.c
===
--- gcc/config/cris/cris.c  (revision 192677)
+++ gcc/config/cris/cris.c  (working copy)
@@ -2698,6 +2698,9 @@ cris_asm_output_mi_thunk (FILE *stream,
  HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
  tree funcdecl)
 {
+  /* Make sure unwind info is emitted for the thunk if needed.  */
+  final_start_function (emit_barrier (), stream, 1);
+
   if (delta > 0)
 fprintf (stream, "\tadd%s " HOST_WIDE_INT_PRINT_DEC ",$%s\n",
 ADDITIVE_SIZE_MODIFIER (delta), delta,
@@ -2735,6 +2738,8 @@ cris_asm_output_mi_thunk (FILE *stream,
   if (TARGET_V32)
fprintf (stream, "\tnop\n");
 }
+
+  final_end_function ();
 }
 
 /* Boilerplate emitted at start of file.

brgds, H-P


ASAN merge...

2012-11-12 Thread David Miller

This has broken the build on every Linux target that hasn't added
the necessary cpu specific code to asan_linux.cc

I'm working on the sparc bits, but I'm really surprised this
happened.


RE: [RFC] New feature to reuse one multilib among different targets

2012-11-12 Thread Terry Guo
> -Original Message-
> From: Joseph Myers [mailto:jos...@codesourcery.com]
> Sent: Saturday, November 10, 2012 12:35 AM
> To: Terry Guo
> Cc: gcc-patches@gcc.gnu.org
> Subject: RE: [RFC] New feature to reuse one multilib among different
> targets
> 
> On Fri, 9 Nov 2012, Terry Guo wrote:
> 
> > You are right that we should make script POSIX compliant. This v3
> patch
> > removed "function" and "local" which don't belong to POSIX standard.
> I also
> > verified that CONFIG_SHELL is passed to this script with value
> "/bin/sh".
> 
> Suppose /bin/sh is not a POSIX shell but the user sets CONFIG_SHELL to
> something else (which is a POSIX shell).  Will SHELL in the makefile
> get
> set to the POSIX shell the user specified as CONFIG_SHELL?  That's
> what's
> needed to be able to use POSIX shell features in this script.
> 

The attached patch is updated to use sub-script rather than the function to
reuse code. Is it ok to avoid the issue you just mentioned?

BR,
Terry

2012-11-13  Terry Guo  

* genmultilib (tmpmultilib3): New refactored sub-script
to convert the option combination into folder name.
(tmpmultilib4): New refactored sub-script to output the
options in a option combination.
(MULTILIB_REUSE): New argument.
* Makefile.in (s-mlib): Add a new argument MULTILIB_REUSE.
* gcc.c (multilib_reuse): New spec.
(set_multilib_dir): Use multilib_reuse.
* doc/fragments.texi: Mention MULTILIB_REUSE.

multilib-reuse-v4.patch
Description: Binary data


[PATCH] Include tm_p.h in asan.c

2012-11-12 Thread David Edelsohn
gcc/asan.c probably should have been split into two files because it
works at multiple levels.  But given that it invokes
ASM_GENERATE_INTERNAL_LABEL, it needs to include tm_p.h to include
-protos.h.

Committed as obvious to allow AIX bootstrap to proceed.

* asan.c: Include tm_p.h

Index: asan.c
===
--- asan.c  (revision 193465)
+++ asan.c  (working copy)
@@ -32,6 +32,7 @@
 #include "expr.h"
 #include "optabs.h"
 #include "output.h"
+#include "tm_p.h"

 /* AddressSanitizer finds out-of-bounds and use-after-free bugs
with <2x slowdown on average.


Re: PATCH: PR other/55292: libsanitizer doesn't support x32

2012-11-12 Thread Andrew Pinski
On Mon, Nov 12, 2012 at 6:02 PM, Diego Novillo  wrote:
> On Mon, Nov 12, 2012 at 6:36 PM, H.J. Lu  wrote:
>> Hi,
>>
>> Linux/x32 doesn't have __NR_mmap2/__NR_fstat64 and uses
>> __NR_mmap/__NR_fstat, just like Linux/x86-64.  Tested on Linux/x32.
>> OK to install?
>
> Patches to libsanitizer should be sent upstream.  We should only
> contain a copy of the master in the LLVM repository.  There should be
> instructions in libsanitizer/README.gcc (Jakub, Dodji, are they there?
>  I can't check ATM).

I rather hate having to submit changes like this in two different
places.  Why can't the people who added the target library like this
take responsibility for doing the merges from the GCC source to the
upstream?  Like libffi is handled.

Thanks,
Andrew Pinski

>
>
> Thanks.  Diego.


Re: [PATCH v3] Add support for sparc compare-and-branch

2012-11-12 Thread David Miller
From: Rainer Orth 
Date: Fri, 26 Oct 2012 11:14:33 +0200

> I tried a bootstrap on Solaris 11.1, but ran into lots of comparison
> failures I've not yet investigated.

I started working on this patch again, in order to incorporate
Richard Henderson's feedback, and I am now getting a comparison
failure.  Is this what you're seeing?

Comparing stages 2 and 3
warning: gcc/cc1-checksum.o differs
warning: gcc/cc1plus-checksum.o differs
warning: gcc/cc1obj-checksum.o differs
Bootstrap comparison failure!
libdecnumber/decNumber.o differs
make[2]: *** [compare] Error 1
make[1]: *** [stage3-bubble] Error 2
make: *** [all] Error 2

In any case, I'm looking into it.


Re: User directed Function Multiversioning via Function Overloading (issue5752064)

2012-11-12 Thread Jason Merrill

On 11/12/2012 08:11 PM, Sriraman Tallam wrote:

+   && !targetm.target_option.function_versions (fn,
+TREE_PURPOSE (match)))


The second argument should be lined up with the left paren if it's on a 
different line.  Perhaps formatting this as


&& !(targetm.target_option.function_versions
 (fn, TREE_PURPOSE (match

would be better.


+  error_at (input_location, "Use of multiversioned function "
+   "Multiversioning needs ifunc which is not supported "


We don't capitalize the first letter of a diagnostic.

OK with those changes.

Jason



Re: PATCH: PR other/55292: libsanitizer doesn't support x32

2012-11-12 Thread H.J. Lu
On Mon, Nov 12, 2012 at 6:02 PM, Diego Novillo  wrote:
> On Mon, Nov 12, 2012 at 6:36 PM, H.J. Lu  wrote:
>> Hi,
>>
>> Linux/x32 doesn't have __NR_mmap2/__NR_fstat64 and uses
>> __NR_mmap/__NR_fstat, just like Linux/x86-64.  Tested on Linux/x32.
>> OK to install?
>
> Patches to libsanitizer should be sent upstream.  We should only
> contain a copy of the master in the LLVM repository.  There should be
> instructions in libsanitizer/README.gcc (Jakub, Dodji, are they there?
>  I can't check ATM).
>

How does it work for

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55291

AM_ENABLE_MULTILIB is used to provide multilib support for
GCC run-time library, which is only defined in config/multi.m4
in GCC source tree.  How do you generate configure using
AM_ENABLE_MULTILIB outside of GCC source tree?

-- 
H.J.


Re: PATCH: PR other/55292: libsanitizer doesn't support x32

2012-11-12 Thread Diego Novillo
On Mon, Nov 12, 2012 at 6:36 PM, H.J. Lu  wrote:
> Hi,
>
> Linux/x32 doesn't have __NR_mmap2/__NR_fstat64 and uses
> __NR_mmap/__NR_fstat, just like Linux/x86-64.  Tested on Linux/x32.
> OK to install?

Patches to libsanitizer should be sent upstream.  We should only
contain a copy of the master in the LLVM repository.  There should be
instructions in libsanitizer/README.gcc (Jakub, Dodji, are they there?
 I can't check ATM).


Thanks.  Diego.


Committed: framework bits for disabling libsanitizer. RFC on which targets for which to disable it.

2012-11-12 Thread Hans-Peter Nilsson
While the fallout(*) from the libsanitizer commit is handled,
it's obvious it should have a noconfigdirs= section in
toplevel/configure.ac like the other target libs.  Here's what I
committed after observing that a cris-elf build passed, where it
previously failed building libsanitizer which wrongly tries to
compile using -fPIC despite checking in its configure.ac IIUC.
But, I'd like to update the target contents there to something a
bit more generic.

Maybe disable libsanitizer everywhere except for (referring to
the three common target-related file-name parts in libsanitizer)
"mac", "win" and "linux"?  Or disable everywhere except x86_64 /
i386?  That's the only port that defines the required
TARGET_ASAN_SHADOW_OFFSET.  Maybe the library configure.ac
should check whether using -fsanitizer is error-free and disable
the libsanitizer build automatically?

toplevel:
* configure.ac: Add section for noconfigdirs for libsanitizer.
Disable for cris-*-* and mmix-*-*.
* configure: Regenerate.

Index: configure.ac
===
--- configure.ac(revision 193455)
+++ configure.ac(working copy)
@@ -547,6 +547,13 @@ case "${target}" in
 ;;
 esac
 
+# Disable libsanitizer for some systems.
+case "${target}" in
+  cris-*-* | crisv32-*-* | mmix-*-*)
+noconfigdirs="$noconfigdirs target-libsanitizer"
+;;
+esac
+
 # Disable libssp for some systems.
 case "${target}" in
   avr-*-*)
Index: configure
===
--- configure   (revision 193455)
+++ configure   (working copy)
@@ -3205,6 +3205,13 @@ case "${target}" in
 ;;
 esac
 
+# Disable libsanitizer for some systems.
+case "${target}" in
+  cris-*-* | crisv32-*-* | mmix-*-*)
+noconfigdirs="$noconfigdirs target-libsanitizer"
+;;
+esac
+
 # Disable libssp for some systems.
 case "${target}" in
   avr-*-*)


*) -fPIC passed when building libsanitizer for targets that
don't support it, lack of multilib setup for libsanitizer,
libsanitizer not installed in version-specific subdir...
Basically, IMHO it should just copy the generic
libgfortran/configure.ac and be done with it.  Right now it has
the smallest configure.ac of the target-libraries.

brgds, H-P


Re: User directed Function Multiversioning via Function Overloading (issue5752064)

2012-11-12 Thread Sriraman Tallam
Hi Jason,

   Made the changes. Also fixed one more segfault bug when ifunc is
not supported.

Thanks,
-Sri.

On Sun, Nov 11, 2012 at 9:04 PM, Jason Merrill  wrote:
> On 11/09/2012 08:33 PM, Sriraman Tallam wrote:
>>
>> + /* Skip calling decls_match for versioned functions.  */
>> +  if (DECL_FUNCTION_VERSIONED (fn)
>> + && DECL_FUNCTION_VERSIONED (TREE_PURPOSE (match)))
>> +   continue;
>> + if (!decls_match (fn, TREE_PURPOSE (match)))
>> +break;
>
>
> This seems like it would allow multiple versioned functions from different
> namespaces; I want to allow mismatches only if they are versions of the same
> function.  I was thinking
>
>
>  for (match = TREE_CHAIN (matches); match; match = TREE_CHAIN
> (match))
> if (!decls_match (fn, TREE_PURPOSE (match))
> && !targetm.target_option.function_versions (fn,
> TREE_PURPOSE (match)))
>   break;
>
>> +  error_at (input_location, "Call/Pointer to multiversioned function"
>> +" without a default cannot be dispatched");
>
>
> Let's just say "use of multiversioned  function without a default".
>
> Jason
>
* cgraph.c (insert_new_cgraph_node_version): Use cgraph_get_node
instead of cgraph_get_create_node.
* cp/class.c (mark_versions_used): Remove.
(resolve_address_of_overloaded_function): Do not call decls_match
for versioned functions. Call get_function_versions_dispatcher.
* cp/decl.c (duplicate_decls): Add comments.
* cp/call.c (get_function_version_dispatcher): Expose function.
(mark_versions_used): Expose function.
* cp/cp-tree.h (mark_versions_used): New declaration.
(get_function_version_dispatcher): Ditto.
* config/i386/i386.c (ix86_get_function_versions_dispatcher): Move ifunc
not supported code to the end.
* testsuite/g++.dg/mv4.C: Add require ifunc. Change error message.
* testsuite/g++.dg/mv5.C: Add require ifunc.
* testsuite/g++.dg/mv6.C: Add require ifunc.

Index: cgraph.c
===
--- cgraph.c(revision 193452)
+++ cgraph.c(working copy)
@@ -206,7 +206,7 @@ insert_new_cgraph_node_version (struct cgraph_node
 void
 delete_function_version (tree decl)
 {
-  struct cgraph_node *decl_node = cgraph_get_create_node (decl);
+  struct cgraph_node *decl_node = cgraph_get_node (decl);
   struct cgraph_function_version_info *decl_v = NULL;
 
   if (decl_node == NULL)
Index: testsuite/g++.dg/mv4.C
===
--- testsuite/g++.dg/mv4.C  (revision 193452)
+++ testsuite/g++.dg/mv4.C  (working copy)
@@ -3,6 +3,7 @@
and its pointer is taken.  */
 
 /* { dg-do compile { target i?86-*-* x86_64-*-* } } */
+/* { dg-require-ifunc "" }  */
 /* { dg-options "-O2 -mno-sse -mno-popcnt" } */
 
 int __attribute__ ((target ("sse")))
@@ -18,6 +19,6 @@ foo ()
 
 int main ()
 {
-  int (*p)() = &foo; /* { dg-error "Pointer to a multiversioned function 
without a default is not allowed" {} } */
+  int (*p)() = &foo; /* { dg-error "Use of multiversioned function without a 
default" {} } */
   return (*p)();
 }
Index: testsuite/g++.dg/mv6.C
===
--- testsuite/g++.dg/mv6.C  (revision 193452)
+++ testsuite/g++.dg/mv6.C  (working copy)
@@ -1,6 +1,7 @@
 /* Test to check if member version multiversioning works correctly.  */
 
 /* { dg-do run { target i?86-*-* x86_64-*-* } } */
+/* { dg-require-ifunc "" }  */
 
 class Foo
 {
Index: testsuite/g++.dg/mv5.C
===
--- testsuite/g++.dg/mv5.C  (revision 193452)
+++ testsuite/g++.dg/mv5.C  (working copy)
@@ -2,6 +2,7 @@
marked comdat with inline keyword.  */
 
 /* { dg-do run { target i?86-*-* x86_64-*-* } } */
+/* { dg-require-ifunc "" }  */
 /* { dg-options "-O2  -mno-popcnt" } */
 
 
Index: cp/class.c
===
--- cp/class.c  (revision 193452)
+++ cp/class.c  (working copy)
@@ -7068,38 +7068,6 @@ pop_lang_context (void)
 {
   current_lang_name = VEC_pop (tree, current_lang_base);
 }
-
-/* fn is a function version dispatcher that is marked used. Mark all the 
-   semantically identical function versions it will dispatch as used.  */
-
-static void
-mark_versions_used (tree fn)
-{
-  struct cgraph_node *node;
-  struct cgraph_function_version_info *node_v;
-  struct cgraph_function_version_info *it_v;
-
-  gcc_assert (TREE_CODE (fn) == FUNCTION_DECL);
-
-  node = cgraph_get_node (fn);
-  if (node == NULL)
-return;
-
-  gcc_assert (node->dispatcher_function);
-
-  node_v = get_cgraph_node_version (node);
-  if (node_v == NULL)
-return;
-
-  /* All semantically identical versions are chained.  Traverse and mark each
- one of them as used.  */
-  it_v = node_v->next;
-

[committed] Fix call branch shortening on PA

2012-11-12 Thread John David Anglin
The attached change fixes PR target/55195.

A recent change to shorten_branches broke branch shortening on PA.  Several
years ago we changed to using function calls to estimate the length of the
call patterns because the "cond" expressions became unmanageable.  The
functions returned the maximum current length for the pattern.  This
worked because the algorithm shortened branches.  Now, when optimizing,
the algorithm starts with small length and increases from there.

The call implementation was broken in a subtle way.  It didn't mark the call
patterns as variable, so they didn't participate in branch shortening.  As
a result, branch distances for conditional forward branches were underestimated
and assembly errors started appearing in large functions.

Joern Rennecke was extremely helpful in debugging and resolving this bug.
He suggested an opaque "cond" that's never used but which tricks
genattrtab into marking the call patterns as variable.  This "cond" also
provides the minimum length for the call patterns.

This led to a another problem.  The insn_default_length for the call patterns
was now set to INT_MAX to indicate that the lengths were undefined.  Delay
slot sequence lengths became negative.  This had to be fixed with
ADJUST_INSN_LENGTH.  I needed to add two new insn types, sibcall and
sh_func_adrs, to uniquely identify these patterns in pa_adjust_insn_length
and provide the correct length.

I also removed the adjustment for a millicode insn with unfilled delay slot
because pa_attr_length_millicode_call already allocates the extra four bytes.

Tested on hppa-unknown-linux-gnu, hppa2.0w-hp-hpux11.11 and hppa64-hp-hpux11.11
with no regressions.  Committed to trunk.

Dave
-- 
J. David Anglin  dave.ang...@nrc-cnrc.gc.ca
National Research Council of Canada  (613) 990-0752 (FAX: 952-6602)

2012-11-12  John David Anglin  

PR target/55195
* config/pa/pa.md (type): Add sibcall and sh_func_adrs insn types.
(in_branch_delay): Don't allow sibcall or sh_func_adrs insns.
(in_nullified_branch_delay): Likewise.
(in_call_delay): Likewise.
Define delay for sibcall insns.  Adjust Z3 and Z4 insn reservations for
new types.  Add opaque cond to mark all calls, sibcalls, dyncalls and
the $$sh_func_adrs call as variable.  Update type of sibcalls and
$$sh_func_adrs call.
* config/pa/pa.c (pa_adjust_insn_length): Revise to return updated
length instead of adjustment.  Handle negative and undefined call
adjustments for insn_default_length.  Remove adjustment for millicode
insn with unfilled delay slot.
(pa_output_millicode_call): Update for revised millicode length.
* config/pa/pa.h (ADJUST_INSN_LENGTH): Revise to set LENGTH.

Index: config/pa/pa.md
===
--- config/pa/pa.md (revision 193396)
+++ config/pa/pa.md (working copy)
@@ -81,7 +81,7 @@
 ;; type "binary" insns have two input operands (1,2) and one output (0)
 
 (define_attr "type"
-  
"move,unary,binary,shift,nullshift,compare,load,store,uncond_branch,btable_branch,branch,cbranch,fbranch,call,dyncall,fpload,fpstore,fpalu,fpcc,fpmulsgl,fpmuldbl,fpdivsgl,fpdivdbl,fpsqrtsgl,fpsqrtdbl,multi,milli,parallel_branch,fpstore_load,store_fpload"
+  
"move,unary,binary,shift,nullshift,compare,load,store,uncond_branch,btable_branch,branch,cbranch,fbranch,call,sibcall,dyncall,fpload,fpstore,fpalu,fpcc,fpmulsgl,fpmuldbl,fpdivsgl,fpdivdbl,fpsqrtsgl,fpsqrtdbl,multi,milli,sh_func_adrs,parallel_branch,fpstore_load,store_fpload"
   (const_string "binary"))
 
 (define_attr "pa_combine_type"
@@ -124,7 +124,7 @@
 ;; For conditional branches. Frame related instructions are not allowed
 ;; because they confuse the unwind support.
 (define_attr "in_branch_delay" "false,true"
-  (if_then_else (and (eq_attr "type" 
"!uncond_branch,btable_branch,branch,cbranch,fbranch,call,dyncall,multi,milli,parallel_branch")
+  (if_then_else (and (eq_attr "type" 
"!uncond_branch,btable_branch,branch,cbranch,fbranch,call,sibcall,dyncall,multi,milli,sh_func_adrs,parallel_branch")
 (eq_attr "length" "4")
 (not (match_test "RTX_FRAME_RELATED_P (insn)")))
(const_string "true")
@@ -133,7 +133,7 @@
 ;; Disallow instructions which use the FPU since they will tie up the FPU
 ;; even if the instruction is nullified.
 (define_attr "in_nullified_branch_delay" "false,true"
-  (if_then_else (and (eq_attr "type" 
"!uncond_branch,btable_branch,branch,cbranch,fbranch,call,dyncall,multi,milli,fpcc,fpalu,fpmulsgl,fpmuldbl,fpdivsgl,fpdivdbl,fpsqrtsgl,fpsqrtdbl,parallel_branch")
+  (if_then_else (and (eq_attr "type" 
"!uncond_branch,btable_branch,branch,cbranch,fbranch,call,sibcall,dyncall,multi,milli,sh_func_adrs,fpcc,fpalu,fpmulsgl,fpmuldbl,fpdivsgl,fpdivdbl,fpsqrtsgl,fpsqrtdbl,parallel_branch")
 (eq_attr "length" "4")
   

Re: Asan/Tsan Unit/Regression testing (was [asan] Emit GIMPLE direclty, small cleanups)

2012-11-12 Thread Joseph S. Myers
On Mon, 12 Nov 2012, Andrew Pinski wrote:

> Also does gtest support cross testing; that is testing over rsh/ssh
> and testing via a simulator?  We should require that as a requirement
> also when it comes to testing infrastructures.

Unfortunately the existing guality tests work by C sources built for the 
target running a GDB binary on the target via popen, rather than having 
DejaGnu run the GDB binary on the host talking to the program on the 
target.  So there's an existing not-cross-friendly piece of testsuite 
code, although it would certainly be good to rework it to work with a 
cross-GDB and cross-compiler.

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


Re: [PATCH] A pass which merges constant stores to bitfields

2012-11-12 Thread Andrew Pinski
On Mon, Nov 12, 2012 at 4:50 PM, Andrew Pinski
 wrote:
> Hi,
>   I know we are in stage3, I thought I would send this out now for
> review as I finally have it ready for consumption as I finally got
> around to removing the limitation of it only working on big-endian.
> This pass was originally written by Adam Nemet while he was at Cavium.
>  I modified it to work on little-endian and also update the code to
> use the aliasing oracle and some of the new VEC interface.
>
> Yes I know I forgot to add documentation for the new option and for
> the new pass.  I will add it soon.

I forgot to say I bootstrapped and tested this on x86_64-linux-gnu
with no regressions.  I have tested it on a big-endian MIPS64 target
too.

>
> Thanks,
> Andrew Pinski
>
> ChangeLog:
> * tree-merge-const-bfstores.c: New file.
> * tree-pass.h (pass_merge_const_bfstores): Add pass.
> * opts.c (default_options_table): Add OPT_fmerge_const_bfstores at -O2
> and above.
> * timevar.def (TV_MERGE_CONST_BFSTORES): New timevar.
> * common.opt (fmerge-const-bfstores): New option.
> * Makefile.in (OBJS): Add tree-merge-const-bfstores.o.
> (tree-merge-const-bfstores.o): New target.
> * passes.c (init_optimization_passes): Add pass_merge_const_bfstores
> right after the last pass_phiopt.


[PATCH] A pass which merges constant stores to bitfields

2012-11-12 Thread Andrew Pinski
Hi,
  I know we are in stage3, I thought I would send this out now for
review as I finally have it ready for consumption as I finally got
around to removing the limitation of it only working on big-endian.
This pass was originally written by Adam Nemet while he was at Cavium.
 I modified it to work on little-endian and also update the code to
use the aliasing oracle and some of the new VEC interface.

Yes I know I forgot to add documentation for the new option and for
the new pass.  I will add it soon.

Thanks,
Andrew Pinski

ChangeLog:
* tree-merge-const-bfstores.c: New file.
* tree-pass.h (pass_merge_const_bfstores): Add pass.
* opts.c (default_options_table): Add OPT_fmerge_const_bfstores at -O2
and above.
* timevar.def (TV_MERGE_CONST_BFSTORES): New timevar.
* common.opt (fmerge-const-bfstores): New option.
* Makefile.in (OBJS): Add tree-merge-const-bfstores.o.
(tree-merge-const-bfstores.o): New target.
* passes.c (init_optimization_passes): Add pass_merge_const_bfstores
right after the last pass_phiopt.
Index: tree-merge-const-bfstores.c
===
--- tree-merge-const-bfstores.c (revision 0)
+++ tree-merge-const-bfstores.c (revision 0)
@@ -0,0 +1,455 @@
+/* Merge constant bitfield stores.
+   Copyright (C) 2007-2012 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC 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.
+
+GCC 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 GCC; see the file COPYING3.  If not see
+.  */
+
+/* This pass merges adjacent or overlapping (in case of unions)
+   constant bitfield stores.  We try to merge stores into preceding
+   stores.  In case the whole structure is zeroed out initially, by
+   merging backward, we can possibly merge into this
+   initialization.
+
+   Requirements:
+
+   1. order shouldn't matter:
+
+ x.b = 2;
+ x.a = 3;
+ x.c = 4;
+
+  2. merge into initialization (with a union example):
+
+ union { uint64_t l; struct { uint64_t a:2; uint64_t b:2 ... } s } u;
+ u.l = 0;
+ ...
+ u.s.b = 2;
+
+  3. merge should happen even if use is in a different bb:
+
+ x.a = 2;
+ x.b = 3;
+ if ()
+   use (x);
+
+  4. don't give up a non-overlapping varying stores:
+
+ extern int i;
+ x.a = 2;
+ x.c = i;
+ x.b = 3;
+
+  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "tree-pass.h"
+#include "rtl.h"
+#include "obstack.h"
+#include "basic-block.h"
+#include "tree.h"
+#include "tree-flow.h"
+#include "langhooks.h"
+#include "timevar.h"
+#include "vec.h"
+#include "diagnostic.h"
+#include "gimple-pretty-print.h"
+
+/* Structure to keep track of constant bit-field stores.  */
+
+typedef struct const_bfstore
+{
+  tree inner;
+  HOST_WIDE_INT bitsize;
+  HOST_WIDE_INT bitpos;
+  tree constval;
+  gimple stmt;
+} const_bfstore;
+
+DEF_VEC_O (const_bfstore);
+DEF_VEC_ALLOC_O (const_bfstore, heap);
+
+static VEC (const_bfstore, heap) *bfstores;
+
+/* Build an unsigned BIT_FIELD_REF expression.  */
+
+static tree
+make_unsigned_bitfield_ref (tree inner, HOST_WIDE_INT bitsize,
+   HOST_WIDE_INT bitpos)
+{
+  enum machine_mode mode;
+  tree exp, unsigned_type;
+
+  mode = get_best_mode (bitsize, bitpos, 0, 0,
+   TYPE_ALIGN (TREE_TYPE (inner)), word_mode, 0);
+  gcc_assert (mode != VOIDmode);
+
+  unsigned_type = build_nonstandard_integer_type (bitsize, 1);
+  exp = build3 (BIT_FIELD_REF, unsigned_type, inner, size_int (bitsize),
+   bitsize_int (bitpos));
+  return exp;
+}
+
+/* Return true iff the bitfields are overlapping.  */
+
+static bool
+overlapping_bitfields (HOST_WIDE_INT bitsize0, HOST_WIDE_INT bitpos0,
+  HOST_WIDE_INT bitsize1, HOST_WIDE_INT bitpos1)
+{
+  return (bitpos0 < bitpos1
+ ? bitpos1 < bitpos0 + bitsize0
+ : bitpos0 < bitpos1 + bitsize1);
+}
+
+/* A bitfield store of OBITSIZE starting at OBITPOS is followed by a
+   bitfield store of NBITSIZE at NBITPOS, compute the new *BITPOS and
+   return the new bitsize or -1 if the stores aren't either adjacent
+   or overlapping.  Also compute *oshift and *nshift which is the
+   number bits the constants need to be shifted to the left before the
+   RHS bits are combined.  */
+
+static HOST_WIDE_INT
+compute_new_bitfield_positions (HOST_WIDE_INT obitsize, HOST_WIDE_INT obitpos,
+   HOST_WIDE_INT nbitsize, HOST_WIDE_INT nbitpos,
+   HOST_WIDE_INT *bitpos

PATCH: PR other/55292: libsanitizer doesn't support x32

2012-11-12 Thread H.J. Lu
Hi,

Linux/x32 doesn't have __NR_mmap2/__NR_fstat64 and uses
__NR_mmap/__NR_fstat, just like Linux/x86-64.  Tested on Linux/x32.
OK to install?

Thanks.


H.J.
--
2012-11-12  H.J. Lu  

PR other/55292
* sanitizer_common/sanitizer_linux.cc (internal_mmap): Use
__NR_mmap if __x86_64__ is defined.
(internal_filesize): Use __NR_fstat if __x86_64__ is defined.

diff --git a/libsanitizer/sanitizer_common/sanitizer_linux.cc 
b/libsanitizer/sanitizer_common/sanitizer_linux.cc
index ab6c5a4..5d29018 100644
--- a/libsanitizer/sanitizer_common/sanitizer_linux.cc
+++ b/libsanitizer/sanitizer_common/sanitizer_linux.cc
@@ -34,7 +34,7 @@ namespace __sanitizer {
 // --- sanitizer_libc.h
 void *internal_mmap(void *addr, uptr length, int prot, int flags,
 int fd, u64 offset) {
-#if __WORDSIZE == 64
+#if __WORDSIZE == 64 || defined __x86_64__
   return (void *)syscall(__NR_mmap, addr, length, prot, flags, fd, offset);
 #else
   return (void *)syscall(__NR_mmap2, addr, length, prot, flags, fd, offset);
@@ -67,7 +67,7 @@ uptr internal_write(fd_t fd, const void *buf, uptr count) {
 }
 
 uptr internal_filesize(fd_t fd) {
-#if __WORDSIZE == 64
+#if __WORDSIZE == 64 || defined __x86_64__
   struct stat st;
   if (syscall(__NR_fstat, fd, &st))
 return -1;


Fix duplicated messages in .ccp dumps

2012-11-12 Thread Eric Botcazou
They show up when a lattice value changed is to CONSTANT.

Tested on x86_64-suse-linux, applied on mainline as obvious.


2012-11-12  Eric Botcazou  

* tree-ssa-ccp.c (dump_lattice_value) : Fix duplication.


-- 
Eric BotcazouIndex: tree-ssa-ccp.c
===
--- tree-ssa-ccp.c	(revision 193405)
+++ tree-ssa-ccp.c	(working copy)
@@ -184,10 +184,12 @@ dump_lattice_value (FILE *outf, const ch
   fprintf (outf, "%sVARYING", prefix);
   break;
 case CONSTANT:
-  fprintf (outf, "%sCONSTANT ", prefix);
   if (TREE_CODE (val.value) != INTEGER_CST
 	  || val.mask.is_zero ())
-	print_generic_expr (outf, val.value, dump_flags);
+	{
+	  fprintf (outf, "%sCONSTANT ", prefix);
+	  print_generic_expr (outf, val.value, dump_flags);
+	}
   else
 	{
 	  double_int cval = tree_to_double_int (val.value).and_not (val.mask);

[v3] remove non-standard name from

2012-11-12 Thread Jonathan Wakely
std::atomic_future was removed by N3170

* include/std/future (atomic_future): Remove declaration of
non-standard name.

Tested x86_64-linux, committed to trunk, 4.7 to follow.
commit 27ccc75ad9c7955aa432f0dc35de94965b7fc3e6
Author: Jonathan Wakely 
Date:   Mon Nov 12 21:37:57 2012 +

* include/std/future (atomic_future): Remove declaration of
non-standard name.

diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future
index 7f71dde..dd1a86b 100644
--- a/libstdc++-v3/include/std/future
+++ b/libstdc++-v3/include/std/future
@@ -115,9 +115,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 class shared_future;
 
-  template
-class atomic_future;
-
   template
 class packaged_task;
 


Re: [PATCH 00/13] Request to merge Address Sanitizer in

2012-11-12 Thread Ian Lance Taylor
On Mon, Nov 12, 2012 at 12:39 PM, H.J. Lu  wrote:
>
> Don't we need a bugzilla component for Sanitizer?

"other"?

Ian


Re: [libbacktrace] Use getexecname() on Solaris

2012-11-12 Thread Ian Lance Taylor
On Wed, Nov 7, 2012 at 5:50 AM, Rainer Orth  
wrote:
> Gerald Pfeifer  writes:
>
>> Just a small note, in the following
>>
>>   +#ifdef __FreeBSD__
>>   +# define DEFAULT_PROCESS_FILENAME "/proc/curproc/file"
>>   +#elif defined(HAVE_GETEXECNAME)
>>   +# define DEFAULT_PROCESS_FILENAME getexecname ()
>>   +#else
>>   +# define DEFAULT_PROCESS_FILENAME "/proc/self/exe"
>>   +#endif
>>
>> would it make sense to have the feature test (HAVE_GETEXECNAME) before
>> the OS test (__FreeBSD__), so that when/if the OS implements the feature
>> in newer versions that takes precedence?
>
> Good point.  I've incorporated this into my patch and regularly include
> it in my *-*-solaris2.{9, 10, 11} and x86_64-unknown-linux-gnu
> bootstraps.

Sorry for the delay on this.  I wanted to do it in a different way
that I think is more flexible and avoids #ifdef __FreeBSD__.  This
patch tries different approaches to find the executable.  It also ha a
chance of working if, e.g., the executable was removed.  Bootstrapped
and ran libbacktrace and Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.  Please let me know if this doesn't fix the
problems on Solaris and FreeBSD.

Thanks for the earlier patches.

Ian


2012-11-12  Ian Lance Taylor  
Rainer Orth  
Gerald Pfeifer  

* configure.ac: Check for getexecname.
* fileline.c: #include .  Define getexecname if not
available.
(fileline_initialize): Try to find the executable in a few
different ways.
* print.c (error_callback): Only print the filename if it came
from the backtrace state.
* configure, config.h.in: Rebuild.


foo.patch
Description: Binary data


Re: [PATCH 00/13] Request to merge Address Sanitizer in

2012-11-12 Thread H.J. Lu
On Thu, Nov 1, 2012 at 12:52 PM,   wrote:
> From: Dodji Seketeli 
>
> Hello,
>
> The set of patches following this message represents the work that
> happened on the asan branch to build up the Address Sanitizer work
> started in the Google branch.
>
> Address Sanitizer (aka asan) is a memory error detector.  It finds
> use-after-free and {heap,stack,global}-buffer overflow bugs in C/C++
> programs.
>
> One can learn about the way it works by reading the pdf slides at [1],
> or by reading the documentation on the wiki page of the project at [2].
>
> To make a long story short, it works by associating each memory region
> of eight consecutive bytes with a shadow byte that tells whether if
> each byte of the memory region is addressable or not.  So,
> conceptually, there is a function 'MemToShadow' which, for each set of
> contiguous eight bytes of memory returns a shadow byte that tells
> whether if each byte is accessible or not.
>
> Then, each memory access is instrumented by the asan pass to retrieve
> the shadow byte of the accessed memory; if the access is to a memory
> address that is deemed non-accessible, a call to an asan runtime
> library function is issued to report a meaningful error to the user,
> and the access is performed, letting the user program proceed despite
> the error.
>
> The advantage of this approach, compared to say, Valgrind[4] is the
> lower time and space overhead.  Eventually, when this tool becomes
> more solid, it'll become complementary to Valgrind.
>
> Apart from the compiler components, asan needs a runtime library to
> function.  We share that library with the LLVM implementation of asan
> that is described at [3].  The last patch of the set imports this
> library in its pristine form into our tree.  The plan is to regularly
> synchronize it with its LLVM upstream repository.
>
> On behalf of the GCC asan developers listed below, I am thus proposing
> these patches for inclusion into trunk.  I chose to follow the
> chronological commits that happened on the [asan] branch, to ease the
> authorship propagation.  Except for some few exceptions, each of these
> commits are reasonably logically atomic, so they hopefully shouldn't
> be too hard to review.
>
> The first patch is the initial import of the asan state from the
> Google branch into the [asan] branch.  Subsequent patches clean the
> code up, add features like protection of stack and global variables,
> instrumentation of memory access through built-in functions, and, last
> but not least, the import of the runtime library.
>
> Please note that the ChangeLog.asan is meant to disappear at commit
> time, as its content will be updated (for the dates) and prepended to
> the normal ChangeLog file.
>
> One noticeable shortcoming that we have at the moment is the lack of a
> DejaGNU test harness for this.  This is planned to be addressed as
> soon as possible.
>

Don't we need a bugzilla component for Sanitizer?

-- 
H.J.


Re: [asan] Patch - fix an ICE in asan.c

2012-11-12 Thread Markus Trippelsdorf
On 2012.11.12 at 19:02 +0100, Jakub Jelinek wrote:
> On Mon, Nov 12, 2012 at 06:13:08PM +0100, Markus Trippelsdorf wrote:
> > Another ICE:
> > 
> >  % cat test.ii
> >  int i;
> > 
> >  % g++ -faddress-sanitizer -c -g -O1 test.ii
> > test.ii:1:7: internal compiler error: Segmentation fault
> >   int i;
> >^
> 
> The RECORD_TYPE doesn't have lang specific payload allocated for it.
> There is no point why we need to describe that in the debug info though.
> 
> So I'd do something like:
> 
> 2012-11-12  Jakub Jelinek  
> 
>   * asan.c (report_error_func): Set DECL_IGNORED_P, don't touch
>   DECL_ASSEMBLER_NAME.
>   (asan_init_func): Likewise.
>   (asan_finish_file): Use void * instead of __asan_global * as
>   type of __asan_{,un}register_globals.  Set DECL_IGNORED_P on
>   the decls.

Thanks.
With your patch applied, it is now possible to successfully (lto-)
bootstrap gcc with CC="gcc -faddress-sanitizer" 
CXX="g++ -faddress-sanitizer".

One just has to apply the following patch from H.J. (that originally
fixed --enable-checking=valgrind):


diff --git a/libcpp/charset.c b/libcpp/charset.c
index cba19a6..6d67bca 100644
--- a/libcpp/charset.c
+++ b/libcpp/charset.c
@@ -1731,7 +1731,10 @@ _cpp_convert_input (cpp_reader *pfile, const char 
*input_charset,
   /* Resize buffer if we allocated substantially too much, or if we
  haven't enough space for the \n-terminator.  */
   if (to.len + 4096 < to.asize || to.len >= to.asize)
-to.text = XRESIZEVEC (uchar, to.text, to.len + 1);
+{
+  to.text = XRESIZEVEC (uchar, to.text, to.len + 17);
+  memset (to.text + to.len + 1, 0, 16);
+}
 
   /* If the file is using old-school Mac line endings (\r only),
  terminate with another \r, not an \n, so that we do not mistake
-- 
Markus


Re: [PATCH] Fix force_nonfallthru_and_redirect with asm goto (PR rtl-optimization/54127)

2012-11-12 Thread Richard Henderson
On 11/12/2012 11:48 AM, Jakub Jelinek wrote:
> 2012-11-12  Jakub Jelinek  
> 
>   PR rtl-optimization/54127
>   * cfgrtl.c (force_nonfallthru_and_redirect): When redirecting
>   asm goto labels from BB_HEAD (e->dest) to target bb, decrement
>   LABEL_NUSES of BB_HEAD (e->dest) and increment LABEL_NUSES of
>   BB_HEAD (target) appropriately and adjust JUMP_LABEL and/or
>   REG_LABEL_TARGET and REG_LABEL_OPERAND.
> 
>   * gcc.dg/torture/pr54127.c: New test.

Ok


r~


Re: [PATCH] Fix some VEC_COND_EXPR ICEs (PR tree-optimization/55281)

2012-11-12 Thread Richard Henderson
On 11/12/2012 11:43 AM, Jakub Jelinek wrote:
> 2012-11-12  Jakub Jelinek  
> 
>   PR tree-optimization/55281
>   * tree-vect-generic.c (expand_vector_condition): Accept any
>   is_gimple_val rather than just SSA_NAME if not COMPARISON_CLASS_P.
>   * fold-const.c (fold_ternary_loc): Fold VEC_COND_EXPR if arg0 is
>   either integer_all_onesp or integer_zerop.
>   * tree-vect-stmts.c (vectorizable_condition): Build the condition
>   using corresponding vector integer type instead of vectype.
> 
>   * gcc.dg/vect/fast-math-pr55281.c: New test.
>   * g++.dg/opt/pr55281.C: New test.

Ok.


r~


[PATCH] Fix force_nonfallthru_and_redirect with asm goto (PR rtl-optimization/54127)

2012-11-12 Thread Jakub Jelinek
Hi!

The following testcase was ICEing on powerpc64-linux.
While force_nonfallthru_and_redirect properly adjusted the LABEL_REFs
in asm goto from the old fallthru block to a new one, it didn't adjust
LABEL_NUSES and didn't adjust JUMP_LABEL resp. REG_LABEL_TARGET.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
ok for trunk (and 4.7 after say a week)?

2012-11-12  Jakub Jelinek  

PR rtl-optimization/54127
* cfgrtl.c (force_nonfallthru_and_redirect): When redirecting
asm goto labels from BB_HEAD (e->dest) to target bb, decrement
LABEL_NUSES of BB_HEAD (e->dest) and increment LABEL_NUSES of
BB_HEAD (target) appropriately and adjust JUMP_LABEL and/or
REG_LABEL_TARGET and REG_LABEL_OPERAND.

* gcc.dg/torture/pr54127.c: New test.

--- gcc/cfgrtl.c.jj 2012-11-05 08:55:21.0 +0100
+++ gcc/cfgrtl.c2012-11-12 11:06:32.254919581 +0100
@@ -1424,14 +1424,46 @@ force_nonfallthru_and_redirect (edge e,
   && (note = extract_asm_operands (PATTERN (BB_END (e->src)
 {
   int i, n = ASM_OPERANDS_LABEL_LENGTH (note);
+  bool adjust_jump_target = false;
 
   for (i = 0; i < n; ++i)
{
  if (XEXP (ASM_OPERANDS_LABEL (note, i), 0) == BB_HEAD (e->dest))
-   XEXP (ASM_OPERANDS_LABEL (note, i), 0) = block_label (target);
+   {
+ LABEL_NUSES (XEXP (ASM_OPERANDS_LABEL (note, i), 0))--;
+ XEXP (ASM_OPERANDS_LABEL (note, i), 0) = block_label (target);
+ LABEL_NUSES (XEXP (ASM_OPERANDS_LABEL (note, i), 0))++;
+ adjust_jump_target = true;
+   }
  if (XEXP (ASM_OPERANDS_LABEL (note, i), 0) == BB_HEAD (target))
asm_goto_edge = true;
}
+  if (adjust_jump_target)
+   {
+ rtx insn = BB_END (e->src), note;
+ rtx old_label = BB_HEAD (e->dest);
+ rtx new_label = BB_HEAD (target);
+
+ if (JUMP_LABEL (insn) == old_label)
+   {
+ JUMP_LABEL (insn) = new_label;
+ note = find_reg_note (insn, REG_LABEL_TARGET, new_label);
+ if (note)
+   remove_note (insn, note);
+   }
+ else
+   {
+ note = find_reg_note (insn, REG_LABEL_TARGET, old_label);
+ if (note)
+   remove_note (insn, note);
+ if (JUMP_LABEL (insn) != new_label
+ && !find_reg_note (insn, REG_LABEL_TARGET, new_label))
+   add_reg_note (insn, REG_LABEL_TARGET, new_label);
+   }
+ while ((note = find_reg_note (insn, REG_LABEL_OPERAND, old_label))
+!= NULL_RTX)
+   XEXP (note, 0) = new_label;
+   }
 }
 
   if (EDGE_COUNT (e->src->succs) >= 2 || abnormal_edge_flags || asm_goto_edge)
--- gcc/testsuite/gcc.dg/torture/pr54127.c.jj   2012-11-12 11:13:45.422433593 
+0100
+++ gcc/testsuite/gcc.dg/torture/pr54127.c  2012-11-12 11:09:07.0 
+0100
@@ -0,0 +1,16 @@
+/* PR rtl-optimization/54127 */
+/* { dg-do compile } */
+
+extern void foo (void) __attribute__ ((__noreturn__));
+
+void
+bar (int x)
+{
+  if (x < 0)
+foo ();
+  if (x == 0)
+return;
+  __asm goto ("# %l[lab] %l[lab2]" : : : : lab, lab2);
+lab:;
+lab2:;
+}

Jakub


Re: [patch] PR51477

2012-11-12 Thread Richard Henderson
On 11/12/2012 01:04 AM, Steven Bosscher wrote:
> gcc/
>   PR rtl-optimization/51447
>   * df-scan.c (df_get_entry_block_def_set): Add global regs to the set.
>   * df-problems.c (df_lr_local_compute): Make global regs always live.
>   * dce.c (deletable_insn_p): Make insns setting a global reg
>   inherently necessary.
> 
> testsuite/
>   PR rtl-optimization/51447
>   * gcc.c-torture/execute/pr51447.c: New test.

Ok.


r~


[PATCH] Fix some VEC_COND_EXPR ICEs (PR tree-optimization/55281)

2012-11-12 Thread Jakub Jelinek
Hi!

This patch fixes two ICEs on the testcases, one is ICE in
expand_vector_condition which wouldn't handle VECTOR_CST as first argument
of VEC_COND_EXPR (plus a change to make sure it is folded earlier if
possible), and the vectorizable_condition change makes sure the condition
is actually using a vector of integers instead of vector of floats and
similar, which crashes because fold-const.c isn't anywhere close to be
prepared for floating point type (or vector float) of NE_EXPR and other
comparison tree codes.

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

2012-11-12  Jakub Jelinek  

PR tree-optimization/55281
* tree-vect-generic.c (expand_vector_condition): Accept any
is_gimple_val rather than just SSA_NAME if not COMPARISON_CLASS_P.
* fold-const.c (fold_ternary_loc): Fold VEC_COND_EXPR if arg0 is
either integer_all_onesp or integer_zerop.
* tree-vect-stmts.c (vectorizable_condition): Build the condition
using corresponding vector integer type instead of vectype.

* gcc.dg/vect/fast-math-pr55281.c: New test.
* g++.dg/opt/pr55281.C: New test.

--- gcc/tree-vect-generic.c.jj  2012-11-02 09:01:55.0 +0100
+++ gcc/tree-vect-generic.c 2012-11-12 12:14:49.978619417 +0100
@@ -892,7 +892,7 @@ expand_vector_condition (gimple_stmt_ite
   int i;
   location_t loc = gimple_location (gsi_stmt (*gsi));
 
-  if (TREE_CODE (a) != SSA_NAME)
+  if (!is_gimple_val (a))
 {
   gcc_assert (COMPARISON_CLASS_P (a));
   a_is_comparison = true;
--- gcc/fold-const.c.jj 2012-11-08 21:08:25.0 +0100
+++ gcc/fold-const.c2012-11-12 15:51:45.118969684 +0100
@@ -14036,6 +14036,16 @@ fold_ternary_loc (location_t loc, enum t
 
   return NULL_TREE;
 
+case VEC_COND_EXPR:
+  if (TREE_CODE (arg0) == VECTOR_CST)
+   {
+ if (integer_all_onesp (arg0) && !TREE_SIDE_EFFECTS (op2))
+   return pedantic_non_lvalue_loc (loc, op1);
+ if (integer_zerop (arg0) && !TREE_SIDE_EFFECTS (op1))
+   return pedantic_non_lvalue_loc (loc, op2);
+   }
+  return NULL_TREE;
+
 case CALL_EXPR:
   /* CALL_EXPRs used to be ternary exprs.  Catch any mistaken uses
 of fold_ternary on them.  */
--- gcc/tree-vect-stmts.c.jj2012-11-07 08:42:08.0 +0100
+++ gcc/tree-vect-stmts.c   2012-11-12 15:29:12.012684236 +0100
@@ -5310,6 +5310,7 @@ vectorizable_condition (gimple stmt, gim
   bb_vec_info bb_vinfo = STMT_VINFO_BB_VINFO (stmt_info);
   VEC (tree, heap) *vec_oprnds0 = NULL, *vec_oprnds1 = NULL;
   VEC (tree, heap) *vec_oprnds2 = NULL, *vec_oprnds3 = NULL;
+  tree vec_cmp_type = vectype;
 
   if (slp_node || PURE_SLP_STMT (stmt_info))
 ncopies = 1;
@@ -5382,6 +5383,15 @@ vectorizable_condition (gimple stmt, gim
   && TREE_CODE (else_clause) != FIXED_CST)
 return false;
 
+  if (!INTEGRAL_TYPE_P (TREE_TYPE (vectype)))
+{
+  unsigned int prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (vectype)));
+  tree cmp_type = build_nonstandard_integer_type (prec, 1);
+  vec_cmp_type = get_same_sized_vectype (cmp_type, vectype);
+  if (vec_cmp_type == NULL_TREE)
+   return false;
+}
+
   if (!vec_stmt)
 {
   STMT_VINFO_TYPE (stmt_info) = condition_vec_info_type;
@@ -5488,8 +5498,8 @@ vectorizable_condition (gimple stmt, gim
   vec_then_clause = VEC_index (tree, vec_oprnds2, i);
   vec_else_clause = VEC_index (tree, vec_oprnds3, i);
 
-  vec_compare = build2 (TREE_CODE (cond_expr), vectype,
-  vec_cond_lhs, vec_cond_rhs);
+ vec_compare = build2 (TREE_CODE (cond_expr), vec_cmp_type,
+   vec_cond_lhs, vec_cond_rhs);
   vec_cond_expr = build3 (VEC_COND_EXPR, vectype,
 vec_compare, vec_then_clause, vec_else_clause);
 
--- gcc/testsuite/gcc.dg/vect/fast-math-pr55281.c.jj2012-11-12 
15:55:58.069579547 +0100
+++ gcc/testsuite/gcc.dg/vect/fast-math-pr55281.c   2012-11-12 
15:56:29.550402151 +0100
@@ -0,0 +1,30 @@
+/* PR tree-optimization/55281 */
+/* { dg-do compile } */
+
+static inline float
+bar (float k, float j)
+{
+  float l = 0.0f;
+  if (k > j)
+l = k;
+  float t = k / j;
+  float v = t * t;
+  if (k == 0)
+v = 0.0f;
+  if (t > 0.4f)
+v += 0.7;
+  if (l != 0)
+v = 1.5 - v;
+  return v;
+}
+
+void
+foo (int *a, int b, float *d, float *e, int *f)
+{
+  int i, l;
+  for (l = 0; l != b; ++l)
+for (i = 0; i != 8; ++i)
+  f[i] = e[i] + bar (a[i], d[i]);
+}
+
+/* { dg-final { cleanup-tree-dump "vect" } } */
--- gcc/testsuite/g++.dg/opt/pr55281.C.jj   2012-11-12 15:53:50.523289232 
+0100
+++ gcc/testsuite/g++.dg/opt/pr55281.C  2012-11-12 15:54:11.529173469 +0100
@@ -0,0 +1,17 @@
+// PR tree-optimization/55281
+// { dg-do compile }
+// { dg-options "-Ofast" }
+
+typedef float VF __attribute__((vector_size (16)));
+
+VF x;
+
+void
+foo (void)
+{
+  VF a, b, c;
+  a = (VF) { 1.0, 2

Re: [PATCH v3] Add support for sparc compare-and-branch

2012-11-12 Thread David Miller
From: Richard Henderson 
Date: Mon, 12 Nov 2012 09:56:21 -0800

> On 10/22/2012 08:39 PM, David Miller wrote:
>> +  /* Compare and Branch is limited to +-2KB.  If it is too far away,
>> + change
>> +
>> + cxbne X, Y, .LC30
>> +
>> + to
>> +
>> + cxbe X, Y, .+12
>> + ba,pt xcc, .LC30
>> +  nop  */
> 
> Based on your no-control-after cbcond comment at the top
> of the patch, surely this should contain another nop as well.

Indeed, I'll fix this up.

> And surely all this code isn't so performance sensitive that
> it needs to be written in such an unreadable way.

Sure, I'll change the code to use one of the the clearer mechanisms
you suggested.

Thanks for the review.


Re: [PATCH v3] Add support for sparc compare-and-branch

2012-11-12 Thread David Miller
From: Eric Botcazou 
Date: Mon, 12 Nov 2012 09:35:48 +0100

>> I strongly doubt that they will be different from the options
>> supported both in cc and fbe in the Solaris Studio 12.3 release:
> 
> They need to provide some form of backward compatibility though, they cannot 
> break the interface of 'as' like that.  Apparently 'fbe' has had its own set 
> of -xarch values for a while and they haven't been compatible with 'as'.

You give them far too much credit :-)

The 'as' updates constantly add inconsistencies in options and
behavior, and even worse (in my opinion) they effectively stopped
updating the 'as' manual page in this area.


Re: [PATCH v3] Add support for sparc compare-and-branch

2012-11-12 Thread David Miller
From: Rainer Orth 
Date: Mon, 12 Nov 2012 16:46:37 +0100

> Eric Botcazou  writes:
> 
>>> No, quite the contrary.  as is just a (sometimes partial) backport of
>>> Studio fbe, though it's hard to tell exactly which Studio version of fbe
>>> forms the basis of as.  Especially for the Solaris 10 as patches, only
>>> particular bugfixes/enhancements have been backported.
>>> 
>>> Backward compatibility is maintained, of course.  as(1) lists
>>> 
>>>  -xarch=v9
>>> 
>>>  Equivalent to: -m64 -xarch=sparc
>>> 
>>> and many more.
>>
>> Does it list -xarch=v8pluse/-xarch=v9e as equivalent to -m32/64 
>> -xarch=sparc4?
>> If so, I don't think that we need to change our scheme, using 'e' instead of 
>> 'd' for SPARC4 instructions should work just fine with both GNU and Sun as.
> 
> as(1) mentions no -xarch value beyond v9b, while strings on the as binary
> reveals v9, v9[a-dv], but no v9e.  Seems to be a gas invention.

It is indeed, a gas invention.

We really need to start using the newer names, as Sun is not going to
provide single letter indicators for sparc4 or future xarch values.

In fact, that's exactly what needed to be worked on from the beginning
for the solaris side of this cbcond patch.  We're talking in circles.
:-)



libgo patch committed: Force first letter of error message to lowercase

2012-11-12 Thread Ian Lance Taylor
One minor difference between the gc and gccgo libraries is that the
error messages returned by the gc library force the first letter of the
error message to be lower case.  This normally doesn't matter, but of
course it does matter for code that compares error strings directly.
Such code is of course non-portable, but people do write it, and gccgo
should behave the same as gc on the same system.  This patch does the
lower case forcing in the gccgo library, the same way as it is done in
the gc library.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

diff -r 767d1b1ee0cf libgo/go/syscall/errstr.go
--- a/libgo/go/syscall/errstr.go	Sat Nov 10 12:21:49 2012 -0800
+++ b/libgo/go/syscall/errstr.go	Mon Nov 12 11:31:07 2012 -0800
@@ -6,22 +6,27 @@
 
 package syscall
 
-//sysnb	strerror_r(errnum int, buf []byte) (err error)
+//sysnb	strerror_r(errnum int, buf []byte) (err Errno)
 //strerror_r(errnum _C_int, buf *byte, buflen Size_t) _C_int
 
 func Errstr(errnum int) string {
 	for len := 128; ; len *= 2 {
 		b := make([]byte, len)
-		err := strerror_r(errnum, b)
-		if err == nil {
+		errno := strerror_r(errnum, b)
+		if errno == 0 {
 			i := 0
 			for b[i] != 0 {
 i++
 			}
+			// Lowercase first letter: Bad -> bad, but
+			// STREAM -> STREAM.
+			if i > 1 && 'A' <= b[0] && b[0] <= 'Z' && 'a' <= b[1] && b[1] <= 'z' {
+b[0] += 'a' - 'A'
+			}
 			return string(b[:i])
 		}
-		if err != ERANGE {
-			return "Errstr failure"
+		if errno != ERANGE {
+			return "errstr failure"
 		}
 	}
 }
diff -r 767d1b1ee0cf libgo/go/syscall/errstr_linux.go
--- a/libgo/go/syscall/errstr_linux.go	Sat Nov 10 12:21:49 2012 -0800
+++ b/libgo/go/syscall/errstr_linux.go	Mon Nov 12 11:31:07 2012 -0800
@@ -19,5 +19,10 @@
 	for b[i] != 0 {
 		i++
 	}
+	// Lowercase first letter: Bad -> bad, but STREAM -> STREAM.
+	if i > 1 && 'A' <= b[0] && b[0] <= 'Z' && 'a' <= b[1] && b[1] <= 'z' {
+		c := b[0] + 'a' - 'A'
+		return string(c) + string(b[1:i])
+	}
 	return string(b[:i])
 }
diff -r 767d1b1ee0cf libgo/go/syscall/errstr_nor.go
--- a/libgo/go/syscall/errstr_nor.go	Sat Nov 10 12:21:49 2012 -0800
+++ b/libgo/go/syscall/errstr_nor.go	Mon Nov 12 11:31:07 2012 -0800
@@ -25,7 +25,15 @@
 	for b[i] != 0 {
 		i++
 	}
-	s := string(b[:i])
+
+	// Lowercase first letter: Bad -> bad, but STREAM -> STREAM.
+	var s string
+	if i > 1 && 'A' <= b[0] && b[0] <= 'Z' && 'a' <= b[1] && b[1] <= 'z' {
+		c := b[0] + 'a' - 'A'
+		s = string(c) + string(b[1:i])
+	} else {
+		s = string(b[:i])
+	}
 
 	errstr_lock.Unlock()
 


(committed) Add libquadmath files to contrib/gcc_update

2012-11-12 Thread Tobias Burnus
Used HJ's commit as motivation to also add the generated files of 
libquadmath files to the gcc_update file.


Committed as .

Tobias
Index: contrib/ChangeLog
===
--- contrib/ChangeLog	(Revision 193447)
+++ contrib/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,7 @@
+2012-11-12  Tobias Burnus  
+
+	* gcc_update: Add libquadmath generated files.
+
 2012-11-12  H.J. Lu  
 
 	* gcc_update: Add libsanitizer generated files.
Index: contrib/gcc_update
===
--- contrib/gcc_update	(Revision 193447)
+++ contrib/gcc_update	(Arbeitskopie)
@@ -123,6 +123,9 @@ libffi/configure: libffi/configure.ac libffi/acloc
 libffi/fficonfig.h.in: libffi/configure.ac libffi/aclocal.m4
 libgfortran/aclocal.m4: libgfortran/configure.ac libgfortran/acinclude.m4
 libgfortran/Makefile.in: libgfortran/Makefile.am libgfortran/configure.ac libgfortran/aclocal.m4
+libquadmath/configure: libquadmath/configure.ac libquadmath/aclocal.m4
+libquadmath/aclocal.m4: libquadmath/configure.ac libquadmath/acinclude.m4
+libquadmath/Makefile.in: libquadmath/Makefile.am libquadmath/configure.ac libgfortran/aclocal.m4
 libgfortran/configure: libgfortran/configure.ac libgfortran/aclocal.m4
 libjava/aclocal.m4: libjava/configure.ac
 libjava/Makefile.in: libjava/Makefile.am libjava/configure.ac libjava/aclocal.m4


Re: [PATCH 10/10] Import the asan runtime library into GCC tree

2012-11-12 Thread H.J. Lu
On Mon, Nov 12, 2012 at 3:47 AM, Dodji Seketeli  wrote:
> Diego Novillo  writes:
>
>> On 2012-11-02 16:10 , Dodji Seketeli wrote:
>>
>>>  * configure.ac: Add libsanitizer to target_libraries.
>>>  * Makefile.def: Ditto.
>>>  * configure: Regenerate.
>>>  * Makefile.in: Regenerate.
>>>  * libsanitizer: New directory for asan runtime.  Contains an empty
>>>  tsan directory.
>>>
>>> gcc:
>>>  * gcc.c (LINK_COMMAND_SPEC): Add -lasan to link command
>>>  if -faddress-sanitizer is on.
>>
>> OK with Jakub's comments addressed.
>>
>> References to -fasan in diagnostics should be replaced.  But there's
>> been another flag name change upstream, so let's do it together with
>> the new flag names.
>
> Done.   This also addresses the comment later made by Tobias below:
>
> Tobias Burnus  writes:
>
>> Other issues:
>
>> * Probably fixed on the branch: gcc/gcc.c still has "fasan" instead of
>> "faddress-sanitizer" for the spec:
>> +%{fasan:-lasan}
>
> Below is a link to the updated patch.
>
> This patch imports the runtime library in the GCC tree, ensures that
> -lasan is passed to the linker when -faddress-sanitizer is used and
> sets up the build system accordingly.
>
>  * configure.ac: Add libsanitizer to target_libraries.
> * Makefile.def: Ditto.
> * configure: Regenerate.
> * Makefile.in: Regenerate.
> * libsanitizer: New directory for asan runtime.  Contains an empty
> tsan directory.
>
> gcc:
> * gcc.c (LINK_COMMAND_SPEC): Add -laddress-sanitizer to link command
> if -faddress-sanitizer is on.
>
> libsanitizer:
>
> Initial checkin: migrate asan runtime from llvm.
>
> http://people.redhat.com/~dseketel/gcc/patches/0011-Import-the-asan-runtime-library-into-GCC-tree.patch
>
> --
> Dodji

I checked in this patch to add libsanitizer generated files.

-- 
H.J.
---
diff --git a/contrib/ChangeLog b/contrib/ChangeLog
index ef5d6f6..233870d 100644
--- a/contrib/ChangeLog
+++ b/contrib/ChangeLog
@@ -1,3 +1,7 @@
+2012-11-12  H.J. Lu  
+
+   * gcc_update: Add libsanitizer generated files.
+
 2012-11-05  Lawrence Crowl  

* compare_two_ftime_report_sets: New.
diff --git a/contrib/gcc_update b/contrib/gcc_update
index 02897ab..d9c2dfb 100755
--- a/contrib/gcc_update
+++ b/contrib/gcc_update
@@ -149,6 +149,9 @@ libatomic/Makefile.in: libatomic/Makefile.am
libatomic/aclocal.m4
 libatomic/testsuite/Makefile.in: libatomic/testsuite/Makefile.am
libatomic/aclocal.m4
 libatomic/configure: libatomic/configure.ac libatomic/aclocal.m4
 libatomic/auto-config.h.in: libatomic/configure.ac libatomic/aclocal.m4
+libsanitizer/aclocal.m4: libsanitizer/configure.ac
+libsanitizer/Makefile.in: libsanitizer/Makefile.am libsanitizer/aclocal.m4
+libsanitizer/configure: libsanitizer/configure.ac libsanitizer/aclocal.m4
 # Top level
 Makefile.in: Makefile.tpl Makefile.def
 configure: configure.ac config/acx.m4


Re: [tsan] ThreadSanitizer instrumentation part

2012-11-12 Thread Wei Mi
For TODO_update_ssa, when we insert tsan_write(&a), current function's
ssa_renaming_needed flag will be set in finalize_ssa_defs because we
insert non-ssaname vdef. An assertion in execute_todo will check
whether we have TODO_update_ssa set when current function's
ssa_renaming_needed flag is set. That is why I will get assertion when
I remove TODO_update_ssa flag.

Is it ok to keep TODO_update_ssa and TODO_update_address_taken?

Thanks,
Wei.

On Mon, Nov 5, 2012 at 4:37 PM, Wei Mi  wrote:
> Hi Jakub,
>
> Thanks for the comments. I fix most of them except the setting of
> TODO_ The new patch.txt is attached.
>
> Thanks,
> Wei.
>
>>> +  TODO_verify_all | TODO_update_ssa
>>
>> Ideally you shouldn't need TODO_update_ssa.
>>
>
> I got error when I removed TODO_update_ssa, so I kept it.
>
>>> +| TODO_update_address_taken /* todo_flags_finish  */
>>
>> And why this?
>>
>
> If we generate tsan_read(&a) for a non-address taken static variable
> a, we need to change a to be address taken, right?
>
> On Sat, Nov 3, 2012 at 11:39 AM, Jakub Jelinek  wrote:
>> On Sat, Nov 03, 2012 at 10:05:35AM -0700, Wei Mi wrote:
>>> --- gcc/sanitizer.def (revision 0)
>>> +++ gcc/sanitizer.def (revision 0)
>>> @@ -0,0 +1,31 @@
>>> +DEF_SANITIZER_BUILTIN(BUILT_IN_TSAN_WRITE_16, "__tsan_write16",
>>> +  BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST)
>>> +
>>> +
>>> +
>>
>> Please remove the trailing whitespace.
>
> Done
>
>>
>>> +/* Builtin used by the implementation of libsanitizer. These
>>> +   functions are mapped to the actual implementation of the
>>> +   libasan and libtsan library. */
>>> +#undef DEF_SANITIZER_BUILTIN
>>> +#define DEF_SANITIZER_BUILTIN(ENUM, NAME, TYPE, ATTRS) \
>>> +  DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,\
>>> +   true, true, true, ATTRS, true, flag_tsan)
>>
>> That should be eventually flag_asan || flag_tsan, as sanitizer.def
>> should be also for asan builtins, or it must be DEF_TSAN_BUILTIN/tsan.def.
>>
>
> Postpone to fix it after asan checkin to trunk.
>
>>> +static tree
>>> +get_memory_access_decl (bool is_write, unsigned size)
>>> +{
>>> +  enum built_in_function fcode;
>>> +
>>> +  if (size <= 1)
>>> +fcode = is_write ? BUILT_IN_TSAN_WRITE_1 :
>>> +   BUILT_IN_TSAN_READ_1;
>>
>> Formatting, : should be below ?.
>
> Fixed.
>
>>> +
>>> +  return builtin_decl_implicit(fcode);
>>
>> Space before (. Several times in the code.
>>
>
> Fixed.
>
>> Also, as is the tsan builtins will be defined only for
>> C/C++ family FEs, so either something needs to be done
>> for other FEs, or perhaps the pass should just error out
>> if say the BUILT_IN_TSAN_INIT isn't defined.
>>
>
> Wrap builtin_decl_implicit in get_tsan_builtin_decl. If
> builtin_decl_implicit return invalid decl, output error message and
> then exit.
>
>>> +static tree
>>> +is_vptr_store (gimple stmt, tree expr, int is_write)
>>
>> is_write should be bool,
>>
>>> +{
>>> +  if (is_write == 1
>>
>> and this just is_write
>>
>>> +static bool
>>> +is_load_of_const_p (tree expr, int is_write)
>>> +{
>>> +  if (is_write)
>>> +return false;
>>
>> Again.
>>
>
> Fixed
>
>>> +  /* The var does not live in memory -> no possibility of races.  */
>>> +  || (tcode == VAR_DECL
>>> +  && !TREE_ADDRESSABLE (expr)
>>> +  && TREE_STATIC (expr) == 0)
>>
>> Please use && !is_global_var (expr) here instead.
>>
>
> Changed.
>
>>> +  /* TODO: handle other cases
>>> + (FIELD_DECL, MEM_REF, ARRAY_RANGE_REF, TARGET_MEM_REF, ADDR_EXPR).  */
>>
>> The comment is obsolete, MEM_REF is handled.
>>
>
> Fixed.
>
>>> +  if (tcode != ARRAY_REF
>>> +  && tcode != VAR_DECL
>>> +  && tcode != COMPONENT_REF
>>> +  && tcode != INDIRECT_REF
>>> +  && tcode != MEM_REF)
>>> +return false;
>>> +
>>> +  stmt = gsi_stmt (gsi);
>>> +  loc = gimple_location (stmt);
>>> +  rhs = is_vptr_store (stmt, expr, is_write);
>>> +#ifdef DEBUG
>>> +  if (rhs == NULL)
>>> +gcc_assert (is_gimple_addressable (expr));
>>> +#endif
>>
>> That should be
>>   gcc_checking_assert (rhs != NULL || is_gimple_addressable (expr));
>> if you want to check it in checking versions only.
>>
>
> Fixed.
>
>>> +  size = int_size_in_bytes(expr_type);
>>
>> Missing space.
>>
>
> Fixed.
>
>>> +  g = gimple_build_call(
>>> +get_memory_access_decl(is_write, size),
>>> +1, expr_ptr);
>>
>> And the formatting here is completely wrong.
>>
>
> Fixed.
>
>>> +}
>>> +  else
>>> +g = gimple_build_call(
>>> +  builtin_decl_implicit(BUILT_IN_TSAN_VPTR_UPDATE),
>>> +  1, expr_ptr);
>>> +  gimple_set_location (g, loc);
>>> +  /* Instrumentation for assignment of a function result
>>> + must be inserted after the call.  Instrumentation for
>>> + reads of function arguments must be inserted before the call.
>>> + That's because the call can contain synchronization.  */
>>> +  if (is_gimple_call (stmt) && is_write)
>>> +{
>>> +  int fl

Re: [PATCH 00/13] Request to merge Address Sanitizer in

2012-11-12 Thread Jack Howarth
On Mon, Nov 12, 2012 at 06:55:32PM +0100, Dodji Seketeli wrote:
> Hello Jack,
> 
> Jack Howarth  writes:
> >> 
> >> Dodji,
> >> I am finding that at r193442 bootstrapping on
> >> x86_64-apple-darwin12 fails with...
> 
> >> ../../../../gcc-4.8-20121112/libsanitizer/interception/interception_mac.cc:16:41:
> >>  fatal error: mach_override/mach_override.h: No such file or directory
> >>  #include "mach_override/mach_override.h"
> >>  ^
> >> compilation terminated.
> 
> Thank you for pointing this out.
> 
> >Copying over the lib/interception/mach_override directory from 
> > llvm.org's compiler-rt 3.2 branch into libsanitizer/interception allows
> > the build of libsanitizer to proceed. I noticed that the mach_override
> > subdirectory has a license file which shows...
> 
> Interesting.
> 
> >
> > Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
> > Some rights reserved: <http://opensource.org/licenses/mit-license.php>
> >
> > Hopefully this subdirectory wasn't omitted for licensing reasons because 
> > without it the bootstrap on darwin
> > is broken.
> 
> Yeah, hopefully.
> 
> Wei, is there any reason why the mach_override directory was left out of
> the libsanitizer commit?  Maybe I missed something during my patch
> slicing?

Dodji,
   I don't see the mach_override directory in the asan gcc branch either so
it appears to have never been ported from llvm's compiler-rt.
Jack

> 
> Cheers.
> 
> -- 
>   Dodji


Re: Asan/Tsan Unit/Regression testing (was [asan] Emit GIMPLE direclty, small cleanups)

2012-11-12 Thread Konstantin Serebryany
Hi,
I don't insist that we use gtest for gcc-asan, I just say that this is
the simplest approach to get 2.5K test suite into gcc,
and the only approach my team will be able to maintain.

gtest is not as portable as the rest of gcc, but neither is asan
run-time library (which is more platform-specific than gtest).

On Mon, Nov 12, 2012 at 10:08 AM, Andrew Pinski  wrote:
> On Mon, Nov 12, 2012 at 10:05 AM, Jakub Jelinek  wrote:
>> On Mon, Nov 12, 2012 at 09:32:04AM -0800, Wei Mi wrote:
>>> Using setjmp/longjmp to do multiple tests in a single testfile, the
>>> test statements in the front could affect the tests in the back. gtest
>>> will fork a new process for every test statement. The forked process
>>> will do only one test and skip all the other test statements. That is
>>> to say, multiple test statements in the same testfile are guaranteed
>>> to be independent from each other in gtest. If we use setjmp/longjmp
>>> pattern to do the test, existing testsuite may need to be rewritten if
>>> their test statements could affect each other.
>>
>> So you can either run the program multiple times from within dejagnu, or
>> fork inside of the macros.  In any case, adding > 5MB of gtest just for that
>> single test or two is IMHO really too much, and similarly adding gtest
>> as another requirement to build gcc.  Does gtest support all the targets
>> that gcc does btw?
>
> Also does gtest support cross testing; that is testing over rsh/ssh
> and testing via a simulator?

I see no reason why gtest will not work via ssh or in simulator.

--kcc

We should require that as a requirement
> also when it comes to testing infrastructures.
>
> Thanks,
> Andrew Pinski
>
>>
>> Jakub


[PATCH] AIX large toc support

2012-11-12 Thread David Edelsohn
AIX has added its equivalent to PPC64 Linux Large TOC support.  The
appended patch implements GCC support and enables it if the AIX system
tools support the new relocs.  This is not the default for XLC and
will not be the default for GCC.

GCC testsuite produces same results if run with -mcmodel=large.

Bootstrapped on powerpc-ibm-aix7.1.0.0.

I wanted to allow a chance for additional eyes before I commit it.

Thanks, David

* configure.ac (HAVE_LD_LARGE_TOC): Add AIX ld test.
* configure: Regenerated.
* config/rs6000/aix61.h (SUBTARGET_OVERRIDE_OPTIONS): Disable
TARGET_NO_FP_IN_TOC and TARGET_NO_SUM_IN_TOC if not CMODEL_SMALL.
CMODEL_MEDIUM means CMODEL_LARGE on AIX.
(ASM_SPEC): -mvsx implies -mpwr6. Add -many.
(ASM_DEFAULT_SPEC): Use -mpwr4.
* config/rs6000/rs6000.md (largetoc_high_aix): New.
(largetoc_high_plus_aix): New.
(largetoc_low): Change to mode iterator. Test TARGET_TOC
instead of TARGET_ELF.
(tocref): Remove TARGET_ELF test.
* config/rs6000/aix64.opt (mcmodel): New.

Index: configure.ac
===
--- configure.ac(revision 193425)
+++ configure.ac(working copy)
@@ -4496,6 +4496,35 @@
 ;;
 esac

+case "$target" in
+  *-*-aix*)
+AC_CACHE_CHECK(linker large toc support,
+gcc_cv_ld_large_toc,
+[gcc_cv_ld_large_toc=no
+if test x$gcc_cv_as != x -a x$gcc_cv_ld != x ; then
+  cat > conftest.s < /dev/null 2>&1; then
+gcc_cv_ld_large_toc=yes
+  fi
+  rm -f conftest conftest.o conftest.s
+fi
+])
+if test x"$gcc_cv_ld_large_toc" = xyes; then
+  AC_DEFINE(HAVE_LD_LARGE_TOC, 1,
+[Define if your AIX linker supports a large TOC.])
+fi
+;;
+esac
+
 AC_CACHE_CHECK(linker --build-id support,
   gcc_cv_ld_buildid,
   [gcc_cv_ld_buildid=no
Index: config/rs6000/aix61.h
===
--- config/rs6000/aix61.h   (revision 193425)
+++ config/rs6000/aix61.h   (working copy)
@@ -39,6 +39,15 @@
 {  \
   error ("-maix64 required: 64-bit computation with 32-bit
addressing not yet supported"); \
 }  \
+  if (rs6000_current_cmodel != CMODEL_SMALL)   \
+{  \
+  TARGET_NO_FP_IN_TOC = 0; \
+  TARGET_NO_SUM_IN_TOC = 0;
\
+}  \
+  if (rs6000_current_cmodel == CMODEL_MEDIUM)  \
+{  \
+  rs6000_current_cmodel = CMODEL_LARGE;\
+}  \
 } while (0);

 #undef ASM_SPEC
@@ -72,10 +81,12 @@
 %{mcpu=620: -m620} \
 %{mcpu=630: -m620} \
 %{mcpu=970: -m970} \
-%{mcpu=G5: -m970}"
+%{mcpu=G5: -m970} \
+%{mvsx: %{!mcpu*: -mpwr6}} \
+-many"

 #undef ASM_DEFAULT_SPEC
-#define ASM_DEFAULT_SPEC "-mppc"
+#define ASM_DEFAULT_SPEC "-mpwr4"

 #undef TARGET_OS_CPP_BUILTINS
 #define TARGET_OS_CPP_BUILTINS() \
Index: config/rs6000/rs6000.md
===
--- config/rs6000/rs6000.md (revision 193425)
+++ config/rs6000/rs6000.md (working copy)
@@ -10339,6 +10339,15 @@
"TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
"addis %0,%2,%1@toc@ha")

+(define_insn "*largetoc_high_aix"
+  [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
+(high:P
+ (unspec [(match_operand:P 1 "" "")
+  (match_operand:P 2 "gpc_reg_operand" "b")]
+ UNSPEC_TOCREL)))]
+   "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
+   "addis %0,%1@u(%2)")
+
 (define_insn "*largetoc_high_plus"
   [(set (match_operand:DI 0 "gpc_reg_operand" "=b*r")
 (high:DI
@@ -10350,11 +10359,22 @@
"TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
"addis %0,%2,%1+%3@toc@ha")

-(define_insn "*largetoc_low"
-  [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
-(lo_sum:DI (match_operand:DI 1 "gpc_reg_operand" "b,!*r")
-  (match_operand:DI 2 "" "")))]
-   "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
+(define_insn "*largetoc_high_plus_aix"
+  [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
+(high:P
+ (plus:P
+   (unspec [(match_operand:P 1 "" "")
+(match_operand:P 2 "gpc_reg_operand" "b")]
+   UNSPEC_TOCREL)
+   (match_operand 3 "const_int_operand" "n"]
+   "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
+   "addis %0,%2,%1+%3@u")
+
+(define_insn "*largetoc_low"
+  [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
+

Re: Asan/Tsan Unit/Regression testing (was [asan] Emit GIMPLE direclty, small cleanups)

2012-11-12 Thread Andrew Pinski
On Mon, Nov 12, 2012 at 10:05 AM, Jakub Jelinek  wrote:
> On Mon, Nov 12, 2012 at 09:32:04AM -0800, Wei Mi wrote:
>> Using setjmp/longjmp to do multiple tests in a single testfile, the
>> test statements in the front could affect the tests in the back. gtest
>> will fork a new process for every test statement. The forked process
>> will do only one test and skip all the other test statements. That is
>> to say, multiple test statements in the same testfile are guaranteed
>> to be independent from each other in gtest. If we use setjmp/longjmp
>> pattern to do the test, existing testsuite may need to be rewritten if
>> their test statements could affect each other.
>
> So you can either run the program multiple times from within dejagnu, or
> fork inside of the macros.  In any case, adding > 5MB of gtest just for that
> single test or two is IMHO really too much, and similarly adding gtest
> as another requirement to build gcc.  Does gtest support all the targets
> that gcc does btw?

Also does gtest support cross testing; that is testing over rsh/ssh
and testing via a simulator?  We should require that as a requirement
also when it comes to testing infrastructures.

Thanks,
Andrew Pinski

>
> Jakub


Re: Asan/Tsan Unit/Regression testing (was [asan] Emit GIMPLE direclty, small cleanups)

2012-11-12 Thread Jakub Jelinek
On Mon, Nov 12, 2012 at 09:32:04AM -0800, Wei Mi wrote:
> Using setjmp/longjmp to do multiple tests in a single testfile, the
> test statements in the front could affect the tests in the back. gtest
> will fork a new process for every test statement. The forked process
> will do only one test and skip all the other test statements. That is
> to say, multiple test statements in the same testfile are guaranteed
> to be independent from each other in gtest. If we use setjmp/longjmp
> pattern to do the test, existing testsuite may need to be rewritten if
> their test statements could affect each other.

So you can either run the program multiple times from within dejagnu, or
fork inside of the macros.  In any case, adding > 5MB of gtest just for that
single test or two is IMHO really too much, and similarly adding gtest
as another requirement to build gcc.  Does gtest support all the targets
that gcc does btw?

Jakub


Re: [asan] Patch - fix an ICE in asan.c

2012-11-12 Thread Jakub Jelinek
On Mon, Nov 12, 2012 at 06:13:08PM +0100, Markus Trippelsdorf wrote:
> Another ICE:
> 
>  % cat test.ii
>  int i;
> 
>  % g++ -faddress-sanitizer -c -g -O1 test.ii
> test.ii:1:7: internal compiler error: Segmentation fault
>   int i;
>^

The RECORD_TYPE doesn't have lang specific payload allocated for it.
There is no point why we need to describe that in the debug info though.

So I'd do something like:

2012-11-12  Jakub Jelinek  

* asan.c (report_error_func): Set DECL_IGNORED_P, don't touch
DECL_ASSEMBLER_NAME.
(asan_init_func): Likewise.
(asan_finish_file): Use void * instead of __asan_global * as
type of __asan_{,un}register_globals.  Set DECL_IGNORED_P on
the decls.

--- gcc/asan.c.jj   2012-11-12 17:39:19.0 +0100
+++ gcc/asan.c  2012-11-12 18:54:57.164914324 +0100
@@ -493,10 +493,10 @@ report_error_func (bool is_store, int si
   fn_type = build_function_type_list (void_type_node, ptr_type_node, 
NULL_TREE);
   def = build_fn_decl (name, fn_type);
   TREE_NOTHROW (def) = 1;
+  DECL_IGNORED_P (def) = 1;
   TREE_THIS_VOLATILE (def) = 1;  /* Attribute noreturn. Surprise!  */
   DECL_ATTRIBUTES (def) = tree_cons (get_identifier ("leaf"),
 NULL, DECL_ATTRIBUTES (def));
-  DECL_ASSEMBLER_NAME (def);
   return def;
 }
 
@@ -511,7 +511,7 @@ asan_init_func (void)
   fn_type = build_function_type_list (void_type_node, NULL_TREE);
   def = build_fn_decl ("__asan_init", fn_type);
   TREE_NOTHROW (def) = 1;
-  DECL_ASSEMBLER_NAME (def);
+  DECL_IGNORED_P (def) = 1;
   return def;
 }
 
@@ -1535,11 +1535,11 @@ asan_finish_file (void)
   DECL_INITIAL (var) = ctor;
   varpool_assemble_decl (varpool_node_for_decl (var));
 
-  type = build_function_type_list (void_type_node,
-  build_pointer_type (TREE_TYPE (type)),
+  type = build_function_type_list (void_type_node, ptr_type_node,
   uptr, NULL_TREE);
   decl = build_fn_decl ("__asan_register_globals", type);
   TREE_NOTHROW (decl) = 1;
+  DECL_IGNORED_P (decl) = 1;
   append_to_statement_list (build_call_expr (decl, 2,
 build_fold_addr_expr (var),
 build_int_cst (uptr, gcount)),
@@ -1547,6 +1547,7 @@ asan_finish_file (void)
 
   decl = build_fn_decl ("__asan_unregister_globals", type);
   TREE_NOTHROW (decl) = 1;
+  DECL_IGNORED_P (decl) = 1;
   append_to_statement_list (build_call_expr (decl, 2,
 build_fold_addr_expr (var),
 build_int_cst (uptr, gcount)),


Jakub


Re: [PATCH 00/13] Request to merge Address Sanitizer in

2012-11-12 Thread Jack Howarth
On Mon, Nov 12, 2012 at 06:37:06PM +0100, Tobias Burnus wrote:
> Jack Howarth wrote:
>> Copying over the lib/interception/mach_override directory from  
>> llvm.org's compiler-rt 3.2 branch into libsanitizer/interception  
>> allows the build of libsanitizer to proceed. I noticed that the  
>> mach_override subdirectory has a license file which shows...
>
> I was about to point to:
>
> https://github.com/llvm-mirror/compiler-rt/tree/master/lib/interception/mach_override
>
> which contains the required files.
>
> Tobias

Tobias,
   This still leaves the question of why they weren't merged? Hopefully this 
isn't due
to some sort of licensing issue for that subdirectory as we can't have a 
bootstrap
that requires files from outside of the source tree.
   Jack


Re: [PATCH v3] Add support for sparc compare-and-branch

2012-11-12 Thread Richard Henderson
On 10/22/2012 08:39 PM, David Miller wrote:
> +  /* Compare and Branch is limited to +-2KB.  If it is too far away,
> + change
> +
> + cxbne X, Y, .LC30
> +
> + to
> +
> + cxbe X, Y, .+12
> + ba,pt xcc, .LC30
> +  nop  */

Based on your no-control-after cbcond comment at the top
of the patch, surely this should contain another nop as well.

> +  *p++ = '\t';
> +  *p++ = '%';
> +  *p++ = '1';
> +  *p++ = ',';
> +  *p++ = ' ';
> +  *p++ = '%';
> +  *p++ = '2';
> +  *p++ = ',';
> +  *p++ = ' ';

And surely all this code isn't so performance sensitive that
it needs to be written in such an unreadable way.

  p = stpcpy (p, "\t%1, %2, ");

is at least a little better.

Though really there's just 3 variable portions of the pattern, so
I wonder if a lesser number of snprintf calls might be good enough.

  if (far)
{
  if (veryfar)
snprintf (buf, sizeof(buf), "c%cb%s\t%%1, %%2, .+16\n\t"
  "b\t%%l3\n\t nop", size_char, cond_str);
  else
snprintf (buf, sizeof(buf), "c%cb%s\t%%1, %%2, .+16\n\t"
  "ba,pt\t%%xcc,%%l3\n\t nop", size_char, cond_str);
}
  else
snprintf (buf, sizeof(buf), "c%cb%s\t%%1, %%2, %%l3", size_char, cond_str);


r~


Re: [PATCH 00/13] Request to merge Address Sanitizer in

2012-11-12 Thread Dodji Seketeli
Hello Jack,

Jack Howarth  writes:
>> 
>> Dodji,
>> I am finding that at r193442 bootstrapping on
>> x86_64-apple-darwin12 fails with...

>> ../../../../gcc-4.8-20121112/libsanitizer/interception/interception_mac.cc:16:41:
>>  fatal error: mach_override/mach_override.h: No such file or directory
>>  #include "mach_override/mach_override.h"
>>  ^
>> compilation terminated.

Thank you for pointing this out.

>Copying over the lib/interception/mach_override directory from llvm.org's 
> compiler-rt 3.2 branch into libsanitizer/interception allows
> the build of libsanitizer to proceed. I noticed that the mach_override
> subdirectory has a license file which shows...

Interesting.

>
> Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
> Some rights reserved: <http://opensource.org/licenses/mit-license.php>
>
> Hopefully this subdirectory wasn't omitted for licensing reasons because 
> without it the bootstrap on darwin
> is broken.

Yeah, hopefully.

Wei, is there any reason why the mach_override directory was left out of
the libsanitizer commit?  Maybe I missed something during my patch
slicing?

Cheers.

-- 
Dodji


Re: Asan/Tsan Unit/Regression testing (was [asan] Emit GIMPLE direclty, small cleanups)

2012-11-12 Thread Mike Stump
On Nov 12, 2012, at 9:32 AM, Wei Mi  wrote:
> Using setjmp/longjmp to do multiple tests in a single testfile, the
> test statements in the front could affect the tests in the back. gtest
> will fork a new process for every test statement.

Some targets don't have fork.  :-(  Ah.


Re: [PATCH 00/13] Request to merge Address Sanitizer in

2012-11-12 Thread Tobias Burnus

Jack Howarth wrote:
Copying over the lib/interception/mach_override directory from 
llvm.org's compiler-rt 3.2 branch into libsanitizer/interception 
allows the build of libsanitizer to proceed. I noticed that the 
mach_override subdirectory has a license file which shows...


I was about to point to:

https://github.com/llvm-mirror/compiler-rt/tree/master/lib/interception/mach_override

which contains the required files.

Tobias


Re: [PATCH 00/13] Request to merge Address Sanitizer in

2012-11-12 Thread Jack Howarth
On Mon, Nov 12, 2012 at 12:20:08PM -0500, Jack Howarth wrote:
> On Mon, Nov 12, 2012 at 05:07:42PM +0100, Dodji Seketeli wrote:
> > Following a request from Jakub, and given the fact that the patch set
> > have been reviewed by Diego, I have committed the last set of patches I
> > have posted to trunk.
> > 
> > This will hopefully ease the polishing work that has started already.
> > 
> > I am of course watching for the fall-outs.
> > 
> > -- 
> > Dodji
> 
> Dodji,
> I am finding that at r193442 bootstrapping on x86_64-apple-darwin12 fails 
> with...
> 
> Making all in interception
> /bin/sh ../libtool --tag=CXX   --mode=compile 
> /sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/./gcc/g++ 
> -B/sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/./gcc/ -nostdinc++ 
> -nostdinc++ 
> -I/sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/x86_64-apple-darwin12.2.0/libstdc++-v3/include/x86_64-apple-darwin12.2.0
>  
> -I/sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/x86_64-apple-darwin12.2.0/libstdc++-v3/include
>  
> -I/sw/src/fink.build/gcc48-4.8.0-1000/gcc-4.8-20121112/libstdc++-v3/libsupc++ 
> -I/sw/src/fink.build/gcc48-4.8.0-1000/gcc-4.8-20121112/libstdc++-v3/include/backward
>  
> -I/sw/src/fink.build/gcc48-4.8.0-1000/gcc-4.8-20121112/libstdc++-v3/testsuite/util
>  
> -L/sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/x86_64-apple-darwin12.2.0/libstdc++-v3/src
>  
> -L/sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/x86_64-apple-darwin12.2.0/libstdc++-v3/src/.libs
>  -B/sw/lib/gcc4.8/x86_64-apple-darwin12.2.0/bin/ 
> -B/sw/lib/gcc4.8/x86_64-apple-darwin12.2.0/lib/ -isystem 
> /sw/lib/gcc4.8/x86_64-apple-darwin12.2.0/include -isystem 
> /sw/lib/gcc4.8/x86_64-apple-darwin12.2.0/sys-include-D_GNU_SOURCE 
> -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS 
> -D__STDC_LIMIT_MACROS  -I. 
> -I../../../../gcc-4.8-20121112/libsanitizer/interception  -I 
> ../../../../gcc-4.8-20121112/libsanitizer/include   -Wall -W 
> -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long  -fPIC 
> -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables 
> -fvisibility=hidden -Wno-variadic-macros -Wno-c99-extensions  -g -O2 -MT 
> interception_mac.lo -MD -MP -MF .deps/interception_mac.Tpo -c -o 
> interception_mac.lo 
> ../../../../gcc-4.8-20121112/libsanitizer/interception/interception_mac.cc
> libtool: compile:  
> /sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/./gcc/g++ 
> -B/sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/./gcc/ -nostdinc++ 
> -nostdinc++ 
> -I/sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/x86_64-apple-darwin12.2.0/libstdc++-v3/include/x86_64-apple-darwin12.2.0
>  
> -I/sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/x86_64-apple-darwin12.2.0/libstdc++-v3/include
>  
> -I/sw/src/fink.build/gcc48-4.8.0-1000/gcc-4.8-20121112/libstdc++-v3/libsupc++ 
> -I/sw/src/fink.build/gcc48-4.8.0-1000/gcc-4.8-20121112/libstdc++-v3/include/backward
>  
> -I/sw/src/fink.build/gcc48-4.8.0-1000/gcc-4.8-20121112/libstdc++-v3/testsuite/util
>  
> -L/sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/x86_64-apple-darwin12.2.0/libstdc++-v3/src
>  
> -L/sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/x86_64-apple-darwin12.2.0/libstdc++-v3/src/.libs
>  -B/sw/lib/gcc4.8/x86_64-apple-darwin12.2.0/bin/ 
> -B/sw/lib/gcc4.8/x86_64-apple-darwin12.2.0/lib/ -isystem 
> /sw/lib/gcc4.8/x86_64-apple-darwin12.2.0/include -isystem 
> /sw/lib/gcc4.8/x86_64-apple-darwin12.2.0/sys-include -D_GNU_SOURCE -D_DEBUG 
> -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I. 
> -I../../../../gcc-4.8-20121112/libsanitizer/interception -I 
> ../../../../gcc-4.8-20121112/libsanitizer/include -Wall -W 
> -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long -fPIC 
> -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables 
> -fvisibility=hidden -Wno-variadic-macros -Wno-c99-extensions -g -O2 -MT 
> interception_mac.lo -MD -MP -MF .deps/interception_mac.Tpo -c 
> ../../../../gcc-4.8-20121112/libsanitizer/interception/interception_mac.cc  
> -fno-common -DPIC -o .libs/interception_mac.o
> ../../../../gcc-4.8-20121112/libsanitizer/interception/interception_mac.cc:16:41:
>  fatal error: mach_override/mach_override.h: No such file or directory
>  #include "mach_override/mach_override.h"
>  ^
> compilation terminated.
> make[3]: *** [interception_mac.lo] Error 1
> make[2]: *** [all-recursive] Error 1
> make[1]: *** [all-target-libsanitizer] Error 2
> make: *** [all] Error 2
> 
> Is this just from a missing file in the merge or do we need to open a PR for 
> this?
>  Jack

Dodji,
   Copying over the lib/interception/mach_override 

Re: Asan/Tsan Unit/Regression testing (was [asan] Emit GIMPLE direclty, small cleanups)

2012-11-12 Thread Wei Mi
On Fri, Nov 9, 2012 at 11:13 AM, Jakub Jelinek  wrote:
> On Fri, Nov 09, 2012 at 11:05:37AM -0800, Wei Mi wrote:
>> gtest integrate multiple tests into the same file with each test being
>> a single line check.  I cannot think out a method to migrate it to
>> dejagnu without using gtest, except splitting a single gtest file to
>> multiple files with each file per test. asan has about 130 tests so
>> have to write 130 files which will be a doable but painful task.
>
> See the glibc _FORTIFY_SOURCE check I've referenced, there it is 3 lines
> per test expected to crash, but could be done in a single macro too.
> If the failure can be intercepted, it can be done in a single process (e.g.
> SIGABRT can, _exit can't that easily), otherwise perhaps say way to skip
> previous tests and communicate with dejagnu how many times it should run the
> executable.
>
> Jakub

Using setjmp/longjmp to do multiple tests in a single testfile, the
test statements in the front could affect the tests in the back. gtest
will fork a new process for every test statement. The forked process
will do only one test and skip all the other test statements. That is
to say, multiple test statements in the same testfile are guaranteed
to be independent from each other in gtest. If we use setjmp/longjmp
pattern to do the test, existing testsuite may need to be rewritten if
their test statements could affect each other.

Thanks,
Wei.


Re: [Darwin] Do not enable -fvar-tracking at -O0

2012-11-12 Thread Mike Stump
On Nov 9, 2012, at 1:42 AM, Eric Botcazou  wrote:
> this is a regression present on the mainline and 4.7 branch.  -fvar-tracking 
> is automatically enabled on Darwin when -g is passed, including at -O0.  This 
> results in bloated and incomplete debug info.

> OK for mainline and 4.7 branch?

Ok.

Thank you Jack, almost missed this.


Re: [PATCH 00/13] Request to merge Address Sanitizer in

2012-11-12 Thread Jack Howarth
On Mon, Nov 12, 2012 at 05:07:42PM +0100, Dodji Seketeli wrote:
> Following a request from Jakub, and given the fact that the patch set
> have been reviewed by Diego, I have committed the last set of patches I
> have posted to trunk.
> 
> This will hopefully ease the polishing work that has started already.
> 
> I am of course watching for the fall-outs.
> 
> -- 
>   Dodji

Dodji,
I am finding that at r193442 bootstrapping on x86_64-apple-darwin12 fails 
with...

Making all in interception
/bin/sh ../libtool --tag=CXX   --mode=compile 
/sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/./gcc/g++ 
-B/sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/./gcc/ -nostdinc++ 
-nostdinc++ 
-I/sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/x86_64-apple-darwin12.2.0/libstdc++-v3/include/x86_64-apple-darwin12.2.0
 
-I/sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/x86_64-apple-darwin12.2.0/libstdc++-v3/include
 -I/sw/src/fink.build/gcc48-4.8.0-1000/gcc-4.8-20121112/libstdc++-v3/libsupc++ 
-I/sw/src/fink.build/gcc48-4.8.0-1000/gcc-4.8-20121112/libstdc++-v3/include/backward
 
-I/sw/src/fink.build/gcc48-4.8.0-1000/gcc-4.8-20121112/libstdc++-v3/testsuite/util
 
-L/sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/x86_64-apple-darwin12.2.0/libstdc++-v3/src
 
-L/sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/x86_64-apple-darwin12.2.0/libstdc++-v3/src/.libs
 -B/sw/lib/gcc4.8/x86_64-apple-darwin12.2.0/bin/ 
-B/sw/lib/gcc4.8/x86_64-apple-darwin12.2.0/lib/ -isystem 
/sw/lib/gcc4.8/x86_64-apple-darwin12.2.0/include -isystem 
/sw/lib/gcc4.8/x86_64-apple-darwin12.2.0/sys-include-D_GNU_SOURCE -D_DEBUG 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS  -I. 
-I../../../../gcc-4.8-20121112/libsanitizer/interception  -I 
../../../../gcc-4.8-20121112/libsanitizer/include   -Wall -W 
-Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long  -fPIC 
-fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables 
-fvisibility=hidden -Wno-variadic-macros -Wno-c99-extensions  -g -O2 -MT 
interception_mac.lo -MD -MP -MF .deps/interception_mac.Tpo -c -o 
interception_mac.lo 
../../../../gcc-4.8-20121112/libsanitizer/interception/interception_mac.cc
libtool: compile:  /sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/./gcc/g++ 
-B/sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/./gcc/ -nostdinc++ 
-nostdinc++ 
-I/sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/x86_64-apple-darwin12.2.0/libstdc++-v3/include/x86_64-apple-darwin12.2.0
 
-I/sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/x86_64-apple-darwin12.2.0/libstdc++-v3/include
 -I/sw/src/fink.build/gcc48-4.8.0-1000/gcc-4.8-20121112/libstdc++-v3/libsupc++ 
-I/sw/src/fink.build/gcc48-4.8.0-1000/gcc-4.8-20121112/libstdc++-v3/include/backward
 
-I/sw/src/fink.build/gcc48-4.8.0-1000/gcc-4.8-20121112/libstdc++-v3/testsuite/util
 
-L/sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/x86_64-apple-darwin12.2.0/libstdc++-v3/src
 
-L/sw/src/fink.build/gcc48-4.8.0-1000/darwin_objdir/x86_64-apple-darwin12.2.0/libstdc++-v3/src/.libs
 -B/sw/lib/gcc4.8/x86_64-apple-darwin12.2.0/bin/ 
-B/sw/lib/gcc4.8/x86_64-apple-darwin12.2.0/lib/ -isystem 
/sw/lib/gcc4.8/x86_64-apple-darwin12.2.0/include -isystem 
/sw/lib/gcc4.8/x86_64-apple-darwin12.2.0/sys-include -D_GNU_SOURCE -D_DEBUG 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I. 
-I../../../../gcc-4.8-20121112/libsanitizer/interception -I 
../../../../gcc-4.8-20121112/libsanitizer/include -Wall -W 
-Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long -fPIC 
-fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables 
-fvisibility=hidden -Wno-variadic-macros -Wno-c99-extensions -g -O2 -MT 
interception_mac.lo -MD -MP -MF .deps/interception_mac.Tpo -c 
../../../../gcc-4.8-20121112/libsanitizer/interception/interception_mac.cc  
-fno-common -DPIC -o .libs/interception_mac.o
../../../../gcc-4.8-20121112/libsanitizer/interception/interception_mac.cc:16:41:
 fatal error: mach_override/mach_override.h: No such file or directory
 #include "mach_override/mach_override.h"
 ^
compilation terminated.
make[3]: *** [interception_mac.lo] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-target-libsanitizer] Error 2
make: *** [all] Error 2

Is this just from a missing file in the merge or do we need to open a PR for 
this?
 Jack


Re: Asan/Tsan Unit/Regression testing (was [asan] Emit GIMPLE direclty, small cleanups)

2012-11-12 Thread Xinliang David Li
On Mon, Nov 12, 2012 at 12:45 AM, Jakub Jelinek  wrote:
> On Fri, Nov 09, 2012 at 12:03:09PM -0800, Kostya Serebryany wrote:
>> Why depending on gtest is bad?
>
> Because gcc already has way too many dependencies (starting from gmp, mpfr,
> libmpc, graphite dependencies, java depenencies), adding another one just
> for the sake of a couple of asan tests would make life for a lot of
> developers harder.

Can the gtest harness be dropped into GCC repo? Gtest can be used for
testing of  any runtime/hardening feature in the compiler or
libraries.

David


>
> Jakub


Re: [asan] Patch - fix an ICE in asan.c

2012-11-12 Thread Markus Trippelsdorf
Another ICE:

 % cat test.ii
 int i;

 % g++ -faddress-sanitizer -c -g -O1 test.ii
test.ii:1:7: internal compiler error: Segmentation fault
  int i;
   ^
0xa5cb5f crash_signal
/home/markus/gcc/gcc/toplev.c:334
inconsistent DWARF line number info
0x4cf588 cp_classify_record
/home/markus/gcc/gcc/cp/cp-lang.c:131
0x7ee7e3 record_type_tag
/home/markus/gcc/gcc/dwarf2out.c:16914
0x7ee7e3 gen_struct_or_union_type_die
/home/markus/gcc/gcc/dwarf2out.c:19078
0x7ee7e3 gen_tagged_type_die
/home/markus/gcc/gcc/dwarf2out.c:19303
0x7ee7e3 gen_tagged_type_die
/home/markus/gcc/gcc/dwarf2out.c:19246
0x7f5dce gen_type_die_with_usage
/home/markus/gcc/gcc/dwarf2out.c:19450
0x7f6b9c modified_type_die
/home/markus/gcc/gcc/dwarf2out.c:10180
0x7f68c5 modified_type_die
/home/markus/gcc/gcc/dwarf2out.c:10238
0x7f8cd0 add_type_attribute
/home/markus/gcc/gcc/dwarf2out.c:16486
0x7f4bf1 gen_formal_parameter_die
/home/markus/gcc/gcc/dwarf2out.c:17079
0x7f520b gen_formal_types_die
/home/markus/gcc/gcc/dwarf2out.c:17175
0x7f181c gen_subprogram_die
/home/markus/gcc/gcc/dwarf2out.c:17909
0x7f8075 force_decl_die
/home/markus/gcc/gcc/dwarf2out.c:19733
0x7f8721 resolve_addr
/home/markus/gcc/gcc/dwarf2out.c:22661
0x7f83f9 resolve_addr
/home/markus/gcc/gcc/dwarf2out.c:22683
0x7f83f9 resolve_addr
/home/markus/gcc/gcc/dwarf2out.c:22683
0x807392 dwarf2out_finish
/home/markus/gcc/gcc/dwarf2out.c:23305
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See  for instructions.
-- 
Markus


Re: [PATCH 00/13] Request to merge Address Sanitizer in

2012-11-12 Thread Konstantin Serebryany
Folks, please remember that the Clang flag has recently changed to
-fsanitize=address (-fsanitize=thread).
This is hopefully the last syntax change there.

--kcc

On Mon, Nov 12, 2012 at 8:45 AM, Tobias Burnus  wrote:
> Jakub Jelinek:
>
>> On Mon, Nov 12, 2012 at 05:07:42PM +0100, Dodji Seketeli wrote:
>>>
>>> Following a request from Jakub, and given the fact that the patch set
>>> have been reviewed by Diego, I have committed the last set of patches I
>>> have posted to trunk.
>>
>>
>> Thanks, I've committed as obvious the following formatting cleanup.
>
>
> Also thanks from my side!
>
> I have also committed a small patch, which restores the single "-f…"
> (instead of "--f…" vs. "f…" and which moved -faddress-sanitizer from the
> optimization to the debugging option section.
>
> Tobias


Re: [asan] Patch - fix an ICE in asan.c

2012-11-12 Thread Dodji Seketeli
Jakub Jelinek  writes:

> The bug is elsewhere, the following patch should fix this
> (and I've reordered the assignments according to the call arg
> number, so that it is more readable at the same time).
> Ok for trunk?
>
> 2012-11-12  Jakub Jelinek  
>
>   * asan.c (instrument_builtin_call) : Fix up
>   dest assignment.
>
> --- gcc/asan.c.jj 2012-11-12 17:16:16.0 +0100
> +++ gcc/asan.c2012-11-12 17:39:19.673022734 +0100
> @@ -1044,16 +1044,16 @@ instrument_builtin_call (gimple_stmt_ite
>/* (s, s, n) style memops.  */
>  case BUILT_IN_BCMP:
>  case BUILT_IN_MEMCMP:
> -  len = gimple_call_arg (call, 2);
>source0 = gimple_call_arg (call, 0);
>source1 = gimple_call_arg (call, 1);
> +  len = gimple_call_arg (call, 2);
>break;
>  
>/* (src, dest, n) style memops.  */
>  case BUILT_IN_BCOPY:
> -  len = gimple_call_arg (call, 2);
>source0 = gimple_call_arg (call, 0);
> -  dest = gimple_call_arg (call, 2);
> +  dest = gimple_call_arg (call, 1);
> +  len = gimple_call_arg (call, 2);
>break;
>  
>/* (dest, src, n) style memops.  */

Indeed.  I was about to send a similar patch after Tobias' report.

Thanks.

-- 
Dodji


Re: [PATCH 00/13] Request to merge Address Sanitizer in

2012-11-12 Thread Tobias Burnus

Jakub Jelinek:

On Mon, Nov 12, 2012 at 05:07:42PM +0100, Dodji Seketeli wrote:

Following a request from Jakub, and given the fact that the patch set
have been reviewed by Diego, I have committed the last set of patches I
have posted to trunk.


Thanks, I've committed as obvious the following formatting cleanup.


Also thanks from my side!

I have also committed a small patch, which restores the single "-f…" 
(instead of "--f…" vs. "f…" and which moved -faddress-sanitizer from the 
optimization to the debugging option section.


Tobias
Index: gcc/ChangeLog
===
--- gcc/ChangeLog	(Revision 193442)
+++ gcc/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,8 @@
+2012-11-12  Tobias Burnus  
+
+	* doc/invoke.texi: Move -faddress-sanitizer from Optimization
+	Options to Debugging Options.
+
 2012-11-12  Jakub Jelinek  
 
 	* asan.c: Formatting cleanups.
@@ -164,7 +169,7 @@
 
 	* Makefile.in: Add asan.c and its dependencies.
 	* common.opt: Add -faddress-sanitizer option.
-	* invoke.texi: Document the new flag.
+	* doc/invoke.texi: Document the new flag.
 	* passes.c: Add the asan pass.
 	* toplev.c (compile_file): Call asan_finish_file.
 	* asan.c: New file.
Index: gcc/doc/invoke.texi
===
--- gcc/doc/invoke.texi	(Revision 193442)
+++ gcc/doc/invoke.texi	(Arbeitskopie)
@@ -289,7 +289,7 @@ Objective-C and Objective-C++ Dialects}.
 @item Debugging Options
 @xref{Debugging Options,,Options for Debugging Your Program or GCC}.
 @gccoptlist{-d@var{letters}  -dumpspecs  -dumpmachine  -dumpversion @gol
--fdbg-cnt-list -fdbg-cnt=@var{counter-value-list} @gol
+-faddress-sanitizer -fdbg-cnt-list -fdbg-cnt=@var{counter-value-list} @gol
 -fdisable-ipa-@var{pass_name} @gol
 -fdisable-rtl-@var{pass_name} @gol
 -fdisable-rtl-@var{pass-name}=@var{range-list} @gol
@@ -354,10 +354,10 @@ Objective-C and Objective-C++ Dialects}.
 @item Optimization Options
 @xref{Optimize Options,,Options that Control Optimization}.
 @gccoptlist{-falign-functions[=@var{n}] -falign-jumps[=@var{n}] @gol
--falign-labels[=@var{n}] -falign-loops[=@var{n}] -faddress-sanitizer @gol
---fassociative-math fauto-inc-dec -fbranch-probabilities @gol
---fbranch-target-load-optimize fbranch-target-load-optimize2 @gol
---fbtr-bb-exclusive -fcaller-saves @gol
+-falign-labels[=@var{n}] -falign-loops[=@var{n}] @gol
+-fassociative-math -fauto-inc-dec -fbranch-probabilities @gol
+-fbranch-target-load-optimize -fbranch-target-load-optimize2 @gol
+-fbtr-bb-exclusive -fcaller-saves @gol
 -fcheck-data-deps -fcombine-stack-adjustments -fconserve-stack @gol
 -fcompare-elim -fcprop-registers -fcrossjumping @gol
 -fcse-follow-jumps -fcse-skip-blocks -fcx-fortran-rules @gol


Re: [asan] Patch - fix an ICE in asan.c

2012-11-12 Thread Jakub Jelinek
On Mon, Nov 12, 2012 at 04:45:55PM +0100, Tobias Burnus wrote:
> First, I have a small hyphen fix patch, which is on top of your
> merge branch. (The "asan" branch itself is okay.)

This patch is preapproved with appropriate ChangeLog entry.
Thanks.

> --- invoke.texi.orig2012-11-12 15:41:31.0 +0100
> +++ invoke.texi 2012-11-12 15:16:33.856424039 +0100
> @@ -356,5 +356,5 @@ Objective-C and Objective-C++ Dialects}.
>  -falign-labels[=@var{n}] -falign-loops[=@var{n}] -faddress-sanitizer @gol
> ---fassociative-math fauto-inc-dec -fbranch-probabilities @gol
> ---fbranch-target-load-optimize fbranch-target-load-optimize2 @gol
> ---fbtr-bb-exclusive -fcaller-saves @gol
> +-fassociative-math -fauto-inc-dec -fbranch-probabilities @gol
> +-fbranch-target-load-optimize -fbranch-target-load-optimize2 @gol
> +-fbtr-bb-exclusive -fcaller-saves @gol
>  -fcheck-data-deps -fcombine-stack-adjustments -fconserve-stack @gol

> Secondly, the following code fails on both the asan branch and on
> the merge branch with an ICE:
> 
> void TI_ASM_Pack_Inst (const int *opnd)
> {
>   int bopnd[5];
>   __builtin_bcopy(opnd, bopnd, sizeof (bopnd));
> }

The bug is elsewhere, the following patch should fix this
(and I've reordered the assignments according to the call arg
number, so that it is more readable at the same time).
Ok for trunk?

2012-11-12  Jakub Jelinek  

* asan.c (instrument_builtin_call) : Fix up
dest assignment.

--- gcc/asan.c.jj   2012-11-12 17:16:16.0 +0100
+++ gcc/asan.c  2012-11-12 17:39:19.673022734 +0100
@@ -1044,16 +1044,16 @@ instrument_builtin_call (gimple_stmt_ite
   /* (s, s, n) style memops.  */
 case BUILT_IN_BCMP:
 case BUILT_IN_MEMCMP:
-  len = gimple_call_arg (call, 2);
   source0 = gimple_call_arg (call, 0);
   source1 = gimple_call_arg (call, 1);
+  len = gimple_call_arg (call, 2);
   break;
 
   /* (src, dest, n) style memops.  */
 case BUILT_IN_BCOPY:
-  len = gimple_call_arg (call, 2);
   source0 = gimple_call_arg (call, 0);
-  dest = gimple_call_arg (call, 2);
+  dest = gimple_call_arg (call, 1);
+  len = gimple_call_arg (call, 2);
   break;
 
   /* (dest, src, n) style memops.  */


Jakub


Re: [PATCH 00/13] Request to merge Address Sanitizer in

2012-11-12 Thread Jakub Jelinek
On Mon, Nov 12, 2012 at 05:07:42PM +0100, Dodji Seketeli wrote:
> Following a request from Jakub, and given the fact that the patch set
> have been reviewed by Diego, I have committed the last set of patches I
> have posted to trunk.

Thanks, I've committed as obvious the following formatting cleanup.
Mostly whitespace changes, otherwise just removed two more occurrences of
 that shouldn't be there.

--- ChangeLog   (revision 193441)
+++ ChangeLog   (working copy)
@@ -1,4 +1,8 @@
-2012-11-12  Wei Mi 
+2012-11-12  Jakub Jelinek  
+
+   * asan.c: Formatting cleanups.
+
+2012-11-12  Wei Mi  
 
* gcc.c (LINK_COMMAND_SPEC): Add -lasan to link command if
-faddress-sanitizer is on.
@@ -28,7 +32,6 @@
* asan.c (create_cond_insert_point_before_iter): Factorize out of ...
(build_check_stmt): ... here.
 
-
 2012-11-12  Dodji Seketeli  
 
* asan.c (create_cond_insert_point_before_iter): Factorize out of ...
@@ -40,7 +43,7 @@
represented by an SSA_NAME.
 
 2012-11-12  Jakub Jelinek  
-   Wei Mi 
+   Wei Mi  
 
* varasm.c: Include asan.h.
(assemble_noswitch_variable): Grow size by asan_red_zone_size
@@ -111,7 +114,7 @@
 
 2012-11-12  Jakub Jelinek  
Xinliang David Li  
-   Dodji Seketeli 
+   Dodji Seketeli  
 
* Makefile.in (GTFILES): Add $(srcdir)/asan.c.
(asan.o): Update the dependencies of asan.o.
@@ -155,9 +158,9 @@
* config/i386/i386.c (ix86_asan_shadow_offset): New function.
(TARGET_ASAN_SHADOW_OFFSET): Define.
 
-2012-11-12  Wei Mi 
-   Diego Novillo 
-   Dodji Seketeli 
+2012-11-12  Wei Mi  
+   Diego Novillo  
+   Dodji Seketeli  
 
* Makefile.in: Add asan.c and its dependencies.
* common.opt: Add -faddress-sanitizer option.
--- asan.c  (revision 193441)
+++ asan.c  (working copy)
@@ -33,42 +33,41 @@ along with GCC; see the file COPYING3.
 #include "optabs.h"
 #include "output.h"
 
-/*
- AddressSanitizer finds out-of-bounds and use-after-free bugs 
- with <2x slowdown on average.
-
- The tool consists of two parts:
- instrumentation module (this file) and a run-time library.
- The instrumentation module adds a run-time check before every memory insn.
-   For a 8- or 16- byte load accessing address X:
- ShadowAddr = (X >> 3) + Offset
- ShadowValue = *(char*)ShadowAddr;  // *(short*) for 16-byte access.
- if (ShadowValue)
-   __asan_report_load8(X);
-   For a load of N bytes (N=1, 2 or 4) from address X:
- ShadowAddr = (X >> 3) + Offset
- ShadowValue = *(char*)ShadowAddr;
- if (ShadowValue)
-   if ((X & 7) + N - 1 > ShadowValue)
- __asan_report_loadN(X);
- Stores are instrumented similarly, but using __asan_report_storeN functions.
- A call too __asan_init() is inserted to the list of module CTORs.
-
- The run-time library redefines malloc (so that redzone are inserted around
- the allocated memory) and free (so that reuse of free-ed memory is delayed),
- provides __asan_report* and __asan_init functions.
-
- Read more:
- http://code.google.com/p/address-sanitizer/wiki/AddressSanitizerAlgorithm
-
- The current implementation supports detection of out-of-bounds and
- use-after-free in the heap, on the stack and for global variables.
-
- [Protection of stack variables]
-
- To understand how detection of out-of-bounds and use-after-free works
- for stack variables, lets look at this example on x86_64 where the
- stack grows downward:
+/* AddressSanitizer finds out-of-bounds and use-after-free bugs
+   with <2x slowdown on average.
+
+   The tool consists of two parts:
+   instrumentation module (this file) and a run-time library.
+   The instrumentation module adds a run-time check before every memory insn.
+ For a 8- or 16- byte load accessing address X:
+   ShadowAddr = (X >> 3) + Offset
+   ShadowValue = *(char*)ShadowAddr;  // *(short*) for 16-byte access.
+   if (ShadowValue)
+__asan_report_load8(X);
+ For a load of N bytes (N=1, 2 or 4) from address X:
+   ShadowAddr = (X >> 3) + Offset
+   ShadowValue = *(char*)ShadowAddr;
+   if (ShadowValue)
+if ((X & 7) + N - 1 > ShadowValue)
+  __asan_report_loadN(X);
+   Stores are instrumented similarly, but using __asan_report_storeN functions.
+   A call too __asan_init() is inserted to the list of module CTORs.
+
+   The run-time library redefines malloc (so that redzone are inserted around
+   the allocated memory) and free (so that reuse of free-ed memory is delayed),
+   provides __asan_report* and __asan_init functions.
+
+   Read more:
+   http://code.google.com/p/address-sanitizer/wiki/AddressSanitizerAlgorithm
+
+   The current implementation supports detection of out-of-bounds and
+   use-after-free in the heap, on the stack and for global variables.
+
+   [Protection of stack variables]
+
+   To understand how detection of out-of-bounds and use-after-free work

Re: [PATCH 05/10] Implement protection of stack variables

2012-11-12 Thread Dodji Seketeli
Jakub Jelinek  writes:

> On Mon, Nov 12, 2012 at 12:30:37PM +0100, Dodji Seketeli wrote:
>> + For this function, the stack protected by asan will be organized as
>> + follows, from the top of the stack to the bottom:
>> +
>> + Slot 1/ [red zone of 32 bytes called 'RIGHT RedZone']
>> +
>> + Slot 2/ [24 bytes for variable 'a']
>> +
>> + Slot 3/ [8 bytes of red zone, that adds up to the space of 'a' to make
>> +  the next slot be 32 bytes aligned; this one is called Partial
>> +  Redzone; this 32 bytes alignment is an asan constraint]
>
> If you are going from top to bottom, the padding (here Slot 3/) goes above
> the variables, so you need to swap Slot 2/ and 3/, 5/ and 6/ and adjust
> comment for former slot 6/.

Done, committed to trunk.

>
>> +
>> + Slot 4/ [red zone of 32 bytes called 'Middle RedZone']
>> +
>> + Slot 5/ [8 bytes for variable 'b']
>> +
>> + Slot 6/ [24 bytes of Partial Red Zone (similar to slot 3]
>> +
>> + Slot 7/ [32 bytes of Red Zone at the bottom of the stack, called 'LEFT
>> +  RedZone']
>> +
> ...
>> + The shadow memory for that stack layout is going to look like this:
>> +
>> + - content of shadow memory 8 bytes for slot 7: 0xF1F1F1F1.
>
> Please strip the extra leading  from the constants, the stores are
> all 32-bit and the constants are just sign-extended.

Done, committed to trunk.

-- 
Dodji


Re: [PATCH 00/13] Request to merge Address Sanitizer in

2012-11-12 Thread Dodji Seketeli
Following a request from Jakub, and given the fact that the patch set
have been reviewed by Diego, I have committed the last set of patches I
have posted to trunk.

This will hopefully ease the polishing work that has started already.

I am of course watching for the fall-outs.

-- 
Dodji


Re: [PATCH v3] Add support for sparc compare-and-branch

2012-11-12 Thread Rainer Orth
Eric Botcazou  writes:

>> No, quite the contrary.  as is just a (sometimes partial) backport of
>> Studio fbe, though it's hard to tell exactly which Studio version of fbe
>> forms the basis of as.  Especially for the Solaris 10 as patches, only
>> particular bugfixes/enhancements have been backported.
>> 
>> Backward compatibility is maintained, of course.  as(1) lists
>> 
>>  -xarch=v9
>> 
>>  Equivalent to: -m64 -xarch=sparc
>> 
>> and many more.
>
> Does it list -xarch=v8pluse/-xarch=v9e as equivalent to -m32/64 -xarch=sparc4?
> If so, I don't think that we need to change our scheme, using 'e' instead of 
> 'd' for SPARC4 instructions should work just fine with both GNU and Sun as.

as(1) mentions no -xarch value beyond v9b, while strings on the as binary
reveals v9, v9[a-dv], but no v9e.  Seems to be a gas invention.

Rainer

-- 
-
Rainer Orth, Center for Biotechnology, Bielefeld University


Re: [asan] Patch - fix an ICE in asan.c

2012-11-12 Thread Tobias Burnus

Dodji Seketeli wrote:
I believe the neqw series of patches I have juste posted address this 
issue.


Thanks a lot for your merging work! I am really looking forward to have 
it available on the trunk!


I guess that your updated patch fixes the issue as it incorporates 
Jakub's patch. (I have not yet re-build your merge branch but have just 
applied Jakub's patch to the "asan" branch. Cloning your merge branch 
takes quite some time and due to --rebase, a simple "git update" doesn't 
work.)


 * * *

I have two minor issues which can be fixed after committal of the 
patches to the trunk.



First, I have a small hyphen fix patch, which is on top of your merge 
branch. (The "asan" branch itself is okay.)


--- invoke.texi.orig2012-11-12 15:41:31.0 +0100
+++ invoke.texi 2012-11-12 15:16:33.856424039 +0100
@@ -356,5 +356,5 @@ Objective-C and Objective-C++ Dialects}.
 -falign-labels[=@var{n}] -falign-loops[=@var{n}] -faddress-sanitizer @gol
---fassociative-math fauto-inc-dec -fbranch-probabilities @gol
---fbranch-target-load-optimize fbranch-target-load-optimize2 @gol
---fbtr-bb-exclusive -fcaller-saves @gol
+-fassociative-math -fauto-inc-dec -fbranch-probabilities @gol
+-fbranch-target-load-optimize -fbranch-target-load-optimize2 @gol
+-fbtr-bb-exclusive -fcaller-saves @gol
 -fcheck-data-deps -fcombine-stack-adjustments -fconserve-stack @gol


 * * *

Secondly, the following code fails on both the asan branch and on the 
merge branch with an ICE:


void TI_ASM_Pack_Inst (const int *opnd)
{
  int bopnd[5];
  __builtin_bcopy(opnd, bopnd, sizeof (bopnd));
}


The ICE is:

fail7.i:1:6: error: type mismatch in pointer plus expression
  _40 = _39 + _38;
as the operands aren't POINTER_P.


That's fixed by the following patch; I am not sure whether it is fully 
correct, but that patched line is used for both pointers and nonpointers 
in *this* example.


Tobias
diff --git a/gcc/asan.c b/gcc/asan.c
index 639dd9f..42f1abe 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -928,7 +928,8 @@ instrument_mem_region_access (tree base, tree len,
 
   /* _2 = _1 + offset;  */
   region_end =
-gimple_build_assign_with_ops (POINTER_PLUS_EXPR,
+gimple_build_assign_with_ops (POINTER_TYPE_P (TREE_TYPE (base))
+  ? POINTER_PLUS_EXPR : PLUS_EXPR,
   make_ssa_name (TREE_TYPE (base), NULL),
   gimple_assign_lhs (region_end), 
   gimple_assign_lhs (offset));


Re: [PATCH v3] Add support for sparc compare-and-branch

2012-11-12 Thread Eric Botcazou
> No, quite the contrary.  as is just a (sometimes partial) backport of
> Studio fbe, though it's hard to tell exactly which Studio version of fbe
> forms the basis of as.  Especially for the Solaris 10 as patches, only
> particular bugfixes/enhancements have been backported.
> 
> Backward compatibility is maintained, of course.  as(1) lists
> 
>  -xarch=v9
> 
>  Equivalent to: -m64 -xarch=sparc
> 
> and many more.

Does it list -xarch=v8pluse/-xarch=v9e as equivalent to -m32/64 -xarch=sparc4?
If so, I don't think that we need to change our scheme, using 'e' instead of 
'd' for SPARC4 instructions should work just fine with both GNU and Sun as.

-- 
Eric Botcazou


Re: [wwwdocs] Update Fortran secrion in 4.8/changes.html

2012-11-12 Thread Tobias Burnus

Gerald Pfeifer wrote:

One question: in general we are using the term "command-line option".
You are introducing two uses of "flag", and the two existing uses of
that are also in the Fortran section.  Is this Fortran terminology or
would it be fine to make this more consistent?


Well, "flag" is GCC teminology (see "man gcc"), though it seems to be 
only used for the -f* options while I (mis)used it here for -W*. I think 
it is better to use the more common term "command-line option".


Tobias


Re: [wwwdocs] Update Fortran secrion in 4.8/changes.html

2012-11-12 Thread Gerald Pfeifer
On Tue, 21 Aug 2012, Tobias Burnus wrote:
>> I noticed you are using ..., as in e,
>> which we usually don't.  Why that?
> My impression was that a one-letter  didn't stand out enough and 
> looked rather odd; if you think it improves consistency or readability, 
> feel free to change it.

That's actually a good point and a clever idea to use .

> I intent to commit the attached patch to document two new warning flags, 
> which were recently added. (Suggested in ISO/IEC Technical Report 24772 
> "Guidance for Avoiding Vulnerabilities through Language Selection and 
> Use".)

I committed a small follow up patch to this (below).

One question: in general we are using the term "command-line option".
You are introducing two uses of "flag", and the two existing uses of
that are also in the Fortran section.  Is this Fortran terminology or
would it be fine to make this more consistent?

Gerald

Index: changes.html
===
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-4.8/changes.html,v
retrieving revision 1.55
diff -u -3 -p -r1.55 changes.html
--- changes.html11 Nov 2012 09:22:18 -  1.55
+++ changes.html12 Nov 2012 15:17:53 -
@@ -194,7 +194,7 @@ B b(42); // OK
 warnings are issued when comparing REAL or
 COMPLEX types for equality and inequality; consider replacing
 a == b by abs(a−b) < eps with a suitable
-eps. The -Wcompare-reals flag is enabled by
+eps. -Wcompare-reals is enabled by
 -Wextra.
 
 The 

Re: [PATCH v3] Add support for sparc compare-and-branch

2012-11-12 Thread Rainer Orth
Eric Botcazou  writes:

>> I strongly doubt that they will be different from the options
>> supported both in cc and fbe in the Solaris Studio 12.3 release:
>
> They need to provide some form of backward compatibility though, they cannot 
> break the interface of 'as' like that.  Apparently 'fbe' has had its own set 
> of -xarch values for a while and they haven't been compatible with 'as'.

No, quite the contrary.  as is just a (sometimes partial) backport of
Studio fbe, though it's hard to tell exactly which Studio version of fbe
forms the basis of as.  Especially for the Solaris 10 as patches, only
particular bugfixes/enhancements have been backported.

Backward compatibility is maintained, of course.  as(1) lists

 -xarch=v9

 Equivalent to: -m64 -xarch=sparc

and many more.

Rainer

-- 
-
Rainer Orth, Center for Biotechnology, Bielefeld University


[PING, PATCH v2, ARM] 64-bit shifts in NEON

2012-11-12 Thread Ulrich Weigand

http://gcc.gnu.org/ml/gcc-patches/2012-10/msg01521.html

Ping.

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  ulrich.weig...@de.ibm.com



Re: libstdc++ PATCH to add abi tag to complex::real/imag

2012-11-12 Thread Jason Merrill

On 11/12/2012 01:50 AM, Marc Glisse wrote:

When we are changing the whole type, I assume the point of using this
attribute instead of the standard solutions (move it to some other
(inline) namespace, for instance) is the -Wabi-tag warning?


Right.

Jason



bit_field_ref of constructor of vectors

2012-11-12 Thread Marc Glisse

Hello,

this patch lets us fold a bit_field_ref of a constructor even when the 
elements are vectors. Writing a testcase is not that convenient because of 
the lack of a dead code elimination pass after forwprop4 (RTL doesn't 
always remove everything either), but I see a clear difference on this 
test on x86_64 without AVX.


typedef double vec __attribute__((vector_size(4*sizeof(double;
void f(vec*x){
  *x+=*x+*x;
}
double g(vec*x){
  return (*x+*x)[3];
}
void h(vec*x, double a, double b, double c, double d){
  vec y={a,b,c,d};
  *x+=y;
}


I don't know if the patch (assuming it is ok) is suitable for stage 3, it 
may have to wait. It passes bootstrap+testsuite.


I am still not quite sure why we even have a valid_gimple_rhs_p function 
(after which we usually give up if it says no) instead of gimplifying, so 
I may have missed a reason why CONSTRUCTOR or BIT_FIELD_REF shouldn't be 
ok.



2012-11-12  Marc Glisse  

* fold-const.c (fold_ternary_loc) [BIT_FIELD_REF]: Handle
CONSTRUCTOR with vector elements.
* tree-ssa-propagate.c (valid_gimple_rhs_p): Handle CONSTRUCTOR
and BIT_FIELD_REF.

--
Marc GlisseIndex: gcc/fold-const.c
===
--- gcc/fold-const.c(revision 193429)
+++ gcc/fold-const.c(working copy)
@@ -14054,65 +14054,75 @@ fold_ternary_loc (location_t loc, enum t
  unsigned HOST_WIDE_INT n = tree_low_cst (arg1, 1);
  unsigned HOST_WIDE_INT idx = tree_low_cst (op2, 1);
 
  if (n != 0
  && (idx % width) == 0
  && (n % width) == 0
  && ((idx + n) / width) <= TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0)))
{
  idx = idx / width;
  n = n / width;
- if (TREE_CODE (type) == VECTOR_TYPE)
+
+ if (TREE_CODE (arg0) == VECTOR_CST)
{
- if (TREE_CODE (arg0) == VECTOR_CST)
-   {
- tree *vals = XALLOCAVEC (tree, n);
- unsigned i;
- for (i = 0; i < n; ++i)
-   vals[i] = VECTOR_CST_ELT (arg0, idx + i);
- return build_vector (type, vals);
-   }
- else
-   {
- VEC(constructor_elt, gc) *vals;
- unsigned i;
- if (CONSTRUCTOR_NELTS (arg0) == 0)
-   return build_constructor (type, NULL);
- if (TREE_CODE (TREE_TYPE (CONSTRUCTOR_ELT (arg0,
-0)->value))
- != VECTOR_TYPE)
-   {
- vals = VEC_alloc (constructor_elt, gc, n);
- for (i = 0;
-  i < n && idx + i < CONSTRUCTOR_NELTS (arg0);
-  ++i)
-   CONSTRUCTOR_APPEND_ELT (vals, NULL_TREE,
-   CONSTRUCTOR_ELT
- (arg0, idx + i)->value);
- return build_constructor (type, vals);
-   }
-   }
+ if (n == 1)
+   return VECTOR_CST_ELT (arg0, idx);
+
+ tree *vals = XALLOCAVEC (tree, n);
+ for (unsigned i = 0; i < n; ++i)
+   vals[i] = VECTOR_CST_ELT (arg0, idx + i);
+ return build_vector (type, vals);
+   }
+
+ /* Constructor elements can be subvectors.  */
+ unsigned HOST_WIDE_INT k = 1;
+ if (CONSTRUCTOR_NELTS (arg0) != 0)
+   {
+ tree cons_elem = TREE_TYPE (CONSTRUCTOR_ELT (arg0, 0)->value);
+ if (TREE_CODE (cons_elem) == VECTOR_TYPE)
+   k = TYPE_VECTOR_SUBPARTS (cons_elem);
}
- else if (n == 1)
+
+ /* We keep an exact subset of the constructor elements.  */
+ if ((idx % k) == 0 && (n % k) == 0)
{
- if (TREE_CODE (arg0) == VECTOR_CST)
-   return VECTOR_CST_ELT (arg0, idx);
- else if (CONSTRUCTOR_NELTS (arg0) == 0)
-   return build_zero_cst (type);
- else if (TREE_CODE (TREE_TYPE (CONSTRUCTOR_ELT (arg0,
- 0)->value))
-  != VECTOR_TYPE)
+ VEC(constructor_elt, gc) *vals;
+ if (CONSTRUCTOR_NELTS (arg0) == 0)
+   return build_constructor (type, NULL);
+ idx /= k;
+ n /= k;
+ if (n == 1)
{
  if (idx < CONSTRUCTOR_NELTS (arg0))
return CONSTRUCTOR_ELT (arg0, idx)->value;
  return build_zero_

Re: [PATCH] [AArch64] Refactor Advanced SIMD builtin initialisation.

2012-11-12 Thread James Greenhalgh

Hi,

This patch is a cleanup of the initialisation code for the
SIMD builtins in the AArch64 port.

We do this in preparation for later patches supporting
TARGET_BUILTIN_DECL and
TARGET_VECTORIZE_BUILTIN_VECTORIZABLE_FUNCTION.

This patch supersedes another, similar patch I posted a few weeks
ago (http://gcc.gnu.org/ml/gcc-patches/2012-10/msg00532.html) which
was OKed, but not committed.

The patch has been regression tested on aarch64-none-elf.

Is this new version OK to commit?

Thanks,
James Greenhalgh

---
gcc/

2012-10-29  James Greenhalgh  
Tejas Belagod  

* config/aarch64/aarch64-builtins.c
(aarch64_simd_builtin_type_bits): Rename to...
(aarch64_simd_builtin_type_mode): ...this, make sequential.
(aarch64_simd_builtin_datum): Refactor members.
(VAR1, VAR2, ..., VAR12): Update accordingly.
(aarch64_simd_builtin_data): Include from aarch64-simd-builtins.def.
(aarch64_builtins): Update accordingly.
(init_aarch64_simd_builtins): Refactor, rename to...
(aarch64_init_simd_builtins): ...this.
(aarch64_simd_builtin_compare): Remove.
(locate_simd_builtin_icode): Likewise.
* config/aarch64/aarch64-protos.h (aarch64_init_builtins): New.
(aarch64_expand_builtin): New.
* config/aarch64/aarch64-simd-builtins.def: New file.
* config/aarch64/aarch64.c (aarch64_init_builtins):
Move to aarch64-builtins.c.
(aarch64_expand_builtin): Likewise.
* config/aarch64/aarch64.h
(aarch64_builtins): Move to aarch64-builtins.c.
diff --git a/gcc/config/aarch64/aarch64-builtins.c b/gcc/config/aarch64/aarch64-builtins.c
index 429a0df..0ce57d3 100644
--- a/gcc/config/aarch64/aarch64-builtins.c
+++ b/gcc/config/aarch64/aarch64-builtins.c
@@ -31,27 +31,28 @@
 #include "diagnostic-core.h"
 #include "optabs.h"
 
-enum aarch64_simd_builtin_type_bits
+enum aarch64_simd_builtin_type_mode
 {
-  T_V8QI = 0x0001,
-  T_V4HI = 0x0002,
-  T_V2SI = 0x0004,
-  T_V2SF = 0x0008,
-  T_DI = 0x0010,
-  T_DF = 0x0020,
-  T_V16QI = 0x0040,
-  T_V8HI = 0x0080,
-  T_V4SI = 0x0100,
-  T_V4SF = 0x0200,
-  T_V2DI = 0x0400,
-  T_V2DF = 0x0800,
-  T_TI = 0x1000,
-  T_EI = 0x2000,
-  T_OI = 0x4000,
-  T_XI = 0x8000,
-  T_SI = 0x1,
-  T_HI = 0x2,
-  T_QI = 0x4
+  T_V8QI,
+  T_V4HI,
+  T_V2SI,
+  T_V2SF,
+  T_DI,
+  T_DF,
+  T_V16QI,
+  T_V8HI,
+  T_V4SI,
+  T_V4SF,
+  T_V2DI,
+  T_V2DF,
+  T_TI,
+  T_EI,
+  T_OI,
+  T_XI,
+  T_SI,
+  T_HI,
+  T_QI,
+  T_MAX
 };
 
 #define v8qi_UP  T_V8QI
@@ -76,8 +77,6 @@ enum aarch64_simd_builtin_type_bits
 
 #define UP(X) X##_UP
 
-#define T_MAX 19
-
 typedef enum
 {
   AARCH64_SIMD_BINOP,
@@ -124,253 +123,174 @@ typedef struct
 {
   const char *name;
   const aarch64_simd_itype itype;
-  const int bits;
-  const enum insn_code codes[T_MAX];
-  const unsigned int num_vars;
-  unsigned int base_fcode;
+  enum aarch64_simd_builtin_type_mode mode;
+  const enum insn_code code;
+  unsigned int fcode;
 } aarch64_simd_builtin_datum;
 
 #define CF(N, X) CODE_FOR_aarch64_##N##X
 
 #define VAR1(T, N, A) \
-  #N, AARCH64_SIMD_##T, UP (A), { CF (N, A) }, 1, 0
+  {#N, AARCH64_SIMD_##T, UP (A), CF (N, A), 0},
 #define VAR2(T, N, A, B) \
-  #N, AARCH64_SIMD_##T, UP (A) | UP (B), { CF (N, A), CF (N, B) }, 2, 0
+  VAR1 (T, N, A) \
+  VAR1 (T, N, B)
 #define VAR3(T, N, A, B, C) \
-  #N, AARCH64_SIMD_##T, UP (A) | UP (B) | UP (C), \
-  { CF (N, A), CF (N, B), CF (N, C) }, 3, 0
+  VAR2 (T, N, A, B) \
+  VAR1 (T, N, C)
 #define VAR4(T, N, A, B, C, D) \
-  #N, AARCH64_SIMD_##T, UP (A) | UP (B) | UP (C) | UP (D), \
-  { CF (N, A), CF (N, B), CF (N, C), CF (N, D) }, 4, 0
+  VAR3 (T, N, A, B, C) \
+  VAR1 (T, N, D)
 #define VAR5(T, N, A, B, C, D, E) \
-  #N, AARCH64_SIMD_##T, UP (A) | UP (B) | UP (C) | UP (D) | UP (E), \
-  { CF (N, A), CF (N, B), CF (N, C), CF (N, D), CF (N, E) }, 5, 0
+  VAR4 (T, N, A, B, C, D) \
+  VAR1 (T, N, E)
 #define VAR6(T, N, A, B, C, D, E, F) \
-  #N, AARCH64_SIMD_##T, UP (A) | UP (B) | UP (C) | UP (D) | UP (E) | UP (F), \
-  { CF (N, A), CF (N, B), CF (N, C), CF (N, D), CF (N, E), CF (N, F) }, 6, 0
+  VAR5 (T, N, A, B, C, D, E) \
+  VAR1 (T, N, F)
 #define VAR7(T, N, A, B, C, D, E, F, G) \
-  #N, AARCH64_SIMD_##T, UP (A) | UP (B) | UP (C) | UP (D) \
-			| UP (E) | UP (F) | UP (G), \
-  { CF (N, A), CF (N, B), CF (N, C), CF (N, D), CF (N, E), CF (N, F), \
-CF (N, G) }, 7, 0
+  VAR6 (T, N, A, B, C, D, E, F) \
+  VAR1 (T, N, G)
 #define VAR8(T, N, A, B, C, D, E, F, G, H) \
-  #N, AARCH64_SIMD_##T, UP (A) | UP (B) | UP (C) | UP (D) \
-		| UP (E) | UP (F) | UP (G) \
-		| UP (H), \
-  { CF (N, A), CF (N, B), CF (N, C), CF (N, D), CF (N, E), CF (N, F), \
-CF (N, G), CF (N, H) }, 8, 0
+  VAR7 (T, N, A, B, C, D, E, F, G) \
+  VAR1 (T, N, H)
 #define VAR9(T, N, A, B, C, D, E, F, G, H, I) \
-  #N, AARCH64_SIMD_##T, UP (A) | UP (B) | UP (C) | UP (D) \
-		| UP (E) | UP (F) | UP (G) \
-		| UP (H) | UP (I), \
-  { CF (N, A), CF (N, B), CF (N, C), CF (N, D), 

Re: [asan] Patch - fix an ICE in asan.c

2012-11-12 Thread Dodji Seketeli
Tobias Burnus  writes:

> The attached test case ICEs (segfault) both on the asan branch and on
> the trunk with Dodji's patches:

Thank you for reporting this.

I believe the neqw series of patches I have juste posted address this
issue.

To ease the testing, you can check out an updated git tree with all
these patches cleanly stacked on top of trunk by doing:

git clone -b asan-merge-assemble git://seketeli.net/~dodji/gcc.git

You can browse the patchset it via the web at: 

http://seketeli.net/git/~dodji/gcc.git/log/?h=asan-merge-assemble

Cheers.

-- 
Dodji


Re: [PATCH 05/10] Implement protection of stack variables

2012-11-12 Thread Jakub Jelinek
On Mon, Nov 12, 2012 at 12:30:37PM +0100, Dodji Seketeli wrote:
> + For this function, the stack protected by asan will be organized as
> + follows, from the top of the stack to the bottom:
> +
> + Slot 1/ [red zone of 32 bytes called 'RIGHT RedZone']
> +
> + Slot 2/ [24 bytes for variable 'a']
> +
> + Slot 3/ [8 bytes of red zone, that adds up to the space of 'a' to make
> +   the next slot be 32 bytes aligned; this one is called Partial
> +   Redzone; this 32 bytes alignment is an asan constraint]

If you are going from top to bottom, the padding (here Slot 3/) goes above
the variables, so you need to swap Slot 2/ and 3/, 5/ and 6/ and adjust
comment for former slot 6/.

> +
> + Slot 4/ [red zone of 32 bytes called 'Middle RedZone']
> +
> + Slot 5/ [8 bytes for variable 'b']
> +
> + Slot 6/ [24 bytes of Partial Red Zone (similar to slot 3]
> +
> + Slot 7/ [32 bytes of Red Zone at the bottom of the stack, called 'LEFT
> +   RedZone']
> +
...
> + The shadow memory for that stack layout is going to look like this:
> +
> + - content of shadow memory 8 bytes for slot 7: 0xF1F1F1F1.

Please strip the extra leading  from the constants, the stores are
all 32-bit and the constants are just sign-extended.

Jakub


Re: [PATCH 10/10] Import the asan runtime library into GCC tree

2012-11-12 Thread Dodji Seketeli
Diego Novillo  writes:

> On 2012-11-02 16:10 , Dodji Seketeli wrote:
>
>>  * configure.ac: Add libsanitizer to target_libraries.
>>  * Makefile.def: Ditto.
>>  * configure: Regenerate.
>>  * Makefile.in: Regenerate.
>>  * libsanitizer: New directory for asan runtime.  Contains an empty
>>  tsan directory.
>>
>> gcc:
>>  * gcc.c (LINK_COMMAND_SPEC): Add -lasan to link command
>>  if -faddress-sanitizer is on.
>
> OK with Jakub's comments addressed.
>
> References to -fasan in diagnostics should be replaced.  But there's
> been another flag name change upstream, so let's do it together with
> the new flag names.

Done.   This also addresses the comment later made by Tobias below:

Tobias Burnus  writes:

> Other issues:

> * Probably fixed on the branch: gcc/gcc.c still has "fasan" instead of
> "faddress-sanitizer" for the spec:
> +%{fasan:-lasan}

Below is a link to the updated patch.

This patch imports the runtime library in the GCC tree, ensures that
-lasan is passed to the linker when -faddress-sanitizer is used and
sets up the build system accordingly.

 * configure.ac: Add libsanitizer to target_libraries.
* Makefile.def: Ditto.
* configure: Regenerate.
* Makefile.in: Regenerate.
* libsanitizer: New directory for asan runtime.  Contains an empty
tsan directory.

gcc:
* gcc.c (LINK_COMMAND_SPEC): Add -laddress-sanitizer to link command
if -faddress-sanitizer is on.

libsanitizer:

Initial checkin: migrate asan runtime from llvm.

http://people.redhat.com/~dseketel/gcc/patches/0011-Import-the-asan-runtime-library-into-GCC-tree.patch

-- 
Dodji


Re: [PATCH 09/10] Instrument built-in memory access function calls

2012-11-12 Thread Dodji Seketeli
Diego Novillo  writes:

> On 2012-11-02 16:05 , Dodji Seketeli wrote:
>
>> +static bool
>> +maybe_instrument_builtin_call (gimple_stmt_iterator *iter)
>> +{
>> +  gimple call = gsi_stmt (*iter);
>> +  location_t loc = gimple_location (call);
>> +
>> +  if (!is_gimple_call (call))
>> +return false;
>
> Nit.  Why not factor this out and change the caller to:
>
> if (is_builtin_call (stmt))
>instrument_builtin_call (stmt);
>
> I don't much like functions that do many combined things.

OK, I have done that in the first patch below.

The second patch applies on top of this one, and is an update in reply
to the thread brought by Tobias, which title is:

09-nov. [Tobias Burnus ] [asan] Patch - fix an ICE in asan.c

It's a patch that Jakub posted in that sub-thread that I have rebased
(and slightly changed some comments) on top of the first patch.

I think both patches should be squashed to make just one patch.

gcc/
* gimple.h (is_gimple_builtin_call): Declare ...
* gimple.c (is_gimple_builtin_call): ... New public function.
* asan.c (insert_if_then_before_iter, instrument_mem_region_access,
instrument_strlen_call, maybe_instrument_builtin_call,
instrument_call): New static functions.
(create_cond_insert_point): Renamed
create_cond_insert_point_before_iter into this.  Add a new
parameter to decide whether to insert the condition before or
after the statement iterator.
(build_check_stmt): Adjust for the new create_cond_insert_point.
Add a new parameter to decide whether to add the instrumentation
code before or after the statement iterator.
(instrument_assignment): Factorize from ...
(transform_statements): ... here.  Use maybe_instrument_call to
instrument builtin function calls as well.
(instrument_derefs): Adjust for the new parameter of
build_check_stmt.  Fix detection of bit-field access.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/asan@192845 
138bc75d-0d04-0410-961f-82ee72b054a4

fixup! Instrument built-in memory access function calls
---
 gcc/ChangeLog.asan |  20 ++
 gcc/asan.c | 604 ++---
 gcc/gimple.c   |  16 ++
 gcc/gimple.h   |   3 +
 4 files changed, 614 insertions(+), 29 deletions(-)


* asan.c (create_cond_insert_point_before_iter): Factorize out of ...
(build_check_stmt): ... here.
 
diff --git a/gcc/asan.c b/gcc/asan.c
index 527405b..ef855fb 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -521,9 +521,9 @@ asan_init_func (void)
 #define PROB_ALWAYS(REG_BR_PROB_BASE)
 
 /* Split the current basic block and create a condition statement
-   insertion point right before the statement pointed to by ITER.
-   Return an iterator to the point at which the caller might safely
-   insert the condition statement.
+   insertion point right before or after the statement pointed to by
+   ITER.  Return an iterator to the point at which the caller might
+   safely insert the condition statement.
 
THEN_BLOCK must be set to the address of an uninitialized instance
of basic_block.  The function will then set *THEN_BLOCK to the
@@ -537,18 +537,21 @@ asan_init_func (void)
statements starting from *ITER, and *THEN_BLOCK is a new empty
block.
 
-   *ITER is adjusted to still point to the same statement it was
-   *pointing to initially.  */
+   *ITER is adjusted to point to always point to the first statement
+of the basic block * FALLTHROUGH_BLOCK.  That statement is the
+same as what ITER was pointing to prior to calling this function,
+if BEFORE_P is true; otherwise, it is its following statement.  */
 
 static gimple_stmt_iterator
-create_cond_insert_point_before_iter (gimple_stmt_iterator *iter,
- bool then_more_likely_p,
- basic_block *then_block,
- basic_block *fallthrough_block)
+create_cond_insert_point (gimple_stmt_iterator *iter,
+ bool before_p,
+ bool then_more_likely_p,
+ basic_block *then_block,
+ basic_block *fallthrough_block)
 {
   gimple_stmt_iterator gsi = *iter;
 
-  if (!gsi_end_p (gsi))
+  if (!gsi_end_p (gsi) && before_p)
 gsi_prev (&gsi);
 
   basic_block cur_bb = gsi_bb (*iter);
@@ -589,18 +592,58 @@ create_cond_insert_point_before_iter 
(gimple_stmt_iterator *iter,
   return gsi_last_bb (cond_bb);
 }
 
+/* Insert an if condition followed by a 'then block' right before the
+   statement pointed to by ITER.  The fallthrough block -- which is the
+   else block of the condition as well as the destination of the
+   outcoming edge of the 'then block' -- starts with the statement
+   pointed to by ITER.
+
+   COND is the condition of the if.  
+
+   If THEN_MORE_LIKELY_P is true, the probability of the edge to the
+   'the

Re: [PATCH 06/10] Implement protection of global variables

2012-11-12 Thread Dodji Seketeli
Diego Novillo  writes:

> On 2012-11-02 16:01 , Dodji Seketeli wrote:
> 
> > * varasm.c: Include asan.h.
> > (assemble_noswitch_variable): Grow size by asan_red_zone_size
> > if decl is asan protected.
> > (place_block_symbol): Likewise.
> > (assemble_variable): If decl is asan protected, increase
> > DECL_ALIGN if needed, and for decls emitted using
> > assemble_variable_contents append padding zeros after it.
> > * Makefile.in (varasm.o): Depend on asan.h.
> > * asan.c: Include output.h.
> > (asan_pp, asan_pp_initialized, asan_ctor_statements): New variables.
> > (asan_pp_initialize, asan_pp_string): New functions.
> > (asan_emit_stack_protection): Use asan_pp{,_initialized}
> > instead of local pp{,_initialized} vars, use asan_pp_initialize
> > and asan_pp_string helpers.
> > (asan_needs_local_alias, asan_protect_global,
> > asan_global_struct, asan_add_global): New functions.
> > (asan_finish_file): Protect global vars that can be protected. Use
> > asan_ctor_statements instead of ctor_statements
> > * asan.h (asan_protect_global): New prototype.
> > (asan_red_zone_size): New inline function.
> 
> OK.

Thanks.

> Please, also put the high-level description in asan.c's documentation.

Done.  Below is the updated patch.

This patch implements the protection of global variables.  See the
comments appended to the beginning of the asan.c file.

* varasm.c: Include asan.h.
(assemble_noswitch_variable): Grow size by asan_red_zone_size
if decl is asan protected.
(place_block_symbol): Likewise.
(assemble_variable): If decl is asan protected, increase
DECL_ALIGN if needed, and for decls emitted using
assemble_variable_contents append padding zeros after it.
* Makefile.in (varasm.o): Depend on asan.h.
* asan.c: Include output.h.
(asan_pp, asan_pp_initialized, asan_ctor_statements): New variables.
(asan_pp_initialize, asan_pp_string): New functions.
(asan_emit_stack_protection): Use asan_pp{,_initialized}
instead of local pp{,_initialized} vars, use asan_pp_initialize
and asan_pp_string helpers.
(asan_needs_local_alias, asan_protect_global,
asan_global_struct, asan_add_global): New functions.
(asan_finish_file): Protect global vars that can be protected. Use
asan_ctor_statements instead of ctor_statements
* asan.h (asan_protect_global): New prototype.
(asan_red_zone_size): New inline function.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/asan@192541 
138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog.asan |  24 
 gcc/Makefile.in|   2 +-
 gcc/asan.c | 344 +++--
 gcc/asan.h |  11 ++
 gcc/varasm.c   |  22 
 5 files changed, 365 insertions(+), 38 deletions(-)

* Makefile.in (asan.o): Depend on $(EXPR_H) $(OPTABS_H).
(cfgexpand.o): Depend on asan.h.
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 7a0b074..83a424e 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -2719,7 +2719,7 @@ varasm.o : varasm.c $(CONFIG_H) $(SYSTEM_H) coretypes.h 
$(TM_H) $(TREE_H) \
output.h $(DIAGNOSTIC_CORE_H) xcoffout.h debug.h $(GGC_H) $(TM_P_H) \
$(HASHTAB_H) $(TARGET_H) langhooks.h gt-varasm.h $(BASIC_BLOCK_H) \
$(CGRAPH_H) $(TARGET_DEF_H) tree-mudflap.h \
-   pointer-set.h $(COMMON_TARGET_H)
+   pointer-set.h $(COMMON_TARGET_H) asan.h
 function.o : function.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) 
$(RTL_ERROR_H) \
$(TREE_H) $(GIMPLE_H) $(FLAGS_H) $(FUNCTION_H) $(EXPR_H) \
$(OPTABS_H) $(LIBFUNCS_H) $(REGS_H) hard-reg-set.h insn-config.h $(RECOG_H) 
\
diff --git a/gcc/asan.c b/gcc/asan.c
index a3bb47b..c88f59d 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -31,6 +31,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "target.h"
 #include "expr.h"
 #include "optabs.h"
+#include "output.h"
 
 /*
  AddressSanitizer finds out-of-bounds and use-after-free bugs 
@@ -166,7 +167,43 @@ along with GCC; see the file COPYING3.  If not see
  non-accessible) the regions of the red zones and mark the regions of
  stack variables as accessible, and emit some epilogue code to
  un-poison (mark as accessible) the regions of red zones right before
- the function exits.  */
+ the function exits.
+
+ [Protection of global variables]
+
+ The basic idea is to insert a red zone between two global variables
+ and install a constructor function that calls the asan runtime to do
+ the populating of the relevant shadow memory regions at load time.
+
+ So the global variables are laid out as to insert a red zone between
+ them. The size of the red zones is so that each variable starts on a
+ 32 bytes boundary.
+
+ Then a constructor function is installed so that, for each global
+ variable, it calls the runtime asan library function
+ __asan_register_globals_with an instance of this

Re: [PATCH 05/10] Implement protection of stack variables

2012-11-12 Thread Dodji Seketeli
Diego Novillo  writes:

> I believe they layout the stack from right to left (top is to the
> right).  Feels like reading a middle earth map.  Kostya, is my
> recollection correct?

Yes, Konstantin replied to this already but I forgot to update the
patch cover letter (that I keep in the commit log of my commits)
accordingly.  It's now updated to link to the paper where the stack
layout from right to left.

> This is a great summary.  Please put it at the top of asan.c or in
> some other prominent place.

OK, I have put it at the top of asan.c.

> 
> 
> > - offset = alloc_stack_frame_space (stack_vars[i].size, alignb);
> > + if (flag_asan && pred)
> > +   {
> > + HOST_WIDE_INT prev_offset = frame_offset;
> > + tree repr_decl = NULL_TREE;
> > +
> > + offset
> > +   = alloc_stack_frame_space (stack_vars[i].size
> > +  + ASAN_RED_ZONE_SIZE,
> > +  MAX (alignb, ASAN_RED_ZONE_SIZE));
> > + VEC_safe_push (HOST_WIDE_INT, heap, data->asan_vec,
> > +prev_offset);
> > + VEC_safe_push (HOST_WIDE_INT, heap, data->asan_vec,
> > +offset + stack_vars[i].size);
> 
> Oh, gee, thanks.  More VEC() code for me to convert ;)

Sorry.

> The patch is OK.

Thanks.  Below is the modified patch I have in my tree.

* Makefile.in (asan.o): Depend on $(EXPR_H) $(OPTABS_H).
(cfgexpand.o): Depend on asan.h.
* asan.c: Include expr.h and optabs.h.
(asan_shadow_set): New variable.
(asan_shadow_cst, asan_emit_stack_protection): New functions.
(asan_init_shadow_ptr_types): Initialize also asan_shadow_set.
* cfgexpand.c: Include asan.h.  Define HOST_WIDE_INT heap vector.
(partition_stack_vars): If i is large alignment and j small
alignment or vice versa, break out of the loop instead of continue,
and put the test earlier.  If flag_asan, break out of the loop
if for small alignment size is different.
(struct stack_vars_data): New type.
(expand_stack_vars): Add DATA argument.  Change PRED type to
function taking size_t argument instead of tree.  Adjust pred
calls.  Fill DATA in and add needed padding in between variables
if -faddress-sanitizer.
(defer_stack_allocation): Defer everything for flag_asan.
(stack_protect_decl_phase_1, stack_protect_decl_phase_2): Take
size_t index into stack_vars array instead of the decl directly.
(asan_decl_phase_3): New function.
(expand_used_vars): Return var destruction sequence.  Adjust
expand_stack_vars calls, add another one for flag_asan.  Call
asan_emit_stack_protection if expand_stack_vars added anything
to the vectors.
(expand_gimple_basic_block): Add disable_tail_calls argument.
(gimple_expand_cfg): Pass true to it if expand_used_vars returned
non-NULL.  Emit the sequence returned by expand_used_vars after
return_label.
* asan.h (asan_emit_stack_protection): New prototype.
(asan_shadow_set): New decl.
(ASAN_RED_ZONE_SIZE, ASAN_STACK_MAGIC_LEFT, ASAN_STACK_MAGIC_MIDDLE,
ASAN_STACK_MAGIC_RIGHT, ASAN_STACK_FRAME_MAGIC): Define.
(asan_protect_stack_decl): New inline.
* toplev.c (process_options): Also disable -faddress-sanitizer on
!FRAME_GROWS_DOWNWARDS targets.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/asan@192540 
138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog.asan |  38 +++
 gcc/Makefile.in|   4 +-
 gcc/asan.c | 306 +++--
 gcc/asan.h |  31 +-
 gcc/cfgexpand.c| 165 +
 gcc/toplev.c   |   4 +-
 6 files changed, 514 insertions(+), 34 deletions(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index b9a1e74..7a0b074 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -2211,7 +2211,7 @@ stor-layout.o : stor-layout.c $(CONFIG_H) $(SYSTEM_H) 
coretypes.h $(TM_H) \
 asan.o : asan.c asan.h $(CONFIG_H) $(SYSTEM_H) $(GIMPLE_H) \
output.h coretypes.h $(GIMPLE_PRETTY_PRINT_H) \
tree-iterator.h $(TREE_FLOW_H) $(TREE_PASS_H) \
-   $(TARGET_H)
+   $(TARGET_H) $(EXPR_H) $(OPTABS_H)
 tree-ssa-tail-merge.o: tree-ssa-tail-merge.c \
$(SYSTEM_H) $(CONFIG_H) coretypes.h $(TM_H) $(BITMAP_H) \
$(FLAGS_H) $(TM_P_H) $(BASIC_BLOCK_H) \
@@ -3082,7 +3082,7 @@ cfgexpand.o : cfgexpand.c $(TREE_FLOW_H) $(CONFIG_H) 
$(SYSTEM_H) \
$(DIAGNOSTIC_H) toplev.h $(DIAGNOSTIC_CORE_H) $(BASIC_BLOCK_H) $(FLAGS_H) 
debug.h $(PARAMS_H) \
value-prof.h $(TREE_INLINE_H) $(TARGET_H) $(SSAEXPAND_H) $(REGS_H) \
$(GIMPLE_PRETTY_PRINT_H) $(BITMAP_H) sbitmap.h \
-   $(INSN_ATTR_H) $(CFGLOOP_H)
+   $(INSN_ATTR_H) $(CFGLOOP_H) asan.h
 cfgrtl.o : cfgrtl.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_ERROR_H) 
\
$(FLAGS_H) insn-config.h $(BASIC_

Re: [PATCH 01/10] Initial import of asan from the Google branch into trunk

2012-11-12 Thread Dodji Seketeli
Tobias Burnus  writes:

> * -fno-address-sanitizer doesn't work (it does in Clang); it is
> explicitly disabled via RejectNegative in gcc/common.opt
>

Fixed in common.opt by removing the RejectNegative.

I am thus sending the updated patch.

* common.opt: Add -faddress-sanitizer option.
* invoke.texi: Document the new flag.
* passes.c: Add the asan pass.
* toplev.c (compile_file): Call asan_finish_file.
* asan.c: New file.
* asan.h: New file.
* tree-pass.h: Declare pass_asan.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/asan@192360 
138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog.asan  |  12 ++
 gcc/Makefile.in |   5 +
 gcc/asan.c  | 404 
 gcc/asan.h  |  26 
 gcc/common.opt  |   4 +
 gcc/doc/invoke.texi |  13 +-
 gcc/passes.c|   1 +
 gcc/toplev.c|   5 +
 gcc/tree-pass.h |   1 +
 9 files changed, 468 insertions(+), 3 deletions(-)
 create mode 100644 gcc/ChangeLog.asan
 create mode 100644 gcc/asan.c
 create mode 100644 gcc/asan.h

diff --git a/gcc/ChangeLog.asan b/gcc/ChangeLog.asan
new file mode 100644
index 000..704aa61
--- /dev/null
+++ b/gcc/ChangeLog.asan
@@ -0,0 +1,12 @@
+2012-10-10  Wei Mi 
+   Diego Novillo 
+   Dodji Seketeli 
+
+   * Makefile.in: Add asan.c and its dependencies.
+   * common.opt: Add -faddress-sanitizer option.
+   * invoke.texi: Document the new flag.
+   * passes.c: Add the asan pass.
+   * toplev.c (compile_file): Call asan_finish_file.
+   * asan.c: New file.
+   * asan.h: New file.
+   * tree-pass.h: Declare pass_asan.
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 24791a4..dde9b50 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1349,6 +1349,7 @@ OBJS = \
tracer.o \
trans-mem.o \
tree-affine.o \
+   asan.o \
tree-call-cdce.o \
tree-cfg.o \
tree-cfgcleanup.o \
@@ -2207,6 +2208,10 @@ stor-layout.o : stor-layout.c $(CONFIG_H) $(SYSTEM_H) 
coretypes.h $(TM_H) \
$(TREE_H) $(PARAMS_H) $(FLAGS_H) $(FUNCTION_H) $(EXPR_H) $(RTL_H) \
$(GGC_H) $(TM_P_H) $(TARGET_H) langhooks.h $(REGS_H) gt-stor-layout.h \
$(DIAGNOSTIC_CORE_H) $(CGRAPH_H) $(TREE_INLINE_H) $(TREE_DUMP_H) $(GIMPLE_H)
+asan.o : asan.c asan.h $(CONFIG_H) pointer-set.h \
+   $(SYSTEM_H) $(TREE_H) $(GIMPLE_H) \
+   output.h $(DIAGNOSTIC_H) coretypes.h $(TREE_DUMP_H) $(FLAGS_H) \
+   tree-pretty-print.h
 tree-ssa-tail-merge.o: tree-ssa-tail-merge.c \
$(SYSTEM_H) $(CONFIG_H) coretypes.h $(TM_H) $(BITMAP_H) \
$(FLAGS_H) $(TM_P_H) $(BASIC_BLOCK_H) \
diff --git a/gcc/asan.c b/gcc/asan.c
new file mode 100644
index 000..4b07c96
--- /dev/null
+++ b/gcc/asan.c
@@ -0,0 +1,404 @@
+/* AddressSanitizer, a fast memory error detector.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+   Contributed by Kostya Serebryany 
+
+This file is part of GCC.
+
+GCC 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.
+
+GCC 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 GCC; see the file COPYING3.  If not see
+.  */
+
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "tree.h"
+#include "tm_p.h"
+#include "basic-block.h"
+#include "flags.h"
+#include "function.h"
+#include "tree-inline.h"
+#include "gimple.h"
+#include "tree-iterator.h"
+#include "tree-flow.h"
+#include "tree-dump.h"
+#include "tree-pass.h"
+#include "diagnostic.h"
+#include "demangle.h"
+#include "langhooks.h"
+#include "ggc.h"
+#include "cgraph.h"
+#include "gimple.h"
+#include "asan.h"
+#include "gimple-pretty-print.h"
+
+/*
+ AddressSanitizer finds out-of-bounds and use-after-free bugs 
+ with <2x slowdown on average.
+
+ The tool consists of two parts:
+ instrumentation module (this file) and a run-time library.
+ The instrumentation module adds a run-time check before every memory insn.
+   For a 8- or 16- byte load accessing address X:
+ ShadowAddr = (X >> 3) + Offset
+ ShadowValue = *(char*)ShadowAddr;  // *(short*) for 16-byte access.
+ if (ShadowValue)
+   __asan_report_load8(X);
+   For a load of N bytes (N=1, 2 or 4) from address X:
+ ShadowAddr = (X >> 3) + Offset
+ ShadowValue = *(char*)ShadowAddr;
+ if (ShadowValue)
+   if ((X & 7) + N - 1 > ShadowValue)
+ __asan_report_loadN(X);
+ Stores are instrumented similarly, but using __asan_report_storeN functions.
+ A call too __asan_init() is inserted to the list of module CTORs.
+
+ The run

Re: [PATCH 02/10] Initial asan cleanups

2012-11-12 Thread Dodji Seketeli
> On 2012-11-02 15:57 , Dodji Seketeli wrote:
> 
> >   /* AddressSanitizer, a fast memory error detector.
> > -   Copyright (C) 2011 Free Software Foundation, Inc.
> > +   Copyright (C) 2011, 2012 Free Software Foundation, Inc.
> 
> I *think* we should only mention 2012, but I don't know if code in
> branches counts for the copyright years.

I have updated this to 2012 only.

> > +  /* Address Sanitizer needs porting to each target architecture.  */
> > +  if (flag_asan && targetm.asan_shadow_offset == NULL)
> > +{
> > +  warning (0, "-fasan not supported for this target");
> 
> Hm, ASAN's flag is now -fsanitizer=[asan,tsan,memory] or some such.

Oh, right.  Sorry, this flew below my radar. In any case, -fasan is
wrong.  It should be at least -faddress-sanitizer as the rest of the
current patch set.  So I am updating the tree accordingly.

> We will need to make that change.  But it can wait until after the
> initial port is in trunk.

I took the opportunity to just update the message to
-faddress-sanitizer for now.  If that is not OK, please let me know.

> This patch is OK.

Thanks.  Below is what I have in my tree.


* toplev.c (process_options): Warn and turn off
-faddress-sanitizer if not supported by target.
* asan.c: Include target.h.
(asan_scale, asan_offset_log_32, asan_offset_log_64,
asan_offset_log): Removed.
(build_check_stmt): Use ASAN_SHADOW_SHIFT and
targetm.asan_shadow_offset ().
(asan_instrument): Don't initialize asan_offset_log.
* asan.h (ASAN_SHADOW_SHIFT): Define.
* target.def (TARGET_ASAN_SHADOW_OFFSET): New hook.
* doc/tm.texi.in (TARGET_ASAN_SHADOW_OFFSET): Add it.
* doc/tm.texi: Regenerated.
* Makefile.in (asan.o): Depend on $(TARGET_H).
* config/i386/i386.c (ix86_asan_shadow_offset): New function.
(TARGET_ASAN_SHADOW_OFFSET): Define.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/asan@192372 
138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog.asan | 18 ++
 gcc/Makefile.in|  2 +-
 gcc/asan.c | 25 ++---
 gcc/asan.h |  6 +-
 gcc/config/i386/i386.c | 11 +++
 gcc/doc/tm.texi|  6 ++
 gcc/doc/tm.texi.in |  2 ++
 gcc/target.def | 11 +++
 gcc/toplev.c   |  7 +++
 9 files changed, 67 insertions(+), 21 deletions(-)

diff --git a/gcc/ChangeLog.asan b/gcc/ChangeLog.asan
index 704aa61..d13a584 100644
--- a/gcc/ChangeLog.asan
+++ b/gcc/ChangeLog.asan
@@ -1,3 +1,21 @@
+2012-10-11  Jakub Jelinek  
+
+   * toplev.c (process_options): Warn and turn off
+   -faddress-sanitizer if not supported by target.
+   * asan.c: Include target.h.
+   (asan_scale, asan_offset_log_32, asan_offset_log_64,
+   asan_offset_log): Removed.
+   (build_check_stmt): Use ASAN_SHADOW_SHIFT and
+   targetm.asan_shadow_offset ().
+   (asan_instrument): Don't initialize asan_offset_log.
+   * asan.h (ASAN_SHADOW_SHIFT): Define.
+   * target.def (TARGET_ASAN_SHADOW_OFFSET): New hook.
+   * doc/tm.texi.in (TARGET_ASAN_SHADOW_OFFSET): Add it.
+   * doc/tm.texi: Regenerated.
+   * Makefile.in (asan.o): Depend on $(TARGET_H).
+   * config/i386/i386.c (ix86_asan_shadow_offset): New function.
+   (TARGET_ASAN_SHADOW_OFFSET): Define.
+
 2012-10-10  Wei Mi 
Diego Novillo 
Dodji Seketeli 
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index dde9b50..469c72f 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -2211,7 +2211,7 @@ stor-layout.o : stor-layout.c $(CONFIG_H) $(SYSTEM_H) 
coretypes.h $(TM_H) \
 asan.o : asan.c asan.h $(CONFIG_H) pointer-set.h \
$(SYSTEM_H) $(TREE_H) $(GIMPLE_H) \
output.h $(DIAGNOSTIC_H) coretypes.h $(TREE_DUMP_H) $(FLAGS_H) \
-   tree-pretty-print.h
+   tree-pretty-print.h $(TARGET_H)
 tree-ssa-tail-merge.o: tree-ssa-tail-merge.c \
$(SYSTEM_H) $(CONFIG_H) coretypes.h $(TM_H) $(BITMAP_H) \
$(FLAGS_H) $(TM_P_H) $(BASIC_BLOCK_H) \
diff --git a/gcc/asan.c b/gcc/asan.c
index 4b07c96..9655b11 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -1,5 +1,5 @@
 /* AddressSanitizer, a fast memory error detector.
-   Copyright (C) 2011 Free Software Foundation, Inc.
+   Copyright (C) 2012 Free Software Foundation, Inc.
Contributed by Kostya Serebryany 
 
 This file is part of GCC.
@@ -42,6 +42,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple.h"
 #include "asan.h"
 #include "gimple-pretty-print.h"
+#include "target.h"
 
 /*
  AddressSanitizer finds out-of-bounds and use-after-free bugs 
@@ -78,15 +79,6 @@ along with GCC; see the file COPYING3.  If not see
  to create redzones for stack and global object and poison them.
 */
 
-/* The shadow address is computed as (X>>asan_scale) + (1<> asan_scale) + (1 << asan_offset_log).  */
+  /* Build
+ (base_addr >> ASAN_SHADOW_SHIFT) | targetm.asan_shadow_offset ().  */
 
   t = build2 (RSHIFT_EXP

Re: [PATCH 03/11] Emit GIMPLE directly instead of gimplifying GENERIC.

2012-11-12 Thread Dodji Seketeli
[I am replying to several emails at once as I believe they are logically
connected]

Tobias Burnus  writes:

> I tried the 01/10 to 10/10 patch series but it doesn't trigger for the
> following test case:
>
> #include 
> #include 
>
> int
> main() {
>   int *i;
>   i = malloc(10*sizeof(*i));
>   free(i);  /* <<< Free memory. */
>   i[10] = 5;  /* <<< out of boundary even if not freed. */
>   printf("%d\n", i[11]);  /* <<< out of boundary even if not freed. */
>   return 0;
> }
>
> (All of them are reported by Clang.) If I look at the dump (or
> assembler), I see the call to __asan_init, __asan_report_store4 and
> __asan_report_load4. However, when running the program ltrace only
> shows the calls to: __libc_start_main, __asan_init, malloc, free and
> printf. I haven't debugged why the condition is false [see attachment
> for the dump].

Right. As David Xinliang says ...

Xinliang David Li  writes:

> It seems that my one line fix in asan branch (r192605) is not included
> in Dodji's patch set.

That's right.

... I meant to 'squash' this patch into ...

From 72ed51c18dd269ee10fa1b70a919d77de498fc06 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek 
Date: Fri, 2 Nov 2012 23:29:30 +0100
Subject: [PATCH 03/11] Emit GIMPLE directly instead of gimplifying GENERIC.

This patch cleanups the instrumentation code generation by emitting
GIMPLE directly, as opposed to emitting GENERIC tree and then
gimplifying them.  It also does some cleanups here and there

* Makefile.in (GTFILES): Add $(srcdir)/asan.c.
(asan.o): Update the dependencies of asan.o.
* asan.c (tm.h, tree.h, tm_p.h, basic-block.h, flags.h
function.h, tree-inline.h, tree-dump.h, diagnostic.h, demangle.h,
langhooks.h, ggc.h, cgraph.h, gimple.h): Remove these unused but
included headers.
(shadow_ptr_types): New variable.
(report_error_func): Change is_store argument to bool, don't append
newline to function name.
(PROB_VERY_UNLIKELY, PROB_ALWAYS): Define.
(build_check_stmt): Change is_store argument to bool.  Emit GIMPLE
directly instead of creating trees and gimplifying them.  Mark
the error reporting function as very unlikely.
(instrument_derefs): Change is_store argument to bool.  Use
int_size_in_bytes to compute size_in_bytes, simplify size check.
Use build_fold_addr_expr instead of build_addr.
(transform_statements): Adjust instrument_derefs caller.
Use gimple_assign_single_p as stmt test.  Don't look at MEM refs
in rhs2.
(asan_init_shadow_ptr_types): New function.
(asan_instrument): Don't push/pop gimplify context.
Call asan_init_shadow_ptr_types if not yet initialized.
* asan.h (ASAN_SHADOW_SHIFT): Adjust comment.

... this one, to comply with Joseph's comment (in another sub-thread)
which was requesting to avoid sending patches that are knowingly broken
for the sake of sending them chronologically; but I obviously forgot to
do so.

It's now fixed and here is the updated patch that combines both commits:

* Makefile.in (GTFILES): Add $(srcdir)/asan.c.
(asan.o): Update the dependencies of asan.o.
* asan.c (tm.h, tree.h, tm_p.h, basic-block.h, flags.h
function.h, tree-inline.h, tree-dump.h, diagnostic.h, demangle.h,
langhooks.h, ggc.h, cgraph.h, gimple.h): Remove these unused but
included headers.
(shadow_ptr_types): New variable.
(report_error_func): Change is_store argument to bool, don't append
newline to function name.
(PROB_VERY_UNLIKELY, PROB_ALWAYS): Define.
(build_check_stmt): Change is_store argument to bool.  Emit GIMPLE
directly instead of creating trees and gimplifying them.  Mark
the error reporting function as very unlikely.
(instrument_derefs): Change is_store argument to bool.  Use
int_size_in_bytes to compute size_in_bytes, simplify size check.
Use build_fold_addr_expr instead of build_addr.
(transform_statements): Adjust instrument_derefs caller.
Use gimple_assign_single_p as stmt test.  Don't look at MEM refs
in rhs2.
(asan_init_shadow_ptr_types): New function.
(asan_instrument): Don't push/pop gimplify context.
Call asan_init_shadow_ptr_types if not yet initialized.
* asan.h (ASAN_SHADOW_SHIFT): Adjust comment.
---
 gcc/ChangeLog.asan |  28 ++
 gcc/Makefile.in|   9 +-
 gcc/asan.c | 284 +++--
 gcc/asan.h |   2 +-
 4 files changed, 200 insertions(+), 123 deletions(-)

diff --git a/gcc/ChangeLog.asan b/gcc/ChangeLog.asan
index d13a584..0345ac7 100644
--- a/gcc/ChangeLog.asan
+++ b/gcc/ChangeLog.asan
@@ -1,4 +1,32 @@
 2012-10-11  Jakub Jelinek  
+   Xinliang David Li  
+   D

[Patch, Fortran, committed] PR55272 - Fix module handling of coarray scalars

2012-11-12 Thread Tobias Burnus

Thanks for the report Damian! And sorry for the breakage.

Fixed with the following obvious patch (committed as Rev. 193429) after 
an all-language bootstrap/regtesting


Tobias
Index: gcc/fortran/ChangeLog
===
--- gcc/fortran/ChangeLog	(Revision 193427)
+++ gcc/fortran/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,9 @@
+2012-11-12  Tobias Burnus  
+
+	PR fortran/55272
+	* module.c (mio_array_spec): Correctly handle coarray
+	scalars.
+
 2012-11-07  Tobias Schlüter  
 
 	PR fortran/51727
Index: gcc/fortran/module.c
===
--- gcc/fortran/module.c	(Revision 193427)
+++ gcc/fortran/module.c	(Arbeitskopie)
@@ -2395,7 +2395,7 @@ mio_array_spec (gfc_array_spec **asp)
   if (iomode == IO_INPUT && as->corank)
 as->cotype = (as->type == AS_DEFERRED) ? AS_DEFERRED : AS_EXPLICIT;
 
-  if (as->rank > 0)
+  if (as->rank + as->corank > 0)
 for (i = 0; i < as->rank + as->corank; i++)
   {
 	mio_expr (&as->lower[i]);
Index: gcc/testsuite/ChangeLog
===
--- gcc/testsuite/ChangeLog	(Revision 193427)
+++ gcc/testsuite/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,9 @@
+2012-11-12  Tobias Burnus  
+
+	PR fortran/55272
+	* gfortran.dg/coarray_29_1.f90: New.
+	* gfortran.dg/coarray_29_2.f90: New.
+
 2012-11-12  Bin Cheng  
 
 	* gcc.dg/hoist-register-pressure-3.c: New test.
Index: gcc/testsuite/gfortran.dg/coarray_29_1.f90
===
--- gcc/testsuite/gfortran.dg/coarray_29_1.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/coarray_29_1.f90	(Arbeitskopie)
@@ -0,0 +1,16 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=single" }
+
+! To be used by coarray_29_2.f90
+! PR fortran/55272
+
+module co_sum_module
+  implicit none
+contains
+  subroutine co_sum(scalar)
+integer scalar[*]
+  end subroutine
+end module
+
+! DO NOT CLEAN UP THE MODULE FILE - coarray_29_2.f90 does it.
+! { dg-final { keep-modules "" } }
Index: gcc/testsuite/gfortran.dg/coarray_29_2.f90
===
--- gcc/testsuite/gfortran.dg/coarray_29_2.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/coarray_29_2.f90	(Arbeitskopie)
@@ -0,0 +1,18 @@
+! { dg-compile }
+! { dg-options "-fcoarray=single" }
+
+! Requires that coarray_29.f90 has been compiled before
+! and that, thus, co_sum_module is available
+
+! PR fortran/55272
+!
+! Contributed by Damian Rouson
+
+program main
+  use co_sum_module
+  implicit none
+  integer score[*] 
+  call co_sum(score)
+end program
+
+! { dg-final { cleanup-modules "co_sum_module" } }


(committed) gcc/diagnostic.c: Add missing va_end call

2012-11-12 Thread Tobias Burnus

An minor obvious fix, found by Coverity.

Committed as Rev. 193428 after all-language-bootstrap/regtesting on 
x86-64-gnu-linux.


Tobias
Index: gcc/ChangeLog
===
--- gcc/ChangeLog	(Revision 193427)
+++ gcc/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,8 @@
+2012-11-12  Tobias Burnus  
+
+	* diagnostic.c (diagnostic_append_note): Also call va_end when
+	inhibit_notes_p.
+
 2012-11-12  Bin Cheng  
 
 	* gcse.c (struct bb_data): Add new fields, old_pressure, live_in
Index: gcc/diagnostic.c
===
--- gcc/diagnostic.c	(Revision 193427)
+++ gcc/diagnostic.c	(Arbeitskopie)
@@ -833,7 +833,10 @@ diagnostic_append_note (diagnostic_context *contex
   va_start (ap, gmsgid);
   diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_NOTE);
   if (context->inhibit_notes_p)
-return;
+{
+  va_end (ap);
+  return;
+}
   pp_set_prefix (context->printer,
  diagnostic_build_prefix (context, &diagnostic));
   pp_newline (context->printer);


Re: [PATCH] Handle abortTransaction with RTM

2012-11-12 Thread Torvald Riegel
On Fri, 2012-11-09 at 21:54 +0100, Andi Kleen wrote:
> > I'm not sure this is quite true.  If a libitm-executed transaction is
> 
> It's just a convention. You don't have to use it.

That's true ...

> Not doing it will
> just make abort profiling harder.

... but I disagree with this one.  This won't only make profiling
harder, but it also can have a negative impact on performance.  If you
think that there's something wrong with the reasons that I gave for why
this can be a performance issue, please say why you think so instead of
just saying that it's just about profiling.

To avoid the potential performance complications, it would probably be
sufficient to encourage people to follow this convention.  For example,
making sure that libitm and other libraries such as glibc are aware of
it (or, ideally, follow it) would cover most of the combinations I
suppose;  perhaps the convention should also be mentioned in the RTM
intrinsics header file.


Torvald



Re: [PATCH,AArch64] Use CSINC instead of CSEL to return 1

2012-11-12 Thread Marcus Shawcroft

On 06/11/12 18:56, Ian Bolton wrote:

Where a CSEL can return the value 1 as one of the alternatives,
it is usually more efficient to use a CSINC than a CSEL (and
never less efficient), since the value of 1 can be derived from
wzr, rather than needing to set it up in a register first.

This patch enables this capability.

It has been regression tested on trunk.

OK for commit?

Cheers,
Ian


OK, and please backport to ARM/aarch64-4.7-branch

Thanks
/Marcus



Re: [PATCH,AArch64] Optimise comparison where intermediate result not used

2012-11-12 Thread Marcus Shawcroft

On 06/11/12 18:49, Ian Bolton wrote:



OK for trunk?

Cheers,
Ian


2012-11-06  Ian Bolton  

   * gcc/config/aarch64/aarch64.md (*compare_neg): New pattern.
   * gcc/testsuite/gcc.target/aarch64/cmn.c: New test.
   * gcc/testsuite/gcc.target/aarch64/adds.c: New test.
   * gcc/testsuite/gcc.target/aarch64/subs.c: New test.



OK, please back port to ARM/aarch64-4.7-branch.

/Marcus



[patch] PR51477

2012-11-12 Thread Steven Bosscher
Hello,

In this PR, a set to a global reg is removed by fast-dce and ud-dce.
Such sets should always be preserved.

The proposed fix is to make global regs always live. This is done in
the df-* parts of the patch from Jakub (the test case is also his).
In addition, ud-dce should consider sets of global regs inherently
necessary for DCE.

Bootstrapped and tested on x86_64-unknown-linux-gnu. OK for trunk?

Ciao!
Steven

gcc/
PR rtl-optimization/51447
* df-scan.c (df_get_entry_block_def_set): Add global regs to the set.
* df-problems.c (df_lr_local_compute): Make global regs always live.

PR rtl-optimization/51447
* dce.c (deletable_insn_p): Make insns setting a global reg
inherently necessary.

testsuite/
PR rtl-optimization/51447
* gcc.c-torture/execute/pr51447.c: New test.


PR51447.diff
Description: Binary data


Re: [PATCH, i386]: Implement post-reload vzeroupper insertion pass

2012-11-12 Thread Uros Bizjak
On Mon, Nov 12, 2012 at 9:51 AM, Vladimir Yakovlev  wrote:

>  We have not do any changes in mode-switching.c if we use
> pass_mode_switching.pass.execute () for call of the
> optimize_mode_switching() in i386.c.

Even better ;)

In addition to this patch, there are two remaining patches for avx
vzeroupper insertion:

- small fix in mode-switching [1]
- cancelation of vzeroupper insertion if there are live SSE registers
crossing vzeroupper [2]

[1] http://gcc.gnu.org/ml/gcc-patches/2012-11/msg00878.html
[2] http://gcc.gnu.org/ml/gcc-patches/2012-11/msg00742.html

BTW: Is it possible to not top-post your replies? Top-post breaks line
of thoughts somehow ...

Thanks,
Uros.


Re: Asan/Tsan Unit/Regression testing (was [asan] Emit GIMPLE direclty, small cleanups)

2012-11-12 Thread Jakub Jelinek
On Fri, Nov 09, 2012 at 12:03:09PM -0800, Kostya Serebryany wrote:
> Why depending on gtest is bad?

Because gcc already has way too many dependencies (starting from gmp, mpfr,
libmpc, graphite dependencies, java depenencies), adding another one just
for the sake of a couple of asan tests would make life for a lot of
developers harder.

Jakub


Re: [patch RFA middle-end] Fix PR target/41993

2012-11-12 Thread Eric Botcazou
> It looks to me, that we in fact want:
> 
> --cut here--
> Index: mode-switching.c
> ===
> --- mode-switching.c(revision 193407)
> +++ mode-switching.c(working copy)
> @@ -330,7 +330,7 @@
>   short_block = 1;
> break;
>   }
> -   if (copy_start >= FIRST_PSEUDO_REGISTER)
> +   if (!targetm.calls.function_value_regno_p (copy_start))
>   {
> last_insn = return_copy;
> continue;
> --cut here--
> 
> If we find an unrelated HARD register, we will fail in the same way as
> described in the PR. This was found by post-reload vzeroupper
> insertion pass that tripped on unrelated hard reg assignment. At this
> point, we are interested only in hard registers that are also used for
> function return value. Actually, even in pre-reload pass, there are no
> other assignments to hard registers.

Fine with me if this passes testing on x86-avx and SH4.

-- 
Eric Botcazou


Re: [asan] Patch - fix an ICE in asan.c

2012-11-12 Thread Jakub Jelinek
On Sat, Nov 10, 2012 at 07:54:34PM +0100, Tobias Burnus wrote:
> 2012-11-10  Tobias Burnus  
>   Jakub Jelinek  
> 
> * asan.c (maybe_instrument_builtin_call): Set *iter
> to gsi for the call at the end.
>   (transform_statements): Leave loop when gsi_end_p.

But IMHO it is still wrong.  On e.g.
typedef __SIZE_TYPE__ size_t;

size_t
foo (size_t x, char *y)
{
  if (x)
x = __builtin_strlen (y);
  return x;
}

size_t
bar (const char *y, const char *z)
{
  size_t a, b;
  a = __builtin_strlen (y);
  b = __builtin_strlen (z);
  return a + b;
}
you don't want to crash in foo (where there are no statements after
strlen in the same bb (with my previous patch it would still crash),
but in bar you also want to instrument both calls, not just the first one.
So, for strlen we need to make sure gsi_next isn't performed in
transform_statements.

2012-11-12  Jakub Jelinek  

* asan.c (instrument_strlen_call): Return bool whether the call has
been instrumented.
(maybe_instrument_builtin_call): Change return value to mean whether
caller should avoid gsi_next before processing next statement.  Pass
thru return value from instrument_strlen_call.  Set *iter to gsi for
the call at the end.
(maybe_instrument_call): Return bool whether caller should avoid
gsi_next.
(transform_statements): Don't do gsi_next if maybe_instrument_call
returned true.

--- gcc/asan.c.jj   2012-11-02 00:09:22.0 +0100
+++ gcc/asan.c  2012-11-12 09:34:03.226777133 +0100
@@ -824,7 +824,7 @@ instrument_mem_region_access (tree base,
access to the last byte of the argument; it uses the result of the
call to deduce the offset of that last byte.  */
 
-static void
+static bool
 instrument_strlen_call (gimple_stmt_iterator *iter)
 {
   gimple call = gsi_stmt (*iter);
@@ -839,7 +839,7 @@ instrument_strlen_call (gimple_stmt_iter
   if (len == NULL)
 /* Some passes might clear the return value of the strlen call;
bail out in that case.  */
-return;
+return false;
   gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (len)));
 
   location_t loc = gimple_location (call);
@@ -881,13 +881,20 @@ instrument_strlen_call (gimple_stmt_iter
/*before_p=*/false, /*is_store=*/false, 1);
 
   /* Ensure that iter points to the statement logically following the
- one it was initially pointing to.  */
+ one it was initially pointing to.  Return true to inform
+ transform_statements that it shouldn't do gsi_next (&i) in that
+ case, that statement is the first statement in a block that would
+ be otherwise skipped (too high block number), by doing gsi_next (&i)
+ either that statement wouldn't be instrumented or, if there are no
+ statement, transform_statements could crash in gsi_next (&i).  */
   *iter = gsi;
+  return true;
 }
 
-/* if the statement pointed to by the iterator iter is a call to a
-   builtin memory access function, instrument it and return true.
-   otherwise, return false.  */
+/* If the statement pointed to by the iterator iter is a call to a
+   builtin memory access function, instrument it.  Return true
+   if *ITER should be processed next, false if gsi_next should
+   be done on it first.  */
 
 static bool
 maybe_instrument_builtin_call (gimple_stmt_iterator *iter)
@@ -951,8 +958,7 @@ maybe_instrument_builtin_call (gimple_st
   break;
 
 case BUILT_IN_STRLEN:
-  instrument_strlen_call (iter);
-  return true;
+  return instrument_strlen_call (iter);
 
 /* And now the __atomic* and __sync builtins.
These are handled differently from the classical memory memory
@@ -1170,7 +1176,7 @@ maybe_instrument_builtin_call (gimple_st
  gcc_unreachable ();
 
instrument_derefs (iter, dest, loc, is_store);
-   return true;
+   return false;
   }
 
 default:
@@ -1191,7 +1197,8 @@ maybe_instrument_builtin_call (gimple_st
   else if (dest != NULL_TREE)
instrument_mem_region_access (dest, len, iter,
  loc, /*is_store=*/true);
-  return true;
+  *iter = gsi_for_stmt (call);
+  return false;
 }
   return false;
 }
@@ -1217,10 +1224,10 @@ instrument_assignment (gimple_stmt_itera
calls that are instrumented are some built-in functions that access
memory.  Look at maybe_instrument_builtin_call to learn more.  */
 
-static void
+static bool
 maybe_instrument_call (gimple_stmt_iterator *iter)
 {
-  maybe_instrument_builtin_call (iter);
+  return maybe_instrument_builtin_call (iter);
 }
 
 /* asan: this looks too complex. Can this be done simpler? */
@@ -1239,14 +1246,19 @@ transform_statements (void)
   FOR_EACH_BB (bb)
 {
   if (bb->index >= saved_last_basic_block) continue;
-  for (i = gsi_start_bb (bb); !gsi_end_p (i); gsi_next (&i))
+  for (i = gsi_start_bb (bb); !gsi_end_p (i); )
 {
  gimple s = gsi_stmt (i);
 
  if (gimp

Re: [PATCH v3] Add support for sparc compare-and-branch

2012-11-12 Thread Eric Botcazou
> I strongly doubt that they will be different from the options
> supported both in cc and fbe in the Solaris Studio 12.3 release:

They need to provide some form of backward compatibility though, they cannot 
break the interface of 'as' like that.  Apparently 'fbe' has had its own set 
of -xarch values for a while and they haven't been compatible with 'as'.

-- 
Eric Botcazou


Re: [patch RFA middle-end] Fix PR target/41993

2012-11-12 Thread Uros Bizjak
On Tue, Nov 6, 2012 at 9:12 AM, Eric Botcazou  wrote:
>> 2012-11-05  Uros Bizjak  
>>   Kaz Kojima  
>>
>>   PR target/41993
>>   * mode-switching.c (create_pre_exit): Set return_copy to
>>   last_insn when copy_start is a pseudo reg.

It looks to me, that we in fact want:

--cut here--
Index: mode-switching.c
===
--- mode-switching.c(revision 193407)
+++ mode-switching.c(working copy)
@@ -330,7 +330,7 @@
  short_block = 1;
break;
  }
-   if (copy_start >= FIRST_PSEUDO_REGISTER)
+   if (!targetm.calls.function_value_regno_p (copy_start))
  {
last_insn = return_copy;
continue;
--cut here--

If we find an unrelated HARD register, we will fail in the same way as
described in the PR. This was found by post-reload vzeroupper
insertion pass that tripped on unrelated hard reg assignment. At this
point, we are interested only in hard registers that are also used for
function return value. Actually, even in pre-reload pass, there are no
other assignments to hard registers.

Uros.


Re: [RFA:] fix PR55030, wrong code from __builtin_setjmp_receiver

2012-11-12 Thread Eric Botcazou
> This is a target-specific blockage insn, but with the general form
> found in all targets defining it.  The default blockage is an empty
> asm-volatile, which is what cse_insn recognized.  The blockage insn is
> there to "prevent scheduling" of the critical insns and register
> values.  It's almost obvious that an unspec_volatile should have that
> effect "too"; at least that's intended by the code in
> expand_builtin_setjmp_receiver.  Luckily (or unluckily regarding the
> presence of the bug) *this* cse code is not run post-frame-layout
> (post-reload-cse does not use this code), or it seems people would
> soon notice register values used from the wrong side of the blockage,
> considering its critical use at the restore of the stack-pointer.
> As mentioned in the previous patch,
> , clobbering
> the frame-pointer (and then using it) does not seem the logical
> alternative to the patch below; the blockage insn should just do its job.

Agreed.

> I updated comments and documentation so it's more apparent that
> register uses should also not be moved across the blockage; see the
> patched comments.
> 
> Tested native x86_64-unknown-linux-gnu w./wo. -m32 and before/after
> 192677.  Ok to commit?
> 
> gcc:
>   PR middle-end/55030
>   * builtins.c (expand_builtin_setjmp_receiver): Update comment
>   regarding purpose of blockage.
>   * emit-rtl.c [!HAVE_blockage] (gen_blockage): Similarly for
>   the head comment.
>   * doc/md.texi (blockage): Update similarly.  Change wording to
>   require one of two forms, rather than implying a wider choice.
>   * cse.c (cse_insn): Where checking for blocking insns, treat
>   UNSPEC_VOLATILE as blocking, besides volatile ASM.

That's fine on principle, but there is a predicate for this (volatile_insn_p) 
so I think we should use it here.  Moreover, cselib_process_insn has the same 
check so we should adjust it as well, which in turn means that dse.c:scan_insn 
should probably be adjusted too.  OK with these changes, thanks.

-- 
Eric Botcazou


Re: [PATCH, i386]: AMD bdver3 enablement

2012-11-12 Thread Uros Bizjak
On Mon, Nov 12, 2012 at 6:34 AM, Gopalasubramanian, Ganesh
 wrote:
>> You can see from the changes of sse.md that this is functionally a no-op 
>> change.
> Sseshuf replaces sselog.
> So, do you mean it should be added with sselog instead of sseadd?
> Adding it with sseadd (instead of sselog) influences the latency information.

sseshuf replaces sselog in some insn patterns, but should be handled
in the same way in *existing* .md files.

Uros,