[LLVMdev] [RFC] NoBuiltin Attribute

Chris Lattner clattner at apple.com
Tue Feb 19 11:49:55 PST 2013


On Feb 19, 2013, at 11:08 AM, Krzysztof Parzyszek <kparzysz at codeaurora.org> wrote:

> On 2/19/2013 12:26 PM, Chris Lattner wrote:
>> 
>> void foo() {
>>   auto fp = printf;
>>   fp("xyz\n");
>> }
>> 
>> With -fno-builtin-printf, we can't optimize the call to printf, even though it only becomes apparent after (trivial) devirtualization.
> 
> Ha.  Good example.
> What would you expect to happen in this case?
> 
> --- a.cpp ---  (with -fno-builtin-printf)
> pointer fptr;
> void foo(bool x) {
>  bar(x);
> }
> void set(bool x) {
>  if (x) fptr = printf;
>  else   fptr = vprintf;
> }
> -------------
> 
> --- b.cpp ---  (no restrictions)
> extern pointer fptr;
> void bar(bool x) {
>  set(x);
>  va_list ap = ...
>  (*fptr)("haha", ap);
> }
> -------------

-fno-builtin applies to the code in foo and set.

> Also, with the options reversed.

Then -fno-builtin would apply to the code in bar.

-Chris




More information about the llvm-dev mailing list