LLVM talks 1: Clang for Chromium
Alex Rønne Petersen
xtzgzorex at gmail.com
Fri Dec 16 06:43:50 PST 2011
On 16-12-2011 13:23, bearophile wrote:
> There are the videos of the 2011 LLVM Developer Meeting:
> http://www.youtube.com/playlist?list=PL970A5BD02C11F80C
>
> Slides too:
> http://llvm.org/devmtg/2011-11/
>
> As usual the LLVM talks are quite interesting. I have started to see the videos/slides, it will require some time.
>
> An interesting talk, "Using clang in the Chromium project":
> http://www.youtube.com/watch?v=IvL3f8xY7Uw
>
> Slides:
> http://llvm.org/devmtg/2011-11/Weber_Wennborg_UsingClangInChromium.pdf
>
> -----------------------------------
>
> It shows some problems found by Clang.
>
>
> a.cc:2:9: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
> if (x |= y)
> ~~^~~~
> a.cc:2:9: note: use '!=' to turn this compound assignment into an inequality comparison
> if (x |= y)
> ^~
> !=
>
> 1 warning generated.
>
>
>
> This code doesn't compile with DMD:
> Error: assignment cannot be used as a condition, perhaps == was meant?
>
> void main() {
> int x, y;
> if (x = y) {}
> }
>
>
> But this gives no errors:
>
> void main() {
> int x, y;
> if (x |= y) {}
> if (x += y) {}
> }
>
>
> Do you know why DMD forbids assignments as conditions, but it accepts compound assignments there? It looks like a incongruence that's better to remove.
>
> -----------------------------------
>
> 10.25 in the video:
>
> a.cc:2:16: warning: operator '?:' has lower precedence than '+'; '+' will be evaluated first
> return x + b ? y : 0;
> ~~~~~ ^
> a.cc:2:16: note: place parentheses around the '?:' expression to evaluate it first
> return x + b ? y : 0;
> ^
> ( )
>
> 1 warning generated.
>
> They say:
>
>> It's a bug every time!
>
>
> Given the frequence of bugs caused by the ?: operator, I think something like this will be good to have in D too.
>
> -----------------------------------
>
> a.cc:8:23: warning: argument to ’sizeof’ in ’memset’ call is the same expression as the destination;
> did you mean to dereference it?
> memset(s, 0, sizeof(s));
> ~ ^
>
> 1 warning generated.
>
> -----------------------------------
>
> At 14.45-16.39 there is an interesting part, about slide 22 of the PDF. It's about crashes/bugs caused by undefined order of evaluation of function arguments. This is a class of bugs that don't have to happen in D2 code.
>
> Bye,
> bearophile
I generally don't like that a compiler throws warnings at me for
perfectly valid code. Yes, it *can* be error prone, but most often, I
know what I'm doing and am actually utilizing a language feature.
Personally, I'd make no warnings the default and add an option that
looks for suspicious stuff like if (a = b).
- Alex
More information about the Digitalmars-d
mailing list