From: Al Viro <viro@ftp.linux.org.uk>
To: Josh Triplett <josht@linux.vnet.ibm.com>
Cc: linux-sparse@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [RFC] bloody mess with __attribute__() syntax
Date: Fri, 6 Jul 2007 08:48:03 +0100 [thread overview]
Message-ID: <20070706074803.GV21478@ftp.linux.org.uk> (raw)
In-Reply-To: <1183661456.2604.43.camel@josh-work.beaverton.ibm.com>
On Thu, Jul 05, 2007 at 11:50:56AM -0700, Josh Triplett wrote:
> No, I mean __attribute__((context(...))), which means something
> different. __context__() works as a statement statement changing the
> context. __attribute__((context(...))) works as an attribute modifying
> a type to say that it requires a given context, and that
> accessing/calling it changes the context. Somewhat of an odd
> distinction, but sparse currently works that way.
That's actually not a qualifier from the syntax point of view...
It makes sense *only* on function types - we simply ignore it
on anything else. And C syntax doesn't allow qualifiers on functions -
not without creative use of typedef (which gets you in nasal demon
country - undefined behaviour).
What syntax do we want? Note that the *only* possible way to get
it kinda-sorta like qualifiers is by
typedef int F(void);
F __attribute__((context(x,0,1))) f;
with no way to actually define the sucker, since for function
definition you can't use such tricks. IOW, no matter what we do,
it won't look like standard C.
If anything, it ought to be an analog of noreturn/pure/fastcall/etc. - same
kind of property should use the same syntax; no need to add confusion.
Unfortunately, gcc does _not_ give a sane way to declare pointers to
such beasts. To quote gcc info:
| ... At present, such attribute specifiers apply
|to the declared object or function, but in future they may attach to the
|outermost adjacent declarator. In simple cases there is no difference,
|but, for example, in
|
| void (****f)(void) __attribute__((noreturn));
|
|at present the `noreturn' attribute applies to `f', which causes a
|warning since `f' is not a function, but in future it may apply to the
|function `****f'. The precise semantics of what attributes in such
|cases will apply to are not yet specified.
Frankly, my preference would be to have that kind of attributes
follow ( parameter-type-list ), ( identifier-list ) or ( ) in productions
for direct-declarator. That would allow uses like
int foo(void) ATTR; // function with attribute
int foo(void) ATTR {....} // function with attribute
int (*foo)(void) ATTR; // pointer to function with attribute
int (*bar(int) ATTR)(void) {...}// function with attribute returning pointer to
// normal function
int (*bar(int))(void) ATTR {...}// normal function returning a pointer to
// function with attribute
AFAICS, that doesn't lead to any problems with parser - no deep lookahead,
etc. Allowing them in declaration-specifiers, OTOH...
Do we want to allow
__attribute__((context(x,0,1))) int foo(void) {....}
int (__attribute__((context(x,0,1))) *foo)(void);
and similar uses? I'd rather prohibit that...
Another fun question: how do we compare these suckers? Suppose
you have foo() and bar() having some kind of contexts. What contexts
do we put into n ? foo : bar and when do we allow that? Similar question
for p = foo; where p is a pointer to function, etc. I realize that the
first argument of __attribute__((context(...,...,...))) is currently ignored
and pretty much hopeless as defined, but...
next prev parent reply other threads:[~2007-07-06 7:48 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-05 9:35 [RFC] bloody mess with __attribute__() syntax Al Viro
2007-07-05 12:03 ` Arnd Bergmann
[not found] ` <OFC2AA6078.1DF7BE7E-ON4225730F.0044BE34-4225730F.0046B6F1@de.ibm.com>
2007-07-05 16:27 ` Al Viro
2007-07-13 9:04 ` Al Viro
2007-07-05 15:36 ` Josh Triplett
2007-07-05 16:43 ` Al Viro
2007-07-05 18:50 ` Josh Triplett
2007-07-05 19:13 ` Al Viro
2007-07-05 19:35 ` Josh Triplett
2007-07-05 20:08 ` Al Viro
2007-07-05 20:56 ` Linus Torvalds
2007-07-06 3:26 ` Al Viro
2007-07-05 21:09 ` Josh Triplett
2007-07-06 7:48 ` Al Viro [this message]
2007-07-06 8:33 ` Josh Triplett
2007-07-06 15:52 ` Al Viro
2007-07-06 19:29 ` Josh Triplett
2007-07-07 2:11 ` Al Viro
2007-07-07 2:28 ` Josh Triplett
2007-07-08 21:50 ` Al Viro
2007-07-07 2:30 ` Al Viro
2007-07-07 2:55 ` Josh Triplett
2007-07-08 21:52 ` Al Viro
2007-07-05 16:41 ` Linus Torvalds
2007-07-05 16:53 ` Al Viro
2007-07-05 17:02 ` Chris Lattner
2007-07-05 17:09 ` Al Viro
2007-07-05 17:26 ` Linus Torvalds
2007-07-05 18:07 ` Al Viro
2007-07-05 18:56 ` Linus Torvalds
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=20070706074803.GV21478@ftp.linux.org.uk \
--to=viro@ftp.linux.org.uk \
--cc=josht@linux.vnet.ibm.com \
--cc=linux-sparse@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.