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


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

Re: What does this code print ?

From Richard Damon <richard@damon-family.org>
Newsgroups comp.lang.c++
Subject Re: What does this code print ?
Date 2023-10-19 16:06 -0400
Organization i2pn2 (i2pn.org)
Message-ID <ugs28l$238c9$2@i2pn2.org> (permalink)
References (10 earlier) <ugnhvc$1t8hq$1@i2pn2.org> <ugrqok$fto1$1@dont-email.me> <20231019110532.810@kylheku.com> <ugrrh1$fto1$4@dont-email.me> <20231019120451.638@kylheku.com>

Show all headers | View raw


On 10/19/23 3:20 PM, Kaz Kylheku wrote:
> On 2023-10-19, Bonita Montero <Bonita.Montero@gmail.com> wrote:
>> Am 19.10.2023 um 20:06 schrieb Kaz Kylheku:
>>
>>> Can you point to any documentation (MSDN?) that would give us confidence
>>> that all which happened is a committed, robust feature that will work
>>> across different versions of MSVC, with different code generation
>>> options?
>>
>> Which option do you think would make MSVC drop the optimization barrier
>> of volatile function pointers? The only volatile compiler option is
>> ISO or MSVC volatile behaviour.
> 
> Possibly, options that turn off optimization entirely, so that the barrier is not
> considered.

Turning off optimizations says that definitely the volatile barrier will 
be obeyed. The question

> 
> It's the wrong question. What piece of documentation specifies that
> there is such an optimization barrier? Not just the optimization
> barrier, but an optimization barrier that causes calling convention
> attributes from a pointer to regenerate the called function body.
> 
> Where did you get this belief?

Well, since the pointer is volatile, the compiler can not assume it 
points to the function that the pointer was set to.

> 
> It is really weird. It similar to a situation like:
> 
>    struct foo { int x; int y } foo_obj = { 1, 2 };
>    struct bar { int y; int x };
> 
>    bar *volatile bar_ptr = (struct bar *) &foo_obj;
> 
>    printf("%d\n", bar_ptr->x); // unexpectedly prints 1
> 
> Wee, the compiler fixed up the ->x reference to the correct offset
> through the wrong type.
> 
> The code looks flatly wrong in the abstract semantics, because a
> function not defined with any calling convention attributes (and thus
> "__cdecl") is being called with incompatible calling conventions.
> 
> In the abstract semantics without optimization, of course we expect real
> function calls to be attempted.
> 
> A plausible explanation for the observed behavior is that the
> function got inlined first, and then due to the volatile, it was
> de-inlined, and this happened in such a way that the calling conventions
> from the pointer influenced the code generation.
> 
> Where is that aspect of it documented?
> 

WHat I see is that we have, as you say, a pointer to a _cdecl function 
being assigned to a different calling convention pointer, so the 
compiler builds a thunk or an "invoker" that accepts a call by the 
specified convention, and then "calls" the specified function. Since 
that function is inlinable, that call just become an inline instance of 
the function. At THIS point, we don't have the volatile barrier, so the 
inlining is possible.

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


Thread

