Comments (7)
The only constraints that the C standard places on a compilers output are:
- That all I/O occurs in the proper order, and
- That all volatile accesses occur in the proper order.
Writing to an arbitrary memory location is neither, so the compiler freely removes it. Accordingly, such accesses must be marked volatile to be preserved for their own sake; otherwise the compiler will remove them if they can be proven never to affect IO or volatile accesses.
from llvm-mos-sdk.
Oh, and since this is C++, infinite loops are undefined behavior. So the compiler can assume that main is unreachable, that is, that the program can never be run ;)
from llvm-mos-sdk.
Well, but at least the return 0
must be emitted, otherwise the program crash. If you try a program like that in any x86 compiler, it doesn't crash. That's for sure a compiler bug.
from llvm-mos-sdk.
The program could never reach a return 0, why should one be emitted. In fact, it's legal to assume the program can never reach the infinite loop.
from llvm-mos-sdk.
Well, but at least the
return 0
must be emitted, otherwise the program crash. If you try a program like that in any x86 compiler, it doesn't crash. That's for sure a compiler bug.
That's called "dead-code elimination" (DCE, for short) optimization. The compiler here does not need to emit "return 0" as that code is "dead", since it cannot be ever reached.
from llvm-mos-sdk.
This happens upstream as well, and it's a "known issue". I think it's unlikely that llvm will treat this output as a bug unless/until the language semantics change.
from llvm-mos-sdk.
This happens upstream as well, and it's a "known issue". I think it's unlikely that llvm will treat this output as a bug unless/until the language semantics change.
But if you change line
*((unsigned char *)0xd020) = 7;
to
*((volatile unsigned char *)0xd020) = 7;
the situation is different. I guess, the problem here, that the compiler does not know it's an I/O register, and since the pointed value is never used otherwise in the code, it looks like a no-op: storing a value which will be never used. Thus the volatile
can help in such a cases. Well, at least, as far as I can see ...
With that volatile
the asm output changes to:
main: # @main
.LBB0_1: # =>This Inner Loop Header: Depth=1
mov byte ptr [53280], 7
jmp .LBB0_1
Surely, the return 0;
still hasn't been emitted, but that's normal, since it's dead-code: because of the infinite loop before, that won't be ever reached, so no point to emit it.
from llvm-mos-sdk.
Related Issues (20)
- start address is indeterminate (because of zp data section)? HOT 1
- Write a simplified libretro runner
- Complete the libc using pieces from pdclibc HOT 1
- Investigate making `text.fixed` for libcalls
- Automatically generated linker scripts lack CMake integration HOT 1
- Verify negative tests fail for the "right" reasons
- Reading directly from memory HOT 2
- Create a test workflow that runs on PRs
- Benchmarks of programs compared to 80s compilers? HOT 3
- Implement libm min and max functions HOT 6
- Builder for Apple Silicon
- mos-sim crash HOT 2
- realloc returns memory overlapping with other memory block HOT 3
- Decide intermediate and long-term support for the 45GS02 CPU and relatives HOT 2
- Sanitize license compliance for dependent projects HOT 1
- Load addresses aren't relocated on CP/M-65 HOT 2
- Import @davidgiven's support for new targets HOT 1
- PCE mkcd relocations don't seem to work. HOT 4
- neo6502 (and maybe other platforms?) - crash in simple loop code HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from llvm-mos-sdk.