aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-11-18 23:52:42 -0500
committerAndrew Kelley <superjoe30@gmail.com>2016-11-18 23:52:42 -0500
commit19037014e5a25eaac9564d22cc04cf12fb6ef98e (patch)
treeec7ec61515ddf48ab94585d054bb69c329febce3 /std
parent31565efe9d6cde2e4909f986d50f8c46166d3311 (diff)
downloadzig-19037014e5a25eaac9564d22cc04cf12fb6ef98e.tar.gz
zig-19037014e5a25eaac9564d22cc04cf12fb6ef98e.zip
IR: more maybe type support
Diffstat (limited to 'std')
-rw-r--r--std/builtin.zig19
1 files changed, 13 insertions, 6 deletions
diff --git a/std/builtin.zig b/std/builtin.zig
index 76978a34b4..5371c2c99e 100644
--- a/std/builtin.zig
+++ b/std/builtin.zig
@@ -1,24 +1,31 @@
// These functions are provided when not linking against libc because LLVM
// sometimes generates code that calls them.
-// TODO dest should be nullable and return value should be nullable
-export fn memset(dest: &u8, c: u8, n: usize) -> &u8 {
+export fn memset(dest: ?&u8, c: u8, n: usize) -> ?&u8 {
@setDebugSafety(this, false);
+ if (n == 0)
+ return dest;
+
+ const d = ??dest;
var index: usize = 0;
while (index != n; index += 1)
- dest[index] = c;
+ d[index] = c;
return dest;
}
-// TODO dest, source, and return value should be nullable
-export fn memcpy(noalias dest: &u8, noalias src: &const u8, n: usize) -> &u8 {
+export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) -> ?&u8 {
@setDebugSafety(this, false);
+ if (n == 0)
+ return dest;
+
+ const d = ??dest;
+ const s = ??src;
var index: usize = 0;
while (index != n; index += 1)
- dest[index] = src[index];
+ d[index] = s[index];
return dest;
}