public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Using std types and functions within GCC
@ 2024-03-14 12:53 Pierrick Philippe
  2024-03-14 13:28 ` Jonathan Wakely
  0 siblings, 1 reply; 6+ messages in thread
From: Pierrick Philippe @ 2024-03-14 12:53 UTC (permalink / raw)
  To: gcc

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

Hi all,

I was wondering, is there any conventions or guidelines regarding the
usage of types and/or functions coming from the C++ std library within
the compiler?

To explicit a bit more, I am working on modification on the analyzer and
might need to use a pair.

Thank you for your time,

Pierrick

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

* Re: Using std types and functions within GCC
  2024-03-14 12:53 Using std types and functions within GCC Pierrick Philippe
@ 2024-03-14 13:28 ` Jonathan Wakely
  2024-03-14 14:49   ` David Malcolm
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Wakely @ 2024-03-14 13:28 UTC (permalink / raw)
  To: Pierrick Philippe; +Cc: gcc

On Thu, 14 Mar 2024 at 12:54, Pierrick Philippe
<pierrick.philippe@irisa.fr> wrote:
>
> Hi all,
>
> I was wondering, is there any conventions or guidelines regarding the
> usage of types and/or functions coming from the C++ std library within
> the compiler?

The relevant header needs to be included from the gcc/system.h header.
Look in there for INCLUDE_STRING, INCLUDE_VECTOR etc. and how those
macros are used in other sources.

> To explicit a bit more, I am working on modification on the analyzer and
> might need to use a pair.

A grep of the source shows that <utility> is already included in
gcc/system.h and std::pair is already used in several places.

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

* Re: Using std types and functions within GCC
  2024-03-14 13:28 ` Jonathan Wakely
@ 2024-03-14 14:49   ` David Malcolm
  2024-03-14 14:55     ` Jonathan Wakely
                       ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: David Malcolm @ 2024-03-14 14:49 UTC (permalink / raw)
  To: Jonathan Wakely, Pierrick Philippe; +Cc: gcc

On Thu, 2024-03-14 at 13:28 +0000, Jonathan Wakely via Gcc wrote:
> On Thu, 14 Mar 2024 at 12:54, Pierrick Philippe
> <pierrick.philippe@irisa.fr> wrote:
> > 
> > Hi all,

Hi Pierrick!  It was good to meet you at FOSDEM.

> > 
> > I was wondering, is there any conventions or guidelines regarding
> > the
> > usage of types and/or functions coming from the C++ std library
> > within
> > the compiler?
> 
> The relevant header needs to be included from the gcc/system.h
> header.
> Look in there for INCLUDE_STRING, INCLUDE_VECTOR etc. and how those
> macros are used in other sources.
> 
> > To explicit a bit more, I am working on modification on the
> > analyzer and
> > might need to use a pair.
> 
> A grep of the source shows that <utility> is already included in
> gcc/system.h and std::pair is already used in several places.

Thanks Jonathan.

A couple of other things to note:

- bear in mind that we need to be somewhat conservative in our usage of
C++ internally: our code needs to be C++11, compilable by GCC 4.8.3,
and parsable by gengtype and by xgettext.  For example, there's at
least one place where I'd have used std::optional, but that's C++14 and
so unavailable.

- some parts of our code manage memory using our custom garbage
collector (via GTY and gengtype), and other parts use C++11 move
semantics.  I suspect that these two approaches to memory management
aren't especially compatible with each other.  For example, our vec<T>
class works with the GC but not (I think) with move, whereas
std::vector works with C++11.  We make the simplifying assumption
within the analyzer that the garbage collector will never run within
the analysis pass, and the analyzer makes use of move semantics, ctors,
dtors, etc.

Feel free to use std::pair in the analyzer.

Hope this is helpful
Dave


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

* Re: Using std types and functions within GCC
  2024-03-14 14:49   ` David Malcolm
@ 2024-03-14 14:55     ` Jonathan Wakely
  2024-03-15 13:00     ` Tom Tromey
  2024-03-15 13:43     ` dkm
  2 siblings, 0 replies; 6+ messages in thread
From: Jonathan Wakely @ 2024-03-14 14:55 UTC (permalink / raw)
  To: David Malcolm; +Cc: Pierrick Philippe, gcc

