"Dude, where's my code?"

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
pocopito
Posts: 238
Joined: Tue Jul 12, 2011 1:31 pm

"Dude, where's my code?"

Post by pocopito »

Has anyone else heard about this application?

"A new system warns programmers when compilers — which convert high-level programs into machine-readable instructions — might simply discard their code."

http://web.mit.edu/newsoffice/2013/syst ... -1016.html

Best

E Diaz
Two first meanings of the dutch word "leren":
1. leren [vc] (learn, larn, acquire) acquire or gain knowledge or skills.
2. leren [v] (teach, learn, instruct) impart skills or knowledge to.
User avatar
Codesquid
Posts: 138
Joined: Tue Aug 23, 2011 10:25 pm
Location: Germany

Re: "Dude, where's my code?"

Post by Codesquid »

Haven't heard of that tool yet, I'm familiar with the problem though. The interaction between compiler optimization and undefined or implementation specific behavior leads to the strangest bugs.

A great series of articles that aptly explains undefined behavior starts at http://blog.llvm.org/2011/05/what-every ... -know.html

clang includes a lot of machinery to find problematic cases, see http://clang.llvm.org/docs/UsersManual. ... generation
nanos gigantium humeris insidentes
Angrim
Posts: 97
Joined: Mon Jun 25, 2012 10:16 pm
Location: Forks, WA
Full name: Ben Nye

Re: "Dude, where's my code?"

Post by Angrim »

pocopito wrote:Has anyone else heard about this application?

"A new system warns programmers when compilers — which convert high-level programs into machine-readable instructions — might simply discard their code."
http://web.mit.edu/newsoffice/2013/syst ... -1016.html

Best

E Diaz
Not too impressed with the article author, this portion of the article at least is just lame
Seasoned C programmers will actually exploit this behavior to verify that program inputs don’t exceed some threshold. Rather than writing a line of code that, say, compares the sum of two numbers to the known threshold for an integer (“if a + b < int_max”), they’ll check to see whether the sum of the numbers is smaller than one of the addends (“if a + b > a”) — whether, that is, the summation causes the integer to wrap around to a smaller value.

According to Wang, programmers give a range of explanations for this practice. Some say that the intent of the comparison — an overflow check — is clearer if they use integer wraparound; others say that the wraparound comparison executes more efficiently than the more conventional comparison;
The actual reason to not use "if (a+b)<int_max" is that it won't do what it is intended to, and instead will evaluate to true in the case that (a+b) wraps around. If someone gives any reason involving clarity of code, they should not be allowed to use C.
wgarvin
Posts: 838
Joined: Thu Jul 05, 2007 5:03 pm
Location: British Columbia, Canada

Re: "Dude, where's my code?"

Post by wgarvin »

Everyone should read John Regehr's integer overflow paper (link to PDF). Actually, read his entire blog! You'll find plenty of interesting stuff in the software correctness or compilers categories.

And also another old favorite:
Dangerous Optimizations and the Loss of Causality

Undefined behaviour is widespread in C/C++ code, and now that compiler writers are increasingly starting to exploit it for optimization purposes, there is a lot of legacy code effectively containing "time bombs" : code with undefined behaviour that used to be compiled into something that worked anyways, but in the future it might stop working. Because optimizers might remove or alter the meaning the programmer assumed that it had, as they are technically allowed to by the standard.
rjgibert
Posts: 317
Joined: Mon Jun 26, 2006 9:44 am

Re: "Dude, where's my code?"

Post by rjgibert »

Regehr specifically talks about the MIT article, which he praises in his blog titled Finding Undefined Behavior Bugs by Finding Dead Code, which is found here: http://blog.regehr.org/archives/970