Re: [PATCH] Dissociate store_expr's temp from exp so that it is not marked as addressable

2012-03-31 Thread Martin Jambor
Hi,

On Fri, Mar 30, 2012 at 10:03:59AM +0200, Richard Guenther wrote:
> On Fri, 30 Mar 2012, Martin Jambor wrote:
> 
> > Hi,
> > 
> > when testing a patch of mine on sparc64-linux, I came across an Ada
> > bootstrap failure due to a structure DECL which was marked addressable
> > but had a register DECL_RTL (and therefore mem_ref_refers_to_non_mem_p
> > failed to trigger on it).
> > 
> > Mode of the structure was TI (16 bytes int) and it was mistakenly
> > marked as addressable during expansion of an assignment statement in
> > which a 12 byte portion of it was copied to another structure with
> > BLKmode.  Specifically, this happened because expand_assignment called
> > store_expr which loaded the required portion to temporary 12 byte
> > BLKmode MEM_P variable and then called emit_block_move from the
> > temporary to the destination.  emit_block_move_hints then marked
> > MEM_EXPR of the temp as addressable because it handled the copy by
> > emitting a library call.  And MEM_EXPR pointed to the DECL of the
> > source of the assignment which I believe is the bug, thus this patch
> > re-sets MEM_EXPR of temp in these cases.
> > 
> > However, if anybody believes the main issue is elsewhere and another
> > component of this chain of events needs to be fixed, I'll be happy to
> > come up with another patch.  so far this patch has passed bootstrap
> > and testing on x86_64-linux and helped my patch which uncovered this
> > issue to reach stage 3 of bootstrap.
> > 
> > What do you think, is it OK for trunk?
> 
> Hmm, I think this should be done at the point we create the mem - where
> does that happen?

The function gets it by simply calling expand_expr_real:

  temp = expand_expr_real (exp, tmp_target, GET_MODE (target),
   (call_param_p
? EXPAND_STACK_PARM : EXPAND_NORMAL),
   &alt_rtl);

I have reproduced the issue again and looked at how expand_expr_real_1
comes up with the MEM attributes in the COMPONENT_REF case.
The memory-backed temporary is created in:

/* Otherwise, if this is a constant or the object is not in memory
   and need be, put it there.  */
else if (CONSTANT_P (op0) || (!MEM_P (op0) && must_force_mem))
  {
tree nt = build_qualified_type (TREE_TYPE (tem),
(TYPE_QUALS (TREE_TYPE (tem))
 | TYPE_QUAL_CONST));
memloc = assign_temp (nt, 1, 1, 1);
emit_move_insn (memloc, op0);
op0 = memloc;
  }

and at the end of the  case, the bitpos is added by adjust_address,
followed by set_mem_attributes (op0, exp, 0);

Indeed it seems that we should not be calling set_mem_attributes if
op0 is based on such temporary... or perhaps just make sure that we
only clear MEM_EXPR afterwards?

For example, the following patch also passes bootstrap and testing on
x86_64-linux, bootstrap on sparc64 is still running (and IMHO has not
yet reached the critical point).

Thanks,

Martin



