public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/aoliva/heads/testme)] c++: mark short-enums as packed
@ 2023-11-19  6:31 Alexandre Oliva
  0 siblings, 0 replies; 3+ messages in thread
From: Alexandre Oliva @ 2023-11-19  6:31 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:48dece46f1b5ea2fa7b3bf8c8165047484073a7c

commit 48dece46f1b5ea2fa7b3bf8c8165047484073a7c
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Sun Nov 19 01:22:31 2023 -0300

    c++: mark short-enums as packed
    
    Unlike C, C++ doesn't mark enums shortened by -fshort-enums as packed.
    This makes for undesirable warning differences between C and C++,
    e.g. c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early*.c
    triggers a warning about a type cast from a pointer to enum that, when
    packed, might not be sufficiently aligned.
    
    This change is not enough for that warning to trigger.  The tree
    expression generated by the C++ front-end is also a little too
    complicated for us get to the base pointer.  A separate patch takes
    care of that.
    
    
    for  gcc/cp/ChangeLog
    
            * decl.cc (finish_enum_value_list): Set TYPE_PACKED if
            use_short_enum, and propagate it to variants.

Diff:
---
 gcc/cp/decl.cc | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 038c5ab71f2..f6d5645d508 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -16881,6 +16881,12 @@ finish_enum_value_list (tree enumtype)
       /* If -fstrict-enums, still constrain TYPE_MIN/MAX_VALUE.  */
       if (flag_strict_enums)
 	set_min_and_max_values_for_integral_type (enumtype, precision, sgn);
+
+      if (use_short_enum)
+	{
+	  TYPE_PACKED (enumtype) = use_short_enum;
+	  fixup_attribute_variants (enumtype);
+	}
     }
   else
     underlying_type = ENUM_UNDERLYING_TYPE (enumtype);

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

* [gcc(refs/users/aoliva/heads/testme)] c++: mark short-enums as packed
@ 2023-11-23 11:46 Alexandre Oliva
  0 siblings, 0 replies; 3+ messages in thread
From: Alexandre Oliva @ 2023-11-23 11:46 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:0d1b4440f1f62aedcc9fe206f1f6845509cecdef

commit 0d1b4440f1f62aedcc9fe206f1f6845509cecdef
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Sun Nov 19 01:22:31 2023 -0300

    c++: mark short-enums as packed
    
    Unlike C, C++ doesn't mark enums shortened by -fshort-enums as packed.
    This makes for undesirable warning differences between C and C++,
    e.g. c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early*.c
    triggers a warning about a type cast from a pointer to enum that, when
    packed, might not be sufficiently aligned.
    
    This change is not enough for that warning to trigger.  The tree
    expression generated by the C++ front-end is also a little too
    complicated for us get to the base pointer.  A separate patch takes
    care of that.
    
    
    for  gcc/cp/ChangeLog
    
            * decl.cc (finish_enum_value_list): Set TYPE_PACKED if
            use_short_enum, and propagate it to variants.

Diff:
---
 gcc/cp/decl.cc | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 4b3791c4606..4200a007d9a 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -16893,6 +16893,12 @@ finish_enum_value_list (tree enumtype)
       /* If -fstrict-enums, still constrain TYPE_MIN/MAX_VALUE.  */
       if (flag_strict_enums)
 	set_min_and_max_values_for_integral_type (enumtype, precision, sgn);
+
+      if (use_short_enum)
+	{
+	  TYPE_PACKED (enumtype) = use_short_enum;
+	  fixup_attribute_variants (enumtype);
+	}
     }
   else
     underlying_type = ENUM_UNDERLYING_TYPE (enumtype);

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

* [gcc(refs/users/aoliva/heads/testme)] c++: mark short-enums as packed
@ 2023-11-19  8:11 Alexandre Oliva
  0 siblings, 0 replies; 3+ messages in thread
From: Alexandre Oliva @ 2023-11-19  8:11 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:985ec4de20aa6b254d0b938a4d682236068027c0

commit 985ec4de20aa6b254d0b938a4d682236068027c0
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Sun Nov 19 01:22:31 2023 -0300

    c++: mark short-enums as packed
    
    Unlike C, C++ doesn't mark enums shortened by -fshort-enums as packed.
    This makes for undesirable warning differences between C and C++,
    e.g. c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early*.c
    triggers a warning about a type cast from a pointer to enum that, when
    packed, might not be sufficiently aligned.
    
    This change is not enough for that warning to trigger.  The tree
    expression generated by the C++ front-end is also a little too
    complicated for us get to the base pointer.  A separate patch takes
    care of that.
    
    
    for  gcc/cp/ChangeLog
    
            * decl.cc (finish_enum_value_list): Set TYPE_PACKED if
            use_short_enum, and propagate it to variants.

Diff:
---
 gcc/cp/decl.cc | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 038c5ab71f2..f6d5645d508 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -16881,6 +16881,12 @@ finish_enum_value_list (tree enumtype)
       /* If -fstrict-enums, still constrain TYPE_MIN/MAX_VALUE.  */
       if (flag_strict_enums)
 	set_min_and_max_values_for_integral_type (enumtype, precision, sgn);
+
+      if (use_short_enum)
+	{
+	  TYPE_PACKED (enumtype) = use_short_enum;
+	  fixup_attribute_variants (enumtype);
+	}
     }
   else
     underlying_type = ENUM_UNDERLYING_TYPE (enumtype);

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

end of thread, other threads:[~2023-11-23 11:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-19  6:31 [gcc(refs/users/aoliva/heads/testme)] c++: mark short-enums as packed Alexandre Oliva
2023-11-19  8:11 Alexandre Oliva
2023-11-23 11:46 Alexandre Oliva

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