Fix divergence of profile data with -flto and without

2018-12-27 Thread Jan Hubicka
Hi,
Firefox was patched to build train run w/o LTO and final build with LTO.
This causes problems where LTO and non-LTO builds diverge during early
optimization. This can happen because free_lang_data clears type
inheritance graph which in turn is rebuilt taking into account what
virtual tables has been optimized out and leads to better
devirutalization. This seems to trigger surprisinly often for Firefox
and is fixed by rebuilding it all the time.

While reducing (a gigantic) testcase I ran into ICE which is fixed too.
Dumping code has sanity check that speculative targets are subset of
full targets list and this condition is broken in a specil case where
new type is introduced into the type inheritnace graph later and one of
lists is cached from time it was not there.

I can not clear the cache each time new type is introduced because
passes use cache addresses to avoid redundant work on lists which was
seen prevoiusly, but it is easy to avoid re-use of the old entries when
this hapens.

Bootstrapped/regtested x86_64-linux, commited to mainline. I plan to
backport this to release branches after few days.
I still see some profile mismatches on Firefox and I am investigating
whether it is difference on firefox or gcc side.

Honza

* ipa-devirt.c (polymorphic_call_target_d): Add n_odr_types.
(polymorphic_call_target_hasher::hash): Hash it.
(polymorphic_call_target_hasher::equal): Compare it.
(possible_polymorphic_call_targets): Set it.
* tree.c (free_lang_data): Rebuild type inheritance graph even on
non-LTO path.

* g++.dg/ipa/devirt-53.C: New testcase.
Index: ipa-devirt.c
===
--- ipa-devirt.c(revision 267432)
+++ ipa-devirt.c(working copy)
@@ -2759,6 +2758,7 @@ struct polymorphic_call_target_d
   vec  targets;
   tree decl_warning;
   int type_warning;
+  unsigned int n_odr_types;
   bool complete;
   bool speculative;
 };
@@ -2784,6 +2784,7 @@ polymorphic_call_target_hasher::hash (co
   hstate.add_hwi (odr_query->type->id);
   hstate.merge_hash (TYPE_UID (odr_query->context.outer_type));
   hstate.add_hwi (odr_query->context.offset);
+  hstate.add_hwi (odr_query->n_odr_types);
 
   if (odr_query->context.speculative_outer_type)
 {
@@ -2814,7 +2815,9 @@ polymorphic_call_target_hasher::equal (c
  == t2->context.maybe_in_construction
  && t1->context.maybe_derived_type == t2->context.maybe_derived_type
  && (t1->context.speculative_maybe_derived_type
- == t2->context.speculative_maybe_derived_type));
+ == t2->context.speculative_maybe_derived_type)
+ /* Adding new type may affect outcome of target search.  */
+ && t1->n_odr_types == t2->n_odr_types);
 }
 
 /* Remove entry in polymorphic call target cache hash.  */
@@ -3220,6 +3223,7 @@ possible_polymorphic_call_targets (tree
   key.otr_token = otr_token;
   key.speculative = speculative;
   key.context = context;
+  key.n_odr_types = odr_types.length ();
   slot = polymorphic_call_target_hash->find_slot (, INSERT);
   if (cache_token)
*cache_token = (void *)*slot;
@@ -3436,6 +3440,7 @@ possible_polymorphic_call_targets (tree
 
   (*slot)->targets = nodes;
   (*slot)->complete = complete;
+  (*slot)->n_odr_types = odr_types.length ();
   if (completep)
 *completep = complete;
 
Index: testsuite/g++.dg/ipa/devirt-53.C
===
--- testsuite/g++.dg/ipa/devirt-53.C(nonexistent)
+++ testsuite/g++.dg/ipa/devirt-53.C(working copy)
@@ -0,0 +1,58 @@
+// { dg-do assemble }
+// { dg-options "-O2 -fdump-tree-fre1-details -std=c++11 -Wno-return-type" }
+typedef unsigned a;
+enum b : a;
+class c {
+public:
+  virtual a d();
+};
+using e = int;
+class f;
+class h {
+public:
+  f *operator->();
+};
+class i {
+public:
+  ~i() { j->d(); }
+  c *j;
+};
+template  class k : i {
+public:
+  k(g *);
+};
+class l;
+class m {
+  virtual b n(const e &, l **);
+};
+class o {
+protected:
+  h p;
+};
+class G {
+  virtual b r(const e &, l **);
+};
+class l : G {};
+class q {
+public:
+  q(l *);
+  template  void s(t);
+};
+class f : c {
+  a d();
+  virtual b r(e);
+
+public:
+  class L : public l, o, m {
+b r(const e , l **) { p->r(y); }
+b n(const e &, l **) { k a = this; }
+  };
+};
+c u;
+void fn1() {
+  c v;
+  k b();
+  q(new f::L).s(v);
+}
+/* Check that f::d appears as possible target.  */
+/* { dg-final { scan-tree-dump "f::d" "fre"  } } */
Index: tree.c
===
--- tree.c  (revision 267432)
+++ tree.c  (working copy)
@@ -6191,7 +6191,12 @@ free_lang_data (void)
   /* If we are the LTO frontend we have freed lang-specific data already.  */
   if (in_lto_p
   || (!flag_generate_lto && !flag_generate_offload))
-return 0;
+{
+  /* Rebuild type inheritance graph even when not doing LTO to get
+

Re: [PATCH] PR fortran/81027 -- Issue error for assumed-shape array

2018-12-27 Thread Steve Kargl
On Thu, Dec 27, 2018 at 12:54:30PM +0100, Dominique d'Humières wrote:
> Hi Steve,
> 
> The test gfortran.dg/pr81027.f90 succeeds without the patch.
> Would not it be better to replace
> 
> { dg-error "is not permitted in an" }
> 
> with something such as
> 
> { dg-error "Assumed-shape array" }
> 
> ?
> 
> Otherwise the patch works as expected.
> 
> Thank for the fix.
> 

For the record, here's the commit message and patch that I committed.

2018-12-27  Steven G. Kargl  

PR fortran/81027
* expr.c (gfc_check_init_expr): Distinguish assumed-shape versus
deferred-shape dummy arguments in an error message.

2018-12-27  Steven G. Kargl  

PR fortran/81027
* gfortran.dg/pr81027.f90: New test.
* gfortran.dg/initialization_7.f90: Update error message.
-- 
Steve
Index: gcc/fortran/expr.c
===
--- gcc/fortran/expr.c	(revision 267435)
+++ gcc/fortran/expr.c	(working copy)
@@ -2869,9 +2869,16 @@ gfc_check_init_expr (gfc_expr *e)
 		break;
 
 	  case AS_DEFERRED:
-		gfc_error ("Deferred array %qs at %L is not permitted "
-			   "in an initialization expression",
-			   e->symtree->n.sym->name, >where);
+		if (!e->symtree->n.sym->attr.allocatable
+		&& !e->symtree->n.sym->attr.pointer
+		&& e->symtree->n.sym->attr.dummy)
+		  gfc_error ("Assumed-shape array %qs at %L is not permitted "
+			 "in an initialization expression",
+			 e->symtree->n.sym->name, >where);
+		else
+		  gfc_error ("Deferred array %qs at %L is not permitted "
+			 "in an initialization expression",
+			 e->symtree->n.sym->name, >where);
 		break;
 
 	  case AS_EXPLICIT:
Index: gcc/testsuite/gfortran.dg/pr81027.f90
===
--- gcc/testsuite/gfortran.dg/pr81027.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr81027.f90	(working copy)
@@ -0,0 +1,11 @@
+program badarray
+  implicit none
+  integer:: j(3) = [1,2,3]
+  call doubling(j)
+contains
+  subroutine doubling(  n)
+integer,intent(in)::n(:)
+integer::m = size(n)  ! { dg-error "Assumed-shape array" }
+print *, m! { dg-error "has no IMPLICIT type" }
+  end subroutine doubling
+end program badarray
Index: gcc/testsuite/gfortran.dg/initialization_7.f90
===
--- gcc/testsuite/gfortran.dg/initialization_7.f90	(revision 267435)
+++ gcc/testsuite/gfortran.dg/initialization_7.f90	(working copy)
@@ -6,7 +6,7 @@
 
 subroutine probleme(p)
   real(kind=8), dimension(:) :: p
-  integer :: nx = size(p, 1)  ! { dg-error "Deferred array" }
+  integer :: nx = size(p, 1)  ! { dg-error "Assumed-shape array" }
   integer :: nix
 
   nix = nx


Re: [PATCH] PR fortran/81509 and fortran/45513

2018-12-27 Thread Steve Kargl
On Thu, Dec 27, 2018 at 11:24:07AM +, Sudakshina Das wrote:
> With the failure as:
> 
> Excess errors:
> /build/src/gcc/libgomp/testsuite/libgomp.fortran/aligned1.f03:55:14: 
> Error: Arguments of 'iand' have different kind type parameters at (1)
> /build/src/gcc/libgomp/testsuite/libgomp.fortran/aligned1.f03:59:14: 
> Error: Arguments of 'iand' have different kind type parameters at (1)
> 

This should be fixed, now.  Sorry about the breakage.

-- 
Steve


PATCH: Updated error messages for ill-formed cases of array initialization by string literal

2018-12-27 Thread Tom Honermann
As requested by Jason in the review of the P0482 (char8_t) core language 
changes, this patch includes updates to the error messages emitted for 
ill-formed cases of array initialization with a string literal.  With 
these changes, error messages that previously looked something like these:


- "char-array initialized from wide string"
- "wide character array initialized from non-wide string"
- "wide character array initialized from incompatible wide string"

now look like:

- "cannot initialize array of type 'char' from a string literal with 
type array of 'short unsigned int'"
- "cannot initialize array of type 'short unsigned int' from a string 
literal with type array of 'char'"
- "cannot initialize array of type 'short unsigned int' from a string 
literal with type array of 'unsigned int'"


These changes affect both the C and C++ front ends.

These changes have dependencies on the (revised) set of patches 
submitted for P0482 (char8_t) and will not apply cleanly without them.


Tested on x86_64-linux.

gcc/c/ChangeLog:

2018-12-26  Tom Honermann  

 * c-typeck.c (digest_init): Revised the error message produced for
 ill-formed cases of array initialization with a string literal.

gcc/cp/ChangeLog:

2018-12-26  Tom Honermann  

 * typeck2.c (digest_init_r): Revised the error message produced for
 ill-formed cases of array initialization with a string literal.

gcc/testsuite/ChangeLog:

2018-12-26  Tom Honermann  

 * gcc/testsuite/g++.dg/ext/char8_t-init-2.C: Updated the expected
 error messages for ill-formed cases of array initialization with a
 string literal.
 * gcc/testsuite/g++.dg/ext/utf-array-short-wchar.C: Likewise.
 * gcc/testsuite/g++.dg/ext/utf-array.C: Likewise.
 * gcc/testsuite/g++.dg/ext/utf8-2.C: Likewise.
 * gcc/testsuite/gcc.dg/init-string-2.c: Likewise.
 * gcc/testsuite/gcc.dg/pr61096-1.c: Likewise.
 * gcc/testsuite/gcc.dg/utf-array-short-wchar.c: Likewise.
 * gcc/testsuite/gcc.dg/utf-array.c: Likewise.
 * gcc/testsuite/gcc.dg/utf8-2.c: Likewise.

Tom.

diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 9d09b8d65fd..4d2129dff2f 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -7447,6 +7447,7 @@ digest_init (location_t init_loc, tree type, tree init, tree origtype,
 	{
 	  struct c_expr expr;
 	  tree typ2 = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)));
+	  bool incompat_string_cst = false;
 	  expr.value = inside_init;
 	  expr.original_code = (strict_string ? STRING_CST : ERROR_MARK);
 	  expr.original_type = NULL;
@@ -7464,27 +7465,22 @@ digest_init (location_t init_loc, tree type, tree init, tree origtype,
 	{
 	  if (typ2 != char_type_node)
 		{
-		  error_init (init_loc, "char-array initialized from wide "
-			  "string");
-		  return error_mark_node;
+		  incompat_string_cst = true;
 		}
 	}
-	  else
+	  else if (!comptypes(typ1, typ2))
 	{
-	  if (typ2 == char_type_node)
-		{
-		  error_init (init_loc, "wide character array initialized "
-			  "from non-wide string");
-		  return error_mark_node;
-		}
-	  else if (!comptypes(typ1, typ2))
-		{
-		  error_init (init_loc, "wide character array initialized "
-			  "from incompatible wide string");
-		  return error_mark_node;
-		}
+	  incompat_string_cst = true;
 	}
 
+  if (incompat_string_cst)
+{
+	  error_at (init_loc, "cannot initialize array of type %qT from "
+	"a string literal with type array of %qT",
+	typ1, typ2);
+	  return error_mark_node;
+}
+
 	  if (TYPE_DOMAIN (type) != NULL_TREE
 	  && TYPE_SIZE (type) != NULL_TREE
 	  && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 782fd7f9cd5..ae3b53dc001 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -1060,46 +1060,43 @@ digest_init_r (tree type, tree init, int nested, int flags,
 	  && TREE_CODE (init) == STRING_CST)
 	{
 	  tree char_type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (init)));
+	  bool incompat_string_cst = false;
 
-	  if (TYPE_PRECISION (typ1) == BITS_PER_UNIT)
+	  if (typ1 != char_type)
 	{
-	  if (typ1 != char8_type_node && char_type == char8_type_node)
+	  /* The array element type does not match the initializing string
+	 literal element type. This is only allowed when initializing
+	 an array of signed char or unsigned char.  */
+	  if (TYPE_PRECISION (typ1) == BITS_PER_UNIT)
 		{
-		  if (complain & tf_error)
-		error_at (loc, "char-array initialized from UTF-8 string");
-		  return error_mark_node;
-		}
-	  else if (typ1 == char8_type_node && char_type == char_type_node)
-		{
-		  if (complain & tf_error)
-		error_at (loc, "char8_t-array initialized from ordinary "
-			  "string");
-		  return error_mark_node;
+		  if (typ1 == char8_type_node)
+		{
+		  /* char8_t array initialized with a non-char8_t
+		 string literal.  */

Re: [PATCH] PR fortran/81027 -- Issue error for assumed-shape array

2018-12-27 Thread Steve Kargl
On Thu, Dec 27, 2018 at 12:54:30PM +0100, Dominique d'Humières wrote:
> Hi Steve,
> 
> The test gfortran.dg/pr81027.f90 succeeds without the patch. Would not it be 
> better to replace
> 
> { dg-error "is not permitted in an" }
> 
> with something such as
> 
> { dg-error "Assumed-shape array" }
> 
> ?
> 
> Otherwise the patch works as expected.
> 

Sure.  I also need to fix initialization_7.f90 that
showed up in some additional testing.

-- 
Steve


Re: [PATCH] PR fortran/81509 and fortran/45513

2018-12-27 Thread Steve Kargl
On Thu, Dec 27, 2018 at 11:24:07AM +, Sudakshina Das wrote:
> > PR fortran/45513
> > PR fortran/81509
> > * gfortran.dg/graphite/id-26.f03: Fix non-conforming use of IAND.
> > * gfortran.dg/pr81509_1.f90: New test.
> > * gfortran.dg/pr81509_2.f90: New test.
> >
> This patch has caused the following failures on aarch64-none-linux-gnu:
> 
> FAIL: libgomp.fortran/aligned1.f03   -O0  (test for excess errors)
> FAIL: libgomp.fortran/aligned1.f03   -O1  (test for excess errors)
> FAIL: libgomp.fortran/aligned1.f03   -O2  (test for excess errors)
> FAIL: libgomp.fortran/aligned1.f03   -O3 -fomit-frame-pointer 
> -funroll-loops -fpeel-loops -ftracer -finline-functions  (test for 
> excess errors)
> FAIL: libgomp.fortran/aligned1.f03   -O3 -g  (test for excess errors)
> FAIL: libgomp.fortran/aligned1.f03   -Os  (test for excess errors)
> 
> With the failure as:
> 
> Excess errors:
> /build/src/gcc/libgomp/testsuite/libgomp.fortran/aligned1.f03:55:14: 
> Error: Arguments of 'iand' have different kind type parameters at (1)
> /build/src/gcc/libgomp/testsuite/libgomp.fortran/aligned1.f03:59:14: 
> Error: Arguments of 'iand' have different kind type parameters at (1)
> 

Well, it nice to see that the patch is catching invalid Fortran.
Can you test this patch?

Index: libgomp/testsuite/libgomp.fortran/aligned1.f03
===
--- libgomp/testsuite/libgomp.fortran/aligned1.f03  (revision 267418)
+++ libgomp/testsuite/libgomp.fortran/aligned1.f03  (working copy)
@@ -52,11 +52,11 @@
   ! Attempt to create 64-byte aligned allocatable
   do i = 1, 64
 allocate (c(1023 + i))
-if (iand (loc (c(1)), 63) == 0) exit
+if (iand (int(loc (c(1)), 8), int(63, 8)) == 0) exit
 deallocate (c)
 allocate (b(i)%a(1023 + i))
 allocate (c(1023 + i))
-if (iand (loc (c(1)), 63) == 0) exit
+if (iand (int(loc (c(1)), 8), int(63, 8)) == 0) exit
 deallocate (c)
   end do
   if (allocated (c)) then



-- 
Steve
20170425 https://www.youtube.com/watch?v=VWUpyCsUKR4
20161221 https://www.youtube.com/watch?v=IbCHE-hONow


Re: [PATCH v4 4/6, Committed] [MIPS] Add Loongson 3A1000 processor support

2018-12-27 Thread Gerald Pfeifer
Hi Paul and Matthew,

I believe it would be good to get this and other MIPS changes covered
in the GCC 9 release notes at https://gcc.gnu.org/gcc-9/changes.html .

Gerald

PS: https://gcc.gnu.org/about.html has background how to go about this.


Re: [PATCH 5/5][libbacktrace] Reduce memory usage in build_address_map

2018-12-27 Thread Ian Lance Taylor via gcc-patches
On Wed, Nov 28, 2018 at 3:18 PM Tom de Vries  wrote:
>
> In build_address_map we allocate a unit, and then look for addresses in the
> unit, which we store in the addrs vector, with the elements pointing to the
> unit.  However, if we cannot find addresses in the unit, the allocated unit is
> not used.
>
> Fix this by detecting if the allocated unit has been used, and reusing it
> otherwise.
>
> Bootstrapped and reg-tested on x86_64.
>
> OK for trunk?
>
> Thanks,
> - Tom
>
> [libbacktrace] Reduce memory usage in build_address_map
>
> 2018-11-28  Tom de Vries  
>
> * dwarf.c (build_address_map): Reuse unused units.
>
> ---
>  libbacktrace/dwarf.c | 13 +
>  1 file changed, 13 insertions(+)
>
> diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c
> index f843fab7529..ff97a20808c 100644
> --- a/libbacktrace/dwarf.c
> +++ b/libbacktrace/dwarf.c
> @@ -1436,9 +1436,11 @@ build_address_map (struct backtrace_state *state, 
> uintptr_t base_address,
>size_t units_count;
>size_t i;
>struct unit **pu;
> +  size_t prev_addrs_count;
>
>memset (>vec, 0, sizeof addrs->vec);
>addrs->count = 0;
> +  prev_addrs_count = 0;
>
>/* Read through the .debug_info section.  FIXME: Should we use the
>   .debug_aranges section?  gdb and addr2line don't use it, but I'm
> @@ -1534,6 +1536,17 @@ build_address_map (struct backtrace_state *state, 
> uintptr_t base_address,
>
>if (unit_buf.reported_underflow)
> goto fail;
> +
> +  if (addrs->count == prev_addrs_count)
> +   {
> + --units_count;
> + units.size -= sizeof (u);
> + units.alc += sizeof (u);
> + free_abbrevs (state, >abbrevs, error_callback, data);
> + backtrace_free (state, u, sizeof *u, error_callback, data);
> +   }
> +  else
> +   prev_addrs_count = addrs->count;
>  }
>if (info.reported_underflow)
>  goto fail;

Please flip the code to make the simple case first.

if (addrs->count > prev_addrs_count)
  prev_addrs_count = addrs->count;
else
  {
/* Unit was not used; remove it from the vector.  */
--units_count;
...
  }

OK with that change.

Thanks.

Ian


Re: [PATCH 4/5][libbacktrace] Simplify memory management in build_address_map

2018-12-27 Thread Ian Lance Taylor via gcc-patches
On Wed, Nov 28, 2018 at 3:17 PM Tom de Vries  wrote:
>
> In the main loop in build_address_map, we first read the abbrevs into a local
> variable abbrevs, and then allocate the corresponding unit, after which we 
> assign
> the abbrevs to the unit.  This results in dedicated free-upon-failure
> handling for the variable, and extra code to make sure that free-upon-failure
> doesn't trigger once the unit has taken ownership of the abbrevs.
>
> Simplify this by reversing the order of abbrev reading and unit allocation,
> and eliminating the abbrevs local variable.
>
> Bootstrapped and reg-tested on x86_64.
>
> OK for trunk?
>
> Thanks,
> - Tom
>
> [libbacktrace] Simplify memory management in build_address_map
>
> 2018-11-28  Tom de Vries  
>
> * dwarf.c (build_address_map): Simplify by removing local variable
> abbrevs.

This is OK.

Thanks.

Ian


libgo patch committed: Delete runtime/export_arm_test.go

2018-12-27 Thread Ian Lance Taylor
This patch by Cherry Zhang deletes runtime/export_arm_test.go.  The
only thing export_arm_test.go does is to export usplit, which does not
exist in gccgo.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
Index: gcc/go/gofrontend/MERGE
===
--- gcc/go/gofrontend/MERGE (revision 267434)
+++ gcc/go/gofrontend/MERGE (working copy)
@@ -1,4 +1,4 @@
-5a9ff61d72c95a50cbbfb0e1bf57646197910363
+416baf55e4890acab244470f6457372987a17a68
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/go/runtime/export_arm_test.go
===
--- libgo/go/runtime/export_arm_test.go (revision 267433)
+++ libgo/go/runtime/export_arm_test.go (nonexistent)
@@ -1,9 +0,0 @@
-// Copyright 2015 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Export guts for testing.
-
-package runtime
-
-var Usplit = usplit


libgo patch committed: Let ARM EABI continue unwind during traceback

2018-12-27 Thread Ian Lance Taylor
This patch by Cherry Zhang lets the ARM32 EABI personality function
continue unwinding when called during traceback.  On ARM32 EABI,
unlike other platforms, the personality function is called during
_Unwind_Backtrace (libgcc/unwind-arm-common.inc:581).  In this case,
simply unwind the frame without returning any handlers. Otherwise
traceback will loop if there is a frame with a defer on stack.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
Index: gcc/go/gofrontend/MERGE
===
--- gcc/go/gofrontend/MERGE (revision 267433)
+++ gcc/go/gofrontend/MERGE (working copy)
@@ -1,4 +1,4 @@
-785414705628bf9d1279a8042e1886440424aade
+5a9ff61d72c95a50cbbfb0e1bf57646197910363
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/runtime/go-unwind.c
===
--- libgo/runtime/go-unwind.c   (revision 267433)
+++ libgo/runtime/go-unwind.c   (working copy)
@@ -444,6 +444,9 @@ PERSONALITY_FUNCTION (int version,
   switch (state & _US_ACTION_MASK)
 {
 case _US_VIRTUAL_UNWIND_FRAME:
+  if (state & _UA_FORCE_UNWIND)
+/* We are called from _Unwind_Backtrace.  No handler to run.  */
+CONTINUE_UNWINDING;
   actions = _UA_SEARCH_PHASE;
   break;
 


Re: [PATCH 3/5][libbacktrace] Fix memory leak in loop in build_address_map

2018-12-27 Thread Ian Lance Taylor via gcc-patches
On Wed, Nov 28, 2018 at 3:17 PM Tom de Vries  wrote:
>
> When failing in build_address_map, we free the unit that's currently being
> handled in the loop, but the ones that already have been allocated are leaked.
>
> Fix this by keeping track of allocated units in a vector, and releasing them
> upon failure.
>
> Also, now that we have a vector of allocated units, move the freeing upon
> failure of the abbrevs associated with each unit to build_address_map, and
> remove the now redundant call to free_unit_addrs_vector.
>
> Bootstrapped and reg-tested on x86_64.
>
> OK for trunk?
>
> Thanks,
> - Tom
>
> [libbacktrace] Fix memory leak in loop in build_address_map
>
> 2018-11-28  Ian Lance Taylor  
> Tom de Vries  
>
> PR libbacktrace/88063
> * dwarf.c (free_unit_addrs_vector): Remove.
> (build_address_map): Keep track of allocated units in vector.  Free
> allocated units and corresponding abbrevs upon failure.  Remove now
> redundant call to free_unit_addrs_vector.  Free addrs vector upon
> failure.  Free allocated unit vector.

This is OK.

Thanks.

Ian


Re: [PATCH 2/5][libbacktrace] Fix memory leak in build_address_map

2018-12-27 Thread Ian Lance Taylor via gcc-patches
On Wed, Nov 28, 2018 at 3:16 PM Tom de Vries  wrote:
>
> While upon failure in build_address_map we call free_unit_addrs_vector, this
> does not actually free the addrs vector, but merely the abbrevs of the units
> pointed at by the elements of the addrs vector.
>
> Fix this by adding code to build_address_map to make sure that the addrs 
> vector
> is freed upon failure.
>
> Bootstrapped and reg-tested on x86_64.
>
> OK for trunk?
>
> Thanks,
> - Tom
>
> [libbacktrace] Fix memory leak in build_address_map
>
> 2018-11-28  Tom de Vries  
>
> * dwarf.c (build_address_map): Free addrs vector upon failure.

This is OK.

Thanks.

Ian


[PATCH 7/8] c++, asm: Do not handle any asm-qualifiers in top-level asm

2018-12-27 Thread Segher Boessenkool
Previously, "volatile" was allowed.  Changing this simplifies the code,
makes things more regular, and makes the C and C++ frontends handle
this the same way.

2018-12-10  Segher Boessenkool  

cp/
* parser.c (cp_parser_asm_definition): Do not allow any asm qualifiers
on top-level asm.

testsuite/
* g++.dg/asm-qual-3.C: New testcase.
* gcc.dg/asm-qual-3.c: New testcase.
---
 gcc/cp/parser.c   |  7 ++-
 gcc/testsuite/g++.dg/asm-qual-3.C | 12 
 gcc/testsuite/gcc.dg/asm-qual-3.c |  9 +
 3 files changed, 23 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/asm-qual-3.C
 create mode 100644 gcc/testsuite/gcc.dg/asm-qual-3.c

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 36d82b8..afc7b96 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -19125,7 +19125,8 @@ cp_parser_asm_definition (cp_parser* parser)
   location_t volatile_loc = UNKNOWN_LOCATION;
   location_t inline_loc = UNKNOWN_LOCATION;
   location_t goto_loc = UNKNOWN_LOCATION;
-  if (cp_parser_allow_gnu_extensions_p (parser))
+
+  if (cp_parser_allow_gnu_extensions_p (parser) && parser->in_function_body)
 for (;;)
   {
cp_token *token = cp_lexer_peek_token (parser->lexer);
@@ -19144,8 +19145,6 @@ cp_parser_asm_definition (cp_parser* parser)
continue;
 
  case RID_INLINE:
-   if (!parser->in_function_body)
- break;
if (inline_loc)
  {
error_at (loc, "duplicate asm qualifier %qT", token->u.value);
@@ -19157,8 +19156,6 @@ cp_parser_asm_definition (cp_parser* parser)
continue;
 
  case RID_GOTO:
-   if (!parser->in_function_body)
- break;
if (goto_loc)
  {
error_at (loc, "duplicate asm qualifier %qT", token->u.value);
diff --git a/gcc/testsuite/g++.dg/asm-qual-3.C 
b/gcc/testsuite/g++.dg/asm-qual-3.C
new file mode 100644
index 000..95c9b57
--- /dev/null
+++ b/gcc/testsuite/g++.dg/asm-qual-3.C
@@ -0,0 +1,12 @@
+// Test that asm-qualifiers are not allowed on toplevel asm.
+// { dg-do compile }
+// { dg-options "-std=gnu++98" }
+
+asm const ("");// { dg-error {expected '\(' before 'const'} }
+asm volatile (""); // { dg-error {expected '\(' before 'volatile'} }
+asm restrict (""); // { dg-error {expected '\(' before 'restrict'} }
+asm inline ("");   // { dg-error {expected '\(' before 'inline'} }
+asm goto (""); // { dg-error {expected '\(' before 'goto'} }
+
+// There are many other things wrong with this code, so:
+// { dg-excess-errors "" }
diff --git a/gcc/testsuite/gcc.dg/asm-qual-3.c 
b/gcc/testsuite/gcc.dg/asm-qual-3.c
new file mode 100644
index 000..f85d8bf
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/asm-qual-3.c
@@ -0,0 +1,9 @@
+/* Test that asm-qualifiers are not allowed on toplevel asm.  */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99" } */
+
+asm const ("");/* { dg-error {expected '\(' before 'const'} } */
+asm volatile (""); /* { dg-error {expected '\(' before 'volatile'} } */
+asm restrict (""); /* { dg-error {expected '\(' before 'restrict'} } */
+asm inline ("");   /* { dg-error {expected '\(' before 'inline'} } */
+asm goto (""); /* { dg-error {expected '\(' before 'goto'} } */
-- 
1.8.3.1



[PATCH 8/8] c: Don't error for const or restrict as asm-qualifier

2018-12-27 Thread Segher Boessenkool
2018-12-27  Segher Boessenkool  

c/
* c-parser.c (c_parser_asm_statement): Output a warning instead of an
error for const and restrict.

testsuite/
* gcc.dg/asm-qual-1.c: Adjust.

---
 gcc/c/c-parser.c  | 2 +-
 gcc/testsuite/gcc.dg/asm-qual-1.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 4baad62..a960169 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -6345,7 +6345,7 @@ c_parser_asm_statement (c_parser *parser)
 
case RID_CONST:
case RID_RESTRICT:
- error_at (loc, "%qE is not an asm qualifier", token->value);
+ warning_at (loc, 0, "%qE is not an asm qualifier", token->value);
  c_parser_consume_token (parser);
  continue;
 
diff --git a/gcc/testsuite/gcc.dg/asm-qual-1.c 
b/gcc/testsuite/gcc.dg/asm-qual-1.c
index eff6b45..4982a6b 100644
--- a/gcc/testsuite/gcc.dg/asm-qual-1.c
+++ b/gcc/testsuite/gcc.dg/asm-qual-1.c
@@ -8,7 +8,7 @@ f (void)
 {
   asm volatile ("");
 
-  asm const (""); /* { dg-error {'const' is not an asm qualifier} } */
+  asm const (""); /* { dg-warning {'const' is not an asm qualifier} } */
 
-  asm restrict (""); /* { dg-error {'restrict' is not an asm qualifier} } */
+  asm restrict (""); /* { dg-warning {'restrict' is not an asm qualifier} } */
 }
-- 
1.8.3.1



[PATCH 6/8] c/c++, asm: Use nicer error for const and restrict

2018-12-27 Thread Segher Boessenkool
Not all qualifiers are asm qualifiers.  We can talk about that in a
nicer way than just giving a generic parser error.

This also adds two testcases for C++, that previously were for C only.

2018-12-10  Segher Boessenkool  

c/
* c-parser.c (c_parser_asm_statement) : Give
a more specific error message (instead of just falling through).

cp/
* parser.c (cp_parser_asm_definition) : Give
a more specific error message (instead of just falling through).

testsuite/
* g++.dg/asm-qual-1.C: New testcase.
* g++.dg/asm-qual-2.C: New testcase.
* gcc.dg/asm-qual-1.c: Update.
---
 gcc/c/c-parser.c  |  6 +
 gcc/cp/parser.c   |  6 +
 gcc/testsuite/g++.dg/asm-qual-1.C | 13 +++
 gcc/testsuite/g++.dg/asm-qual-2.C | 46 +++
 gcc/testsuite/gcc.dg/asm-qual-1.c |  6 ++---
 5 files changed, 73 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/asm-qual-1.C
 create mode 100644 gcc/testsuite/g++.dg/asm-qual-2.C

diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index ca04910..4baad62 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -6343,6 +6343,12 @@ c_parser_asm_statement (c_parser *parser)
  c_parser_consume_token (parser);
  continue;
 
+   case RID_CONST:
+   case RID_RESTRICT:
+ error_at (loc, "%qE is not an asm qualifier", token->value);
+ c_parser_consume_token (parser);
+ continue;
+
default:
  break;
}
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 44fdace..36d82b8 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -19169,6 +19169,12 @@ cp_parser_asm_definition (cp_parser* parser)
cp_lexer_consume_token (parser->lexer);
continue;
 
+ case RID_CONST:
+ case RID_RESTRICT:
+   error_at (loc, "%qT is not an asm qualifier", token->u.value);
+   cp_lexer_consume_token (parser->lexer);
+   continue;
+
  default:
break;
  }
diff --git a/gcc/testsuite/g++.dg/asm-qual-1.C 
b/gcc/testsuite/g++.dg/asm-qual-1.C
new file mode 100644
index 000..3fba592
--- /dev/null
+++ b/gcc/testsuite/g++.dg/asm-qual-1.C
@@ -0,0 +1,13 @@
+// Test that qualifiers other than volatile are disallowed on asm.
+// { dg-do compile }
+// { dg-options "-std=gnu++98" }
+
+void
+f ()
+{
+  asm volatile ("");
+
+  asm const (""); // { dg-error {'const' is not an asm qualifier} }
+
+  asm __restrict (""); // { dg-error {'__restrict' is not an asm qualifier} }
+}
diff --git a/gcc/testsuite/g++.dg/asm-qual-2.C 
b/gcc/testsuite/g++.dg/asm-qual-2.C
new file mode 100644
index 000..52968bd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/asm-qual-2.C
@@ -0,0 +1,46 @@
+// Test that qualifiers on asm are allowed in any order.
+// { dg-do compile }
+// { dg-options "-std=c++98" }
+
+void
+f ()
+{
+  asm volatile goto (""  lab);
+  asm volatile inline ("" :::);
+  asm inline volatile ("" :::);
+  asm inline goto (""  lab);
+  asm goto volatile (""  lab);
+  asm goto inline (""  lab);
+
+  asm volatile inline goto (""  lab);
+  asm volatile goto inline (""  lab);
+  asm inline volatile goto (""  lab);
+  asm inline goto volatile (""  lab);
+  asm goto volatile inline (""  lab);
+  asm goto inline volatile (""  lab);
+
+  /* Duplicates are not allowed.  */
+  asm goto volatile volatile (""  lab);  /* { dg-error "" } */
+  asm volatile goto volatile (""  lab);  /* { dg-error "" } */
+  asm volatile volatile goto (""  lab);  /* { dg-error "" } */
+  asm goto goto volatile (""  lab);  /* { dg-error "" } */
+  asm goto volatile goto (""  lab);  /* { dg-error "" } */
+  asm volatile goto goto (""  lab);  /* { dg-error "" } */
+
+  asm inline volatile volatile ("" :::);  /* { dg-error "" } */
+  asm volatile inline volatile ("" :::);  /* { dg-error "" } */
+  asm volatile volatile inline ("" :::);  /* { dg-error "" } */
+  asm inline inline volatile ("" :::);  /* { dg-error "" } */
+  asm inline volatile inline ("" :::);  /* { dg-error "" } */
+  asm volatile inline inline ("" :::);  /* { dg-error "" } */
+
+  asm goto inline inline (""  lab);  /* { dg-error "" } */
+  asm inline goto inline (""  lab);  /* { dg-error "" } */
+  asm inline inline goto (""  lab);  /* { dg-error "" } */
+  asm goto goto inline (""  lab);  /* { dg-error "" } */
+  asm goto inline goto (""  lab);  /* { dg-error "" } */
+  asm inline goto goto (""  lab);  /* { dg-error "" } */
+
+lab:
+  ;
+}
diff --git a/gcc/testsuite/gcc.dg/asm-qual-1.c 
b/gcc/testsuite/gcc.dg/asm-qual-1.c
index cb37283..eff6b45 100644
--- a/gcc/testsuite/gcc.dg/asm-qual-1.c
+++ b/gcc/testsuite/gcc.dg/asm-qual-1.c
@@ -8,9 +8,7 @@ f (void)
 {
   asm volatile ("");
 
-  asm const (""); /* { dg-error {expected '\(' before 'const'} } */
-  /* { dg-error {expected identifier} {} {target *-*-*} .-1 } */
+  asm const (""); 

[PATCH 5/8] c/c++, asm: Use nicer error for duplicate asm qualifiers

2018-12-27 Thread Segher Boessenkool
Also as suggested by Jason.

Segher

2018-12-10  Segher Boessenkool  

c/
* c-parser.c (c_parser_asm_statement): Keep track of the location each
asm qualifier is first seen; use that to give nicer "duplicate asm
qualifier" messages.  Delete 'quals" variable, instead pass the
"is_volatile_ flag to build_asm_stmt directly.
* c-tree.h (build_asm_stmt): Make the first arg bool instead of tree.
* c-typeck.c (build_asm_stmt): Ditto; adjust.

cp/
* parser.c (cp_parser_asm_definition): Rewrite the loop to work without
"done" boolean variable.
* parser.c (cp_parser_asm_definition): Keep track of the location each
asm qualifier is first seen; use that to give nicer "duplicate asm
qualifier" messages.
---
 gcc/c/c-parser.c | 57 
 gcc/c/c-tree.h   |  2 +-
 gcc/c/c-typeck.c |  4 ++--
 gcc/cp/parser.c  | 45 
 4 files changed, 73 insertions(+), 35 deletions(-)

diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index b632f68..ca04910 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -6292,41 +6292,54 @@ c_parser_for_statement (c_parser *parser, bool ivdep, 
unsigned short unroll,
 static tree
 c_parser_asm_statement (c_parser *parser)
 {
-  tree quals, str, outputs, inputs, clobbers, labels, ret;
-  bool simple, is_volatile, is_inline, is_goto;
+  tree str, outputs, inputs, clobbers, labels, ret;
+  bool simple;
   location_t asm_loc = c_parser_peek_token (parser)->location;
   int section, nsections;
 
   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
   c_parser_consume_token (parser);
 
-  quals = NULL_TREE;
-  is_volatile = false;
-  is_inline = false;
-  is_goto = false;
+  /* Handle the asm-qualifier-list.  */
+  location_t volatile_loc = UNKNOWN_LOCATION;
+  location_t inline_loc = UNKNOWN_LOCATION;
+  location_t goto_loc = UNKNOWN_LOCATION;
   for (;;)
 {
-  switch (c_parser_peek_token (parser)->keyword)
+  c_token *token = c_parser_peek_token (parser);
+  location_t loc = token->location;
+  switch (token->keyword)
{
case RID_VOLATILE:
- if (is_volatile)
-   break;
- is_volatile = true;
- quals = c_parser_peek_token (parser)->value;
+ if (volatile_loc)
+   {
+ error_at (loc, "duplicate asm qualifier %qE", token->value);
+ inform (volatile_loc, "first seen here");
+   }
+ else
+   volatile_loc = loc;
  c_parser_consume_token (parser);
  continue;
 
case RID_INLINE:
- if (is_inline)
-   break;
- is_inline = true;
+ if (inline_loc)
+   {
+ error_at (loc, "duplicate asm qualifier %qE", token->value);
+ inform (inline_loc, "first seen here");
+   }
+ else
+   inline_loc = loc;
  c_parser_consume_token (parser);
  continue;
 
case RID_GOTO:
- if (is_goto)
-   break;
- is_goto = true;
+ if (goto_loc)
+   {
+ error_at (loc, "duplicate asm qualifier %qE", token->value);
+ inform (goto_loc, "first seen here");
+   }
+ else
+   goto_loc = loc;
  c_parser_consume_token (parser);
  continue;
 
@@ -6336,6 +6349,10 @@ c_parser_asm_statement (c_parser *parser)
   break;
 }
 
+  bool is_volatile = (volatile_loc != UNKNOWN_LOCATION);
+  bool is_inline = (inline_loc != UNKNOWN_LOCATION);
+  bool is_goto = (goto_loc != UNKNOWN_LOCATION);
+
   /* ??? Follow the C++ parser rather than using the
  lex_untranslated_string kludge.  */
   parser->lex_untranslated_string = true;
@@ -6410,9 +6427,9 @@ c_parser_asm_statement (c_parser *parser)
   if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
 c_parser_skip_to_end_of_block_or_statement (parser);
 
-  ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
-  clobbers, labels, simple,
-  is_inline));
+  ret = build_asm_stmt (is_volatile,
+   build_asm_expr (asm_loc, str, outputs, inputs,
+   clobbers, labels, simple, is_inline));
 
  error:
   parser->lex_untranslated_string = false;
diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h
index 7f34bdc..aa66aa2 100644
--- a/gcc/c/c-tree.h
+++ b/gcc/c/c-tree.h
@@ -679,7 +679,7 @@ extern tree c_start_case (location_t, location_t, tree, 
bool);
 extern void c_finish_case (tree, tree);
 extern tree build_asm_expr (location_t, tree, tree, tree, tree, tree, bool,
bool);
-extern tree build_asm_stmt (tree, tree);
+extern tree build_asm_stmt (bool, tree);
 extern int c_types_compatible_p (tree, tree);
 extern tree c_begin_compound_stmt (bool);
 extern tree 

[PATCH 4/8] c/c++, asm: Write the asm-qualifier loop without "done" boolean

2018-12-27 Thread Segher Boessenkool
As suggested by Jason.

Segher

2018-12-10  Segher Boessenkool  

c/
* c-parser.c (c_parser_asm_statement): Rewrite the loop to work without
"done" boolean variable.

cp/
* parser.c (cp_parser_asm_definition): Rewrite the loop to work without
"done" boolean variable.
---
 gcc/c/c-parser.c | 65 +--
 gcc/cp/parser.c  | 71 +---
 2 files changed, 62 insertions(+), 74 deletions(-)

diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index e45f70b..b632f68 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -6304,40 +6304,37 @@ c_parser_asm_statement (c_parser *parser)
   is_volatile = false;
   is_inline = false;
   is_goto = false;
-  for (bool done = false; !done; )
-switch (c_parser_peek_token (parser)->keyword)
-  {
-  case RID_VOLATILE:
-   if (!is_volatile)
- {
-   is_volatile = true;
-   quals = c_parser_peek_token (parser)->value;
-   c_parser_consume_token (parser);
- }
-   else
- done = true;
-   break;
-  case RID_INLINE:
-   if (!is_inline)
- {
-   is_inline = true;
-   c_parser_consume_token (parser);
- }
-   else
- done = true;
-   break;
-  case RID_GOTO:
-   if (!is_goto)
- {
-   is_goto = true;
-   c_parser_consume_token (parser);
- }
-   else
- done = true;
-   break;
-  default:
-   done = true;
-  }
+  for (;;)
+{
+  switch (c_parser_peek_token (parser)->keyword)
+   {
+   case RID_VOLATILE:
+ if (is_volatile)
+   break;
+ is_volatile = true;
+ quals = c_parser_peek_token (parser)->value;
+ c_parser_consume_token (parser);
+ continue;
+
+   case RID_INLINE:
+ if (is_inline)
+   break;
+ is_inline = true;
+ c_parser_consume_token (parser);
+ continue;
+
+   case RID_GOTO:
+ if (is_goto)
+   break;
+ is_goto = true;
+ c_parser_consume_token (parser);
+ continue;
+
+   default:
+ break;
+   }
+  break;
+}
 
   /* ??? Follow the C++ parser rather than using the
  lex_untranslated_string kludge.  */
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 3fd9a02..7660565 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -19124,47 +19124,38 @@ cp_parser_asm_definition (cp_parser* parser)
   cp_function_chain->invalid_constexpr = true;
 }
 
-  /* See if the next token is `volatile'.  */
+  /* Handle the asm-qualifier-list.  */
   if (cp_parser_allow_gnu_extensions_p (parser))
-for (bool done = false; !done ; )
-  switch (cp_lexer_peek_token (parser->lexer)->keyword)
-   {
-   case RID_VOLATILE:
- if (!volatile_p)
-   {
- /* Remember that we saw the `volatile' keyword.  */
- volatile_p = true;
- /* Consume the token.  */
- cp_lexer_consume_token (parser->lexer);
-   }
- else
-   done = true;
- break;
-   case RID_INLINE:
- if (!inline_p && parser->in_function_body)
-   {
- /* Remember that we saw the `inline' keyword.  */
- inline_p = true;
- /* Consume the token.  */
- cp_lexer_consume_token (parser->lexer);
-   }
- else
-   done = true;
- break;
-   case RID_GOTO:
- if (!goto_p && parser->in_function_body)
-   {
- /* Remember that we saw the `goto' keyword.  */
- goto_p = true;
- /* Consume the token.  */
- cp_lexer_consume_token (parser->lexer);
-   }
- else
-   done = true;
- break;
-   default:
- done = true;
-   }
+for (;;)
+  {
+   switch (cp_lexer_peek_token (parser->lexer)->keyword)
+ {
+ case RID_VOLATILE:
+   if (volatile_p)
+ break;
+   volatile_p = true;
+   cp_lexer_consume_token (parser->lexer);
+   continue;
+
+ case RID_INLINE:
+   if (inline_p || !parser->in_function_body)
+ break;
+   inline_p = true;
+   cp_lexer_consume_token (parser->lexer);
+   continue;
+
+ case RID_GOTO:
+   if (goto_p || !parser->in_function_body)
+ break;
+   goto_p = true;
+   cp_lexer_consume_token (parser->lexer);
+   continue;
+
+ default:
+   break;
+ }
+   break;
+  }
 
   /* Look for the opening `('.  */
   if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
-- 
1.8.3.1



[PATCH 2/8] asm inline

2018-12-27 Thread Segher Boessenkool
The Linux kernel people want a feature that makes GCC pretend some
inline assembler code is tiny (while it would think it is huge), so
that such code will be inlined essentially always instead of
essentially never.

This patch lets you say "asm inline" instead of just "asm", with the
result that that inline assembler is always counted as minimum cost
for inlining.  It implements this for C and C++, making "inline"
another asm-qualifier (supplementing "volatile" and "goto").

2018-12-06  Segher Boessenkool  

* doc/extend.texi (Using Assembly Language with C): Document asm inline.
(Size of an asm): Fix typo.  Document asm inline.
* gimple-pretty-print.c (dump_gimple_asm): Handle asm inline.
* gimple.h (enum gf_mask): Add GF_ASM_INLINE.
(gimple_asm_set_volatile): Fix typo.
(gimple_asm_inline_p): New.
(gimple_asm_set_inline): New.
* gimplify.c (gimplify_asm_expr): Propagate the asm inline flag from
tree to gimple.
* ipa-icf-gimple.c (func_checker::compare_gimple_asm): Compare the
gimple_asm_inline_p flag, too.
* tree-core.h (tree_base): Document that protected_flag is ASM_INLINE_P
in an ASM_EXPR.
* tree-inline.c (estimate_num_insns): If gimple_asm_inline_p return
a minimum size for an asm.
* tree.h (ASM_INLINE_P): New.

gcc/c/
* c-parser.c (c_parser_asm_statement): Detect the inline keyword
after asm.  Pass a flag for it to build_asm_expr.
* c-tree.h (build_asm_expr): Update declaration.
* c-typeck.c (build_asm_stmt): Add is_inline parameter.  Use it to
set ASM_INLINE_P.

gcc/cp/
* cp-tree.h (finish_asm_stmt): Update declaration.
* parser.c (cp_parser_asm_definition): Detect the inline keyword
after asm.  Pass a flag for it to finish_asm_stmt.
* pt.c (tsubst_expr): Pass the ASM_INLINE_P flag to finish_asm_stmt.
* semantics.c (finish_asm_stmt): Add inline_p parameter.  Use it to
set ASM_INLINE_P.

gcc/testsuite/
* c-c++-common/torture/asm-inline.c: New testcase.
* gcc.dg/asm-qual-2.c: Test asm inline, too.
---
 gcc/c/c-parser.c| 21 --
 gcc/c/c-tree.h  |  3 +-
 gcc/c/c-typeck.c|  7 +++-
 gcc/cp/cp-tree.h|  2 +-
 gcc/cp/parser.c | 15 ++-
 gcc/cp/pt.c |  2 +-
 gcc/cp/semantics.c  |  5 ++-
 gcc/doc/extend.texi | 15 ++-
 gcc/gimple-pretty-print.c   |  2 +
 gcc/gimple.h| 26 +++-
 gcc/gimplify.c  |  1 +
 gcc/ipa-icf-gimple.c|  3 ++
 gcc/testsuite/c-c++-common/torture/asm-inline.c | 53 +
 gcc/testsuite/gcc.dg/asm-qual-2.c   | 25 
 gcc/tree-core.h |  3 ++
 gcc/tree-inline.c   |  3 ++
 gcc/tree.h  |  3 ++
 17 files changed, 174 insertions(+), 15 deletions(-)
 create mode 100644 gcc/testsuite/c-c++-common/torture/asm-inline.c

diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 7ec53b3..51cc2be 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -6261,11 +6261,12 @@ c_parser_for_statement (c_parser *parser, bool ivdep, 
unsigned short unroll,
 }
 
 /* Parse an asm statement, a GNU extension.  This is a full-blown asm
-   statement with inputs, outputs, clobbers, and volatile and goto tag
-   allowed.
+   statement with inputs, outputs, clobbers, and volatile, inline, and goto
+   tags allowed.
 
asm-qualifier:
  volatile
+ inline
  goto
 
asm-qualifier-list:
@@ -6292,7 +6293,7 @@ static tree
 c_parser_asm_statement (c_parser *parser)
 {
   tree quals, str, outputs, inputs, clobbers, labels, ret;
-  bool simple, is_volatile, is_goto;
+  bool simple, is_volatile, is_inline, is_goto;
   location_t asm_loc = c_parser_peek_token (parser)->location;
   int section, nsections;
 
@@ -6301,6 +6302,7 @@ c_parser_asm_statement (c_parser *parser)
 
   quals = NULL_TREE;
   is_volatile = false;
+  is_inline = false;
   is_goto = false;
   for (bool done = false; !done; )
 switch (c_parser_peek_token (parser)->keyword)
@@ -6315,6 +6317,16 @@ c_parser_asm_statement (c_parser *parser)
else
  done = true;
break;
+  case RID_INLINE:
+   if (!is_inline)
+ {
+   is_inline = true;
+   quals = c_parser_peek_token (parser)->value;
+   c_parser_consume_token (parser);
+ }
+   else
+ done = true;
+   break;
   case RID_GOTO:
if (!is_goto)
  {
@@ -6403,7 +6415,8 @@ c_parser_asm_statement (c_parser *parser)
 c_parser_skip_to_end_of_block_or_statement 

[PATCH 3/8] c: Delete a stray line in asm inline

2018-12-27 Thread Segher Boessenkool
I noticed I accidentally copied a line too many from the "volatile"
handling to the "inline" handling.  This fixes it.

Tested on powerpc64-linux {-m32,-m64}; committing as trivial and obvious.

Segher

2018-12-08  Segher Boessenkool  

gcc/c/
* c-parser (c_parser_asm_statement) [RID_INLINE]: Delete stray line
setting "quals".
---
 gcc/c/c-parser.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 51cc2be..e45f70b 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -6321,7 +6321,6 @@ c_parser_asm_statement (c_parser *parser)
if (!is_inline)
  {
is_inline = true;
-   quals = c_parser_peek_token (parser)->value;
c_parser_consume_token (parser);
  }
else
-- 
1.8.3.1



[PATCH 1/8] asm qualifiers (PR55681)

2018-12-27 Thread Segher Boessenkool
PR55681 observes that currently only one qualifier is allowed for
inline asm, so that e.g. "volatile asm" is allowed, "const asm" is also
okay (with a warning), but "const volatile asm" gives an error.  Also
"goto" has to be last.

This patch changes things so that only "asm-qualifiers" are allowed,
that is "volatile" and "goto", in any combination, in any order, but
without repetitions.

2018-12-06  Segher Boessenkool  

PR inline-asm/55681
* doc/extend.texi (Basic Asm): Update grammar.
(Extended Asm): Update grammar.

gcc/c/
PR inline-asm/55681
* c-parser.c (c_parser_asm_statement): Update grammar.  Allow any
combination of volatile and goto, in any order, without repetitions.

gcc/cp/
PR inline-asm/55681
* parser.c (cp_parser_asm_definition): Update grammar.  Allow any
combination of volatile and goto, in any order, without repetitions.

gcc/testsuite/
PR inline-asm/55681
* gcc.dg/asm-qual-1.c: Test that "const" and "restrict" are refused.
* gcc.dg/asm-qual-2.c: New test, test that asm-qualifiers are allowed
in any order, but that duplicates are not allowed.
---
 gcc/c/c-parser.c  | 74 +
 gcc/cp/parser.c   | 77 ++-
 gcc/doc/extend.texi   |  8 ++--
 gcc/testsuite/gcc.dg/asm-qual-1.c | 10 +++--
 gcc/testsuite/gcc.dg/asm-qual-2.c | 21 +++
 5 files changed, 127 insertions(+), 63 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/asm-qual-2.c

diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 4772086..7ec53b3 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -6261,60 +6261,72 @@ c_parser_for_statement (c_parser *parser, bool ivdep, 
unsigned short unroll,
 }
 
 /* Parse an asm statement, a GNU extension.  This is a full-blown asm
-   statement with inputs, outputs, clobbers, and volatile tag
+   statement with inputs, outputs, clobbers, and volatile and goto tag
allowed.
 
+   asm-qualifier:
+ volatile
+ goto
+
+   asm-qualifier-list:
+ asm-qualifier-list asm-qualifier
+ asm-qualifier
+
asm-statement:
- asm type-qualifier[opt] ( asm-argument ) ;
- asm type-qualifier[opt] goto ( asm-goto-argument ) ;
+ asm asm-qualifier-list[opt] ( asm-argument ) ;
 
asm-argument:
  asm-string-literal
  asm-string-literal : asm-operands[opt]
  asm-string-literal : asm-operands[opt] : asm-operands[opt]
- asm-string-literal : asm-operands[opt] : asm-operands[opt] : 
asm-clobbers[opt]
-
-   asm-goto-argument:
+ asm-string-literal : asm-operands[opt] : asm-operands[opt] \
+   : asm-clobbers[opt]
  asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
: asm-goto-operands
 
-   Qualifiers other than volatile are accepted in the syntax but
-   warned for.  */
+   The form with asm-goto-operands is valid if and only if the
+   asm-qualifier-list contains goto, and is the only allowed form in that case.
+   Duplicate asm-qualifiers are not allowed.  */
 
 static tree
 c_parser_asm_statement (c_parser *parser)
 {
   tree quals, str, outputs, inputs, clobbers, labels, ret;
-  bool simple, is_goto;
+  bool simple, is_volatile, is_goto;
   location_t asm_loc = c_parser_peek_token (parser)->location;
   int section, nsections;
 
   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
   c_parser_consume_token (parser);
-  if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
-{
-  quals = c_parser_peek_token (parser)->value;
-  c_parser_consume_token (parser);
-}
-  else if (c_parser_next_token_is_keyword (parser, RID_CONST)
-  || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
-{
-  warning_at (c_parser_peek_token (parser)->location,
- 0,
- "%E qualifier ignored on asm",
- c_parser_peek_token (parser)->value);
-  quals = NULL_TREE;
-  c_parser_consume_token (parser);
-}
-  else
-quals = NULL_TREE;
 
+  quals = NULL_TREE;
+  is_volatile = false;
   is_goto = false;
-  if (c_parser_next_token_is_keyword (parser, RID_GOTO))
-{
-  c_parser_consume_token (parser);
-  is_goto = true;
-}
+  for (bool done = false; !done; )
+switch (c_parser_peek_token (parser)->keyword)
+  {
+  case RID_VOLATILE:
+   if (!is_volatile)
+ {
+   is_volatile = true;
+   quals = c_parser_peek_token (parser)->value;
+   c_parser_consume_token (parser);
+ }
+   else
+ done = true;
+   break;
+  case RID_GOTO:
+   if (!is_goto)
+ {
+   is_goto = true;
+   c_parser_consume_token (parser);
+ }
+   else
+ done = true;
+   break;
+  default:
+   done = true;
+  }
 
   /* ??? Follow the C++ parser rather than using the
  lex_untranslated_string kludge.  */
diff --git 

[PATCH 0/8] asm inline backport

2018-12-27 Thread Segher Boessenkool
Hi!

I'd like to backport the "asm inline" series to 8 branch and 7 branch.
The patches are identical to trunk, except I added a patch 8/8 that
makes these branches not error on code it only warned on before (that
is, C code that uses restrict or const as asm qualifier).

The 7 backport has a context change in tree-inline.c, but everything
else is identical.

The goal of backporting is that users (Linux, mostly) can start using
it sooner.

Is this okay for 8?  Is it okay for 7?


Segher


Segher Boessenkool (8):
  asm qualifiers (PR55681)
  asm inline
  c: Delete a stray line in asm inline
  c/c++, asm: Write the asm-qualifier loop without "done" boolean
  c/c++, asm: Use nicer error for duplicate asm qualifiers
  c/c++, asm: Use nicer error for const and restrict
  c++, asm: Do not handle any asm-qualifiers in top-level asm
  c: Don't error for const or restrict as asm-qualifier

 gcc/c/c-parser.c| 112 ---
 gcc/c/c-tree.h  |   5 +-
 gcc/c/c-typeck.c|  11 ++-
 gcc/cp/cp-tree.h|   2 +-
 gcc/cp/parser.c | 117 +---
 gcc/cp/pt.c |   2 +-
 gcc/cp/semantics.c  |   5 +-
 gcc/doc/extend.texi |  23 -
 gcc/gimple-pretty-print.c   |   2 +
 gcc/gimple.h|  26 +-
 gcc/gimplify.c  |   1 +
 gcc/ipa-icf-gimple.c|   3 +
 gcc/testsuite/c-c++-common/torture/asm-inline.c |  53 +++
 gcc/testsuite/g++.dg/asm-qual-1.C   |  13 +++
 gcc/testsuite/g++.dg/asm-qual-2.C   |  46 ++
 gcc/testsuite/g++.dg/asm-qual-3.C   |  12 +++
 gcc/testsuite/gcc.dg/asm-qual-1.c   |   8 +-
 gcc/testsuite/gcc.dg/asm-qual-2.c   |  46 ++
 gcc/testsuite/gcc.dg/asm-qual-3.c   |   9 ++
 gcc/tree-core.h |   3 +
 gcc/tree-inline.c   |   3 +
 gcc/tree.h  |   3 +
 22 files changed, 420 insertions(+), 85 deletions(-)
 create mode 100644 gcc/testsuite/c-c++-common/torture/asm-inline.c
 create mode 100644 gcc/testsuite/g++.dg/asm-qual-1.C
 create mode 100644 gcc/testsuite/g++.dg/asm-qual-2.C
 create mode 100644 gcc/testsuite/g++.dg/asm-qual-3.C
 create mode 100644 gcc/testsuite/gcc.dg/asm-qual-2.c
 create mode 100644 gcc/testsuite/gcc.dg/asm-qual-3.c

-- 
1.8.3.1



Re: GCC 8 backports

2018-12-27 Thread Martin Liška
On 11/20/18 11:58 AM, Martin Liška wrote:
> On 10/3/18 11:23 AM, Martin Liška wrote:
>> On 9/25/18 8:48 AM, Martin Liška wrote:
>>> Hi.
>>>
>>> One more tested patch.
>>>
>>> Martin
>>>
>>
>> One more tested patch.
>>
>> Martin
>>
> 
> Hi.
> 
> One another tested patch that I'm going to install.
> 
> Martin
> 

Hi.

One another tested patch that I'm going to install.

Thanks,
Martin
>From 97052eab40506300510336bf668d4adc2a60a7cf Mon Sep 17 00:00:00 2001
From: hubicka 
Date: Fri, 21 Dec 2018 19:13:06 +
Subject: [PATCH] Backport r267338

gcc/ChangeLog:

2018-12-15  Jan Hubicka  

	PR ipa/88561
	* ipa-polymorphic-call.c
	(ipa_polymorphic_call_context::ipa_polymorphic_call_context): Handle
	arguments of thunks correctly.
	(ipa_polymorphic_call_context::get_dynamic_context): Be ready for
	NULL instance pinter.
	* lto-cgraph.c (lto_output_node): Always stream thunk info.

gcc/testsuite/ChangeLog:

2018-12-15  Jan Hubicka  

	PR ipa/88561
	* g++.dg/tree-prof/devirt.C: New testcase.
---
 gcc/ipa-polymorphic-call.c  |  32 +-
 gcc/lto-cgraph.c|   8 +-
 gcc/testsuite/g++.dg/tree-prof/devirt.C | 123 
 3 files changed, 159 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/tree-prof/devirt.C

diff --git a/gcc/ipa-polymorphic-call.c b/gcc/ipa-polymorphic-call.c
index 13aca94dd00..d5e4a6a6f97 100644
--- a/gcc/ipa-polymorphic-call.c
+++ b/gcc/ipa-polymorphic-call.c
@@ -995,9 +995,22 @@ ipa_polymorphic_call_context::ipa_polymorphic_call_context (tree fndecl,
 	{
 	  outer_type
 	 = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (base_pointer)));
+	  cgraph_node *node = cgraph_node::get (current_function_decl);
 	  gcc_assert (TREE_CODE (outer_type) == RECORD_TYPE
 		  || TREE_CODE (outer_type) == UNION_TYPE);
 
+	  /* Handle the case we inlined into a thunk.  In this case
+	 thunk has THIS pointer of type bar, but it really receives
+	 address to its base type foo which sits in bar at
+	 0-thunk.fixed_offset.  It starts with code that adds
+	 think.fixed_offset to the pointer to compensate for this.
+
+	 Because we walked all the way to the begining of thunk, we now
+	 see pointer _offset and need to compensate
+	 for it.  */
+	  if (node->thunk.fixed_offset)
+	offset -= node->thunk.fixed_offset * BITS_PER_UNIT;
+
 	  /* Dynamic casting has possibly upcasted the type
 	 in the hiearchy.  In this case outer type is less
 	 informative than inner type and we should forget
@@ -1005,7 +1018,11 @@ ipa_polymorphic_call_context::ipa_polymorphic_call_context (tree fndecl,
 	  if ((otr_type
 	   && !contains_type_p (outer_type, offset,
 otr_type))
-	  || !contains_polymorphic_type_p (outer_type))
+	  || !contains_polymorphic_type_p (outer_type)
+	  /* If we compile thunk with virtual offset, the THIS pointer
+		 is adjusted by unknown value.  We can't thus use outer info
+		 at all.  */
+	  || node->thunk.virtual_offset_p)
 	{
 	  outer_type = NULL;
 	  if (instance)
@@ -1030,7 +1047,15 @@ ipa_polymorphic_call_context::ipa_polymorphic_call_context (tree fndecl,
 	  maybe_in_construction = false;
 	}
 	  if (instance)
-	*instance = base_pointer;
+	{
+	  /* If method is expanded thunk, we need to apply thunk offset
+		 to instance pointer.  */
+	  if (node->thunk.virtual_offset_p
+		  || node->thunk.fixed_offset)
+		*instance = NULL;
+	  else
+	*instance = base_pointer;
+	}
 	  return;
 	}
   /* Non-PODs passed by value are really passed by invisible
@@ -1547,6 +1572,9 @@ ipa_polymorphic_call_context::get_dynamic_type (tree instance,
   HOST_WIDE_INT instance_offset = offset;
   tree instance_outer_type = outer_type;
 
+  if (!instance)
+return false;
+
   if (otr_type)
 otr_type = TYPE_MAIN_VARIANT (otr_type);
 
diff --git a/gcc/lto-cgraph.c b/gcc/lto-cgraph.c
index 40baf858ca5..305f22bd7e9 100644
--- a/gcc/lto-cgraph.c
+++ b/gcc/lto-cgraph.c
@@ -546,7 +546,11 @@ lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node,
   streamer_write_bitpack ();
   streamer_write_data_stream (ob->main_stream, section, strlen (section) + 1);
 
-  if (node->thunk.thunk_p)
+  /* Stream thunk info always because we use it in
+ ipa_polymorphic_call_context::ipa_polymorphic_call_context
+ to properly interpret THIS pointers for thunks that has been converted
+ to Gimple.  */
+  if (node->definition)
 {
   streamer_write_uhwi_stream
 	 (ob->main_stream,
@@ -1317,7 +1321,7 @@ input_node (struct lto_file_decl_data *file_data,
   if (section)
 node->set_section_for_node (section);
 
-  if (node->thunk.thunk_p)
+  if (node->definition)
 {
   int type = streamer_read_uhwi (ib);
   HOST_WIDE_INT fixed_offset = streamer_read_uhwi (ib);
diff --git a/gcc/testsuite/g++.dg/tree-prof/devirt.C b/gcc/testsuite/g++.dg/tree-prof/devirt.C
new file mode 100644
index 000..05c9a26e7a4
--- 

Re: [PATCH] PR fortran/81027 -- Issue error for assumed-shape array

2018-12-27 Thread Dominique d'Humières
Hi Steve,

The test gfortran.dg/pr81027.f90 succeeds without the patch. Would not it be 
better to replace

{ dg-error "is not permitted in an" }

with something such as

{ dg-error "Assumed-shape array" }

?

Otherwise the patch works as expected.

Thank for the fix.

Dominique



Re: [PATCH] PR fortran/81509 and fortran/45513

2018-12-27 Thread Sudakshina Das
Hi Steve

On 23/12/18 6:49 PM, Steve Kargl wrote:
> This is a re-submission of a patch I submitted 15 months ago.
> See https://gcc.gnu.org/ml/fortran/2017-09/msg00124.html
>
> At that time one reviewer OK'd the patch for committing,
> and one reviewer raised objections to the patch as I
> chose to remove dubious extensions to the Fortran standard.
> I withdrew that patch with the expection that Someone
> would fix the bug.  Well, Someone has not materialized.
>
> The patch has been retested on i586-*-freebsd and x86_64-*-freebsd.
>
> OK to commit as-is?
>
> Here's the text from the above URL.
>
> In short, F2008 now allows boz-literal-constants in IAND, IOR, IEOR,
> DSHIFTL, DSHIFTR, and MERGE_BITS.  gfortran currently allows a BOZ
> argument, but she was not enforcing restrictions in F2008.  The
> attach patch causes gfortran to conform to F2008.
>
> As a side effect, the patch removes a questionable GNU Fortran
> extension that allowed arguments to IAND, IOR, and IEOR to have
> different kind type parameters.  The behavior of this extension
> was not documented.
>
> 2017-09-27  Steven G. Kargl  
>
>   PR fortran/45513
>   PR fortran/81509
>   * check.c: Rename function gfc_check_iand to gfc_check_iand_ieor_ior.
>   * check.c (boz_args_check): New function.  Check I and J not both BOZ.
>   (gfc_check_dshift,gfc_check_iand_ieor_ior, gfc_check_ishft,
>gfc_check_and, gfc_check_merge_bits): Use it.
>   * check.c (gfc_check_iand_ieor_ior): Force conversion of BOZ to kind
>   type of other agrument.  Remove silly GNU extension.
>   (gfc_check_ieor, gfc_check_ior): Delete now unused functions.
>   * intrinsic.c (add_functions): Use gfc_check_iand_ieor_ior. Wrap long
>   line.
>   * intrinsic.h: Rename gfc_check_iand to gfc_check_iand_ieor_ior.
>   Delete prototype for bool gfc_check_ieor and gfc_check_ior
>   * intrinsic.texi: Update documentation for boz-literal-constant.
>
> 2017-09-27  Steven G. Kargl  
>
>   PR fortran/45513
>   PR fortran/81509
>   * gfortran.dg/graphite/id-26.f03: Fix non-conforming use of IAND.
>   * gfortran.dg/pr81509_1.f90: New test.
>   * gfortran.dg/pr81509_2.f90: New test.
>
This patch has caused the following failures on aarch64-none-linux-gnu:

FAIL: libgomp.fortran/aligned1.f03   -O0  (test for excess errors)
FAIL: libgomp.fortran/aligned1.f03   -O1  (test for excess errors)
FAIL: libgomp.fortran/aligned1.f03   -O2  (test for excess errors)
FAIL: libgomp.fortran/aligned1.f03   -O3 -fomit-frame-pointer 
-funroll-loops -fpeel-loops -ftracer -finline-functions  (test for 
excess errors)
FAIL: libgomp.fortran/aligned1.f03   -O3 -g  (test for excess errors)
FAIL: libgomp.fortran/aligned1.f03   -Os  (test for excess errors)

With the failure as:

Excess errors:
/build/src/gcc/libgomp/testsuite/libgomp.fortran/aligned1.f03:55:14: 
Error: Arguments of 'iand' have different kind type parameters at (1)
/build/src/gcc/libgomp/testsuite/libgomp.fortran/aligned1.f03:59:14: 
Error: Arguments of 'iand' have different kind type parameters at (1)

Thanks

Sudi



[PATCH] Cherry pick libsanitizer patch (https://reviews.llvm.org/D54856).

2018-12-27 Thread Martin Liška
Hi.

I've tested the revision that I'm planning to cherry pick on x86_64-linux-gnu.

I'm going to install the patch.
Martin

libsanitizer/ChangeLog:

2018-12-27  Martin Liska  

* asan/asan_errors.cc (ErrorAllocTypeMismatch::Print): Cherry
pick rL350085.
* asan/asan_errors.h (struct ErrorAllocTypeMismatch): Likewise.
---
 libsanitizer/asan/asan_errors.cc | 5 ++---
 libsanitizer/asan/asan_errors.h  | 7 +++
 2 files changed, 5 insertions(+), 7 deletions(-)


diff --git a/libsanitizer/asan/asan_errors.cc b/libsanitizer/asan/asan_errors.cc
index b9d02a74a0d..65941f65bf8 100644
--- a/libsanitizer/asan/asan_errors.cc
+++ b/libsanitizer/asan/asan_errors.cc
@@ -123,9 +123,8 @@ void ErrorAllocTypeMismatch::Print() {
   Decorator d;
   Printf("%s", d.Error());
   Report("ERROR: AddressSanitizer: %s (%s vs %s) on %p\n",
- scariness.GetDescription(),
- alloc_names[alloc_type], dealloc_names[dealloc_type],
- addr_description.addr);
+ scariness.GetDescription(), alloc_names[alloc_type],
+ dealloc_names[dealloc_type], addr_description.Address());
   Printf("%s", d.Default());
   CHECK_GT(dealloc_stack->size, 0);
   scariness.Print();
diff --git a/libsanitizer/asan/asan_errors.h b/libsanitizer/asan/asan_errors.h
index 5ed15dc9817..b155f2452af 100644
--- a/libsanitizer/asan/asan_errors.h
+++ b/libsanitizer/asan/asan_errors.h
@@ -108,8 +108,8 @@ struct ErrorFreeNotMalloced : ErrorBase {
 
 struct ErrorAllocTypeMismatch : ErrorBase {
   const BufferedStackTrace *dealloc_stack;
-  HeapAddressDescription addr_description;
   AllocType alloc_type, dealloc_type;
+  AddressDescription addr_description;
 
   ErrorAllocTypeMismatch() = default;  // (*)
   ErrorAllocTypeMismatch(u32 tid, BufferedStackTrace *stack, uptr addr,
@@ -117,9 +117,8 @@ struct ErrorAllocTypeMismatch : ErrorBase {
   : ErrorBase(tid, 10, "alloc-dealloc-mismatch"),
 dealloc_stack(stack),
 alloc_type(alloc_type_),
-dealloc_type(dealloc_type_) {
-GetHeapAddressInformation(addr, 1, _description);
-  };
+dealloc_type(dealloc_type_),
+addr_description(addr, 1, false) {}
   void Print();
 };
 



Re: [Committed] XFAIL gfortran.dg/ieee/ieee_9.f90

2018-12-27 Thread Ramana Radhakrishnan
Still on holiday, but this maybe because long double is 64bit on arm32. Real128 
may end up being mapped to long double for fortran on armhf ?

Ramana

From: Sudakshina Das
Sent: Thursday, December 27, 2018 8:46:29 AM
To: s...@troutmask.apl.washington.edu; Janne Blomqvist
Cc: Fortran List; GCC Patches; nd; kyrylo.tkac...@foss.arm.com; Ramana 
Radhakrishnan; Richard Earnshaw
Subject: Re: [Committed] XFAIL gfortran.dg/ieee/ieee_9.f90

Hi

On 25/12/18 5:13 PM, Steve Kargl wrote:
> On Tue, Dec 25, 2018 at 09:51:03AM +0200, Janne Blomqvist wrote:
>> On Mon, Dec 24, 2018 at 9:42 PM Steve Kargl <
>> s...@troutmask.apl.washington.edu> wrote:
>>
>>> On Mon, Dec 24, 2018 at 09:29:50PM +0200, Janne Blomqvist wrote:
 On Mon, Dec 24, 2018 at 8:05 PM Steve Kargl <
 s...@troutmask.apl.washington.edu> wrote:

> I've added the following patch to a recently committed testcase.
>
> Index: gcc/testsuite/gfortran.dg/ieee/ieee_9.f90
> ===
> --- gcc/testsuite/gfortran.dg/ieee/ieee_9.f90   (revision 267413)
> +++ gcc/testsuite/gfortran.dg/ieee/ieee_9.f90   (working copy)
> @@ -1,4 +1,4 @@
> -! { dg-do run }
> +! { dg-do run { xfail arm*-*-gnueabi arm*-*-gnueabihf } }
>   program foo
>  use ieee_arithmetic
>  use iso_fortran_env
>
 The problem seems to be that GFortran says the real128 kind value is > 0
 (i.e. that the target supports quad precision floating point (with
>>> software
 emulation, presumably)), but then trying to use it fails.

 Would be nice if somebody who cares about arm-none-linux-gnueabihf could
 help figure out the proper resolution instead of papering over it with
 XFAIL.

 But I guess XFAIL is good enough until said somebody turns up.

>>> Thanks for chasing down the details.  I have no access to arm*-*-*.
>>>
>>> It's a shame the real128 is defined, and arm*-*-* doesn't
>>> actually use it.  I certainly have no time or interest in
>>> fix this.
>>>
>> I think there are arm systems on the compile farm, but I haven't actually
>> checked myself, just going by the error messages Sudi Das reported.
>>
>> That being said, having slept over it, I actually think there is a problem
>> with the testcase, and not with arm*. So the errors in the testcase occurs
>> in code like
>>
>> if (real128 > 0) then
>>  p = int(ieee_scalb(real(x, real128), int(i, int8)))
>>  if (p /= 64) stop 3
>> end if
>>
>> So if real128 is negative, as it should be if the target doesn't support
>> quad precision float, the branch will never be taken, but the frontend will
>> still generate code for it (though it will later be optimized away as
>> unreachable), and that's where the error occurs. So the testcase would need
>> something like
>>
>> integer, parameter :: large_real = max (real64, real128)
>> ! ...
>> if (real128 > 0) then
>>  p = int(ieee_scalb(real(x, large_real), int(i, int8)))
>>  if (p /= 64) stop 3
>> end if
>>
>> If you concur, please consider a patch fixing the testcase and removing the
>> xfail pre-approved.
>>
> Indeed, you are probably correct that gfortran will generate
> intermediate code and then garbage collect it.  This then will
> give an error for real(..., real128) in the statement for p.
> If real128 /= 4, 8, 10, or 16.  I'll fix the testcase.
>
> Do you know if we can get gfortran to pre-define macros for cpp?
> That is, it would be nice if gfortran would recognize, say,
> HAVE_GFC_REAL_10 and HAVE_GFC_REAL_16 if the target supports those
> types.  Then the testcase could be copied to ieee_9.F90, and
> modified to
>
> #ifdef HAVE_REAL_16
>  p = int(ieee_scalb(real(x, 16), int(i, int8)))
>  if (p /= 64) stop 3
> #endif
>
Thanks for looking into this. Sorry I was on holiday for Christmas.
CC'ing Arm maintainers in case they have something to add.

Thanks

Sudi



Re: [Committed] XFAIL gfortran.dg/ieee/ieee_9.f90

2018-12-27 Thread Sudakshina Das
Hi

On 25/12/18 5:13 PM, Steve Kargl wrote:
> On Tue, Dec 25, 2018 at 09:51:03AM +0200, Janne Blomqvist wrote:
>> On Mon, Dec 24, 2018 at 9:42 PM Steve Kargl <
>> s...@troutmask.apl.washington.edu> wrote:
>>
>>> On Mon, Dec 24, 2018 at 09:29:50PM +0200, Janne Blomqvist wrote:
 On Mon, Dec 24, 2018 at 8:05 PM Steve Kargl <
 s...@troutmask.apl.washington.edu> wrote:

> I've added the following patch to a recently committed testcase.
>
> Index: gcc/testsuite/gfortran.dg/ieee/ieee_9.f90
> ===
> --- gcc/testsuite/gfortran.dg/ieee/ieee_9.f90   (revision 267413)
> +++ gcc/testsuite/gfortran.dg/ieee/ieee_9.f90   (working copy)
> @@ -1,4 +1,4 @@
> -! { dg-do run }
> +! { dg-do run { xfail arm*-*-gnueabi arm*-*-gnueabihf } }
>   program foo
>  use ieee_arithmetic
>  use iso_fortran_env
>
 The problem seems to be that GFortran says the real128 kind value is > 0
 (i.e. that the target supports quad precision floating point (with
>>> software
 emulation, presumably)), but then trying to use it fails.

 Would be nice if somebody who cares about arm-none-linux-gnueabihf could
 help figure out the proper resolution instead of papering over it with
 XFAIL.

 But I guess XFAIL is good enough until said somebody turns up.

>>> Thanks for chasing down the details.  I have no access to arm*-*-*.
>>>
>>> It's a shame the real128 is defined, and arm*-*-* doesn't
>>> actually use it.  I certainly have no time or interest in
>>> fix this.
>>>
>> I think there are arm systems on the compile farm, but I haven't actually
>> checked myself, just going by the error messages Sudi Das reported.
>>
>> That being said, having slept over it, I actually think there is a problem
>> with the testcase, and not with arm*. So the errors in the testcase occurs
>> in code like
>>
>> if (real128 > 0) then
>>  p = int(ieee_scalb(real(x, real128), int(i, int8)))
>>  if (p /= 64) stop 3
>> end if
>>
>> So if real128 is negative, as it should be if the target doesn't support
>> quad precision float, the branch will never be taken, but the frontend will
>> still generate code for it (though it will later be optimized away as
>> unreachable), and that's where the error occurs. So the testcase would need
>> something like
>>
>> integer, parameter :: large_real = max (real64, real128)
>> ! ...
>> if (real128 > 0) then
>>  p = int(ieee_scalb(real(x, large_real), int(i, int8)))
>>  if (p /= 64) stop 3
>> end if
>>
>> If you concur, please consider a patch fixing the testcase and removing the
>> xfail pre-approved.
>>
> Indeed, you are probably correct that gfortran will generate
> intermediate code and then garbage collect it.  This then will
> give an error for real(..., real128) in the statement for p.
> If real128 /= 4, 8, 10, or 16.  I'll fix the testcase.
>
> Do you know if we can get gfortran to pre-define macros for cpp?
> That is, it would be nice if gfortran would recognize, say,
> HAVE_GFC_REAL_10 and HAVE_GFC_REAL_16 if the target supports those
> types.  Then the testcase could be copied to ieee_9.F90, and
> modified to
>
> #ifdef HAVE_REAL_16
>  p = int(ieee_scalb(real(x, 16), int(i, int8)))
>  if (p /= 64) stop 3
> #endif
>
Thanks for looking into this. Sorry I was on holiday for Christmas. 
CC'ing Arm maintainers in case they have something to add.

Thanks

Sudi