_FORTIFY_SOURCE for std::vector

Marc Glisse marc.glisse@inria.fr
Mon Jun 4 19:08:00 GMT 2012


On Mon, 4 Jun 2012, Florian Weimer wrote:

> On 06/01/2012 01:34 PM, Jakub Jelinek wrote:
>> Have you looked at the assembly differences with this in?
>
> It's not great.
>
> Here's an example:
>
> void
> write(std::vector<float>& blob, unsigned n, float v1, float v2, float v3, 
> float v4)
> {
>  blob[n] = v1;
>  blob[n + 1] = v2;
>  blob[n + 2] = v3;
>  blob[n + 3] = v4;
> }

Would be great if it ended up testing only n and n+3.
__attribute__((__noreturn__)) is not quite strong enough to allow this 
optimization, it would require something like 
__attribute__((__crashing__)) to let the compiler know that if the 
function is called, you don't care what happens to blob. And possibly the 
use of a signed n.

Note that even when the optimization would be legal, gcc seems to have a 
few difficulties:

extern "C" void fail() __attribute((noreturn));
void write(signed m, signed n)
{
   if((n+3)>m) fail();
   if((n+2)>m) fail();
   if((n+1)>m) fail();
   if(n>m) fail();
}

keeps 3 tests.

-- 
Marc Glisse



More information about the Gcc-patches mailing list