* clang mis-compiles "x"[2]
@ 2023-08-28 16:43 David Laight
2023-08-28 20:46 ` Nick Desaulniers
0 siblings, 1 reply; 2+ messages in thread
From: David Laight @ 2023-08-28 16:43 UTC (permalink / raw)
To: 'llvm@lists.linux.dev'
Clang mis-compiles:
int foo(void) { return "a"[2]; }
to be just a 'ret' instruction.
While clearly non-sensical returning the input value of %rax
doesn't make any sense.
gcc generates a real string and then returns the byte after
the '\0' - which is (sort of) what the code asks for.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: clang mis-compiles "x"[2]
2023-08-28 16:43 clang mis-compiles "x"[2] David Laight
@ 2023-08-28 20:46 ` Nick Desaulniers
0 siblings, 0 replies; 2+ messages in thread
From: Nick Desaulniers @ 2023-08-28 20:46 UTC (permalink / raw)
To: David Laight; +Cc: llvm
On Mon, Aug 28, 2023 at 9:44 AM David Laight <David.Laight@aculab.com> wrote:
>
> Clang mis-compiles:
>
> int foo(void) { return "a"[2]; }
>
> to be just a 'ret' instruction.
>
> While clearly non-sensical returning the input value of %rax
> doesn't make any sense.
>
> gcc generates a real string and then returns the byte after
> the '\0' - which is (sort of) what the code asks for.
Reports of what code is generated when there is very clearly UB are
inappropriate for this list.
I encourage you to inspect the output of -fsanitize=undefined before
making such reports to compiler vendors.
https://godbolt.org/z/o4E6o33fP
Perhaps you're conflating the address of one past the end of an object
being defined, vs the value one past the end of an object which is
not.
>
> David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
>
>
--
Thanks,
~Nick Desaulniers
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-08-28 20:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-28 16:43 clang mis-compiles "x"[2] David Laight
2023-08-28 20:46 ` Nick Desaulniers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).