On Thu, Jun 11, 2026 at 4:52 AM Richard Biener
<[email protected]> wrote:
>
> On Thu, Jun 11, 2026 at 7:03 AM Andrew Pinski
> <[email protected]> wrote:
> >
> > On Wed, Jun 10, 2026 at 11:50 AM <[email protected]> wrote:
> > >
> > >
> > >
> > > On Jun 10, 2026, at 3:58 AM, Richard Biener <[email protected]> 
> > > wrote:
> > >
> > > +  int m_saved;
> > >
> > > +};
> > >
> > > On Tue, Jun 9, 2026 at 9:45 PM Sammy Al Hashemi <[email protected]> wrote:
> > >
> > >
> > > The -Wstrict-aliasing warning was gated on flag_strict_aliasing, so
> > >
> > > passing -fno-strict-aliasing silenced the warning even when explicitly
> > >
> > > requested with -Wstrict-aliasing.  The warning analysis is purely
> > >
> > > type-based and does not depend on the optimization being active, so
> > >
> > > temporarily enable flag_strict_aliasing around the alias set query
> > >
> > > calls to get meaningful results for the warning.
> > >
> > >
> > > gcc/c-family/ChangeLog:
> > >
> > >
> > >        * c-warn.cc (strict_aliasing_warning): Remove guard on
> > >
> > >        flag_strict_aliasing.  Temporarily enable it via RAII around
> > >
> > >        alias set queries so the warning fires independently.
> > >
> > >
> > > gcc/ChangeLog:
> > >
> > >
> > >        * doc/invoke.texi (-Wstrict-aliasing): Document that the
> > >
> > >        warning now works independently of -fstrict-aliasing.
> > >
> > >
> > > gcc/testsuite/ChangeLog:
> > >
> > >
> > >        * c-c++-common/Wstrict-aliasing2-with-fno.c: New test.
> > >
> > >        * c-c++-common/Wstrict-aliasing3-with-fno.c: New test.
> > >
> > >
> > > Signed-off-by: Sammy Al Hashemi <[email protected]>
> > >
> > > ---
> > >
> > > Thanks for your feedback, I'm still new to contributing here so I
> > >
> > > appreciate it.
> > >
> > >
> > > Changes from v2:
> > >
> > >    - Added RAII class (auto_override_flag) to save/restore
> > >
> > >      flag_strict_aliasing
> > >
> > >    - Filled in ChangeLog descriptions
> > >
> > >
> > > gcc/c-family/c-warn.cc                        | 28 +++++++++++++++++--
> > >
> > > gcc/doc/invoke.texi                           | 16 +++++++----
> > >
> > > .../c-c++-common/Wstrict-aliasing2-with-fno.c | 12 ++++++++
> > >
> > > .../c-c++-common/Wstrict-aliasing3-with-fno.c | 12 ++++++++
> > >
> > > 4 files changed, 60 insertions(+), 8 deletions(-)
> > >
> > > create mode 100644 gcc/testsuite/c-c++-common/Wstrict-aliasing2-with-fno.c
> > >
> > > create mode 100644 gcc/testsuite/c-c++-common/Wstrict-aliasing3-with-fno.c
> > >
> > >
> > > diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc
> > >
> > > index 1767d2dc090..072c16f9b64 100644
> > >
> > > --- a/gcc/c-family/c-warn.cc
> > >
> > > +++ b/gcc/c-family/c-warn.cc
> > >
> > > @@ -685,6 +685,27 @@ warn_if_unused_value (const_tree exp, location_t 
> > > locus, bool quiet)
> > >
> > >     }
> > >
> > > }
> > >
> > >
> > > +/* RAII guard to temporarily override an integer flag, restoring its
> > >
> > > +   original value when the guard goes out of scope.  */
> > >
> > > +class auto_override_flag
> > >
> > > +{
> > >
> > > +public:
> > >
> > > +  auto_override_flag (int &flag, int new_value)
> > >
> > > +    : m_flag (flag), m_saved (flag)
> > >
> > > +  {
> > >
> > > +    m_flag = new_value;
> > >
> > > +  }
> > >
> > > +
> > >
> > > +  ~auto_override_flag ()
> > >
> > > +  {
> > >
> > > +    m_flag = m_saved;
> > >
> > > +  }
> > >
> > > +
> > >
> > > +private:
> > >
> > > +  int &m_flag;
> > >
> > > +  int m_saved;
> > >
> > > +};
> > >
> > >
> > > Somehow I think we already have such class, in the C++ frontend?
> > >
> > >
> > > If it’s there I’m happy to make the switch. I’m still new to the codebase 
> > > and would be curious if there is a general spot where common utilities 
> > > like this belong.
> >
> >
> > For now you can place it in c-common.h since it is only used for the
> > C++ front-end and the common parts of C/C++ front-ends.
> > Otherwise system.h might be an ok place for common utils that don't
> > fit other places; that maybe a new header file might be useful.
>
> I think there's definitely room for use elsewhere.  Just grep for 'flag_.* = 
> '.
>
> What I wanted to say is that I think I have seen such a class in GCC already
> for save/restore of some variable.  IIRC in the C++ frontend.  But I cannot
> find it right now ...

It is in cp-tree.h:
```
/* RAII sentinel that saves the value of a variable, optionally
   overrides it right away, and restores its value when the sentinel
   id destructed.  */

template <typename T>
class temp_override
```


>
> Richard.
>
> >
> > Thanks,
> > Andrea

Reply via email to