RISC OS Open
A fast and easily customised operating system for ARM devices
ROOL
Home | News | Downloads | Bugs | Bounties | Forum | Documents | Photos | Contact us
Account

Previous|Next

  • Tickets
  • » Ticket #496

Ticket #496 (Open)Tue Nov 03 10:22:28 UTC 2020

cc 5.83: Assignment of struct return value incorrectly optimised away

Reported by: Julie Stamp (8365) Severity: Normal
Part: RISC OS: C/C++ toolchain Release:
Milestone: Status Open

Details by Julie Stamp (8365):

If I run the below code I get

*cc c.test 
Norcroft RISC OS ARM C vsn 5.83 [01 Jun 2020]
*test
00008ce0 7
00008ce0 14

whereas I would expect to get different addresses, which I do with debug:

*cc c.test  -g
Norcroft RISC OS ARM C vsn 5.83 [01 Jun 2020]
*test
00008d00 7
00008d0c 14

#include <stdio.h>
#include <stdbool.h>

typedef struct
{
  int x; /* If you remove this, the problem goes away */
  char y[1];
  int z; /* Just to show it's not y being at the end causing it */
} t_t;

typedef struct
{
  int a; /* This must come first */
  t_t *t;
} s_t;

static t_t t1 = {0,{7},0};
static t_t t2 = {0,{14},0};

s_t f(void)
{
  s_t s = { 0, &t2 };
  return s;
}

int main(int argc, char **argv)
{
  s_t s = { 0, &t1 };
  printf("%p %d\n", s.t->y, s.t->y[0]);
  s = f();
  printf("%p %d\n", s.t->y, s.t->y[0]);
  return 0;
}







Changelog:

Modified by Julie Stamp (8365) Thu, December 03 2020 - 15:55:37 GMT

  • Summary changed from Misoptimisation to cc 5.83: Assignment of struct return value incorrectly optimised away

Modified by Julie Stamp (8365) Thu, December 03 2020 - 16:16:48 GMT

  • Attachment added: example

Attached is another example of this sort of thing, this time using div_t.

Modified by Julie Stamp (8365) Thu, December 03 2020 - 16:18:31 GMT

For output I get

a = 43795, b = 1

rather than the expected

a = 2, b = 1

  • Comment on, or change status of, this ticket

Previous|Next

Search tickets

Social

Follow us on and

ROOL Store

Buy RISC OS Open merchandise here, including SD cards for Raspberry Pi and more.

Donate! Why?

Help ROOL make things happen – please consider donating!

RISC OS IPR

RISC OS is an Open Source operating system owned by RISC OS Developments Ltd and licensed primarily under the Apache 2.0 license.

Options

  • Tickets
  • New ticket
  • Milestones
  • Subversion: Changesets
  • Subversion: Browse
  • CVS: Revisions
  • CVS: Browse
  • Search

RSS feeds Rss

  • Tickets
  • Everything!
  • More feeds...
Site design © RISC OS Open Limited 2018 except where indicated
The RISC OS Open Collaboa theme is distantly based on the Collaboa default layout

Valid XHTML 1.0  |  Valid CSS

Powered by Collaboa
This site runs on Rails

Hosted by Arachsys