Deutsch   English   Français   Italiano  
<vav0hm$10iod$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bernd Linsel <bl1-thispartdoesnotbelonghere@gmx.com>
Newsgroups: comp.arch
Subject: Re: Computer architects leaving Intel...
Date: Sat, 31 Aug 2024 13:58:46 +0200
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <vav0hm$10iod$1@dont-email.me>
References: <2024Aug30.161204@mips.complang.tuwien.ac.at>
 <memo.20240830164247.19028y@jgd.cix.co.uk> <vasruo$id3b$1@dont-email.me>
 <2024Aug30.195831@mips.complang.tuwien.ac.at> <vat5ap$jthk$2@dont-email.me>
 <vaunhb$vckc$1@dont-email.me> <vautmu$vr5r$1@dont-email.me>
 <vauum2$10cpt$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 31 Aug 2024 13:58:46 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="45ab6619ef85b2365705a908f791e928";
	logging-data="1067789"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/bAycfKgWwhWNnTEDz11j8"
User-Agent: Betterbird (Linux)
Cancel-Lock: sha1:1xDHc6D2btBspywh4xjMHeFK1hU=
Content-Language: en-US
In-Reply-To: <vauum2$10cpt$1@dont-email.me>
Bytes: 2507

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