public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/99779] New: [GCC-10.1.0]A bug when assign to a pointer by function which process the pointer inside.
@ 2021-03-26  1:32 xin.liu@compiler-dev.com
  2021-03-26  2:19 ` [Bug c/99779] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: xin.liu@compiler-dev.com @ 2021-03-26  1:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99779

            Bug ID: 99779
           Summary: [GCC-10.1.0]A bug when assign to a pointer by function
                    which process the pointer inside.
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xin.liu@compiler-dev.com
  Target Milestone: ---

As shown in the following testcase:

int helloa = 12;
int hellob = 13;
int *fp=&helloa;
int __attribute__((noinline)) foo()
{
  fp=&hellob;
  return 15;
}
int main()
{
  *fp = foo();
  printf("helloa=%d,hellob=%d\n",helloa,hellob);
}

compile with gcc-10.1.0 and any optimization, the result is

    helloa=15,hellob=13

but with clang-10.0.1, the result is

    helloa=12,hellob=15

According to this testcase, in my opinion ,the clang's result is right.
gcc do not process it correctly.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c/99779] [GCC-10.1.0]A bug when assign to a pointer by function which process the pointer inside.
  2021-03-26  1:32 [Bug c/99779] New: [GCC-10.1.0]A bug when assign to a pointer by function which process the pointer inside xin.liu@compiler-dev.com
@ 2021-03-26  2:19 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-03-26  2:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99779

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
In C, it is unspecified which side of the equal gets evaluated first.
So in this case (*fp = foo();):
this could be done as
int *fpp = fp;
*fpp = foo();
OR:
int t = foo();
*fp = t;

BOTH are valid for C.
C++11 and above have different rules with respect to sequence points.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-26  2:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-26  1:32 [Bug c/99779] New: [GCC-10.1.0]A bug when assign to a pointer by function which process the pointer inside xin.liu@compiler-dev.com
2021-03-26  2:19 ` [Bug c/99779] " pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).