RISC OS Open
Safeguarding the past, present and future of RISC OS for everyone
ROOL
Home | News | Downloads | Bugs | Bounties | Forum | Documents | Photos | Contact us
Account

Previous|Next

  • Tickets
  • » Ticket #504

Ticket #504 (Fixed)Thu Feb 11 02:02:20 UTC 2021

cc 5.85: Compiler considers local variable not accessed by inline assembler BL

Reported by: Timothy Baldwin (184) Severity: Normal
Part: RISC OS: C/C++ toolchain Release:
Milestone: Status Fixed

Details by Timothy Baldwin (184):

Consider this program which erroneously prints “FAIL”:
<code><pre>#include <stdio.h>

void set_x(int *x) {
*x = 1;
}

int test(void) {
int x = 0;
__asm {
MOV r0, &x
BL set_x, {r0}, {}, {r0-r3, ip, lr, psr}
}
return x;
}

int main(void) {
int x = test();
puts(x ? “OK” : “FAIL”);
return !x;
}</pre></code>

The function test compiles to:
<code><pre>test
STMDB sp!,{v1,lr}
SUB sp,sp,#4
MOV a1,sp
BL set_x
MOV a1,#0
ADD sp,sp,#4
LDMIA sp!,{v1,pc}</pre></code>

Which although it allocates storage for the local variable and passes it’s address to set_x neither initialises the memory nor reads it. In the practical problem I was trying to call a non-APCS routine.

GCC would require “memory” specifying in the clobber list, but for ROOL C no requirement nor method is documented. Arrays or structs appear to work.

Changelog:

Modified by Sprow (202) Thu, March 11 2021 - 14:37:29 GMT

  • Summary changed from DDE30 C Compiler considers local variable not accessed by inline assembler BL to cc 5.85: Compiler considers local variable not accessed by inline assembler BL

If you wrap the test() function in a

#pragma no_optimise_cse
#pragma optimise_cse

it works. It should know because of address-of x there’s a chance whatever x is may be modified by the function call, but for some reason hasn’t understood that as it does if you make a function call in C.

Modified by Sprow (202) Mon, November 01 2021 - 08:38:31 GMT

  • Status changed from Open to Fixed

Fixed in cc 5.88

  • 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