What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-11 05:30 +0200
  Re: What does this code print ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-10-11 14:03 +0100
    Re: What does this code print ? gazelle@shell.xmission.com (Kenny McCormack) - 2023-10-11 13:12 +0000
      Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-11 19:22 +0200
        Re: What does this code print ? scott@slp53.sl.home (Scott Lurndal) - 2023-10-11 17:41 +0000
          Re: What does this code print ? Bo Persson <bo@bo-persson.se> - 2023-10-11 20:24 +0200
          Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-13 05:24 +0200
            Re: What does this code print ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-10-13 17:53 +0100
              Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-14 15:50 +0200
        Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-13 12:12 -0400
          Re: What does this code print ? scott@slp53.sl.home (Scott Lurndal) - 2023-10-13 17:27 +0000
          Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-14 15:52 +0200
            Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-14 11:26 -0400
              Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-15 09:08 +0200
                Re: What does this code print ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-15 12:55 -0700
                Re: What does this code print ? Richard Damon <news.x.richarddamon@xoxy.net> - 2023-10-15 22:19 -0400
                Re: What does this code print ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-18 20:58 -0700
    Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-11 19:21 +0200
    Re: What does this code print ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-11 12:41 -0700
      Re: What does this code print ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-11 12:43 -0700
      Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-13 05:25 +0200
    Re: What does this code print ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-12 20:50 -0700
      Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-13 08:50 +0200
        Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-13 12:15 -0400
          Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-14 15:53 +0200
            Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-14 11:26 -0400
              Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-15 09:00 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-15 13:15 -0400
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-17 07:47 +0200
                Re: What does this code print ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-17 11:34 -0700
        Re: What does this code print ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-10-13 16:34 +0000
          Re: What does this code print ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-13 13:12 -0700
            Re: What does this code print ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-10-14 02:36 +0000
              Re: What does this code print ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-13 20:44 -0700
              Re: What does this code print ? Paavo Helde <eesnimi@osa.pri.ee> - 2023-10-14 11:51 +0300
                Re: What does this code print ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-17 11:35 -0700
                Re: What does this code print ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-10-17 20:06 +0000
                Re: What does this code print ? Paavo Helde <eesnimi@osa.pri.ee> - 2023-10-18 11:43 +0300
                Re: What does this code print ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-10-18 17:29 +0000
                Re: What does this code print ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-18 11:31 -0700
                Re: What does this code print ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-19 14:43 -0700
          Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-14 15:54 +0200
            Re: What does this code print ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-10-14 18:05 +0000
              Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-14 14:58 -0400
              Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-15 08:58 +0200
        Re: What does this code print ? Richard Damon <news.x.richarddamon@xoxy.net> - 2023-10-14 12:47 -0400
          Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-15 09:07 +0200
            Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-15 09:12 +0200
              Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-15 09:16 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-15 13:35 -0400
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-17 07:48 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-17 23:04 -0400
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-19 19:58 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-19 14:39 -0400
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-19 19:58 +0200
                Re: What does this code print ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-10-19 18:06 +0000
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-19 20:11 +0200
                Re: What does this code print ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-10-19 19:20 +0000
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-19 16:06 -0400
                Re: What does this code print ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-19 14:45 -0700
                Re: What does this code print ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-10-19 23:26 +0000
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-20 09:19 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-20 05:47 -0400
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-20 17:59 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-20 19:16 -0700
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-21 08:02 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-21 08:38 -0700
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-21 19:40 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-21 10:54 -0700
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-21 20:34 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-21 12:45 -0700
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-22 04:18 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-21 19:28 -0700
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-22 06:53 +0200
                Re: What does this code print ? Branimir Maksimovic <branimir.maksimovic@icloud.com> - 2023-10-22 09:59 +0000
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-22 07:12 -0700
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-23 19:05 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-23 10:40 -0700
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-24 16:03 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-24 07:28 -0700
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-24 17:01 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-24 08:28 -0700
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-24 18:27 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-24 10:05 -0700
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-24 19:08 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-24 10:39 -0700
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-24 20:25 +0200
                Re: What does this code print ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-10-24 19:48 +0000
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-25 10:54 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-25 08:43 -0700
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-25 17:57 +0200
                Re: What does this code print ? Branimir Maksimovic <branimir.maksimovic@icloud.com> - 2023-10-24 16:40 +0000
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-24 19:07 +0200
                Re: What does this code print ? scott@slp53.sl.home (Scott Lurndal) - 2023-10-24 15:25 +0000
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-24 08:34 -0700
                Re: What does this code print ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-10-24 16:34 +0000
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-24 19:05 +0200
                Re: What does this code print ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-10-20 14:50 +0000
                Re: What does this code print ? Bo Persson <bo@bo-persson.se> - 2023-10-20 17:34 +0200
                Re: What does this code print ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-10-20 15:59 +0000
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-20 18:00 +0200
                Re: What does this code print ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-10-20 16:06 +0000
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-20 18:40 +0200
                Re: What does this code print ? gazelle@shell.xmission.com (Kenny McCormack) - 2023-10-20 20:07 +0000
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-21 08:04 +0200
              Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-15 13:35 -0400
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-17 07:50 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-17 23:08 -0400
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-19 20:02 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-19 14:43 -0400
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-19 20:02 +0200
            Re: What does this code print ? scott@slp53.sl.home (Scott Lurndal) - 2023-10-15 14:36 +0000
              Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-15 18:15 +0200
                Re: What does this code print ? Richard Damon <news.x.richarddamon@xoxy.net> - 2023-10-15 22:23 -0400
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-17 07:51 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-17 23:08 -0400
            Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-15 13:25 -0400
        Re: What does this code print ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-14 11:33 -0700
          Re: What does this code print ? Paavo Helde <eesnimi@osa.pri.ee> - 2023-10-14 21:54 +0300
            Re: What does this code print ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-14 11:56 -0700
            Re: What does this code print ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-24 15:53 -0700
              Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-25 15:07 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-25 08:43 -0700
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-25 18:01 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-25 09:21 -0700
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-25 18:24 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-25 11:23 -0700
                Re: What does this code print ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-25 15:02 -0700
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-26 07:13 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-25 23:09 -0700
                Re: What does this code print ? James Kuyper <jameskuyper@alumni.caltech.edu> - 2023-10-25 23:55 -0400
                Re: What does this code print ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-25 15:01 -0700
                Re: What does this code print ? Bonita Montero <Bonita.Montero@gmail.com> - 2023-10-26 07:15 +0200
                Re: What does this code print ? Richard Damon <richard@damon-family.org> - 2023-10-25 23:12 -0700

csiph-web