[patch, doc] fix some overfull hboxes

2017-12-17 Thread Sandra Loosemore
I've checked in this patch to fix some formatting problems that caused 
overfull hbox (that is, lines that overflow the margin) warnings when 
building the GCC user manual.


This isn't exhaustive -- in particular, I see that the long CPU names in 
the AArch64 and ARM options sections are causing a pile of both 
underfull and overfull hbox warnings.  I think the solution here is to 
format these lists in a more tabular way instead of as flowed text 
(perhaps like @gccoptlist formatting in the "Option Summary" section) 
and do it that way uniformly for all targets that have such lists. 
That's a bigger project which I'll throw back into the pile for now.


-Sandra
2017-12-17  Sandra Loosemore  

	gcc/
	* doc/extend.texi (x86 Function Attributes): Reformat nocf_check
	example	to avoid overfull hbox.
	* doc/invoke.texi (Option Summary): Add missing @gol.
	(C++ Dialect Options): Reformat -Wnoexcept-type example to avoid 
	overfull hbox.
	
Index: gcc/doc/extend.texi
===
--- gcc/doc/extend.texi	(revision 255772)
+++ gcc/doc/extend.texi	(working copy)
@@ -5765,21 +5765,27 @@ int foo (void) __attribute__(nocf_check)
 void (*foo1)(void) __attribute__(nocf_check);
 void (*foo2)(void);
 
+/* foo's address is assumed to be valid.  */
 int
-foo (void) /* The function's address is assumed to be valid.  */
+foo (void) 
 
-  /* This call site is not checked for control-flow validity.  */
+  /* This call site is not checked for control-flow 
+ validity.  */
   (*foo1)();
 
-  foo1 = foo2; /* A warning is printed about attribute mismatch.  */
-  /* This call site is still not checked for control-flow validity.  */
+  /* A warning is issued about attribute mismatch.  */
+  foo1 = foo2; 
+
+  /* This call site is still not checked.  */
   (*foo1)();
 
-  /* This call site is checked for control-flow validity.  */
+  /* This call site is checked.  */
   (*foo2)();
 
-  foo2 = foo1; /* A warning is printed about attribute mismatch.  */
-  /* This call site is still checked for control-flow validity.  */
+  /* A warning is issued about attribute mismatch.  */
+  foo2 = foo1; 
+
+  /* This call site is still checked.  */
   (*foo2)();
 
   return 0;
Index: gcc/doc/invoke.texi
===
--- gcc/doc/invoke.texi	(revision 255773)
+++ gcc/doc/invoke.texi	(working copy)
@@ -549,7 +549,7 @@ Objective-C and Objective-C++ Dialects}.
 -fdisable-tree-@var{pass-name}=@var{range-list} @gol
 -fdump-noaddr  -fdump-unnumbered  -fdump-unnumbered-links @gol
 -fdump-class-hierarchy@r{[}-@var{n}@r{]} @gol
--fdump-final-insns@r{[}=@var{file}@r{]}
+-fdump-final-insns@r{[}=@var{file}@r{]} @gol
 -fdump-ipa-all  -fdump-ipa-cgraph  -fdump-ipa-inline @gol
 -fdump-lang-all @gol
 -fdump-lang-@var{switch} @gol
@@ -2935,12 +2935,18 @@ Warn if the C++17 feature making @code{n
 type changes the mangled name of a symbol relative to C++14.  Enabled
 by @option{-Wabi} and @option{-Wc++17-compat}.
 
+As an example:
+
 @smallexample
 template  void f(T t) @{ t(); @};
 void g() noexcept;
-void h() @{ f(g); @} // in C++14 calls f, in C++17 calls f
+void h() @{ f(g); @} 
 @end smallexample
 
+@noindent
+In C++14, @code{f} calls calls @code{f}, but in
+C++17 it calls @code{f}.
+
 @item -Wclass-memaccess @r{(C++ and Objective-C++ only)}
 @opindex Wclass-memaccess
 Warn when the destination of a call to a raw memory function such as


Re: [PATCH][arm] Add -mverbose-cost-dump and de-verbosify cost dumps

2017-12-17 Thread Sandra Loosemore

On 12/14/2017 10:50 PM, Sandra Loosemore wrote:

On 12/14/2017 11:48 AM, Kyrill Tkachov wrote:


[snip]

Thanks, done. I haven't created a new Target-specific developers 
options table but instead listed the targets the options apply to in 
parentheses.

Attached is the latest iteration.

Thank you for the review,
Kyrill

2017-12-14  Kyrylo Tkachov  

 * doc/invoke.texi (GCC Developer options): Add Target-specific
 developer options subsection.  Populate it with AArch64 and ARM
 options.
 (Options Summary): List the above.


Hmmm, there are still various problems here, and now I notice that 
there's already an entry for -moverride= in the AArch64 Options section. 
  I need to go through the docs for all targets and make sure everything 
is treated uniformly, so I think it would be more efficient for me to 
take this over than to continue to iterate with you to get the patch 
right.  I'll try to get to it this weekend.


OK, I've checked in the attached patch.

I apologize for having given you a bum steer on this previously.  :-( 
When I dug around in the existing documentation lists, I found a dozen 
or more existing target-specific developer options already listed in the 
sections for the respective targets (FRV, in particular, has a whole 
pile of them documented as "for debugging the compiler").  I thought it 
made more sense in terms of the highly target-specific-ness of what many 
of these options do to leave them all where they are now, as well as 
less work than moving them all to another section.  So I similarly added 
the docs for the missing ARM and AArch64 developer options to the 
existing sections for those respective targets as well.


-Sandra
2017-12-17  Sandra Loosemore  
	Kyrylo Tkachov  

	gcc/
	* doc/invoke.texi (Option Summary): Add -mverbose-cost-dump
	to AArch64 and ARM lists, plus missing -mflip-thumb for ARM.
	(AArch64 Options): Document -mverbose-cost-dump.
	(ARM Options): Likewise, plus -mflip-thumb.
Index: gcc/doc/invoke.texi
===
--- gcc/doc/invoke.texi	(revision 255768)
+++ gcc/doc/invoke.texi	(working copy)
@@ -598,7 +598,8 @@ Objective-C and Objective-C++ Dialects}.
 -mlow-precision-recip-sqrt  -mlow-precision-sqrt  -mlow-precision-div @gol
 -mpc-relative-literal-loads @gol
 -msign-return-address=@var{scope} @gol
--march=@var{name}  -mcpu=@var{name}  -mtune=@var{name}  -moverride=@var{string}}
+-march=@var{name}  -mcpu=@var{name}  -mtune=@var{name}  @gol
+-moverride=@var{string}  -mverbose-cost-dump}
 
 @emph{Adapteva Epiphany Options}
 @gccoptlist{-mhalf-reg-file  -mprefer-short-insn-regs @gol
@@ -648,7 +649,7 @@ Objective-C and Objective-C++ Dialects}.
 -mpic-register=@var{reg} @gol
 -mnop-fun-dllimport @gol
 -mpoke-function-name @gol
--mthumb  -marm @gol
+-mthumb  -marm  -mflip-thumb @gol
 -mtpcs-frame  -mtpcs-leaf-frame @gol
 -mcaller-super-interworking  -mcallee-super-interworking @gol
 -mtp=@var{name}  -mtls-dialect=@var{dialect} @gol
@@ -659,6 +660,7 @@ Objective-C and Objective-C++ Dialects}.
 -mslow-flash-data @gol
 -masm-syntax-unified @gol
 -mrestrict-it @gol
+-mverbose-cost-dump @gol
 -mpure-code @gol
 -mcmse}
 
@@ -14556,6 +14558,11 @@ across releases.
 
 This option is only intended to be useful when developing GCC.
 
+@item -mverbose-cost-dump
+@opindex mverbose-cost-dump
+Enable verbose cost model dumping in the debug dump files.  This option is
+provided for use in debugging the compiler.
+
 @item -mpc-relative-literal-loads
 @itemx -mno-pc-relative-literal-loads
 @opindex mpc-relative-literal-loads
@@ -16237,6 +16244,12 @@ You can also override the ARM and Thumb
 by using the @code{target("thumb")} and @code{target("arm")} function attributes
 (@pxref{ARM Function Attributes}) or pragmas (@pxref{Function Specific Option Pragmas}).
 
+@item -mflip-thumb 
+@opindex mflip-thumb
+Switch ARM/Thumb modes on alternating functions.
+This option is provided for regression testing of mixed Thumb/ARM code
+generation, and is not intended for ordinary use in compiling code.
+
 @item -mtpcs-frame
 @opindex mtpcs-frame
 Generate a stack frame that is compliant with the Thumb Procedure Call
@@ -16351,6 +16364,11 @@ an option used only for regression testi
 intended for ordinary use in compiling code.  This option is disabled
 by default.
 
+@item -mverbose-cost-dump
+@opindex mverbose-cost-dump
+Enable verbose cost model dumping in the debug dump files.  This option is
+provided for use in debugging the compiler.
+
 @item -mpure-code
 @opindex mpure-code
 Do not allow constant data to be placed in code sections.


[committed] correct handling of anti-ranges in -Warray-bounds for built-ins (PR 83446)

2017-12-17 Thread Martin Sebor

I checked in the attached patch to restore i686 bootstrap due
to a -Warray-bounds false positive triggered by the -Wrestrict
enhancement committed yesterday in r255758.

Martin
PR bootstrap/83446 - Bootstrap failed on i686

gcc/testsuite/ChangeLog:

	PR bootstrap/83446
	* c-c++-common/Warray-bounds-3.c: Adjust.
	* gcc.dg/Warray-bounds-25.c: New test.

gcc/ChangeLog:

	PR bootstrap/83446
	* gimple-ssa-warn-restrict.c
	(builtin_memref::offset_out_of_bounds): Correct the handling of
	anti-ranges.

