Re: AW: AW: Feature request for "friendship" of pointers in "C"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Question: is there an "exec a.out" button in the example?

On 03.02.20 10:40, Xi Ruoyao wrote:
On 2020-02-03 01:34 -0800, J Decker wrote:
On Mon, Feb 3, 2020 at 1:29 AM aotto <aotto1968@xxxxxxxxxxx> wrote:

Hi,

this is a test: https://godbolt.org/z/8PpX8W

why is method_base(&aO->obj, 1); so much worse than method_base(aO, 1);
  it's the same resulting code...


  method_base(aO, 1);
mov rax, QWORD PTR [rbp-8]
mov esi, 1
mov rdi, rax
call method_base

method_base(&aO->obj, 1);
mov rax, QWORD PTR [rbp-8]
mov esi, 1
mov rdi, rax
call method_base

and there's no forced cast....
If a0 is NULL, the standard specifies "(base *) a0" will also be NULL (6.3.2.3
p4).  But, &a0->obj is undefined behavior.

Considering:

method_base(&a0->obj);

if (a0 != NULL)
   return -EINVAL;

return a0->foo + 233;

Then an optimizing C compiler could do some analysis:

(1) If a0 is NULL, &a0->obj invokes undefined behavior.  There is no requirement
from the standard so we don't need to consider this situation.

(2) If a0 is not NULL, the if statement is useless and can be optimized away.

So the code may be optimized to:

method_base(&a0->obj);
return a0->foo + 233;   /* crash when a0 is NULL */





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux