Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #68529

Re: Strange code-generation

From Paavo Helde <myfirstname@osa.pri.ee>
Newsgroups comp.lang.c++
Subject Re: Strange code-generation
Date 2019-09-19 22:00 +0300
Organization A noiseless patient Spider
Message-ID <qm0j97$go6$1@dont-email.me> (permalink)
References <qlo0kb$uhe$1@news.albasani.net> <qm0cgp$qrg$1@news.albasani.net> <qm0e7p$g9k$1@dont-email.me> <qm0g0l$jcq$1@news.albasani.net>

Show all headers | View raw


On 19.09.2019 21:05, Bonita Montero wrote:
>
> gcc handles null-Pointers according to the standard:
>
> D *f( B *b )
> {
>      return static_cast<D *>(b);
> }
>
> This results in this:
>
>      testq    %rdi, %rdi
>      je       .L3
>      leaq    -12(%rdi), %rax
>      ret
> .L3:
>      xorl    %eax, %eax
>      ret
>
> So on one side gcc is so clever as to assume that references
> are never null, but on the other side you have no way to say
> gcc that a pointer to be downcastet won't be null.

Except that you have:

D *f( B *b ) {
   if (b) {
     return static_cast<D *>(b);
   } else {
     __builtin_unreachable();
   }
}

 > g++ -O2 -c test1.cpp -S

_Z1fP1B:
.LFB0:
         .cfi_startproc
         leaq    -12(%rdi), %rax
         ret
         .cfi_endproc

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Strange code-generation Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-16 14:53 +0200
  Re: Strange code-generation Paavo Helde <myfirstname@osa.pri.ee> - 2019-09-16 16:59 +0300
    Re: Strange code-generation Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-16 21:08 +0200
    Re: Strange code-generation Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-09-18 08:47 -0700
      Re: Strange code-generation Paavo Helde <myfirstname@osa.pri.ee> - 2019-09-18 21:06 +0300
        Re: Strange code-generation Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-11-09 05:52 -0800
        Re: Strange code-generation "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-11-09 19:15 +0100
  Re: Strange code-generation Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-19 19:05 +0200
    Re: Strange code-generation David Brown <david.brown@hesbynett.no> - 2019-09-19 19:34 +0200
      Re: Strange code-generation Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-19 20:05 +0200
        Re: Strange code-generation Paavo Helde <myfirstname@osa.pri.ee> - 2019-09-19 22:00 +0300
        Re: Strange code-generation David Brown <david.brown@hesbynett.no> - 2019-09-20 08:21 +0200

csiph-web