Skip to content

Add __builtin_trap to x86 #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions x86/Asm.v
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ Inductive instruction: Type :=
| Plabel(l: label)
| Pallocframe(sz: Z)(ofs_ra ofs_link: ptrofs)
| Pfreeframe(sz: Z)(ofs_ra ofs_link: ptrofs)
| Ptrap
| Pbuiltin(ef: external_function)(args: list (builtin_arg preg))(res: builtin_res preg)
(** Instructions not generated by [Asmgen] -- TO CHECK *)
| Padcl_ri (rd: ireg) (n: int)
Expand Down Expand Up @@ -967,6 +968,8 @@ Definition exec_instr (f: function) (i: instruction) (rs: regset) (m: mem) : out
end
end
end
| Ptrap =>
Stuck
| Pbuiltin ef args res =>
Stuck (**r treated specially below *)
(** The following instructions and directives are not generated
Expand Down
3 changes: 3 additions & 0 deletions x86/Asmexpand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,9 @@ let expand_builtin_inline name args res =
(* no operation *)
| "__builtin_nop", [], _ ->
emit Pnop
(* Unconditional trap *)
| "__builtin_trap", [], _ ->
emit Ptrap
(* Catch-all *)
| _ ->
raise (Error ("unrecognized builtin " ^ name))
Expand Down
3 changes: 3 additions & 0 deletions x86/CBuiltins.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ let builtins = {
(TVoid [], [TPtr(TInt(IUShort, []), []); TInt(IUShort, [])], false);
"__builtin_write32_reversed",
(TVoid [], [TPtr(TInt(IUInt, []), []); TInt(IUInt, [])], false);
(* Unconditional trap *)
"__builtin_trap",
(TVoid [], [], false);
]
}

Expand Down
2 changes: 2 additions & 0 deletions x86/TargetPrinter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,8 @@ module Target(System: SYSTEM):TARGET =
| Pallocframe(sz, ofs_ra, ofs_link)
| Pfreeframe(sz, ofs_ra, ofs_link) ->
assert false
| Ptrap ->
fprintf oc "ud2\n"
| Pbuiltin(ef, args, res) ->
begin match ef with
| EF_annot(kind,txt, targs) ->
Expand Down