This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Obscure crashes due to gcc 4.9 -O2 => -fisolate-erroneous-paths-dereference

> On Feb 20, 2015, at 12:01 PM, Jeff Law <> wrote:
> On 02/20/15 04:43, Jonathan Wakely wrote:
>>> ...
>> I'm inclined to agree.
>> Most developers aren't aware of the preconditions on memcpy, but GCC
>> optimizes aggressively based on those preconditions, so we have a
>> large and potentially dangerous gap between what developers expect and
>> what actually happens.
> But that's always true -- this isn't any different than aliasing, arithmetic overflow, etc.  The standards define the contract between the compiler/library implementors and the developers.  Once the contract is broken, all bets are off.

True.  The unfortunate problem with C, and even more so with C++, is that the contract is so large and complex that few, if any, are skilled enough language lawyers to know what exactly it says.  For that matter, the contract (the standard) is large and complex enough that it has bugs and ambiguities, so the contract is not in fact precisely defined.

Thereâs a nice paper that drives this home:

For example, while most people know about the âno overlapsâ rule of memcpy, stuff like aliasing are far more obscure. Or the exact meaning (if there is one) of âvolatileâ.

It also doesnât help that a large fraction of the contract is unenforced.  You only find out about it when a new version of the compiler starts using a particular rule to make an optimization that suddenly breaks 10 year old code. I remember some heated debates between Linux folks and compiler builders when such things strike the Linux kernel.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]