public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: Alex Henrie <alexhenrie24@gmail.com>
Cc: Joseph Myers <joseph@codesourcery.com>,
	Martin Sebor <msebor@gmail.com>,
	    gcc-patches@gcc.gnu.org, msebor@gcc.gnu.org,
	    Zebediah Figura <z.figura12@gmail.com>
Subject: Re: [PATCH] PR c/86407 - Add option to ignore fndecl attributes on function pointers
Date: Mon, 03 Jun 2019 08:25:00 -0000	[thread overview]
Message-ID: <alpine.LSU.2.20.1906031020450.10704@zhemvz.fhfr.qr> (raw)
In-Reply-To: <CAMMLpeQBt8vv-dsWAW4PZ1ULuaTOyC3s-Ub3ctuzrQtC0EQyiQ@mail.gmail.com>

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

On Fri, 31 May 2019, Alex Henrie wrote:

> On Fri, May 31, 2019 at 1:38 AM Richard Biener <rguenther@suse.de> wrote:
> >
> > On Thu, 30 May 2019, Alex Henrie wrote:
> >
> > > In Wine we need a way to (without warnings) put ms_hook_prologue into
> > > a macro that is applied to functions, function pointers, and function
> > > pointer typedefs. It sounds like you're saying that you will not
> > > accept a patch that silences or splits off warnings about using
> > > ms_hook_prologue with function pointers and function pointer typedefs.
> > > So how do you think Wine's problem should be solved?
> >
> > I think ms_hook_prologue should be allowed to apply to function types
> > and function decls.  If you say it should apply to function pointers
> > then I suppose you want to have it apply to the pointed to function
> > of the function pointer - but that's not possible without an indirection
> > via a function pointer typedef IIRC.
> 
> No, if ms_hook_prologue is applied to a function pointer, it shouldn't
> do anything except maybe trigger some optimization of the code around
> the indirect function call.
> 
> > I also have the following which _may_ motivate that attributes
> > currently not applying to function types (because they only
> > affect function definitions) should also apply there:
> >
> > typedef int  (myfun)  (int *) __attribute__((nonnull(1)));
> > myfun x;
> > int x(int *p) { return p != (int*)0; }
> >
> > this applies nonnull to the function definition of 'x' but
> > I put the attribute on the typedef.  I didn't manage to
> > do without the myfun x; declaration.
> 
> That is a great example and another compelling reason to allow
> "fndecl" attributes in more places.
> 
> > > It seems to me that any information about the target of a function
> > > pointer, even the flatten attribute or the ms_hook_prologue attribute,
> > > provides information that could be useful for optimizing the code
> > > around the indirect function call. That sounds like a compelling
> > > argument for allowing these attributes in more places without
> > > warnings.
> >
> > Sure.  Can you write down the three cases after macro expansion
> > here to clarify what you need?  Esp. say what the attribute should
> > apply to.  Just silencing the warning without actually achieving
> > what you want would be bad I think ;)
> 
> Essentially, the following needs to compile without warnings:
> 
> #define WINAPI __attribute__((__stdcall__)) \
>                __attribute__((__ms_hook_prologue__))
> 
> typedef unsigned int (WINAPI *APPLICATION_RECOVERY_CALLBACK)(void*);
> 
> void WINAPI foo()
> {
>     APPLICATION_RECOVERY_CALLBACK bar;
>     unsigned int (WINAPI *baz)(void*);
> }

OK, so it's being that attributes with effect only on function
bodies are harmless on function types / indirect calls.  Of
course in case the user expects sth like a thunk to be generated
for calls through such type then a warning that the attribute has
no effect is warranted.

I'd vote for splitting -Wattributes to distinguish

t.c:2:1: warning: ‘ms_ho_prologue’ attribute directive ignored 
[-Wattributes]
 void __attribute__((__ms_ho_prologue__)) bar () {}
 ^~~~
t.c:4:1: warning: ‘ms_hook_prologue’ attribute only applies to functions 
[-Wattributes]
 typedef void __attribute__((__ms_hook_prologue__)) (*fn_t)();

so you could disable the second while retaining the first.  You
could be also more careful in the source where you place the
attributes...

Richard.

  reply	other threads:[~2019-06-03  8:25 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-24  3:57 Alex Henrie
2019-05-24  8:01 ` Richard Biener
2019-05-24 15:49   ` Alex Henrie
2019-05-25  6:34     ` Richard Biener
2019-05-25 17:20       ` Alex Henrie
2019-05-27  7:26         ` Richard Biener
2019-05-28 19:41     ` Martin Sebor
2019-05-29  7:16       ` Richard Biener
2019-05-30  8:28       ` Alex Henrie
2019-05-31  1:09         ` Joseph Myers
2019-05-31  5:58           ` Alex Henrie
2019-05-31  8:23             ` Richard Biener
2019-05-31 20:47               ` Alex Henrie
2019-06-03  8:25                 ` Richard Biener [this message]
2019-06-03 15:17             ` Joseph Myers
2019-05-24 15:23 ` Martin Sebor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LSU.2.20.1906031020450.10704@zhemvz.fhfr.qr \
    --to=rguenther@suse.de \
    --cc=alexhenrie24@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    --cc=msebor@gcc.gnu.org \
    --cc=msebor@gmail.com \
    --cc=z.figura12@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).