aboutsummaryrefslogtreecommitdiff
path: root/src/check_builtin.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-05-24 22:39:27 +0100
committergingerBill <bill@gingerbill.org>2021-05-24 22:39:27 +0100
commit0c46d06e6308281be257b0529874b7c8cc110ea3 (patch)
treec41b5619fa9fd5500e9ec0d58b5348bba438e617 /src/check_builtin.cpp
parent44b6e7c45db3bb3cc6ff30bca08d0b761b975c30 (diff)
Add `intrinsics.mem_zero`
Diffstat (limited to 'src/check_builtin.cpp')
-rw-r--r--src/check_builtin.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp
index 1acb9732f..1630b5b7d 100644
--- a/src/check_builtin.cpp
+++ b/src/check_builtin.cpp
@@ -2106,6 +2106,47 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
}
break;
+ case BuiltinProc_mem_zero:
+ {
+ operand->mode = Addressing_NoValue;
+ operand->type = t_invalid;
+
+ Operand ptr = {};
+ Operand len = {};
+ check_expr(c, &ptr, ce->args[0]);
+ check_expr(c, &len, ce->args[1]);
+ if (ptr.mode == Addressing_Invalid) {
+ return false;
+ }
+ if (len.mode == Addressing_Invalid) {
+ return false;
+ }
+
+
+ if (!is_type_pointer(ptr.type)) {
+ gbString str = type_to_string(ptr.type);
+ error(ptr.expr, "Expected a pointer value for '%.*s', got %s", LIT(builtin_procs[id].name), str);
+ gb_string_free(str);
+ return false;
+ }
+ if (!is_type_integer(len.type)) {
+ gbString str = type_to_string(len.type);
+ error(len.expr, "Expected an integer value for the number of bytes for '%.*s', got %s", LIT(builtin_procs[id].name), str);
+ gb_string_free(str);
+ return false;
+ }
+
+ if (len.mode == Addressing_Constant) {
+ i64 n = exact_value_to_i64(len.value);
+ if (n < 0) {
+ gbString str = expr_to_string(len.expr);
+ error(len.expr, "Expected a non-negative integer value for the number of bytes for '%.*s', got %s", LIT(builtin_procs[id].name), str);
+ gb_string_free(str);
+ }
+ }
+ }
+ break;
+
case BuiltinProc_atomic_fence:
case BuiltinProc_atomic_fence_acq: