public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C PATCH to suppress a bogus "defaulting to int" warning (PR c/77323)
@ 2016-08-24 10:18 Marek Polacek
  2016-08-24 10:20 ` Marek Polacek
  2016-08-24 21:41 ` Joseph Myers
  0 siblings, 2 replies; 3+ messages in thread
From: Marek Polacek @ 2016-08-24 10:18 UTC (permalink / raw)
  To: GCC Patches, Joseph Myers

When declaring something using an unsupported type specifier, such as __int128
on 32-bit systems, or _Float128x, the error for the unsupported type is
followed by a warning about the type defaulting to int.

But for unsupported types this warning isn't useful.  The problem was that for
these unsupported types typespec_word was set to cts_none, so in
finish_declspecs we'd set default_int_p and thus warn in grokdeclarator.

How to fix this became clear when I looked at how we handle fixed-point types
and decimal floating point types -- by setting typespec_word even when we've
given an error.  The finish_declspecs hunk is needed so that we don't pass
a null type to grokdeclarator.

Tested also with
make check-c RUNTESTFLAGS='dg.exp=pr77323.c --target_board=unix\{-m32,-m64\}'

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

2016-08-24  Marek Polacek  <polacek@redhat.com>

	PR c/77323
	* c-decl.c (declspecs_add_type): Set typespec_word even when __intN
	or _FloatN or _FloatNx is not supported.
	(finish_declspecs): Set type to integer_type_node when _FloatN or
	_FloatNx is not supported.

	* gcc.dg/pr77323.c: New test.

diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index 0fb2d20..0c52a64 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -10190,10 +10190,13 @@ declspecs_add_type (location_t loc, struct c_declspecs *specs,
 			  ("both %<__int%d%> and %<short%> in "
 			   "declaration specifiers"),
 			  int_n_data[specs->int_n_idx].bitsize);
-	      else if (! int_n_enabled_p [specs->int_n_idx])
-		error_at (loc,
-			  "%<__int%d%> is not supported on this target",
-			  int_n_data[specs->int_n_idx].bitsize);
+	      else if (! int_n_enabled_p[specs->int_n_idx])
+		{
+		  specs->typespec_word = cts_int_n;
+		  error_at (loc,
+			    "%<__int%d%> is not supported on this target",
+			    int_n_data[specs->int_n_idx].bitsize);
+		}
 	      else
 		{
 		  specs->typespec_word = cts_int_n;
@@ -10400,12 +10403,15 @@ declspecs_add_type (location_t loc, struct c_declspecs *specs,
 			   ? "x"
 			   : ""));
 	      else if (FLOATN_NX_TYPE_NODE (specs->floatn_nx_idx) == NULL_TREE)
-		error_at (loc,
-			  "%<_Float%d%s%> is not supported on this target",
-			  floatn_nx_types[specs->floatn_nx_idx].n,
-			  (floatn_nx_types[specs->floatn_nx_idx].extended
-			   ? "x"
-			   : ""));
+		{
+		  specs->typespec_word = cts_floatn_nx;
+		  error_at (loc,
+			    "%<_Float%d%s%> is not supported on this target",
+			    floatn_nx_types[specs->floatn_nx_idx].n,
+			    (floatn_nx_types[specs->floatn_nx_idx].extended
+			     ? "x"
+			     : ""));
+		}
 	      else
 		{
 		  specs->typespec_word = cts_floatn_nx;
@@ -10892,9 +10898,12 @@ finish_declspecs (struct c_declspecs *specs)
     case cts_floatn_nx:
       gcc_assert (!specs->long_p && !specs->short_p
 		  && !specs->signed_p && !specs->unsigned_p);
-      specs->type = (specs->complex_p
-		     ? COMPLEX_FLOATN_NX_TYPE_NODE (specs->floatn_nx_idx)
-		     : FLOATN_NX_TYPE_NODE (specs->floatn_nx_idx));
+      if (FLOATN_NX_TYPE_NODE (specs->floatn_nx_idx) == NULL_TREE)
+	specs->type = integer_type_node;
+      else if (specs->complex_p)
+	specs->type = COMPLEX_FLOATN_NX_TYPE_NODE (specs->floatn_nx_idx);
+      else
+	specs->type = FLOATN_NX_TYPE_NODE (specs->floatn_nx_idx);
       break;
     case cts_dfloat32:
     case cts_dfloat64:
diff --git gcc/testsuite/gcc.dg/pr77323.c gcc/testsuite/gcc.dg/pr77323.c
index e69de29..281c334 100644
--- gcc/testsuite/gcc.dg/pr77323.c
+++ gcc/testsuite/gcc.dg/pr77323.c
@@ -0,0 +1,6 @@
+/* PR c/77323 */
+/* { dg-do compile { target ia32 } } */
+/* { dg-options "" } */
+
+__int128 a; /* { dg-error "not supported" } */
+_Float128x b; /* { dg-error "not supported" } */

	Marek

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: C PATCH to suppress a bogus "defaulting to int" warning (PR c/77323)
  2016-08-24 10:18 C PATCH to suppress a bogus "defaulting to int" warning (PR c/77323) Marek Polacek
@ 2016-08-24 10:20 ` Marek Polacek
  2016-08-24 21:41 ` Joseph Myers
  1 sibling, 0 replies; 3+ messages in thread
From: Marek Polacek @ 2016-08-24 10:20 UTC (permalink / raw)
  To: GCC Patches, Joseph Myers

On Wed, Aug 24, 2016 at 12:18:17PM +0200, Marek Polacek wrote:
> When declaring something using an unsupported type specifier, such as __int128
> on 32-bit systems, or _Float128x, the error for the unsupported type is
> followed by a warning about the type defaulting to int.
> 
> But for unsupported types this warning isn't useful.  The problem was that for
> these unsupported types typespec_word was set to cts_none, so in
> finish_declspecs we'd set default_int_p and thus warn in grokdeclarator.
> 
> How to fix this became clear when I looked at how we handle fixed-point types
> and decimal floating point types -- by setting typespec_word even when we've
> given an error.  The finish_declspecs hunk is needed so that we don't pass
> a null type to grokdeclarator.
> 
> Tested also with
> make check-c RUNTESTFLAGS='dg.exp=pr77323.c --target_board=unix\{-m32,-m64\}'
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?

And now tested on ppc64le-redhat-linux, too.

	Marek

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: C PATCH to suppress a bogus "defaulting to int" warning (PR c/77323)
  2016-08-24 10:18 C PATCH to suppress a bogus "defaulting to int" warning (PR c/77323) Marek Polacek
  2016-08-24 10:20 ` Marek Polacek
@ 2016-08-24 21:41 ` Joseph Myers
  1 sibling, 0 replies; 3+ messages in thread
From: Joseph Myers @ 2016-08-24 21:41 UTC (permalink / raw)
  To: Marek Polacek; +Cc: GCC Patches

On Wed, 24 Aug 2016, Marek Polacek wrote:

> 2016-08-24  Marek Polacek  <polacek@redhat.com>
> 
> 	PR c/77323
> 	* c-decl.c (declspecs_add_type): Set typespec_word even when __intN
> 	or _FloatN or _FloatNx is not supported.
> 	(finish_declspecs): Set type to integer_type_node when _FloatN or
> 	_FloatNx is not supported.
> 
> 	* gcc.dg/pr77323.c: New test.

OK.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-08-24 21:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-24 10:18 C PATCH to suppress a bogus "defaulting to int" warning (PR c/77323) Marek Polacek
2016-08-24 10:20 ` Marek Polacek
2016-08-24 21:41 ` Joseph Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).