GCC Undefined Behavior Sanitizer

Marco Leise via Digitalmars-d digitalmars-d at puremagic.com
Fri Oct 17 02:42:01 PDT 2014


Am Fri, 17 Oct 2014 08:38:11 +0000
schrieb "Paulo  Pinto" <pjmlp at progtools.org>:

> On Thursday, 16 October 2014 at 21:00:18 UTC, bearophile wrote:
> > Just found with Reddit. C seems one step ahead of D with this:
> >
> > http://developerblog.redhat.com/2014/10/16/gcc-undefined-behavior-sanitizer-ubsan/
> >
> > Bye,
> > bearophile
> 
> The sad thing about this tools is that they are all about fixing 
> the holes introduced by C into the wild.
> 
> So in the end when using C and C++, we need to have compiler + 
> static analyzer + sanitizers, in a real life example of "Worse is 
> Better", instead of fixing the languages.
> 
> At least, C++ is on the path of having less undefined behaviors, 
> as the work group clearly saw the benefits don't outweigh the 
> costs and is now the process of cleaning the standard in that 
> regard.
> 
> As an outsider, I think D would be better by having only defined 
> behaviors.
> 
> --
> Paulo

I have a feeling back then the C designers weren't quite sure
how the language would work out on current and future
architectures, so they gave implementations some freedom here
and there. Now that C/C++ is the primary language for any
architecture, the table turned and the hardware designers
build chips that behave "as expected" in some cases that C/C++
left undefined. That in turn allows C/C++ to become more
restrictive. Or maybe I don't know what I'm talking about.

What behavior is undefined in D? I'm not kidding, I don't
really know of any list of undefined behaviors. The only thing
I remember is casting away immutable and modifying the content
is undefined behavior. Similar to C/C++ I think this is to
allow current and future compilers to perform as of yet
unknown optimizations on immutable data structures.

Once such optimizations become well known in 10 to 20 years or
so, D will define that behavior, too. Just like C/C++.

-- 
Marco



More information about the Digitalmars-d mailing list