Index: gcc/expr.c
===
--- gcc/expr.c  (revision 185792)
+++ gcc/expr.c  (working copy)
@@ -9564,6 +9564,7 @@ expand_expr_real_1 (tree exp, rtx target
tree tem = get_inner_reference (exp, &bitsize, &bitpos, &offset,
&mode1, &unsignedp, &volatilep, true);
rtx orig_op0, memloc;
+   bool do_set_mem_attrs = true;
 
/* If we got back the original object, something is wrong.  Perhaps
   we are evaluating an expression too early.  In any event, don't
@@ -9669,6 +9670,7 @@ expand_expr_real_1 (tree exp, rtx target
memloc = assign_temp (nt, 1, 1, 1);
emit_move_insn (memloc, op0);
op0 = memloc;
+   do_set_mem_attrs = false;
  }
 
if (offset)
@@ -9841,7 +9843,8 @@ expand_expr_real_1 (tree exp, rtx target
emit_move_insn (new_rtx, op0);
op0 = copy_rtx (new_rtx);
PUT_MODE (op0, BLKmode);
-   set_mem_attributes (op0, exp, 1);
+   if (do_set_mem_attrs)
+ set_mem_attributes (op0, exp, 1);
  }
 
return op0;
@@ -9862,7 +9865,8 @@ expand_expr_real_1 (tree exp, rtx target
if (op0 == orig_op0)
  op0 = copy_rtx (op0);
 
-   set_mem_attributes (op0, exp, 0);
+   if (do_set_mem_attrs)
+ set_mem_attributes (op0, exp, 0);
if (REG_P (XEXP (op0, 0)))
  mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
 


Re: [PATCH] Remove bogus assert from CCP's insert_clobbers_for_var

2012-03-31 Thread Martin Jambor
Hi,

On Fri, Mar 30, 2012 at 01:23:00PM +0200, Eric Botcazou wrote:
> > On IRC I've been told that is OK and the that CCP cannot make such
> > assumtions.  Since it is only a missed-optimization if the call to the
> > builtin is not found and processed (basically PR 51491 again but only
> > in cases like these), I thought it best to just remove the assert by
> > the following simple patch, bootstrapped and tested on x86_64-linux.
> 
> Please do that on the 4.7 branch as well if the assertion is incorrect.

Done.

Thanks,

Martin

> 
> -- 
> Eric Botcazou


Re: [PATCH] Remove bogus assert from CCP's insert_clobbers_for_var

2012-03-31 Thread Eric Botcazou
> > Please do that on the 4.7 branch as well if the assertion is incorrect.
>
> Done.

Thanks.  I've now reverted the kludge I put for Ada because of it:
  http://gcc.gnu.org/ml/gcc-patches/2012-03/msg01616.html

-- 
Eric Botcazou


Re: [PATCH][3/n] Cleanup internal interfaces

2012-03-31 Thread Uros Bizjak
Hello!

> 2012-03-29  Richard Guenther  
>
>   * cgraph.h (cgraph_materialize_all_clones): Remove.
>   (reset_inline_failed): Likewise.
>   * cgraphunit.c (cgraph_materialize_all_clones): Make static.
>   * cgraphbuild.c (reset_inline_failed): Remove.
>   * rtl.h (cse_main): Remove.
>   (extended_count): Likewise.

alpha uses extended_count, so the alpha bootstrap currently breaks
after this patch.

Uros.


[PATCH] Add implicit C linkage for win32-specific entry points

2012-03-31 Thread Jacek Caban
This is my first patch to GCC, so please let me know if I did something 
wrong. This patch fixes common annoyance on w64-mingw32 targets, where 
once needs to add explicit "C" linkage to make C++ app work with wmain 
entry point.


* decl.c: Allow custom target implicit C linkage
* mingw-w64.h: Specify entry points with implicit C linkage
* main.C: Added implicit C linkage tests
---
 gcc/config/i386/mingw-w64.h |6 ++
 gcc/cp/decl.c   |8 ++--
 gcc/testsuite/g++.dg/ext/main.C |   24 
 3 files changed, 36 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/main.C


diff --git a/gcc/config/i386/mingw-w64.h b/gcc/config/i386/mingw-w64.h
index a45ce28..1ce940a 100644
--- a/gcc/config/i386/mingw-w64.h
+++ b/gcc/config/i386/mingw-w64.h
@@ -85,3 +85,9 @@ along with GCC; see the file COPYING3.  If not see
   %{static:-Bstatic} %{!static:-Bdynamic} \
   %{shared|mdll: " SUB_LINK_ENTRY " --enable-auto-image-base} \
   %(shared_libgcc_undefs)"
+
+#define CPP_IMPLICIT_TARGET_CLANG(ident) \
+(  !strcmp(ident, "wmain") \
+|| !strcmp(ident, "DllMain") \
+|| !strcmp(ident, "WinMain") \
+|| !strcmp(ident, "wWinMain"))
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index a89523d..307e5c1 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -7290,12 +7290,16 @@ grokfndecl (tree ctype,
   else if (!ctype)
 DECL_CONTEXT (decl) = FROB_CONTEXT (current_decl_namespace ());
 
-  /* `main' and builtins have implicit 'C' linkage.  */
+  /* `main', builtins and some target specific functions have implicit 'C' linkage.  */
   if ((MAIN_NAME_P (declarator)
|| (IDENTIFIER_LENGTH (declarator) > 10
 	   && IDENTIFIER_POINTER (declarator)[0] == '_'
 	   && IDENTIFIER_POINTER (declarator)[1] == '_'
-	   && strncmp (IDENTIFIER_POINTER (declarator)+2, "builtin_", 8) == 0))
+	   && strncmp (IDENTIFIER_POINTER (declarator)+2, "builtin_", 8) == 0)
+#ifdef CPP_IMPLICIT_TARGET_CLANG
+   || CPP_IMPLICIT_TARGET_CLANG(IDENTIFIER_POINTER (declarator))
+#endif
+   )
   && current_lang_name == lang_name_cplusplus
   && ctype == NULL_TREE
   && DECL_FILE_SCOPE_P (decl))
diff --git a/gcc/testsuite/g++.dg/ext/main.C b/gcc/testsuite/g++.dg/ext/main.C
new file mode 100644
index 000..4c5f1ea
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/main.C
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+
+/* Check if entry points get implicit C linkage. If they don't, compiler will
+ * error on incompatible declarations */
+
+int main();
+extern "C" int main();
+
+#ifdef __MINGW32__
+
+int wmain();
+extern "C" int wmain();
+
+int DllMain();
+extern "C" int DllMain();
+
+int WinMain();
+extern "C" int WinMain();
+
+int wWinMain();
+extern "C" int wWinMain();
+
+#endif
+



Re: [PATCH] Add implicit C linkage for win32-specific entry points

2012-03-31 Thread Eric Botcazou
> This is my first patch to GCC, so please let me know if I did something
> wrong. This patch fixes common annoyance on w64-mingw32 targets, where
> once needs to add explicit "C" linkage to make C++ app work with wmain
> entry point.
>
>   * decl.c: Allow custom target implicit C linkage
>   * mingw-w64.h: Specify entry points with implicit C linkage
>   * main.C: Added implicit C linkage tests

There are mutiple ChangeLog files in the tree and you need to write an entry 
for each of them, using a path relative to the directory where it is found:

gcc/ChangeLog
* config/i386/mingw-w64.h: ...

