Bug 61593 - Support '#pragma mark - foo' on non-Darwin targets (by simply ignoring it without warning)
Summary: Support '#pragma mark - foo' on non-Darwin targets (by simply ignoring it wit...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.9.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: easyhack
Depends on:
Blocks:
 
Reported: 2014-06-24 15:58 UTC by Sean
Modified: 2023-07-07 07:27 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-10-21 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sean 2014-06-24 15:58:04 UTC
On OS X, it is common to use:

#pragma mark - foo

to divide source code into sections.

This is supported by clang and Apple's old gcc fork.

gcc however warns:

  warning: ignoring #pragma mark  [-Wunknown-pragmas]

And -Wunknown-pragmas is part of -Wall.  I'm aware I could use -Wno-unknown-pragmas, but building clean at -Wall is important.

As clang does a lot to be compatible with gcc, I'm hoping gcc can do a little to be compatible with clang here. :)

No codegen or anything would be required, just ignore and don't warn when #pragma mark is encountered.

Cheers.
Comment 1 Eric Gallager 2016-12-07 16:47:03 UTC
The gcc documentation says pragma mark should be accepted:
https://gcc.gnu.org/onlinedocs/gcc/Darwin-Pragmas.html#Darwin-Pragmas
Comment 2 Sean 2016-12-07 17:00:20 UTC
Eric, thanks for your reply.

Those docs read to me like the pragma is only supported *on* Darwin.

I guess I was not clear when creating this ticket: I'm interested in the pragma being accepted on any platform.

In our situation, we have portable code that runs on Darwin and Linux and would like to use those pragma marks in that code.
Comment 3 Eric Gallager 2017-07-20 20:08:28 UTC
(In reply to Sean from comment #2)
> Eric, thanks for your reply.
> 
> Those docs read to me like the pragma is only supported *on* Darwin.
> 
> I guess I was not clear when creating this ticket: I'm interested in the
> pragma being accepted on any platform.
> 
> In our situation, we have portable code that runs on Darwin and Linux and
> would like to use those pragma marks in that code.

Changing component to target and re-titling, then... I'd confirm it, too, but I only have Darwin to test on (not Linux)
Comment 4 Eric Gallager 2017-10-21 01:55:42 UTC
(In reply to Eric Gallager from comment #3)
> (In reply to Sean from comment #2)
> > Eric, thanks for your reply.
> > 
> > Those docs read to me like the pragma is only supported *on* Darwin.
> > 
> > I guess I was not clear when creating this ticket: I'm interested in the
> > pragma being accepted on any platform.
> > 
> > In our situation, we have portable code that runs on Darwin and Linux and
> > would like to use those pragma marks in that code.
> 
> Changing component to target and re-titling, then... I'd confirm it, too,
> but I only have Darwin to test on (not Linux)

Now that I have access to the compile farm, I've tested this on Linux and can confirm.
Comment 5 Eric Gallager 2019-01-17 04:20:28 UTC
It should be pretty easy; in config/darwin.h #pragma mark is registered as part of the DARWIN_REGISTER_TARGET_PRAGMAS() macro like this:

if (!flag_preprocess_only)					\
      cpp_register_pragma (parse_in, NULL, "mark",		\
			   darwin_pragma_ignore, false);

...and then darwin_pragma_ignore() is a simple no-op declared in config/darwin-protos.h and defined in config/darwin-c.c. So I guess it'd just have to be re-titled and moved somewhere generic?
Comment 6 Iain Sandoe 2019-03-24 13:27:55 UTC
I think you only require this to work for Darwin, right?
so as Eric says, we could have another darwin-specific pragma.
Patch Eric? ( ;) )
Comment 7 Sean 2019-03-24 15:44:58 UTC
Iain, no. Please see comment #2.
Comment 8 Iain Sandoe 2019-03-24 15:56:06 UTC
(In reply to Sean from comment #7)
> Iain, no. Please see comment #2.

ah gotcha .. then it's a question of producing a general patch rather than a darwin-specific one and posting it for review (with some suitable justification as to its merit).
Comment 9 Jakub Jelinek 2020-05-07 11:56:10 UTC
GCC 10.1 has been released.
Comment 10 Richard Biener 2020-07-23 06:52:04 UTC
GCC 10.2 is released, adjusting target milestone.
Comment 11 Richard Biener 2021-04-08 12:02:28 UTC
GCC 10.3 is being released, retargeting bugs to GCC 10.4.
Comment 12 Jakub Jelinek 2022-06-28 10:31:02 UTC
GCC 10.4 is being released, retargeting bugs to GCC 10.5.
Comment 13 Jonathan Wakely 2022-11-04 20:29:24 UTC
(In reply to Eric Gallager from comment #5)
> It should be pretty easy; in config/darwin.h #pragma mark is registered as
> part of the DARWIN_REGISTER_TARGET_PRAGMAS() macro like this:
> 
> if (!flag_preprocess_only)					\
>       cpp_register_pragma (parse_in, NULL, "mark",		\
> 			   darwin_pragma_ignore, false);
> 
> ...and then darwin_pragma_ignore() is a simple no-op declared in
> config/darwin-protos.h and defined in config/darwin-c.c. So I guess it'd
> just have to be re-titled and moved somewhere generic?

I looked into doing this as a follow-up to my PR 85487 patch. However, the definition of c_register_pragma in gcc/c-family/c-pragma.cc says:

/* Front-end wrappers for pragma registration to avoid dragging
   cpplib.h in almost everywhere.  */

So I don't think we want to include cpplib.h in that file, which means that it can't make the same call to cpp_register_pragma.

I don't know the reason for treating that pragma differently from the others (this appears to be the only use of cpp_register_pragma in the whole of GCC!), so I don't want to change it. That means I won't be tackling this one myself.

Maybe it could just use c_register_pragmas, or maybe including cpplib.h in c-pragma.cc is OK.

If somebody else wants to, my patch for PR 85487 (which I'm going to re-propose soon) adds a target-independent handle_pragma_ignore that could be used for this, once the issue above is cleared up.