-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sema: catch invalid asm input operands
Fixes #7843
- Loading branch information
r00ster91
committed
Jul 11, 2023
1 parent
6bc9c4f
commit c3d96b7
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
export fn a() void { | ||
asm volatile ("" | ||
: | ||
: [_] "{al}" (u8), | ||
); | ||
} | ||
export fn b() void { | ||
asm volatile ("" | ||
: | ||
: [_] "{a}" (0), | ||
[_] "{x}" (&&void), | ||
); | ||
} | ||
export fn c() void { | ||
asm volatile ("" | ||
: | ||
: [_] "{x}" (1), | ||
[_] "{x}" (struct {}{}), | ||
); | ||
} | ||
export fn d() void { | ||
asm volatile ("" | ||
: | ||
: [_] "{x}" (((packed struct { x: u8 }){ .x = 1 })), | ||
[_] "{x}" (extern struct { x: u8 }{ .x = 1 }), | ||
[_] "{x}" (struct { x: u8 }{ .x = 1 }), | ||
); | ||
} | ||
export fn e() void { | ||
asm volatile ("" | ||
: | ||
: [_] "{x}" (@Vector(3, u8){ 1, 2, 3 }), | ||
[_] "{x}" ([2]*const type{ &u8, &u8 }), | ||
); | ||
} | ||
export fn f() void { | ||
asm volatile ("" | ||
: | ||
: [_] "{x}" (undefined), | ||
); | ||
} | ||
export fn g() void { | ||
asm volatile ("" | ||
: | ||
: [_] "{x}" ({}), | ||
); | ||
} | ||
export fn h() void { | ||
asm volatile ("" | ||
: | ||
: [_] "{x}" (@as([]const u8, "hello")), | ||
); | ||
} | ||
|
||
// error | ||
// backend=stage2 | ||
// target=native | ||
// | ||
// :4:23: error: type 'type' is comptime-only and cannot be used for an asm input operand | ||
// :11:22: error: type '*const *const type' is comptime-only and cannot be used for an asm input operand | ||
// :18:31: error: type 'tmp.c__struct_1046' does not have runtime bits and cannot be used for an asm input operand | ||
// :26:38: error: type 'tmp.d__struct_1049' does not have well-defined memory layout and cannot be used for an asm input operand | ||
// :33:36: error: type '[2]*const type' is comptime-only and cannot be used for an asm input operand | ||
// :39:22: error: type '@TypeOf(undefined)' is comptime-only and cannot be used for an asm input operand | ||
// :45:22: error: type 'void' does not have runtime bits and cannot be used for an asm input operand | ||
// :51:22: error: type '[]const u8' does not have well-defined memory layout and cannot be used for an asm input operand |