gcc/cp/ChangeLog:
* decl.c: ...

gcc/testsuite/ChangeLog:
* g++.dg/ext/main.C: ...

-- 
Eric Botcazou


[PATCH] Add implicit C linkage for win32-specific entry points

2012-03-31 Thread Jacek Caban

Fixed Changelog as requested by Eric. Thanks.


gcc/ChangeLog
* config/i386/mingw-w64.h: Specify entry points with implicit C linkage

gcc/cp/ChangeLog:
* decl.c: Allow custom target implicit C linkage

gcc/testsuite/ChangeLog:
* g++.dg/ext/main.C: Added implicit C linkage tests
---
 gcc/config/i386/mingw-w64.h |6 ++
 gcc/cp/decl.c   |8 ++--
 gcc/testsuite/g++.dg/ext/main.C |   24 
 3 files changed, 36 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/main.C


diff --git a/gcc/config/i386/mingw-w64.h b/gcc/config/i386/mingw-w64.h
index a45ce28..1ce940a 100644
--- a/gcc/config/i386/mingw-w64.h
+++ b/gcc/config/i386/mingw-w64.h
@@ -85,3 +85,9 @@ along with GCC; see the file COPYING3.  If not see
   %{static:-Bstatic} %{!static:-Bdynamic} \
   %{shared|mdll: " SUB_LINK_ENTRY " --enable-auto-image-base} \
   %(shared_libgcc_undefs)"
+
+#define CPP_IMPLICIT_TARGET_CLANG(ident) \
+(  !strcmp(ident, "wmain") \
+|| !strcmp(ident, "DllMain") \
+|| !strcmp(ident, "WinMain") \
+|| !strcmp(ident, "wWinMain"))
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index a89523d..307e5c1 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -7290,12 +7290,16 @@ grokfndecl (tree ctype,
   else if (!ctype)
 DECL_CONTEXT (decl) = FROB_CONTEXT (current_decl_namespace ());
 
-  /* `main' and builtins have implicit 'C' linkage.  */
+  /* `main', builtins and some target specific functions have implicit 'C' linkage.  */
   if ((MAIN_NAME_P (declarator)
|| (IDENTIFIER_LENGTH (declarator) > 10
 	   && IDENTIFIER_POINTER (declarator)[0] == '_'
 	   && IDENTIFIER_POINTER (declarator)[1] == '_'
-	   && strncmp (IDENTIFIER_POINTER (declarator)+2, "builtin_", 8) == 0))
+	   && strncmp (IDENTIFIER_POINTER (declarator)+2, "builtin_", 8) == 0)
+#ifdef CPP_IMPLICIT_TARGET_CLANG
+   || CPP_IMPLICIT_TARGET_CLANG(IDENTIFIER_POINTER (declarator))
+#endif
+   )
   && current_lang_name == lang_name_cplusplus
   && ctype == NULL_TREE
   && DECL_FILE_SCOPE_P (decl))
diff --git a/gcc/testsuite/g++.dg/ext/main.C b/gcc/testsuite/g++.dg/ext/main.C
new file mode 100644
index 000..4c5f1ea
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/main.C
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+
+/* Check if entry points get implicit C linkage. If they don't, compiler will
+ * error on incompatible declarations */
+
+int main();
+extern "C" int main();
+
+#ifdef __MINGW32__
+
+int wmain();
+extern "C" int wmain();
+
+int DllMain();
+extern "C" int DllMain();
+
+int WinMain();
+extern "C" int WinMain();
+
+int wWinMain();
+extern "C" int wWinMain();
+
+#endif
+



[PATCH]: Restore alpha boostrap by partial revert

2012-03-31 Thread Uros Bizjak
Hello!

Attached patch restores alpha bootstrap.

2012-03-31  Uros Bizjak  

Partially revert:
2012-03-29  Richard Guenther  

* rtl.h (extended_count): Remove.
* combine.c (extended_count): Remove.

Bootstrapped on alphaev68-pc-linux-gnu.

OK for mainline?

Uros.
Index: combine.c
===
--- combine.c   (revision 186039)
+++ combine.c   (working copy)
@@ -9674,6 +9674,31 @@
   return NULL;
 }
 
+/* Return the number of "extended" bits there are in X, when interpreted
+   as a quantity in MODE whose signedness is indicated by UNSIGNEDP.  For
+   unsigned quantities, this is the number of high-order zero bits.
+   For signed quantities, this is the number of copies of the sign bit
+   minus 1.  In both case, this function returns the number of "spare"
+   bits.  For example, if two quantities for which this function returns
+   at least 1 are added, the addition is known not to overflow.
+
+   This function will always return 0 unless called during combine, which
+   implies that it must be called from a define_split.  */
+
+unsigned int
+extended_count (const_rtx x, enum machine_mode mode, int unsignedp)
+{
+  if (nonzero_sign_valid == 0)
+return 0;
+
+  return (unsignedp
+ ? (HWI_COMPUTABLE_MODE_P (mode)
+? (unsigned int) (GET_MODE_PRECISION (mode) - 1
+  - floor_log2 (nonzero_bits (x, mode)))
+: 0)
+ : num_sign_bit_copies (x, mode) - 1);
+}
+
 /* This function is called from `simplify_shift_const' to merge two
outer operations.  Specifically, we have already found that we need
to perform operation *POP0 with constant *PCONST0 at the outermost
Index: rtl.h
===
--- rtl.h   (revision 186039)
+++ rtl.h   (working copy)
@@ -2455,6 +2455,7 @@
 const_rtx, unsigned int);
 
 /* In combine.c  */