On Thu, 14 Mar 2024 at 14:49, David Malcolm <dmalcolm@redhat.com> wrote:
>
> On Thu, 2024-03-14 at 13:28 +0000, Jonathan Wakely via Gcc wrote:
> > On Thu, 14 Mar 2024 at 12:54, Pierrick Philippe
> > <pierrick.philippe@irisa.fr> wrote:
> > >
> > > Hi all,
>
> Hi Pierrick!  It was good to meet you at FOSDEM.
>
> > >
> > > I was wondering, is there any conventions or guidelines regarding
> > > the
> > > usage of types and/or functions coming from the C++ std library
> > > within
> > > the compiler?
> >
> > The relevant header needs to be included from the gcc/system.h
> > header.
> > Look in there for INCLUDE_STRING, INCLUDE_VECTOR etc. and how those
> > macros are used in other sources.
> >
> > > To explicit a bit more, I am working on modification on the
> > > analyzer and
> > > might need to use a pair.
> >
> > A grep of the source shows that <utility> is already included in
> > gcc/system.h and std::pair is already used in several places.
>
> Thanks Jonathan.
>
> A couple of other things to note:
>
> - bear in mind that we need to be somewhat conservative in our usage of
> C++ internally: our code needs to be C++11, compilable by GCC 4.8.3,
> and parsable by gengtype and by xgettext.  For example, there's at
> least one place where I'd have used std::optional, but that's C++14 and
> so unavailable.

C++17, so even more unavailable!

> - some parts of our code manage memory using our custom garbage
> collector (via GTY and gengtype), and other parts use C++11 move
> semantics.  I suspect that these two approaches to memory management
> aren't especially compatible with each other.  For example, our vec<T>
> class works with the GC but not (I think) with move, whereas
> std::vector works with C++11.  We make the simplifying assumption
> within the analyzer that the garbage collector will never run within
> the analysis pass, and the analyzer makes use of move semantics, ctors,
> dtors, etc.
>
> Feel free to use std::pair in the analyzer.
>
> Hope this is helpful
> Dave
>

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

* Re: Using std types and functions within GCC
  2024-03-14 14:49   ` David Malcolm
  2024-03-14 14:55     ` Jonathan Wakely
@ 2024-03-15 13:00     ` Tom Tromey
  2024-03-15 13:43     ` dkm
  2 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2024-03-15 13:00 UTC (permalink / raw)
  To: David Malcolm via Gcc; +Cc: Jonathan Wakely, Pierrick Philippe, David Malcolm

>>>>> "David" == David Malcolm via Gcc <gcc@gcc.gnu.org> writes:

David> For example, there's at
David> least one place where I'd have used std::optional, but that's C++14 and
David> so unavailable.

FWIW, gdb had its own gdb::optional (which was really just a
stripped-down copy of the one from libstdc++) to fill exactly this need,
at least until we moved to C++17 this year.  If you need it you could
easily lift it from the gdb repository.

Tom

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

* Re: Using std types and functions within GCC
  2024-03-14 14:49   ` David Malcolm
  2024-03-14 14:55     ` Jonathan Wakely
  2024-03-15 13:00     ` Tom Tromey
@ 2024-03-15 13:43     ` dkm
  2 siblings, 0 replies; 6+ messages in thread
From: dkm @ 2024-03-15 13:43 UTC (permalink / raw)
  To: Tom Tromey, David Malcolm via Gcc
  Cc: Jonathan Wakely, Pierrick Philippe, David Malcolm, arthur.cohen,
	pierre-emmanuel.patry

March 15, 2024 at 2:00 PM, "Tom Tromey" <tom@tromey.com> wrote:
 
> > 
> > "David" == David Malcolm via Gcc <gcc@gcc.gnu.org> writes:
> > 
> 
> David> For example, there's at
> David> least one place where I'd have used std::optional, but that's C++14 and
> David> so unavailable.
> 
> FWIW, gdb had its own gdb::optional (which was really just a
> stripped-down copy of the one from libstdc++) to fill exactly this need,
> at least until we moved to C++17 this year. If you need it you could
> easily lift it from the gdb repository.
> 

Hi,

In the Rust frontend, we are using a single header implementation from https://github.com/TartanLlama/optional, until we can use something from libstdc++.

Marc

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

end of thread, other threads:[~2024-03-15 13:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-14 12:53 Using std types and functions within GCC Pierrick Philippe
2024-03-14 13:28 ` Jonathan Wakely
2024-03-14 14:49   ` David Malcolm
2024-03-14 14:55     ` Jonathan Wakely
2024-03-15 13:00     ` Tom Tromey
2024-03-15 13:43     ` dkm

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