develooper Front page | perl.perl5.porters | Postings from September 2013

__attribute__((nonnull)) side effects (was: Enhancement request - aprototype attribute)

Thread Next
From:
Peter Martini
Date:
September 18, 2013 00:29
Subject:
__attribute__((nonnull)) side effects (was: Enhancement request - aprototype attribute)
Message ID:
CAFyW6MQXtBEyDYzzBtPxfq50nUF7OXMZwmwtEmDPWdSzNOBU9A@mail.gmail.com
So, fun:

I'm using gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3), and found that
the attribute((nonnull)) added in the function declaration completely
neutered the asserts on the parameters.

Specifically,

S_move_proto_attr(pTHX_ OP **proto, OP **attrs,, const GV * name) was
defined with  __attribute__nonnull__(pTHX_3), and with that set, the
compiler apparently optimized out any checks for null on name.

I tried:

assert(name)
if(name == NULL){ assert(0);}

and didn't hit either assert, despite name *actually* being NULL.

Using assert(*attrs) did trigger the assertion, since *attrs wasn't
affected by the attribute nonnull, and removing
attribute__nonnull__(pTHX_3) from proto.h caused the assertion to
properly trigger again.

For good measure, I threw in :

if (name == NULL) {
Perl_warn(aTHX_ "Name is null\n");
}

And that code was completely optimized out. with a default Configure
run of "./Configure -Dusedevel -DDEBUGGING -des"

That's a little scary ...

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About