Did you know that inline assembly is safe?
Quirin Schroll
qs.il.paperinik at gmail.com
Sat May 6 16:23:22 UTC 2023
On Saturday, 6 May 2023 at 14:55:08 UTC, Dany12L wrote:
> Hi,
>
> I found that in D for some reason it is possible to declare the
> assembly inline as @safe, this honestly seems crazy to me...
> The compiler can't do any checks on the assembly code to ensure
> it's @safe and it's certainly up to the developer to check it
> but D is @trusted to do this.
>
> void main() @safe {
> asm @safe {
> mov [RIP], 0;
> }
> }
>
> This code simply compiles and of course then you get SIGSEGV
> when you run it..
>
> I believe inline assembly should only be allowed @system and
> @trusted, and under no circumstances should it allowed be @safe
`@safe` should be immediately disallowed for `asm`. I guess,
theoretically, assembly code can be `@safe` under very specific
circumstances, e.g. code that writes no memory. Useful? I don’t
think so.
More information about the Digitalmars-d
mailing list