[llvm-dev] How to prevent optimizing away a call + its arguments

Mehdi AMINI via llvm-dev llvm-dev at lists.llvm.org
Wed Jun 21 17:25:04 PDT 2017


Hi Kuba,

Try:

__attribute__(optnone)

See
https://clang.llvm.org/docs/AttributeReference.html#optnone-clang-optnone

-- 
Mehdi


2017-06-21 16:16 GMT-07:00 Kuba Mracek via llvm-dev <llvm-dev at lists.llvm.org
>:

> Hi llvm-dev,
>
> I have a C function:
>
> __attribute__((__visibility__("default")))
> __attribute__((used))
> __attribute__((noinline))
> void please_do_not_optimize_me_away(int arg1, void *arg2) {
>   asm volatile("" :::);
> }
>
> (the purpose is that this function will be used dynamically at runtime,
> perhaps by interposing the function, or via the debugger)
>
> I really thought this will not get optimized out, but I've realized (the
> hard way) that LLVM will happily optimize a call to this function, and
> replace all arguments with undef, because it figures out that they're not
> really needed.
>
> I'm going to fix this by passing the arguments explicitly as inputs to the
> asm, but is that expected?  Is there any more reasonable way (attribute) of
> telling that the compiler should really not expect anything from the body
> of the function, not assume that it's not doing anything, and not
> optimizing out arguments?
>
> Thanks,
> Kuba
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170621/15716cb9/attachment.html>


More information about the llvm-dev mailing list