Liste des Groupes | Revenir à c arch |
On 03/09/2024 20:39, BGB wrote:Usually the role of the compiler is to make existing code work as it did before, not to cause it to break, even in the face of UB.On 9/2/2024 8:36 AM, MitchAlsup1 wrote:No, the error in the code caused the code to break. You don't get to blame the compiler if you write rubbish. You get to /thank/ the compiler if it has helpfully added an instruction to cause the program to stop abruptly with a UD2 instruction.On Mon, 2 Sep 2024 5:55:34 +0000, Thomas Koenig wrote:>
>George Neuner <gneuner2@comcast.net> schrieb:>
>I'm not going to argue about whether UB in code is wrong. The>
question I have concerns what to do with something that explicitly is
mentioned as UB in some standard N, but was not addressed in previous
standards.
>
Was it always UB? Or should it be considered ID until it became UB?
Can you give an exapmple?
Memcopy() with overlapping pointers.
I had just recently discovered that newer versions of GCC will cause code to break if it is missing a return value in C++ mode.
>
Note that in C, falling off the end of Foo here is fine - it is only if the caller attempts to use the non-existent return value that there is UB. Thus in C mode, gcc implements Foo as "ret" (when optimised), and will only warn you if you enable warnings.It worked fine in the older instance of WSL running GCC 4.8.0 ("Ubuntu 14"), but sorta exploded when switching to a newer instance of WSL (with "Ubuntu 22")...
In C++, it is the act of falling off the end of Foo that is UB, thus the compiler will generate an UB2 (for -O0) or no code at all (when optimised), and will warn you without requiring options.
It would have been nicer if it crashed in a way where GDB could show me the point at which the crash was triggered...So:If your compiler tells you you are doing something stupid, and you ignore it, I really don't think you can claim "the compiler broke my code".
int Foo() { }
>
Will (in theory) cause the program to crash when called (emitting a 'UD2' instruction), except in WSL it seems this doesn't quite work correctly (the UD2 doesn't result in an immediate crash), and the program seemingly instead "goes off the rails and crashes at a later point" (GCC omits the epilog when it does this, and seemingly control flow then goes into whatever function follows in the binary, crashing when that function tries to return seemingly by branching to an invalid address or similar).
>
This was mostly effecting "init" functions in my Verilator test benches...
>
>
Well, that, and a more inconsistent variant, where if one declares struct fields as 8 and 3 bytes and then strncpy's 11 bytes into the combined field, it may also insert a UD2 and skip emitting the following code.
>
...
>
>
But, yeah, that was annoying...
>
Les messages affichés proviennent d'usenet.