+extern unsigned int extended_count (const_rtx, enum machine_mode, int);
 extern rtx remove_death (unsigned int, rtx);
 extern void dump_combine_stats (FILE *);
 extern void dump_combine_total_stats (FILE *);


Re: [Patch ARM] Fix PR51819.

2012-03-31 Thread Ulrich Weigand
Ramana Radhakrishnan wrote:

> PR51819 is a case where we were actually putting out alignment hints
> for the wrong memory size. The attached patch corrects this and
> another latent issue that I spotted.


Your patch did:

/* Only certain alignment specifiers are supported by the hardware.  */
if (memsize == 16 && (align % 32) == 0)
  align_bits = 256;
-   else if ((memsize == 8 || memsize == 16) && (align % 16) == 0)
+   else if (memsize == 16 && (align % 16) == 0)
  align_bits = 128;
-   else if ((align % 8) == 0)
+   else if (memsize >= 8 && (align % 8) == 0)
  align_bits = 64;
else
  align_bits = 0;


However, I'm still seeing incorrect memory hints (with an add-on patch):

  Error: bad alignment -- `vld1.64 {d18-d19},[r3:256]'


The ISA document specifies the following supported alignment hints:

  64  8-byte alignment
 128 16-byte alignment, available only if  contains two or four registers
 256 32-byte alignment, available only if  contains four registers


Shouldn't the check be implemented along the following lines?

if (memsize == 32 && (align % 32) == 0)
  align_bits = 256;
else if ((memsize == 16 || memsize == 32) && (align % 16) == 0)
  align_bits = 128;
else if (memsize >= 8 && (align % 8) == 0)
  align_bits = 64;
else
  align_bits = 0;

Bye,
Ulrich

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



Re: [C Patch]: pr52543

2012-03-31 Thread Kenneth Zadeck
New version of the patch, with all of Richard Sandiford's comments 
applied and retested.


Ok for commit?

Kenny

2012-03-31 Kenneth Zadeck 

* toplev.c (backend_init_target): Call initializer for lower-subreg 
pass.


* lower-subreg.c (target_info): New static var.
(compute_move_cost, profitable_shift_p, init_lower_subreg): New
functions.
(find_pseudo_copy, resolve_simple_move): Added code to only split 
based on costs.

(find_decomposable_subregs): Added code to mark as decomposable
moves that are not profitable.
(find_decomposable_shift_zext): Added code to only decompose
shifts and zext if profitable.
(resolve_shift_zext): Added comment.
(decompose_multiword_subregs): Dump list of profitable
transformations.  Add code to skip non profitable transformations.

*rtl.h(init_lower_subreg): Added declaration.

Index: toplev.c
===
--- toplev.c	(revision 186034)
+++ toplev.c	(working copy)
@@ -1660,6 +1660,7 @@ backend_init_target (void)
   /* rtx_cost is mode-dependent, so cached values need to be recomputed
  on a mode change.  */
   init_expmed ();
+  init_lower_subreg ();
 
   /* We may need to recompute regno_save_code[] and regno_restore_code[]
  after a mode change as well.  */
Index: lower-subreg.c
===
--- lower-subreg.c	(revision 186034)
+++ lower-subreg.c	(working copy)
@@ -41,6 +41,7 @@ along with GCC; see the file COPYING3.
 #include "tree-pass.h"
 #include "df.h"
 
+
 #ifdef STACK_GROWS_DOWNWARD
 # undef STACK_GROWS_DOWNWARD
 # define STACK_GROWS_DOWNWARD 1
@@ -52,10 +53,36 @@ DEF_VEC_P (bitmap);
 DEF_VEC_ALLOC_P (bitmap,heap);
 
 /* Decompose multi-word pseudo-registers into individual
-   pseudo-registers when possible.  This is possible when all the uses
-   of a multi-word register are via SUBREG, or are copies of the
-   register to another location.  Breaking apart the register permits
-   more CSE and permits better register allocation.  */
+   pseudo-registers when possible and profitable.  This is possible
+   when all the uses of a multi-word register are via SUBREG, or are
+   copies of the register to another location.  Breaking apart the
+   register permits more CSE and permits better register allocation.
+   This is profitable if the machine does not have move instructions
+   to do this.  
+
+   This pass only splits moves with modes that are wider than
+   word_mode and ASHIFTs, LSHIFTRTs and ZERO_EXTENDs with integer
+   modes that are twice the width of word_mode.  The latter could be
+   generalized if there was a need to do this, but the trend in
+   architectures is to not need this.
+
+   There are two useful preprocessor defines for use by maintainers:  
+
+   #define LOG_COSTS
+
+   if you wish to see the actual cost estimates that are being used
+   for each mode wider than word mode and the cost estimates for zero
+   extension and the shifts.   This can be useful when port maintainers 
+   are tuning insn rtx costs.
+
+   #define FORCE_LOWERING
+
+   if you wish to test the pass with all the transformation forced on.
+   This can be useful for finding bugs in the transformations.
+
+   Both of these should not be enabled at the same time. */
+
+#define FORCE_LOWERING
 
 /* Bit N in this bitmap is set if regno N is used in a context in
which we can decompose it.  */
@@ -75,8 +102,188 @@ static bitmap subreg_context;
copy from reg M to reg N.  */
 static VEC(bitmap,heap) *reg_copy_graph;
 
-/* Return whether X is a simple object which we can take a word_mode
-   subreg of.  */
+static struct {
+
+  /* This pass can transform 4 different operations: move, ashift,
+ lshiftrt, and zero_extend.  There is a boolean vector for move
+ splitting that is indexed by mode and is true for each mode that is
+ to have its copies split.  The other three operations are only done
+ for one mode so they are only controlled by a single boolean  .*/
+  bool move_modes_to_split[MAX_MACHINE_MODE];
+  
+  /* Other splitting operations to be done on the this platform.  */
+  bool splitting_ashift[MAX_BITS_PER_WORD];
+  bool splitting_lshiftrt[MAX_BITS_PER_WORD];
+  bool splitting_zext;
+
+  bool something_to_do;
+
+  /* Precomputed cost values used to determine if lowering shift
+ operations is profitable.  */ 
+  int word_mode_move_cost;
+  int move_zero_cost;
+} target_info;
+
+/* See what the move cost is.  */
+static int 
+compute_move_cost (enum machine_mode mode)
+{
+  rtx src = gen_rtx_REG (mode, FIRST_PSEUDO_REGISTER);
+  rtx trg = gen_rtx_REG (mode, FIRST_PSEUDO_REGISTER + 1);
+  rtx pat = gen_rtx_SET (VOIDmode, trg, src);
+
+  return insn_rtx_cost (pat, true);
+}
+
+
+/* Return true if it is profitable to lower and shift by SHIFT_AMT.
+   CODE can be either ASHIFT or LSHIFTRT.  */
+static bool
+profitable_shift_p (enum rtx_code code, int shift_amt)
+{
+  rtx trg = gen_rtx_

[PATCH, RFC] Extend __attribute__((format)) with user-specified conversion sequences

2012-03-31 Thread Eddie Kohler

Hi,

Projects not uncommonly extend printf and/or scanf with new conversion 
characters, such gcc's own %< and %> for fancy quotes. Unfortunately, new 
conversion characters make __attribute__((format)) unusable for these 
functions, so errors go uncaught.


This patch adds an extra optional argument to __attribute__((format)) that 
defines new conversion characters.


The syntax is very simple. The extra argument, an even-length C string 
constant, is interpreted as a set of character pairs. For example, "<%" says 
"interpret the character '<' like you would '%'": as a conversion specifier 
that consumes no arguments from the argument list. "Ad" says "interpret 'A' 
like 'd'": as a conversion specifier that consumes an int. "<%>%,%;0" says 
'<', '>', and ',' are zero-argument conversion specifiers, and ';' is a flag 
like '0'.


This is actually pretty flexible, simple to implement, and suffices for my use 
(the Click modular router). Perhaps you see obvious ways I could improve it? A 
full-fledged little language for format string definitions seems like too much 
work for now, unfortunately, but the character-pair syntax could be extended 
later.


Thanks for any comments or feedback,
Eddie Kohler
commit 97fb50f9dd205266ea7bb6e719105909c0d87f80
Author: Eddie Kohler 
Date:   Sat Mar 31 11:44:38 2012 -0400

gcc/c-family/
* c-format.c (check_format_info_main): Support character mappings:
users can change what characters mean per attribute.
(create_dynamic_format_type): New function.
(decode_format_attr): Use it when parsing attributes.
* c-format.h (format_kind_info): Add char_map member.
* c-common.c (c_common_format_attribute_table): Support it.

gcc/doc/
* extend.texi (function attributes): Document it.

Signed-off-by: Eddie Kohler 

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index fc83b04..597f084 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -748,7 +748,7 @@ const struct attribute_spec 
c_common_format_attribute_table[] =
 {
   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
affects_type_identity } */
-  { "format", 3, 3, false, true,  true,
+  { "format", 3, 4, false, true,  true,
  handle_format_attribute, false },
   { "format_arg", 1, 1, false, true,  true,
  handle_format_arg_attribute, false },
diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c
index 9fabc39..cdebfcf 100644
--- a/gcc/c-family/c-format.c
+++ b/gcc/c-family/c-format.c
@@ -76,6 +76,7 @@ typedef struct function_format_info
 
 static bool decode_format_attr (tree, function_format_info *, int);
 static int decode_format_type (const char *);
+static int create_dynamic_format_type (int format_type, const char *char_map);
 
 static bool check_format_string (tree argument,
 unsigned HOST_WIDE_INT format_num,
@@ -274,6 +275,9 @@ decode_format_attr (tree args, function_format_info *info, 
int validated_p)
   tree format_num_expr = TREE_VALUE (TREE_CHAIN (args));
   tree first_arg_num_expr
 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args)));
+  tree char_map_expr = TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (args)));
+  if (char_map_expr)
+char_map_expr = TREE_VALUE (char_map_expr);
 
   if (TREE_CODE (format_type_id) != IDENTIFIER_NODE)
 {
@@ -320,6 +324,20 @@ decode_format_attr (tree args, function_format_info *info, 
int validated_p)
   return false;
 }
 
+  if (char_map_expr != NULL)
+{
+  if (TREE_CODE (char_map_expr) != STRING_CST
+ || (TREE_STRING_LENGTH (char_map_expr) % 2) != 1
+ || TREE_STRING_POINTER (char_map_expr)[TREE_STRING_LENGTH 
(char_map_expr)] != 0)
+   {
+ gcc_assert (!validated_p);
+ error ("%<...%> has invalid format character map");
+ return false;
+   }
+  info->format_type = create_dynamic_format_type (info->format_type,
+ TREE_STRING_POINTER 
(char_map_expr));
+}
+
   if (info->first_arg_num != 0 && info->first_arg_num <= info->format_num)
 {
   gcc_assert (!validated_p);
@@ -831,64 +849,64 @@ static const format_kind_info format_types_orig[] =
 printf_flag_specs, printf_flag_pairs,
 
FMT_FLAG_ARG_CONVERT|FMT_FLAG_DOLLAR_MULTIPLE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_EMPTY_PREC_OK,
 'w', 0, 'p', 0, 'L', 0,
-&integer_type_node, &integer_type_node
+&integer_type_node, &integer_type_node, NULL
   },
   { "asm_fprintf",   asm_fprintf_length_specs,  asm_fprintf_char_table, " 
+#0-", NULL,
 asm_fprintf_flag_specs, asm_fprintf_flag_pairs,
 FMT_FLAG_ARG_CONVERT|FMT_FLAG_EMPTY_PREC_OK,
 'w', 0, 'p', 0, 'L', 0,
-NULL, NULL
+NULL, NULL, NULL
   },
   { "gcc_diag",   gcc_diag_length_specs,  gcc_diag_char_table, "q+#", NULL,
 gcc_diag_flag_specs, gcc_diag_flag_pairs,
 FMT

Re: [IA-64] Work around bug in unwinder

2012-03-31 Thread Eric Botcazou
> Looks ok, given the other ugliness in this macro.

Thanks.  There is another pending workaround for IA-64:
  http://gcc.gnu.org/ml/gcc-patches/2012-03/msg00451.html
as well as an implementation of stack checking in the back-end:
  http://gcc.gnu.org/ml/gcc-patches/2012-03/msg00452.html

-- 
Eric Botcazou


[PATCH] PR c++/40942 - Failure of template specialization partial ordering

2012-03-31 Thread Dodji Seketeli
Hello,

G++ compiles the example below without error:

struct S
{
  template 
  S (T const *) //#0
  { }

  template 
  S (char const (&)[N]) //#1
  { }
};

int
main()
{
  S s1 ("test"); // #3 This should error out because the 
 // call to S constructor is ambiguous.
}

But the call to the constructor at #3 should be considered ambiguous.

G++ considers this call non-ambiguous and chooses #1 because during
overload resolution, the partial ordering of the two constructors ends
up considering that the second S constructor template is more
specialized than the first one.

It does so because it wrongly applies an array-to-pointer decay
conversion to the "array of const char" parameter type of S in #1 (after
the reference-removing conversion that is allowed in that context),
converting it into a "pointer to const char".

That decay conversion is not allowed in the context of partial ordering
of template instantiations ([temp.deduct.partial]/5 lists the
conversions allowed in that context and doesn't mention any decay
conversion).  It is only allowed in the context of a function call.

I believe this behaviour dates back from 2001 when the commit r39604
[1] was added, and the commit r97336 [2] that implemented DR 214
worked hard to keep it.

Here are the change logs of the two commits in question.

[1]:

commit a1d01fd0e4b8bf97295885cfbbf8fe6f382efa4c
Author: nathan 
Date:   Mon Feb 12 14:38:25 2001 +

cp:
* pt.c (maybe_adjust_types_for_deduction, DEDUCE_ORDER case):
Remove spurious information in comment. Allow further
adjustments of REFERENCE_TYPE args.
testsuite:
* g++.old-deja/g++.pt/spec40.C: New test.

[2]:

commit 517ee39a43d80fd91cc7c91c244ca0fc6e1d008e
Author: nathan 
Date:   Thu Mar 31 17:36:17 2005 +

cp:
PR c++/19203, implement DR 214
* call.c (joust): Use more_specialized_fn.
* cp-tree.h (DEDUCE_ORDER): Remove.
(more_specialized): Replace with ...
(more_specialized_fn): ... this.
* pt.c (maybe_adjust_types_for_deduction): Remove DEDUCE_ORDER
case.
(type_unification_real): Remove DEDUCE_ORDER case.
(more_specialized): Replace with ...
(more_specialized_fn): ... this.  Implement DR 214.
(most_specialized_instantiation): Use get_bindings_real directly.
testsuite:
PR c++/19203, DR 214
* g++.dg/parse/ambig3.C: Not ambiguous.
* g++.dg/template/spec20.C: New.
* g++.dg/template/spec21.C: New.

Fixed thus by removing the decay conversion in the context of partial
ordering of template instantiations.

Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk.

gcc/cp/

* pt.c (more_specialized_fn):  Don't apply decay conversion to
types of function parameters.

gcc/testsuite/

* g++.old-deja/g++.pt/spec40.C: Adjust to take the resolution of
DR 214 in account.
---
 gcc/cp/pt.c|   40 
 gcc/testsuite/g++.old-deja/g++.pt/spec40.C |   27 ---
 2 files changed, 23 insertions(+), 44 deletions(-)

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 9b410a7..04ba37d 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -17132,46 +17132,6 @@ more_specialized_fn (tree pat1, tree pat2, int len)
  quals2 = cp_type_quals (arg2);
}
 
-  if ((quals1 < 0) != (quals2 < 0))
-   {
- /* Only of the args is a reference, see if we should apply
-array/function pointer decay to it.  This is not part of
-DR214, but is, IMHO, consistent with the deduction rules
-for the function call itself, and with our earlier
-implementation of the underspecified partial ordering
-rules.  (nathan).  */
- if (quals1 >= 0)
-   {
- switch (TREE_CODE (arg1))
-   {
-   case ARRAY_TYPE:
- arg1 = TREE_TYPE (arg1);
- /* FALLTHROUGH. */
-   case FUNCTION_TYPE:
- arg1 = build_pointer_type (arg1);
- break;
-
-   default:
- break;
-   }
-   }
- else
-   {
- switch (TREE_CODE (arg2))
-   {
-   case ARRAY_TYPE:
- arg2 = TREE_TYPE (arg2);
- /* FALLTHROUGH. */
-   case FUNCTION_TYPE:
- arg2 = build_pointer_type (arg2);
- break;
-
-   default:
- break;
-   }
-   }
-   }
-
   arg1 = TYPE_MAIN_VARIANT (arg1);
   arg2 = TYPE_MAIN_VARIANT (arg2);
 
diff --git a/gcc/testsuite/g++.old-deja/g++.pt/spec40.C 
b/gcc/testsuite/g++.old-deja/g++.pt/spec40.C
index 70abb6f..fc37f41 100644
--- a/gcc/testsuite/g++.old-deja/g++.pt/spec40.C
+++ b/gcc/testsuite/g++.old-deja/g++.pt/spec40.C
@@ 

Re: PATCH: Add OPTION_MASK_ISA_X86_64 and support TARGET_BI_ARCH == 2

2012-03-31 Thread H.J. Lu
On Fri, Mar 30, 2012 at 1:36 PM, H.J. Lu  wrote:
> On Fri, Mar 30, 2012 at 1:23 PM, Jack Howarth  
> wrote:
>> On Fri, Mar 30, 2012 at 11:32:37AM -0700, H.J. Lu wrote:
>>> On Fri, Mar 30, 2012 at 11:05 AM, Jack Howarth  
>>> wrote:
>>> > On Fri, Mar 30, 2012 at 09:18:13AM -0700, H.J. Lu wrote:
>>> >> On Fri, Mar 30, 2012 at 8:11 AM, Rainer Orth
>>> >>  wrote:
>>> >> > Mike Stump  writes:
>>> >> >
>>> >> >>> Here is the new patch.  OK for trunk if there are no regressions on
>>> >> >>> Linux/ia32 and Linux/x86-64?
>>> >> >>
>>> >> >> Too bad you didn't test 32-bit darwin, causes:
>>> >> >>
>>> >> >>   http://gcc.gnu.org/PR52784
>>> >> >>
>>> >> >> Could you please revert or fix, thanks.
>>> >> >
>>> >> > Same problem on Solaris 10 and 11/x86.
>>> >> >
>>> >> >        Rainer
>>> >> >
>>> >>
>>> >> When i[34567]86-*-* targets are configured with --enable-targets=all,
>>> >> TARGET_BI_ARCH is defined as 1, but TARGET_64BIT_DEFAULT
>>> >> isn't defined.  It leads to
>>> >>
>>> >>    if (!TARGET_64BIT)
>>> >>      ix86_isa_flags &= ~(OPTION_MASK_ABI_64 | OPTION_MASK_ABI_X32);
>>> >>
>>> >> Since TARGET_64BIT is false by default, -m64 and -mx32 don't work
>>> >> correctly.  This patch changes TARGET_BI_ARCH to 3 for
>>> >> i[34567]86-*-* targets configured with --enable-targets=all.  Tested on
>>> >> Linux/ia32 with bootstrap and Linux/ia32 with --enable-targets=all
>>> >> --disable-bootstrap.  Please try on other OSes.
>>> >
>>> > H.J.,
>>> >   This patch solves the bootstrap of current gcc trunk on
>>> > i386-apple-darwin10. Thanks.
>>> >          Jack
>>> >
>>>
>>> Here is a smaller patch.
>>
>> H.J.,
>>  The smaller patch also solves the bootstrap failure on i386-apple-darwin10.
>>           Jack
>>
>
> Please ignore the smaller patch since preprocessor may handle
> TARGET_64BIT_DEFAULT properly.
>

Please try this even smaller patch.  If it works for you, I will
check it in as an obvious fix.

Thanks.


-- 
H.J.


gcc-pr52784-2.patch
Description: Binary data


Re: PATCH: Add OPTION_MASK_ISA_X86_64 and support TARGET_BI_ARCH == 2

2012-03-31 Thread Jack Howarth
On Sat, Mar 31, 2012 at 11:20:27AM -0700, H.J. Lu wrote:
> On Fri, Mar 30, 2012 at 1:36 PM, H.J. Lu  wrote:
> > On Fri, Mar 30, 2012 at 1:23 PM, Jack Howarth  
> > wrote:
> >> On Fri, Mar 30, 2012 at 11:32:37AM -0700, H.J. Lu wrote:
> >>> On Fri, Mar 30, 2012 at 11:05 AM, Jack Howarth  
> >>> wrote:
> >>> > On Fri, Mar 30, 2012 at 09:18:13AM -0700, H.J. Lu wrote:
> >>> >> On Fri, Mar 30, 2012 at 8:11 AM, Rainer Orth
> >>> >>  wrote:
> >>> >> > Mike Stump  writes:
> >>> >> >
> >>> >> >>> Here is the new patch.  OK for trunk if there are no regressions on
> >>> >> >>> Linux/ia32 and Linux/x86-64?
> >>> >> >>
> >>> >> >> Too bad you didn't test 32-bit darwin, causes:
> >>> >> >>
> >>> >> >>   http://gcc.gnu.org/PR52784
> >>> >> >>
> >>> >> >> Could you please revert or fix, thanks.
> >>> >> >
> >>> >> > Same problem on Solaris 10 and 11/x86.
> >>> >> >
> >>> >> >        Rainer
> >>> >> >
> >>> >>
> >>> >> When i[34567]86-*-* targets are configured with --enable-targets=all,
> >>> >> TARGET_BI_ARCH is defined as 1, but TARGET_64BIT_DEFAULT
> >>> >> isn't defined.  It leads to
> >>> >>
> >>> >>    if (!TARGET_64BIT)
> >>> >>      ix86_isa_flags &= ~(OPTION_MASK_ABI_64 | OPTION_MASK_ABI_X32);
> >>> >>
> >>> >> Since TARGET_64BIT is false by default, -m64 and -mx32 don't work
> >>> >> correctly.  This patch changes TARGET_BI_ARCH to 3 for
> >>> >> i[34567]86-*-* targets configured with --enable-targets=all.  Tested on
> >>> >> Linux/ia32 with bootstrap and Linux/ia32 with --enable-targets=all
> >>> >> --disable-bootstrap.  Please try on other OSes.
> >>> >
> >>> > H.J.,
> >>> >   This patch solves the bootstrap of current gcc trunk on
> >>> > i386-apple-darwin10. Thanks.
> >>> >          Jack
> >>> >
> >>>
> >>> Here is a smaller patch.
> >>
> >> H.J.,
> >>  The smaller patch also solves the bootstrap failure on 
> >> i386-apple-darwin10.
> >>           Jack
> >>
> >
> > Please ignore the smaller patch since preprocessor may handle
> > TARGET_64BIT_DEFAULT properly.
> >
> 
> Please try this even smaller patch.  If it works for you, I will
> check it in as an obvious fix.

H.J.,
   The latest gcc-pr52784-2.patch patch also allows current gcc trunk to
bootstrap on i386-apple-darwin10.
 Jack

> 
> Thanks.
> 
> 
> -- 
> H.J.




PATCH: PR bootstrap/52812: --enable-targets=all --with-multilib-list=m32,m64,mx32 doesn't work with i686-linux

2012-03-31 Thread H.J. Lu
Hi,

I checked in this patch as an obvious fix to handle -mx32 like -m64.
Tested on Linux/ia32 with

--enable-targets=all --with-multilib-list=m32,m64,mx32

Thanks.

H.J.
--
Index: libgomp/configure.tgt
===
--- libgomp/configure.tgt   (revision 186048)
+++ libgomp/configure.tgt   (working copy)
@@ -59,7 +59,7 @@ if test $enable_linux_futex = yes; then
 i[456]86-*-linux*)
config_path="linux/x86 linux posix"
case " ${CC} ${CFLAGS} " in
- *" -m64 "*)
+ *" -m64 "*|*" -mx32 "*)
;;
  *)
if test -z "$with_arch"; then
Index: libgomp/ChangeLog
===
--- libgomp/ChangeLog   (revision 186048)
+++ libgomp/ChangeLog   (working copy)
@@ -1,3 +1,8 @@
+2012-03-31  H.J. Lu  
+
+   PR bootstrap/52812
+   * configure.tgt (i[456]86-*-linux*): Handle -mx32 like -m64.
+
 2012-03-22  Jakub Jelinek  
 
PR middle-end/52547
Index: libitm/configure.tgt
===
--- libitm/configure.tgt(revision 186048)
+++ libitm/configure.tgt(working copy)
@@ -53,7 +53,7 @@ case "${target_cpu}" in
 
   i[3456]86)
case " ${CC} ${CFLAGS} " in
- *" -m64 "*)
+ *" -m64 "*|*" -mx32 "*)
;;
  *)
if test -z "$with_arch"; then
Index: libitm/ChangeLog
===
--- libitm/ChangeLog(revision 186048)
+++ libitm/ChangeLog(working copy)
@@ -1,3 +1,8 @@
+2012-03-31  H.J. Lu  
+
+   PR bootstrap/52812
+   * configure.tgt (i[456]86-*-linux*): Handle -mx32 like -m64.
+
 2012-03-16  Bernhard Reutner-Fischer  
 
* testsuite/lib/libitm.exp: load fortran-modules.exp