public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Make C++ honor the enum mode attribute
@ 2016-04-30  5:54 Bernd Edlinger
  2016-05-07  9:55 ` [PING] " Bernd Edlinger
  2016-05-18 21:07 ` Jason Merrill
  0 siblings, 2 replies; 4+ messages in thread
From: Bernd Edlinger @ 2016-04-30  5:54 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill, Jakub Jelinek

[-- Attachment #1: Type: text/plain, Size: 1171 bytes --]

Hi,

this was already posted in february, but has not yet been reviewed, so I thought
it is time now to post it again...

As a follow-up for Jakub's c/69669 fix, I'd like to have the enum mode also honored
in C++ code, because the mode attribute now finally really works in C, but it is
completely and silently(!) ignored by C++ code, which results in incompatible
code.

So I duplicated what is done in c/c-decl.c also in cp/decl.c.  That worked
immediately, except that it is not possible to explicitly check the "mode"
attribute in the TYPE_ATTRIBUTES (enumtype) because that attribute
is never copied to the type, and the original attribute list is not available
here.  That should be OK, as this check was added to fix pr52085 which
does not apply here, because C++ does not support enum forward
declarations.

If that patch is not appropriate for stage  4, I would at least want to emit
an attribute directive ignored warning in c++ mode.  I think that could
be done in handle_mode_attribute.  But fixing that feature is cooler.


Boot-strapped and regression tested on x86_64-pc-linux-gnu.
Ok for trunk and gcc-6 branch?


Thanks
Bernd.

[-- Attachment #2: changelog-enum-mode.txt --]
[-- Type: text/plain, Size: 238 bytes --]

cp:
2016-02-06  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	* decl.c (finish_enum_value_list): Use the specified mode.

testsuite:
2016-02-06  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	* c-c++-common/pr69669.c: Check the used mode.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: patch-enum-mode.diff --]
[-- Type: text/x-patch; name="patch-enum-mode.diff", Size: 1340 bytes --]

Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(Revision 233176)
+++ gcc/cp/decl.c	(Arbeitskopie)
@@ -13310,6 +13310,19 @@ finish_enum_value_list (tree enumtype)
       use_short_enum = flag_short_enums
         || lookup_attribute ("packed", TYPE_ATTRIBUTES (enumtype));
 
+      /* If the precision of the type was specified with an attribute and it
+	 was too small, give an error.  Otherwise, use it.  */
+      if (TYPE_PRECISION (enumtype))
+	{
+	  if (precision > TYPE_PRECISION (enumtype))
+	    error ("specified mode too small for enumeral values");
+	  else
+	    {
+	      use_short_enum = true;
+	      precision = TYPE_PRECISION (enumtype);
+	    }
+	}
+
       for (itk = (use_short_enum ? itk_char : itk_int);
            itk != itk_none;
            itk++)
Index: gcc/testsuite/c-c++-common/pr69669.c
===================================================================
--- gcc/testsuite/c-c++-common/pr69669.c	(Revision 233176)
+++ gcc/testsuite/c-c++-common/pr69669.c	(Arbeitskopie)
@@ -1,5 +1,6 @@
 /* PR c/69669 */
 /* { dg-do compile } */
+/* { dg-options "-fdump-rtl-final" } */
 
 enum __attribute__((mode(QI))) E { F = 1 };
 
@@ -8,3 +9,5 @@ foo (enum E *x, int y)
 {
   *x = (enum E) y;
 }
+
+/* { dg-final { scan-rtl-dump-times "mem:QI" 1 "final" } } */

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

* [PING] [PATCH] Make C++ honor the enum mode attribute
  2016-04-30  5:54 [PATCH] Make C++ honor the enum mode attribute Bernd Edlinger
@ 2016-05-07  9:55 ` Bernd Edlinger
  2016-05-18 18:12   ` [PING**2] " Bernd Edlinger
  2016-05-18 21:07 ` Jason Merrill
  1 sibling, 1 reply; 4+ messages in thread
From: Bernd Edlinger @ 2016-05-07  9:55 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill, Jakub Jelinek

Ping..

For this patch: https://gcc.gnu.org/ml/gcc-patches/2016-04/msg02069.html

Thanks
Bernd.

On 04/30/16 07:54, Bernd Edlinger wrote:
> Hi,
>
> this was already posted in february, but has not yet been reviewed, so I thought
> it is time now to post it again...
>
> As a follow-up for Jakub's c/69669 fix, I'd like to have the enum mode also honored
> in C++ code, because the mode attribute now finally really works in C, but it is
> completely and silently(!) ignored by C++ code, which results in incompatible
> code.
>
> So I duplicated what is done in c/c-decl.c also in cp/decl.c.  That worked
> immediately, except that it is not possible to explicitly check the "mode"
> attribute in the TYPE_ATTRIBUTES (enumtype) because that attribute
> is never copied to the type, and the original attribute list is not available
> here.  That should be OK, as this check was added to fix pr52085 which
> does not apply here, because C++ does not support enum forward
> declarations.
>
> If that patch is not appropriate for stage  4, I would at least want to emit
> an attribute directive ignored warning in c++ mode.  I think that could
> be done in handle_mode_attribute.  But fixing that feature is cooler.
>
>
> Boot-strapped and regression tested on x86_64-pc-linux-gnu.
> Ok for trunk and gcc-6 branch?
>
>
> Thanks
> Bernd.
>

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

* [PING**2] [PATCH] Make C++ honor the enum mode attribute
  2016-05-07  9:55 ` [PING] " Bernd Edlinger
@ 2016-05-18 18:12   ` Bernd Edlinger
  0 siblings, 0 replies; 4+ messages in thread
From: Bernd Edlinger @ 2016-05-18 18:12 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill, Jakub Jelinek

Ping...

On 07.05.2016 11:54 Bernd Edlinger wrote:
> Ping..
>
> For this patch: https://gcc.gnu.org/ml/gcc-patches/2016-04/msg02069.html
>
> Thanks
> Bernd.
>

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

* Re: [PATCH] Make C++ honor the enum mode attribute
  2016-04-30  5:54 [PATCH] Make C++ honor the enum mode attribute Bernd Edlinger
  2016-05-07  9:55 ` [PING] " Bernd Edlinger
@ 2016-05-18 21:07 ` Jason Merrill
  1 sibling, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2016-05-18 21:07 UTC (permalink / raw)
  To: Bernd Edlinger, gcc-patches; +Cc: Jakub Jelinek

OK.

Jason

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

end of thread, other threads:[~2016-05-18 21:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-30  5:54 [PATCH] Make C++ honor the enum mode attribute Bernd Edlinger
2016-05-07  9:55 ` [PING] " Bernd Edlinger
2016-05-18 18:12   ` [PING**2] " Bernd Edlinger
2016-05-18 21:07 ` Jason Merrill

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).