Sujet : Re: Computer architects leaving Intel...
De : bl1-thispartdoesnotbelonghere (at) *nospam* gmx.com (Bernd Linsel)
Groupes : comp.archDate : 31. Aug 2024, 12:58:46
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vav0hm$10iod$1@dont-email.me>
References : 1 2 3 4 5 6 7 8
User-Agent : Betterbird (Linux)
On 31.08.24 13:26, Thomas Koenig wrote:
So, sorry for the too-quick examples earlier...
What about
int foo (int a)
{
return a + 1;
}
or
int foo(int *a)
{
return *a;
}
Both can exhibit undefined behavior, and for both it
is impossible for the compiler to tell at compile-time.
So the compiler should just compile both functions (gcc 12.2.0 with -O3 does):
$ gcc -Wall -Wextra -Wpedantic -O3 -xc -std=gnu11 -c - -o foo.o
int foo(int a)
{
return a + 1;
}
int bar(int *a)
{
return *a;
}
^D
$ objdump -d foo.o
foo.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <foo>:
0: 8d 47 01 lea 0x1(%rdi),%eax
3: c3 ret
4: 66 66 2e 0f 1f 84 00 data16 cs nopw 0x0(%rax,%rax,1)
b: 00 00 00 00
f: 90 nop
0000000000000010 <bar>:
10: 8b 07 mov (%rdi),%eax
12: c3 ret
All as expected.
What I don't want is that the compiler makes assumptions, concludes UB, feels entitled to compile whatever it wants and deliver rubbish without telling about it.
-- Bernd Linsel