News for hackers. Stuff that matters.
Re:Clang vs. Clang by robinsonb5 on Sunday August 04, 2024 @04:37AM (#41152004)
There's a world of difference between code that's dead because of a static define, and code that's dead because of an inference the compiler made.

A dead code report would be a useful thing, though, especially if it could give the reason for removal. (Something like the list of removed registers in the Quartus analysis report when building for FPGAs.)

Re:Clang vs. Clang by anon-3988 on Sunday August 04, 2024 @08:03AM (#41152975)
I am guessing there would be a LOT of false negatives of compilers removing dead code for good reason. For example, if you only use a portion of a library's enum then it seems reasonable to me that the compilers optimizes away all the if-else that uses those enums that will never manifest.
Re:Clang vs. Clang by thayne on Sunday August 04, 2024 @11:21AM (#41154103)
I don't think it is unreasonable to have an option for "warn me about places that might be UB" that would tell you if it removes something it thinks is dead because it assumed UB doesn't happen?
Re:Clang vs. Clang by ncruces on Sunday August 04, 2024 @05:04AM (#41152101)

  #define DEBUG i<num+100
The example is silly, but you should get the point. DEBUG can be anything.
Re:Clang vs. Clang by robinsonb5 on Monday August 05, 2024 @10:44AM (#41161844)
Fair point, however your example is a runtime check, so shouldn't result in dead code.

(And if DEBUG is a static define then it still won't result in dead code since the preprocessor will remove it, and the compiler will never actually see it.)

EDIT: and now I realise I misread the first example all along - I read "#if (DEBUG)" rather than "if (DEBUG)".

Re:Clang vs. Clang by umanwizard on Sunday August 04, 2024 @11:25PM (#41157917)
> There's a world of difference between code that's dead because of a static define, and code that's dead because of an inference the compiler made.

Not really, that’s the problem. After many passes of transforming the code through optimization it is hard for the compiler to tell why a given piece of code is dead. Compiler writers aren’t just malicious as a lot of people seem to think when discussions like this come up.

Re:Clang vs. Clang by robinsonb5 on Monday August 05, 2024 @10:49AM (#41161892)
Yeah, I know the compiler writers aren't being deliberately malicious. But I can understand why people perceive the end result - the compiler itself - as having become "lawful evil" - an adversary rather than an ally.