public inbox for llvm@lists.linux.dev
 help / color / mirror / Atom feed
* 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

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