pawn-lang / compiler

Pawn compiler for SA-MP with bug fixes and new features - runs on Windows, Linux, macOS
Other
303 stars 70 forks source link

`#pragma naked` is allowed to be used on functions `main()` and `entry()` #656

Closed Daniel-Cortez closed 3 years ago

Daniel-Cortez commented 3 years ago

Issue description:

The compiler allows to use #pragma naked on functions main() and entry() - this is clearly an oversight, as those functions are required to have stack cleanup code due to the way they're used.

Minimal complete verifiable example (MCVE):

// Function main() is called from the VM. It's not meant to be naked, so defining it as one
// would cause an "invalid instruction" runtime error as soon as the script is loaded.
#pragma naked
main(){}

// Similarly to the above example, defining function entry() as naked will cause
// a runtime error when the state of "auto1" is changed to "ST1".
#pragma naked 
entry() <auto1:ST1>{}

Workspace Information:

Y-Less commented 3 years ago

That's not a mistake. naked just means you'll do the stack cleanup yourself manually (i.e. in assembly).

Daniel-Cortez commented 3 years ago

Ah, I see. I'll close this issue then.