Index: gcc/gimple-ssa-warn-restrict.c
===
--- gcc/gimple-ssa-warn-restrict.c	(revision 255771)
+++ gcc/gimple-ssa-warn-restrict.c	(working copy)
@@ -413,7 +413,9 @@ builtin_memref::offset_out_of_bounds (int strict,
 
   if (DECL_P (base) && TREE_CODE (TREE_TYPE (base)) == ARRAY_TYPE)
 {
-  if (offrng[1] < offrng[0])
+  /* Check for offset in an anti-range with a negative lower bound.
+	 For such a range, consider only the non-negative subrange.  */
+  if (offrng[1] < offrng[0] && offrng[1] < 0)
   	offrng[1] = maxobjsize;
 }
 
Index: gcc/testsuite/c-c++-common/Warray-bounds-3.c
===
--- gcc/testsuite/c-c++-common/Warray-bounds-3.c	(revision 255771)
+++ gcc/testsuite/c-c++-common/Warray-bounds-3.c	(working copy)
@@ -123,8 +123,11 @@ void test_memcpy_bounds_anti_range (char *d, const
  (yet).  */
   T (char, 9, a, a + SAR ( 1,  6), 3);   /* { dg-warning "forming offset \\\[9, 0] is out of the bounds \\\[0, 9] of object " "memcpy" { xfail *-*-* } } */
 
-  T (char, 9, a, a + SAR ( 2,  6), 3);   /* { dg-warning "forming offset 10 is out of the bounds \\\[0, 9] of object " "memcpy" } */
-  T (char, 9, a, a + SAR ( 3,  6), 3);   /* { dg-warning "forming offset 10 is out of the bounds \\\[0, 9] of object " "memcpy" } */
+  /* The range of offsets is the union of [0, 1] and [7, PTRDIFF_MAX]
+ of which the first subrange is valid and thus no warming for memcpy
+ is issued.  Similarly for the next test.  */
+  T (char, 9, a, a + SAR ( 2,  6), 3);
+  T (char, 9, a, a + SAR ( 3,  6), 3);
 
   T (char, 9, a, a + SAR (-1,  7), 3);   /* { dg-warning "forming offset \\\[10, 11] is out of the bounds \\\[0, 9] of object " "memcpy" } */
   T (char, 9, a, a + SAR (-2,  8), 3);   /* { dg-warning "forming offset \\\[10, 12] is out of the bounds \\\[0, 9] of object " "memcpy" } */
Index: gcc/testsuite/gcc.dg/Warray-bounds-25.c
===
--- gcc/testsuite/gcc.dg/Warray-bounds-25.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/Warray-bounds-25.c	(working copy)
@@ -0,0 +1,33 @@
+/* PR tree-optimization/83446 - Bootstrap failed on i686
+   { dg-do compile }
+   { dg-options "-O2 -Warray-bounds" } */
+
+char a[4];
+
+void f0i (void *d, int n)
+{
+  if (n < 0) n = 0;
+
+  __builtin_memcpy (d, a + sizeof a - n, n);
+}
+
+void f0L (void *d, long n)
+{
+  if (n < 0) n = 0;
+
+  __builtin_memcpy (d, a + sizeof a - n, n);
+}
+
+void f0u (void *d, unsigned n)
+{
+  if (n < 0) n = 1;
+
+  __builtin_memcpy (d, a + sizeof a - n, n);   /* { dg-bogus "\\\[-Warray-bounds" } */
+}
+
+void f1lu (void *d, unsigned long n)
+{
+  if (n < 1) n = 1;
+
+  __builtin_memcpy (d, a + sizeof a - n, n);   /* { dg-bogus "\\\[-Warray-bounds" } */
+}


[v2 of PATCH 06/14] Strip location wrappers in operand_equal_p

2017-12-17 Thread David Malcolm
On Mon, 2017-12-11 at 18:37 -0500, Jason Merrill wrote:
> On 11/10/2017 04:45 PM, David Malcolm wrote:
> > gcc/c-family/ChangeLog:
> > * c-warn.c (sizeof_pointer_memaccess_warning): Strip any
> > location
> > wrappers from src and dest.
> 
> Here the existing calls to tree_strip_nop_conversions ought to
> handle 
> the wrappers.

They don't; when EXP is a VIEW_CONVERT_EXPR wrapper around a VAR_DECL...

11887   static inline bool
11888   tree_nop_conversion (const_tree exp)
11889   {
11890 tree outer_type, inner_type;
11891   
11892 if (!CONVERT_EXPR_P (exp)
11893 && TREE_CODE (exp) != NON_LVALUE_EXPR)
11894   return false;

...tree_nop_conversion bails out at this "return false;", and hence
tree_strip_nop_conversions simply returns the wrapper that was passed
in.

I tried adding fold_for_warn on src and dest, but it doesn't do quite
the right thing, as
  FAIL: c-c++-common/Wsizeof-pointer-memaccess2.c  -std=gnu++98  (test for 
warnings, line 482)
  FAIL: c-c++-common/Wsizeof-pointer-memaccess2.c  -std=gnu++98  (test for 
warnings, line 483)
  FAIL: c-c++-common/Wsizeof-pointer-memaccess2.c  -std=gnu++98  (test for 
warnings, line 484)
...due to "src" changing from being a VAR_DECL to being its STRING_CST
value after the fold_for_warn,

So one approach for Wsizeof-pointer-memaccess*.c is the patch I posted
("[PATCH 06/14] Fix Wsizeof-pointer-memaccess*.c"), which ensures that
any wrappers have been stripped before the call to operand_equal_p in
sizeof_pointer_memaccess_warning.

Alternatively, here's a patch which strips wrappers in operand_equal_p.
FWIW I prefer doing it in sizeof_pointer_memaccess_warning, rather than
touching operand_equal_p.

What do you think?

Successfully bootstrapped on x86_64-pc-linux-gnu, as
part of the kit.

gcc/ChangeLog:
* fold-const.c (operand_equal_p): Strip any location wrappers,
before computing hashes.
---
 gcc/fold-const.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 0f11076..2b938900 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -2804,6 +2804,9 @@ combine_comparisons (location_t loc,
 int
 operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
 {
+  STRIP_ANY_LOCATION_WRAPPER (arg0);
+  STRIP_ANY_LOCATION_WRAPPER (arg1);
+
   /* When checking, verify at the outermost operand_equal_p call that
  if operand_equal_p returns non-zero then ARG0 and ARG1 has the same
  hash value.  */
-- 
1.8.5.3



[i386] PR81842 [CET] -fcf-protection -mcet is incompatible with makecontext family functions

2017-12-17 Thread Tsimbalist, Igor V
-fcf-protection -mcet is incompatible with makecontext family functions
since they can't properly set up and destroy shadow stack pointer. This
change provides a mechanism to help detection shadow stack compatibility.
The current proposal is to add -mcheck-shstk-compat option which will
predefine __CHECK_SHSTK_COMPAT__ macro. The option will be
set on by default.  Then we can add a code

#if defined __SHSTK__ && defined __CHECK_SHSTK_COMPAT__
# error This source is incompatible with -mshstk
#endif

to .

Ok for trunk?

Igor


0001-Add-mcheck-shstk-compat.patch
Description: 0001-Add-mcheck-shstk-compat.patch


[patch, doc] fix paste-o (?)

2017-12-17 Thread Sandra Loosemore
Here's another trivial cleanup for an error in the manual I spotted 
while looking for something else:  in the ARC Options section, there was 
an @opindex and description for -mlra, but no @item table entry.  Looks 
like this was probably a cut-and-paste error.


Patch committed as obvious.

-Sandra
2017-12-17  Sandra Loosemore  

	gcc/
	* doc/invoke.texi (ARC Options): Add missing -mlra entry.
Index: gcc/doc/invoke.texi
===
--- gcc/doc/invoke.texi	(revision 255766)
+++ gcc/doc/invoke.texi	(working copy)
@@ -15335,6 +15335,7 @@ Enable the use of indexed loads.  This c
 optimizers then assume that indexed stores exist, which is not
 the case.
 
+@item -mlra
 @opindex mlra
 Enable Local Register Allocation.  This is still experimental for ARC,
 so by default the compiler uses standard reload


[PATCH, testsuite]: Avoid -Wformat warnings in guality.h

2017-12-17 Thread Uros Bizjak
The patch avoids following -Wformat warnings for 64bit targets:

guality.h: In function ‘guality_check’:
guality.h:366:19: warning: format ‘%lli’ expects argument of type
‘long long int’, but argument 4 has type ‘gualchk_t’ {aka ‘long int’}
[-Wformat=]
  fprintf (stderr, "PASS: " GUALITY_TEST ": %s is %lli\n", name, value);

2017-12-17  Uros Bizjak  

* gcc.dg/guality/guality.h (guality_check): Cast %lli arguments
inf fprintf statements to long long int.

Tested on x86_64-linux-gnu {,-m32} and committed to mainline SVN.

Uros.
Index: gcc.dg/guality/guality.h
===
--- gcc.dg/guality/guality.h(revision 255651)
+++ gcc.dg/guality/guality.h(working copy)
@@ -363,15 +363,18 @@
 switch (result)
   {
   case PASS:
-   fprintf (stderr, "PASS: " GUALITY_TEST ": %s is %lli\n", name, value);
+   fprintf (stderr, "PASS: " GUALITY_TEST ": %s is %lli\n", name,
+(long long int) value);
break;
   case INCORRECT:
-   fprintf (stderr, "FAIL: " GUALITY_TEST ": %s is %lli, not %lli\n", 
name, xvalue, value);
+   fprintf (stderr, "FAIL: " GUALITY_TEST ": %s is %lli, not %lli\n", name,
+(long long int) xvalue, (long long int) value);
break;
   case INCOMPLETE:
fprintf (stderr, "%s: " GUALITY_TEST ": %s is %s, expected %lli\n",
 unknown_ok ? "UNRESOLVED" : "FAIL", name,
-unavailable < 0 ? "not computable" : "optimized away", value);
+unavailable < 0 ? "not computable" : "optimized away",
+(long long int) value);
result = unknown_ok ? INCOMPLETE : INCORRECT;
break;
   default:


Re: [patch,committed] Remove external links that texinfo would shred.

2017-12-17 Thread Gerald Pfeifer
On Tue, 11 Jul 2017, Georg-Johann Lay wrote:
> texinfo is shredding external links.
> 
> Applied the following patch to prevent uses from 404 not found.
> 
> Johann
> 
> gcc/
>   * doc/extend.texi (AVR Function Attributes): Remove weblink to
>   Binutils doc as TEXI will mess them up.
>   * doc/invoke.texi (AVR Options): Same here.

Strictly speaking it's not makeinfo, but post-processing I put in place 
many years ago to compensate what _was_ a silly change in makeinfo which
started generating "_002d" instead of "-" (and similar substitutions).

In other words, strict correctness was valued over usability and 
backwards-compatibility, let alone intuition or esthetics. 

Unfortunately the workaround has been causing some collateral damage,
too, one of which your patch avoided.

Sorry, and thanks!

Gerald


[committed] hppa: Fix comment for pa_som_asm_init_sections

2017-12-17 Thread John David Anglin
Committed to trunk.

Dave
--
John David Anglin   dave.ang...@bell.net


2017-12-17  John David Anglin  

* config/pa/pa.c (pa_som_asm_init_sections): Fix comment.

Index: config/pa/pa.c
===
--- config/pa/pa.c  (revision 255616)
+++ config/pa/pa.c  (working copy)
@@ -9794,7 +9797,7 @@
   output_section_asm_op (data);
 }
 
-/* Implement TARGET_ASM_INITIALIZE_SECTIONS  */
+/* Implement TARGET_ASM_INIT_SECTIONS.  */
 
 static void
 pa_som_asm_init_sections (void)


[v2 of PATCH 13/14] c-format.c: handle location wrappers

2017-12-17 Thread David Malcolm
On Mon, 2017-12-11 at 18:45 -0500, Jason Merrill wrote:
> On 11/10/2017 04:45 PM, David Malcolm wrote:
> > gcc/c-family/ChangeLog:
> >* c-format.c (check_format_arg): Strip any location wrapper
> > around
> >format_tree.
> > ---
> >gcc/c-family/c-format.c | 9 -
> >1 file changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c
> > index 164d035..6b436ec 100644
> > --- a/gcc/c-family/c-format.c
> > +++ b/gcc/c-family/c-format.c
> > @@ -1536,6 +1536,8 @@ check_format_arg (void *ctx, tree
> > format_tree,
> >
> >  location_t fmt_param_loc = EXPR_LOC_OR_LOC (format_tree,
> > input_location);
> >
> > +  STRIP_ANY_LOCATION_WRAPPER (format_tree);
> > +
> >  if (VAR_P (format_tree))
> >{
> >  /* Pull out a constant value if the front end didn't.  */
>
> It seems like we want fold_for_warn here instead of the special
> variable
> handling.  That probably makes sense for the other places you change
> in
> this patch, too.
>
> Jason

Here's an updated version of the patch which uses fold_for_warn,
rather than STRIP_ANY_LOCATION_WRAPPER.

In one place it was necessary to add a STRIP_NOPS, since the
fold_for_warn can add a cast around a:
  ADDR_EXPR  (
STRING_CST)
turning it into a:
  NOP_EXPR (
ADDR_EXPR  (
  STRING_CST))
which without a STRIP_NOPS leads to a bail-out here:
  1596if (TREE_CODE (format_tree) != ADDR_EXPR)
  1597  {
  1598res->number_non_literal++;
  1599return;
  1600  }
and thus -Wformat-security not recognizing string literals.

Successfully bootstrapped on x86_64-pc-linux-gnu, as
part of the kit.

Is this OK for trunk, assuming the rest of the kit is approved?

gcc/c-family/ChangeLog:
* c-format.c (check_format_arg): Strip any location wrapper around
format_tree.
---
 gcc/c-family/c-format.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c
index 164d035..47aca55 100644
--- a/gcc/c-family/c-format.c
+++ b/gcc/c-family/c-format.c
@@ -1536,6 +1536,8 @@ check_format_arg (void *ctx, tree format_tree,
 
   location_t fmt_param_loc = EXPR_LOC_OR_LOC (format_tree, input_location);
 
+  format_tree = fold_for_warn (format_tree);
+
   if (VAR_P (format_tree))
 {
   /* Pull out a constant value if the front end didn't.  */
@@ -1591,13 +1593,14 @@ check_format_arg (void *ctx, tree format_tree,
}
   offset = int_cst_value (arg1);
 }
+  STRIP_NOPS (format_tree);
   if (TREE_CODE (format_tree) != ADDR_EXPR)
 {
   res->number_non_literal++;
   return;
 }
   res->format_string_loc = EXPR_LOC_OR_LOC (format_tree, input_location);
-  format_tree = TREE_OPERAND (format_tree, 0);
+  format_tree = fold_for_warn (TREE_OPERAND (format_tree, 0));
   if (format_types[info->format_type].flags 
   & (int) FMT_FLAG_PARSE_ARG_CONVERT_EXTERNAL)
 {
@@ -1634,7 +1637,9 @@ check_format_arg (void *ctx, tree format_tree,
   if (TREE_CODE (format_tree) == ARRAY_REF
   && tree_fits_shwi_p (TREE_OPERAND (format_tree, 1))
   && (offset += tree_to_shwi (TREE_OPERAND (format_tree, 1))) >= 0)
-format_tree = TREE_OPERAND (format_tree, 0);
+{
+  format_tree = fold_for_warn (TREE_OPERAND (format_tree, 0));
+}
   if (offset < 0)
 {
   res->number_non_literal++;
-- 
1.8.5.3



Re: [PATCH] Support -std=f2018

2017-12-17 Thread Jerry DeLisle
On 12/17/2017 02:02 AM, Janne Blomqvist wrote:
> The Fortran committee has decided to rename the upcoming Fortran 2015
> standard to Fortran 2018.  This is not a reflection of a three year
> delay in the process, but rather they are following other standards in
> adopting the year of publication for the name. For more details see
> N2144.
> 
> This patch renames GFC_STD_F2015 to GFC_STD_F2018, and makes it a
> separate flag rather than an alias for GFC_STD_GNU. Also, it adds a
> -std=f2018 argument, and documents it.
> 
> Regtested on x86_64-pc-linux-gnu, Ok for trunk?
> 

Yes, OK

Jerry


Re: [PING 2][PATCH] enhance -Wrestrict to handle string built-ins (PR 78918)

2017-12-17 Thread H.J. Lu
On Sat, Dec 16, 2017 at 4:01 PM, Martin Sebor  wrote:
> On 12/11/2017 03:27 PM, Jeff Law wrote:
>>
>> On 12/08/2017 12:19 PM, Martin Sebor wrote:
>>>
>>> Attached is revision 8 of the patch with the changes suggested
>>> and/or requested below.
>>
>>
>> [ Big snip. ]
>>
>>>
>>>
>>> gcc-78918.diff
>>>
>>>
>>> PR tree-optimization/78918 - missing -Wrestrict on memcpy copying over
>>> self
>>>
>>> gcc/c-family/ChangeLog:
>>>
>>> PR tree-optimization/78918
>>> * c-common.c (check_function_restrict): Avoid checking built-ins.
>>> * c.opt (-Wrestrict): Include in -Wall.
>>>
>>> gcc/ChangeLog:
>>>
>>> PR tree-optimization/78918
>>> * Makefile.in (OBJS): Add gimple-ssa-warn-restrict.o.
>>> * builtins.c (check_sizes): Rename...
>>> (check_access): ...to this.  Rename function arguments for
>>> clarity.
>>> (check_memop_sizes): Adjust names.
>>> (expand_builtin_memchr, expand_builtin_memcpy): Same.
>>> (expand_builtin_memmove, expand_builtin_mempcpy): Same.
>>> (expand_builtin_strcat, expand_builtin_stpncpy): Same.
>>> (check_strncat_sizes, expand_builtin_strncat): Same.
>>> (expand_builtin_strncpy, expand_builtin_memset): Same.
>>> (expand_builtin_bzero, expand_builtin_memcmp): Same.
>>> (expand_builtin_memory_chk, maybe_emit_chk_warning): Same.
>>> (maybe_emit_sprintf_chk_warning): Same.
>>> (expand_builtin_strcpy): Adjust.
>>> (expand_builtin_stpcpy): Same.
>>> (expand_builtin_with_bounds): Detect out-of-bounds accesses
>>> in pointer-checking forms of memcpy, memmove, and mempcpy.
>>> (gcall_to_tree_minimal, max_object_size): Define new functions.
>>> * builtins.h (max_object_size): Declare.
>>> * calls.c (alloc_max_size): Call max_object_size instead of
>>> hardcoding ssizetype limit.
>>> (get_size_range): Handle new argument.
>>> * calls.h (get_size_range): Add a new argument.
>>> * cfgexpand.c (expand_call_stmt): Propagate no-warning bit.
>>> * doc/invoke.texi (-Wrestrict): Adjust, add example.
>>> * gimple-fold.c (gimple_fold_builtin_memory_op): Detect
>>> overlapping
>>> operations.
>>> (gimple_fold_builtin_memory_chk): Same.
>>> (gimple_fold_builtin_stxcpy_chk): New function.
>>> * gimple-ssa-warn-restrict.c: New source.
>>> * gimple-ssa-warn-restrict.h: New header.
>>> * gimple.c (gimple_build_call_from_tree): Propagate location.
>>> * passes.def (pass_warn_restrict): Add new pass.
>>> * tree-pass.h (make_pass_warn_restrict): Declare.
>>> * tree-ssa-strlen.c (handle_builtin_strcpy): Detect overlapping
>>> operations.
>>> (handle_builtin_strcat): Same.
>>> (strlen_optimize_stmt): Rename...
>>> (strlen_check_and_optimize_stmt): ...to this.  Handle strncat,
>>> stpncpy, strncpy, and their checking forms.
>>>
>>> gcc/testsuite/ChangeLog:
>>>
>>> PR tree-optimization/78918
>>> * c-c++-common/Warray-bounds.c: New test.
>>> * c-c++-common/Warray-bounds-2.c: New test.
>>> * c-c++-common/Warray-bounds-3.c: New test.
>>> * c-c++-common/Wrestrict-2.c: New test.
>>> * c-c++-common/Wrestrict.c: New test.
>>> * c-c++-common/Wrestrict.s: New test.
>>> * c-c++-common/Wsizeof-pointer-memaccess1.c: Adjust
>>> * c-c++-common/Wsizeof-pointer-memaccess2.c: Same.
>>> * g++.dg/torture/Wsizeof-pointer-memaccess1.C: Same.
>>> * g++.dg/torture/Wsizeof-pointer-memaccess2.C: Same.
>>> * gcc.dg/memcpy-6.c: New test.
>>> * gcc.dg/pr69172.c: Adjust.
>>> * gcc.dg/pr79223.c: Same.
>>> * gcc.dg/Wrestrict-2.c: New test.
>>> * gcc.dg/Wrestrict.c: New test.
>>> * gcc.dg/Wsizeof-pointer-memaccess1.c
>>> * gcc.target/i386/chkp-stropt-17.c: New test.
>>> * gcc.dg/torture/Wsizeof-pointer-memaccess1.c: Adjust.
>>
>> OK.  Thanks for your patience.  I know this was a ton of work and even
>> more waiting.
>
>
> Thanks.  In more testing I uncovered a few minor glitches.  I've
> fixed those and committed r255755.  Attached is the committed patch
> for reference.
>
> Martin

This caused:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83446

-- 
H.J.


[PATCH v2] libgo: Add support for sh

2017-12-17 Thread John Paul Adrian Glaubitz
Hello!

This is the second version of my patch to add support for SuperH
in libgo. The changes over my first patch in [1] are:

 * account for little- and big-endian targets
 * account for sh3- and sh4-specific parameters

I have not added support for SH-1 and SH-2 targets for now as
most Linux distributions with SH support usually target sh3 and
sh4 only.

I have already signed the Google CLA in the past when I contributed
a small patch to Kubernetes.

Thanks,
Adrian

> [1] https://gcc.gnu.org/ml/gcc-patches/2017-12/msg0.html

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - glaub...@debian.org
`. `'   Freie Universitaet Berlin - glaub...@physik.fu-berlin.de
  `-GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
>From ce83430f1a8d34f005f46208e4c8ab22ad00c879 Mon Sep 17 00:00:00 2001
From: John Paul Adrian Glaubitz 
Date: Sat, 16 Dec 2017 10:05:20 +0100
Subject: [PATCH] 2017-12-17  John Paul Adrian Glaubitz
 

	PR go/83308
	* libgo/configure.ac: Add support for sh3, sh3be, sh4, sh4be.
	* libgo/go/go/build/syslist.go: Add sh3, sh3be, sh4, sh4be to goarchList.
	* libgo/go/cmd/cgo/main.go: Enable build on sh3, sh3be, sh4, sh4be.
	* libgo/go/runtime/hash32.go: Likewise.
	* libgo/go/runtime/lfstack_32bit.go: Likewise.
	* libgo/go/runtime/unaligned2.go: Likewise.
	* libgo/go/syscall/endian_big.go: Enable build on sh3be, sh4be.
	* libgo/go/syscall/endian_little.go: Enable build on sh3, sh4.
	* libgo/match.sh: Add architecture matching for sh3, sh3be, sh4, sh4be.
	* libgo/testsuite/gotest: Likewise.
---
 ChangeLog | 14 ++
 libgo/configure.ac| 34 --
 libgo/go/cmd/cgo/main.go  |  8 
 libgo/go/go/build/syslist.go  |  2 +-
 libgo/go/runtime/hash32.go|  2 +-
 libgo/go/runtime/lfstack_32bit.go |  2 +-
 libgo/go/runtime/unaligned2.go|  2 +-
 libgo/go/syscall/endian_big.go|  2 +-
 libgo/go/syscall/endian_little.go |  2 +-
 libgo/match.sh|  4 ++--
 libgo/testsuite/gotest|  4 ++--
 11 files changed, 64 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 275a340f6a8..18c3cfe0743 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2017-12-17  John Paul Adrian Glaubitz 
+
+	PR go/83308
+	* libgo/configure.ac: Add support for sh3, sh3be, sh4, sh4be.
+	* libgo/go/go/build/syslist.go: Add sh3, sh3be, sh4, sh4be to goarchList.
+	* libgo/go/cmd/cgo/main.go: Enable build on sh3, sh3be, sh4, sh4be.
+	* libgo/go/runtime/hash32.go: Likewise.
+	* libgo/go/runtime/lfstack_32bit.go: Likewise.
+	* libgo/go/runtime/unaligned2.go: Likewise.
+	* libgo/go/syscall/endian_big.go: Enable build on sh3be, sh4be.
+	* libgo/go/syscall/endian_little.go: Enable build on sh3, sh4.
+	* libgo/match.sh: Add architecture matching for sh3, sh3be, sh4, sh4be.
+	* libgo/testsuite/gotest: Likewise.
+
 2017-12-12  Stafford Horne  
 
 	* configure.ac: Remove logic adding gdb to noconfigsdirs for or1k.
diff --git a/libgo/configure.ac b/libgo/configure.ac
index 7b0c629653f..63cd857c23f 100644
--- a/libgo/configure.ac
+++ b/libgo/configure.ac
@@ -208,10 +208,10 @@ AC_SUBST(USE_DEJAGNU)
 # supported by the gofrontend and all architectures supported by the
 # gc toolchain.
 # N.B. Keep in sync with gcc/testsuite/go.test/go-test.exp (go-set-goarch).
-ALLGOARCH="386 alpha amd64 amd64p32 arm armbe arm64 arm64be ia64 m68k mips mipsle mips64 mips64le mips64p32 mips64p32le ppc ppc64 ppc64le s390 s390x sparc sparc64"
+ALLGOARCH="386 alpha amd64 amd64p32 arm armbe arm64 arm64be ia64 m68k mips mipsle mips64 mips64le mips64p32 mips64p32le ppc ppc64 ppc64le s390 s390x sh3 sh3be sh4 sh4be sparc sparc64"
 
 # All known GOARCH_FAMILY values.
-ALLGOARCHFAMILY="I386 ALPHA AMD64 ARM ARM64 IA64 M68K MIPS MIPS64 PPC PPC64 S390 S390X SPARC SPARC64"
+ALLGOARCHFAMILY="I386 ALPHA AMD64 ARM ARM64 IA64 M68K MIPS MIPS64 PPC PPC64 S390 S390X SH SPARC SPARC64"
 
 GOARCH=unknown
 GOARCH_FAMILY=unknown
@@ -360,6 +360,36 @@ GOARCH_MINFRAMESIZE=8
 GOARCH_CACHELINESIZE=256
 GOARCH_PCQUANTUM=2
 ;;
+  sh3eb*-*-*)
+GOARCH=sh3be
+GOARCH_FAMILY=SH
+GOARCH_BIGENDIAN=1
+GOARCH_CACHELINESIZE=16
+GOARCH_PCQUANTUM=2
+GOARCH_MINFRAMESIZE=4
+;;
+  sh3*-*-*)
+GOARCH=sh3
+GOARCH_FAMILY=SH
+GOARCH_CACHELINESIZE=16
+GOARCH_PCQUANTUM=2
+GOARCH_MINFRAMESIZE=4
+;;
+  sh4eb*-*-*)
+GOARCH=sh4be
+GOARCH_FAMILY=SH
+GOARCH_BIGENDIAN=1
+GOARCH_CACHELINESIZE=32
+GOARCH_PCQUANTUM=2
+GOARCH_MINFRAMESIZE=4
+;;
+  sh4*-*-*)
+GOARCH=sh4
+GOARCH_FAMILY=SH
+GOARCH_CACHELINESIZE=32
+GOARCH_PCQUANTUM=2
+GOARCH_MINFRAMESIZE=4
+;;
   sparc*-*-*)
 AC_COMPILE_IFELSE([
 #if defined(__sparcv9) || defined(__arch64__)
diff --git a/libgo/go/cmd/cgo/main.go b/libgo/go/cmd/cgo/main.go
index c9a44fdd166..a45283e7fa0 

Re: [PATCH][i386] Correct imul (r64) latency for modern Intel CPUs

2017-12-17 Thread Markus Trippelsdorf
On 2017.12.17 at 12:26 +0100, Jan Hubicka wrote:
> > Since Nehalem the 64bit multiplication latency is three cycles, not
> > four. So update the costs to reflect reality.
> 
> I looked into the imul latencies and was a bit confused, decided to look
> into it later and forgot.
> 
> Agner Fog's table http://www.agner.org/optimize/instruction_tables.pdf
> lists for sandybridge-skylake costs of 3 cycles for everything except for
> 16bit (which is 4 cycles).
> 
> For earlier chips this is more varying.
>  Merom (core duo) and Wolfdale is 3 or everything except for 5 for 64bit.
>  Nehalem is 3 for everything however 64bit has smaller throughput.
> 
> We do not have spearate table for sandybridge, but I guess we do not care
> that much about older cores (Vladimir is still running a tester on one,
> so we do benchmark them).
> 
> So I guess the change is OK.  I do not see this as very good reason to split
> the sandybridge table out, but perhaps drop a comment in case we will want
> to do it in future.

Thanks. Here is what I have committed (r255760):

diff --git a/gcc/config/i386/x86-tune-costs.h b/gcc/config/i386/x86-tune-costs.h
index 648219338308..477e478f1f77 100644
--- a/gcc/config/i386/x86-tune-costs.h
+++ b/gcc/config/i386/x86-tune-costs.h
@@ -1538,8 +1538,8 @@ struct processor_costs skylake_cost = {
   {COSTS_N_INSNS (3),  /* cost of starting multiply for QI */
COSTS_N_INSNS (4),  /*   HI */
COSTS_N_INSNS (3),  /*   SI */
-   COSTS_N_INSNS (4),  /*   DI */
-   COSTS_N_INSNS (4)}, /*other */
+   COSTS_N_INSNS (3),  /*   DI */
+   COSTS_N_INSNS (3)}, /*other */
   0,   /* cost of multiply per each bit set */
   /* Expanding div/mod currently doesn't consider parallelism. So the cost
  model is not realistic. We compensate by increasing the latencies a bit.  
*/
@@ -2341,8 +2341,9 @@ struct processor_costs core_cost = {
   {COSTS_N_INSNS (3),  /* cost of starting multiply for QI */
COSTS_N_INSNS (4),  /*   HI */
COSTS_N_INSNS (3),  /*   SI */
-   COSTS_N_INSNS (4),  /*   DI */
-   COSTS_N_INSNS (4)}, /*other */
+   /* Here we tune for Sandybridge or newer.  */
+   COSTS_N_INSNS (3),  /*   DI */
+   COSTS_N_INSNS (3)}, /*other */
   0,   /* cost of multiply per each bit set */
   /* Expanding div/mod currently doesn't consider parallelism. So the cost
  model is not realistic. We compensate by increasing the latencies a bit.  
*/
diff --git a/gcc/testsuite/gcc.target/i386/wmul-3.c 
b/gcc/testsuite/gcc.target/i386/wmul-3.c
new file mode 100644
index ..5f1619076386
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/wmul-3.c
@@ -0,0 +1,66 @@
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-options "-O2 -march=sandybridge" } */
+
+#include 
+#include 
+
+static const char b100_tab[200] = {
+'0', '0', '0', '1', '0', '2', '0', '3', '0', '4',
+'0', '5', '0', '6', '0', '7', '0', '8', '0', '9',
+'1', '0', '1', '1', '1', '2', '1', '3', '1', '4',
+'1', '5', '1', '6', '1', '7', '1', '8', '1', '9',
+'2', '0', '2', '1', '2', '2', '2', '3', '2', '4',
+'2', '5', '2', '6', '2', '7', '2', '8', '2', '9',
+'3', '0', '3', '1', '3', '2', '3', '3', '3', '4',
+'3', '5', '3', '6', '3', '7', '3', '8', '3', '9',
+'4', '0', '4', '1', '4', '2', '4', '3', '4', '4',
+'4', '5', '4', '6', '4', '7', '4', '8', '4', '9',
+'5', '0', '5', '1', '5', '2', '5', '3', '5', '4',
+'5', '5', '5', '6', '5', '7', '5', '8', '5', '9',
+'6', '0', '6', '1', '6', '2', '6', '3', '6', '4',
+'6', '5', '6', '6', '6', '7', '6', '8', '6', '9',
+'7', '0', '7', '1', '7', '2', '7', '3', '7', '4',
+'7', '5', '7', '6', '7', '7', '7', '8', '7', '9',
+'8', '0', '8', '1', '8', '2', '8', '3', '8', '4',
+'8', '5', '8', '6', '8', '7', '8', '8', '8', '9',
+'9', '0', '9', '1', '9', '2', '9', '3', '9', '4',
+'9', '5', '9', '6', '9', '7', '9', '8', '9', '9',
+};
+
+void uint64_to_ascii_ta7_32_base100(uint64_t val, char *dst) {
+  const int64_t POW10_10 = ((int64_t)10) * 1000 * 1000 * 1000;
+  const uint64_t POW2_57_DIV_POW100_4 =
+  ((int64_t)(1) << 57) / 100 / 100 / 100 / 100 + 1;
+  const uint64_t MASK32 = ((int64_t)(1) << 32) - 1;
+  int64_t hix = val / POW10_10;
+  int64_t lox = val % POW10_10;
+  int64_t lor = lox & (uint64_t)(-2);
+  uint64_t hi = hix * POW2_57_DIV_POW100_4;
+  uint64_t lo = lor * POW2_57_DIV_POW100_4;
+  memcpy(dst + 0 * 

Re: [PATCH][i386] Correct imul (r64) latency for modern Intel CPUs

2017-12-17 Thread Jan Hubicka
> Since Nehalem the 64bit multiplication latency is three cycles, not
> four. So update the costs to reflect reality.

I looked into the imul latencies and was a bit confused, decided to look
into it later and forgot.

Agner Fog's table http://www.agner.org/optimize/instruction_tables.pdf
lists for sandybridge-skylake costs of 3 cycles for everything except for
16bit (which is 4 cycles).

For earlier chips this is more varying.
 Merom (core duo) and Wolfdale is 3 or everything except for 5 for 64bit.
 Nehalem is 3 for everything however 64bit has smaller throughput.

We do not have spearate table for sandybridge, but I guess we do not care
that much about older cores (Vladimir is still running a tester on one,
so we do benchmark them).

So I guess the change is OK.  I do not see this as very good reason to split
the sandybridge table out, but perhaps drop a comment in case we will want
to do it in future.

Honza
> 
> Tested on X86_64.
> OK for trunk?
> 
> Thanks.
> 
>   * x86-tune-costs.h (skylake_cost, core_cost): Decrease r64 multiply
>   latencies.
> 
>   * gcc.target/i386/wmul-3.c: New test.
> 
> diff --git a/gcc/config/i386/x86-tune-costs.h 
> b/gcc/config/i386/x86-tune-costs.h
> index 648219338308..ddb47ba44056 100644
> --- a/gcc/config/i386/x86-tune-costs.h
> +++ b/gcc/config/i386/x86-tune-costs.h
> @@ -1538,8 +1538,8 @@ struct processor_costs skylake_cost = {
>{COSTS_N_INSNS (3),/* cost of starting multiply 
> for QI */
> COSTS_N_INSNS (4),/*  
>  HI */
> COSTS_N_INSNS (3),/*  
>  SI */
> -   COSTS_N_INSNS (4),/*  
>  DI */
> -   COSTS_N_INSNS (4)},   /*
> other */
> +   COSTS_N_INSNS (3),/*  
>  DI */
> +   COSTS_N_INSNS (3)},   /*
> other */
>0, /* cost of multiply per each bit set */
>/* Expanding div/mod currently doesn't consider parallelism. So the cost
>   model is not realistic. We compensate by increasing the latencies a 
> bit.  */
> @@ -2341,8 +2341,8 @@ struct processor_costs core_cost = {
>{COSTS_N_INSNS (3),/* cost of starting multiply 
> for QI */
> COSTS_N_INSNS (4),/*  
>  HI */
> COSTS_N_INSNS (3),/*  
>  SI */
> -   COSTS_N_INSNS (4),/*  
>  DI */
> -   COSTS_N_INSNS (4)},   /*
> other */
> +   COSTS_N_INSNS (3),/*  
>  DI */
> +   COSTS_N_INSNS (3)},   /*
> other */
>0, /* cost of multiply per each bit set */
>/* Expanding div/mod currently doesn't consider parallelism. So the cost
>   model is not realistic. We compensate by increasing the latencies a 
> bit.  */
> diff --git a/gcc/testsuite/gcc.target/i386/wmul-3.c 
> b/gcc/testsuite/gcc.target/i386/wmul-3.c
> new file mode 100644
> index ..66c077c2cc0d
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/wmul-3.c
> @@ -0,0 +1,66 @@
> +/* { dg-do compile { target { ! ia32 } } } */
> +/* { dg-options "-O2 -march=haswell" } */
> +
> +#include 
> +#include 
> +
> +static const char b100_tab[200] = {
> +'0', '0', '0', '1', '0', '2', '0', '3', '0', '4',
> +'0', '5', '0', '6', '0', '7', '0', '8', '0', '9',
> +'1', '0', '1', '1', '1', '2', '1', '3', '1', '4',
> +'1', '5', '1', '6', '1', '7', '1', '8', '1', '9',
> +'2', '0', '2', '1', '2', '2', '2', '3', '2', '4',
> +'2', '5', '2', '6', '2', '7', '2', '8', '2', '9',
> +'3', '0', '3', '1', '3', '2', '3', '3', '3', '4',
> +'3', '5', '3', '6', '3', '7', '3', '8', '3', '9',
> +'4', '0', '4', '1', '4', '2', '4', '3', '4', '4',
> +'4', '5', '4', '6', '4', '7', '4', '8', '4', '9',
> +'5', '0', '5', '1', '5', '2', '5', '3', '5', '4',
> +'5', '5', '5', '6', '5', '7', '5', '8', '5', '9',
> +'6', '0', '6', '1', '6', '2', '6', '3', '6', '4',
> +'6', '5', '6', '6', '6', '7', '6', '8', '6', '9',
> +'7', '0', '7', '1', '7', '2', '7', '3', '7', '4',
> +'7', '5', '7', '6', '7', '7', '7', '8', '7', '9',
> +'8', '0', '8', '1', '8', '2', '8', '3', '8', '4',
> +'8', '5', '8', '6', '8', '7', '8', '8', '8', '9',
> +'9', '0', '9', '1', '9', '2', '9', '3', '9', '4',
> +'9', '5', '9', '6', '9', '7', '9', '8', '9', '9',
> +};
> +
> +void uint64_to_ascii_ta7_32_base100(uint64_t val, char *dst) {
> +  const int64_t POW10_10 = ((int64_t)10) * 1000 * 1000 * 1000;
> +  const uint64_t POW2_57_DIV_POW100_4 =
> +  ((int64_t)(1) << 57) / 100 / 100 / 100 / 100 

Re: [PATCH] Support -std=f2018

2017-12-17 Thread Robin Curtis
Apologies for lobbing this request to all you wonderful folk who maintain and 
develop GFORTRAN. 

Given that you are making noises about Fortran 2018 - and the language is still 
alive, kicking and thriving -  can you recommend and/or point me at a public 
domain GUI that works well with GFORTRAN? 

As a Fortran end User I marvel at your ongoing efforts !!

Regards / thanks.  Happy Christmas and Best Wishes for (Fortran) 2018. 

Robin Curtis

> On 17 Dec 2017, at 10:02, Janne Blomqvist  wrote:
> 
> The Fortran committee has decided to rename the upcoming Fortran 2015
> standard to Fortran 2018.  This is not a reflection of a three year
> delay in the process, but rather they are following other standards in
> adopting the year of publication for the name. For more details see
> N2144.
> 
> This patch renames GFC_STD_F2015 to GFC_STD_F2018, and makes it a
> separate flag rather than an alias for GFC_STD_GNU. Also, it adds a
> -std=f2018 argument, and documents it.
> 
> Regtested on x86_64-pc-linux-gnu, Ok for trunk?
> 
> gcc/fortran/ChangeLog:
> 
> 2017-12-17  Janne Blomqvist  
> 
>   * decl.c (gfc_match_implicit_none): Use GFC_STD_F2018 instead of
>   GFC_STD_F2015.
>   * error.c (gfc_notify_std): Add GFC_STD_F2018{_DEL,_OBS} to
>   switch.
>   * gfortran.texi: Document -std=f2018.
>   * interface.c (compare_parameter): Fix comment.
>   * invoke.texi: Document -std=f2018.
>   * lang.opt: Add -std=f2018 argumnet.
>   * libgfortran.h (GFC_STD_F2015): Rename to GFC_STD_F0218, use
>   separate flag bit.
>   (GFC_STD_F2018_DEL): New macro.
>   (GFC_STD_F2018_OBS): Likewise.
>   * match.c (gfc_match_stopcode): Use GFC_STD_F2018.
>   * options.c (set_default_std_flags): Add F2018 flags to defaults.
>   (gfc_handle_option): Set options for -std=f2018.
> 
> gcc/testsuite/ChangeLog:
> 
> 2017-12-17  Janne Blomqvist  
> 
>   * gfortran.dg/error_stop_3.f90: Update -std= option, fix comments.
>   * gfortran.dg/error_stop_4.f90: Update error message.
>   * gfortran.dg/implicit_14.f90: Likewise.
>   * gfortran.dg/spellcheck-procedure_2.f90: Don't warn for F2018
>   features.
> ---
> gcc/fortran/decl.c |   2 +-
> gcc/fortran/error.c|   9 ++
> gcc/fortran/gfortran.texi  | 108 +
> gcc/fortran/interface.c|   2 +-
> gcc/fortran/invoke.texi|  62 ++--
> gcc/fortran/lang.opt   |   6 +-
> gcc/fortran/libgfortran.h  |   5 +-
> gcc/fortran/match.c|   2 +-
> gcc/fortran/options.c  |  14 ++-
> gcc/testsuite/gfortran.dg/error_stop_3.f90 |   5 +-
> gcc/testsuite/gfortran.dg/error_stop_4.f90 |   5 +-
> gcc/testsuite/gfortran.dg/implicit_14.f90  |   4 +-
> .../gfortran.dg/spellcheck-procedure_2.f90 |   2 +-
> 13 files changed, 140 insertions(+), 86 deletions(-)
> 
> diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
> index d46083c..53a87b6 100644
> --- a/gcc/fortran/decl.c
> +++ b/gcc/fortran/decl.c
> @@ -4114,7 +4114,7 @@ gfc_match_implicit_none (void)
>   if (c == '(')
> {
>   (void) gfc_next_ascii_char ();
> -  if (!gfc_notify_std (GFC_STD_F2015, "IMPORT NONE with spec list at 
> %C"))
> +  if (!gfc_notify_std (GFC_STD_F2018, "IMPORT NONE with spec list at 
> %C"))
>   return MATCH_ERROR;
> 
>   gfc_gobble_whitespace ();
> diff --git a/gcc/fortran/error.c b/gcc/fortran/error.c
> index 2cece49..f11dadc 100644
> --- a/gcc/fortran/error.c
> +++ b/gcc/fortran/error.c
> @@ -864,6 +864,15 @@ gfc_notify_std (int std, const char *gmsgid, ...)
> 
>   switch (std)
>   {
> +case GFC_STD_F2018_DEL:
> +  msg = _("Fortran 2018 deleted feature:");
> +  break;
> +case GFC_STD_F2018_OBS:
> +  msg = _("Fortran 2018 obsolescent feature:");
> +  break;
> +case GFC_STD_F2018:
> +  msg = _("Fortran 2018:");
> +  break;
> case GFC_STD_F2008_TS:
>   msg = "TS 29113/TS 18508:";
>   break;
> diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi
> index 36c7b94..aabf268 100644
> --- a/gcc/fortran/gfortran.texi
> +++ b/gcc/fortran/gfortran.texi
> @@ -180,7 +180,7 @@ Part I: Invoking GNU Fortran
> * Runtime::  Influencing runtime behavior with environment 
> variables.
> 
> Part II: Language Reference
> -* Fortran 2003 and 2008 status::  Fortran 2003 and 2008 features supported 
> by GNU Fortran.
> +* Fortran standards status::  Fortran 2003, 2008 and 2018 features 
> supported by GNU Fortran.
> * Compiler Characteristics::  User-visible implementation details.
> * Extensions::Language extensions implemented by GNU 
> Fortran.
> * Mixed-Language Programming::Interoperability with C

[PATCH] Support -std=f2018

2017-12-17 Thread Janne Blomqvist
The Fortran committee has decided to rename the upcoming Fortran 2015
standard to Fortran 2018.  This is not a reflection of a three year
delay in the process, but rather they are following other standards in
adopting the year of publication for the name. For more details see
N2144.

This patch renames GFC_STD_F2015 to GFC_STD_F2018, and makes it a
separate flag rather than an alias for GFC_STD_GNU. Also, it adds a
-std=f2018 argument, and documents it.

Regtested on x86_64-pc-linux-gnu, Ok for trunk?

gcc/fortran/ChangeLog:

2017-12-17  Janne Blomqvist  

* decl.c (gfc_match_implicit_none): Use GFC_STD_F2018 instead of
GFC_STD_F2015.
* error.c (gfc_notify_std): Add GFC_STD_F2018{_DEL,_OBS} to
switch.
* gfortran.texi: Document -std=f2018.
* interface.c (compare_parameter): Fix comment.
* invoke.texi: Document -std=f2018.
* lang.opt: Add -std=f2018 argumnet.
* libgfortran.h (GFC_STD_F2015): Rename to GFC_STD_F0218, use
separate flag bit.
(GFC_STD_F2018_DEL): New macro.
(GFC_STD_F2018_OBS): Likewise.
* match.c (gfc_match_stopcode): Use GFC_STD_F2018.
* options.c (set_default_std_flags): Add F2018 flags to defaults.
(gfc_handle_option): Set options for -std=f2018.

gcc/testsuite/ChangeLog:

2017-12-17  Janne Blomqvist  

* gfortran.dg/error_stop_3.f90: Update -std= option, fix comments.
* gfortran.dg/error_stop_4.f90: Update error message.
* gfortran.dg/implicit_14.f90: Likewise.
* gfortran.dg/spellcheck-procedure_2.f90: Don't warn for F2018
features.
---
 gcc/fortran/decl.c |   2 +-
 gcc/fortran/error.c|   9 ++
 gcc/fortran/gfortran.texi  | 108 +
 gcc/fortran/interface.c|   2 +-
 gcc/fortran/invoke.texi|  62 ++--
 gcc/fortran/lang.opt   |   6 +-
 gcc/fortran/libgfortran.h  |   5 +-
 gcc/fortran/match.c|   2 +-
 gcc/fortran/options.c  |  14 ++-
 gcc/testsuite/gfortran.dg/error_stop_3.f90 |   5 +-
 gcc/testsuite/gfortran.dg/error_stop_4.f90 |   5 +-
 gcc/testsuite/gfortran.dg/implicit_14.f90  |   4 +-
 .../gfortran.dg/spellcheck-procedure_2.f90 |   2 +-
 13 files changed, 140 insertions(+), 86 deletions(-)

diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index d46083c..53a87b6 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -4114,7 +4114,7 @@ gfc_match_implicit_none (void)
   if (c == '(')
 {
   (void) gfc_next_ascii_char ();
-  if (!gfc_notify_std (GFC_STD_F2015, "IMPORT NONE with spec list at %C"))
+  if (!gfc_notify_std (GFC_STD_F2018, "IMPORT NONE with spec list at %C"))
return MATCH_ERROR;
 
   gfc_gobble_whitespace ();
diff --git a/gcc/fortran/error.c b/gcc/fortran/error.c
index 2cece49..f11dadc 100644
--- a/gcc/fortran/error.c
+++ b/gcc/fortran/error.c
@@ -864,6 +864,15 @@ gfc_notify_std (int std, const char *gmsgid, ...)
 
   switch (std)
   {
+case GFC_STD_F2018_DEL:
+  msg = _("Fortran 2018 deleted feature:");
+  break;
+case GFC_STD_F2018_OBS:
+  msg = _("Fortran 2018 obsolescent feature:");
+  break;
+case GFC_STD_F2018:
+  msg = _("Fortran 2018:");
+  break;
 case GFC_STD_F2008_TS:
   msg = "TS 29113/TS 18508:";
   break;
diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi
index 36c7b94..aabf268 100644
--- a/gcc/fortran/gfortran.texi
+++ b/gcc/fortran/gfortran.texi
@@ -180,7 +180,7 @@ Part I: Invoking GNU Fortran
 * Runtime::  Influencing runtime behavior with environment 
variables.
 
 Part II: Language Reference
-* Fortran 2003 and 2008 status::  Fortran 2003 and 2008 features supported by 
GNU Fortran.
+* Fortran standards status::  Fortran 2003, 2008 and 2018 features 
supported by GNU Fortran.
 * Compiler Characteristics::  User-visible implementation details.
 * Extensions::Language extensions implemented by GNU 
Fortran.
 * Mixed-Language Programming::Interoperability with C
@@ -243,16 +243,15 @@ or alternative to, the Unix @command{f95} command;
 @section About GNU Fortran
 
 The GNU Fortran compiler supports the Fortran 77, 90 and 95 standards
-completely, parts of the Fortran 2003 and Fortran 2008 standards, and
+completely, parts of the Fortran 2003, 2008 and 2018 standards, and
 several vendor extensions.  The development goal is to provide the
 following features:
 
 @itemize @bullet
 @item
-Read a user's program,
-stored in a file and containing instructions written
-in Fortran 77, Fortran 90, Fortran 95, Fortran 2003 or Fortran 2008.
-This file contains @dfn{source code}.
+Read a user's program, stored in a file and containing 

[PATCH][i386] Correct imul (r64) latency for modern Intel CPUs

2017-12-17 Thread Markus Trippelsdorf
Since Nehalem the 64bit multiplication latency is three cycles, not
four. So update the costs to reflect reality.

Tested on X86_64.
OK for trunk?

Thanks.

* x86-tune-costs.h (skylake_cost, core_cost): Decrease r64 multiply
latencies.

* gcc.target/i386/wmul-3.c: New test.

diff --git a/gcc/config/i386/x86-tune-costs.h b/gcc/config/i386/x86-tune-costs.h
index 648219338308..ddb47ba44056 100644
--- a/gcc/config/i386/x86-tune-costs.h
+++ b/gcc/config/i386/x86-tune-costs.h
@@ -1538,8 +1538,8 @@ struct processor_costs skylake_cost = {
   {COSTS_N_INSNS (3),  /* cost of starting multiply for QI */
COSTS_N_INSNS (4),  /*   HI */
COSTS_N_INSNS (3),  /*   SI */
-   COSTS_N_INSNS (4),  /*   DI */
-   COSTS_N_INSNS (4)}, /*other */
+   COSTS_N_INSNS (3),  /*   DI */
+   COSTS_N_INSNS (3)}, /*other */
   0,   /* cost of multiply per each bit set */
   /* Expanding div/mod currently doesn't consider parallelism. So the cost
  model is not realistic. We compensate by increasing the latencies a bit.  
*/
@@ -2341,8 +2341,8 @@ struct processor_costs core_cost = {
   {COSTS_N_INSNS (3),  /* cost of starting multiply for QI */
COSTS_N_INSNS (4),  /*   HI */
COSTS_N_INSNS (3),  /*   SI */
-   COSTS_N_INSNS (4),  /*   DI */
-   COSTS_N_INSNS (4)}, /*other */
+   COSTS_N_INSNS (3),  /*   DI */
+   COSTS_N_INSNS (3)}, /*other */
   0,   /* cost of multiply per each bit set */
   /* Expanding div/mod currently doesn't consider parallelism. So the cost
  model is not realistic. We compensate by increasing the latencies a bit.  
*/
diff --git a/gcc/testsuite/gcc.target/i386/wmul-3.c 
b/gcc/testsuite/gcc.target/i386/wmul-3.c
new file mode 100644
index ..66c077c2cc0d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/wmul-3.c
@@ -0,0 +1,66 @@
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-options "-O2 -march=haswell" } */
+
+#include 
+#include 
+
+static const char b100_tab[200] = {
+'0', '0', '0', '1', '0', '2', '0', '3', '0', '4',
+'0', '5', '0', '6', '0', '7', '0', '8', '0', '9',
+'1', '0', '1', '1', '1', '2', '1', '3', '1', '4',
+'1', '5', '1', '6', '1', '7', '1', '8', '1', '9',
+'2', '0', '2', '1', '2', '2', '2', '3', '2', '4',
+'2', '5', '2', '6', '2', '7', '2', '8', '2', '9',
+'3', '0', '3', '1', '3', '2', '3', '3', '3', '4',
+'3', '5', '3', '6', '3', '7', '3', '8', '3', '9',
+'4', '0', '4', '1', '4', '2', '4', '3', '4', '4',
+'4', '5', '4', '6', '4', '7', '4', '8', '4', '9',
+'5', '0', '5', '1', '5', '2', '5', '3', '5', '4',
+'5', '5', '5', '6', '5', '7', '5', '8', '5', '9',
+'6', '0', '6', '1', '6', '2', '6', '3', '6', '4',
+'6', '5', '6', '6', '6', '7', '6', '8', '6', '9',
+'7', '0', '7', '1', '7', '2', '7', '3', '7', '4',
+'7', '5', '7', '6', '7', '7', '7', '8', '7', '9',
+'8', '0', '8', '1', '8', '2', '8', '3', '8', '4',
+'8', '5', '8', '6', '8', '7', '8', '8', '8', '9',
+'9', '0', '9', '1', '9', '2', '9', '3', '9', '4',
+'9', '5', '9', '6', '9', '7', '9', '8', '9', '9',
+};
+
+void uint64_to_ascii_ta7_32_base100(uint64_t val, char *dst) {
+  const int64_t POW10_10 = ((int64_t)10) * 1000 * 1000 * 1000;
+  const uint64_t POW2_57_DIV_POW100_4 =
+  ((int64_t)(1) << 57) / 100 / 100 / 100 / 100 + 1;
+  const uint64_t MASK32 = ((int64_t)(1) << 32) - 1;
+  int64_t hix = val / POW10_10;
+  int64_t lox = val % POW10_10;
+  int64_t lor = lox & (uint64_t)(-2);
+  uint64_t hi = hix * POW2_57_DIV_POW100_4;
+  uint64_t lo = lor * POW2_57_DIV_POW100_4;
+  memcpy(dst + 0 * 10 + 0, _tab[(hi >> 57) * 2], 2);
+  memcpy(dst + 1 * 10 + 0, _tab[(lo >> 57) * 2], 2);
+  hi = (hi >> 25) + 1;
+  lo = (lo >> 25) + 1;
+  hi = (hi & MASK32) * 100;
+  lo = (lo & MASK32) * 100;
+  memcpy(dst + 0 * 10 + 2, _tab[(hi >> 32) * 2], 2);
+  hi = (hi & MASK32) * 100;
+  memcpy(dst + 1 * 10 + 2, _tab[(lo >> 32) * 2], 2);
+  lo = (lo & MASK32) * 100;
+  memcpy(dst + 0 * 10 + 4, _tab[(hi >> 32) * 2], 2);
+  hi = (hi & MASK32) * 100;
+  memcpy(dst + 1 * 10 + 4, _tab[(lo >> 32) * 2], 2);
+  lo = (lo & MASK32) * 100;
+  memcpy(dst + 0 * 10 + 6, _tab[(hi >> 32) * 2], 2);
+  hi = (hi & MASK32) * 100;
+  memcpy(dst + 1 * 10 + 6, _tab[(lo >> 32) * 2], 2);
+  lo = (lo & MASK32) * 100;
+  hi >>= 32;
+  lo >>= 32;
+  lo = (lo & (-2)) | (lox & 1);
+  memcpy(dst + 0 * 10 + 8, _tab[hi * 2], 2);
+  memcpy(dst +