[cfe-dev] [RFC] add Function Attribute to disable optimization

Jeffrey Walton noloader at gmail.com
Mon Jun 17 10:29:17 PDT 2013


Hi Andrea,

This would be very useful.

On Mon, Jun 17, 2013 at 11:58 AM,  <Andrea_DiBiagio at sn.scee.net> wrote:
>
> I previously made a proposal for adding a pragma for per-function
> optimization level control due to a number of requests from our customers
> (See http://comments.gmane.org/gmane.comp.compilers.clang.devel/28958 for
> the previous discussion), however the discussion was inconclusive.  Some
> of my colleagues recently had the opportunity to discuss the proposal with
> a number of people at and before the recent Bay Area social where it was
> generally agreed that we should resubmit a new scaled-down proposal that
> still addresses our users' primary use-case without introducing the
> complexity of full per-function optimization level control at this time.
Unlike the cited use case, I encounter two others in the field during
code reviews.

First is to ensure dead-writes are not removed. For example, a
function that zeroizes or wipes memory is subject to removal during
optimization. I often have to look at program's disassembly to ensure
the memset is not removed by the optimizer.

Second is to ensure that questionable code (undefined behavior) is not
removed. I see this most often in overflow checks when the programmer
uses an `int` rather than an `usigned int`. This would also likely
relieve the need for -fwrapv since we don't have to worry about the
compiler or optimizer dropping code.

There are a few ways to get around the issues, but the easiest would
be to apply per-function optimizations through instrumentation (such
as a pragma). Microsoft compilers already allow us to do the same.

Jeff



More information about the cfe-dev mailing list