aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-09-23 12:43:01 +0300
committerVeikka Tuominen <git@vexu.eu>2022-09-23 17:39:06 +0300
commit3de5c3b5038d03759d8f5521627fdbbcad28c795 (patch)
treebc15e22562a59f73c478454290fe4307d1a163be /src
parent8d1fdfc8ede94b1aea524041c1df10c42d4002e4 (diff)
downloadzig-3de5c3b5038d03759d8f5521627fdbbcad28c795.tar.gz
zig-3de5c3b5038d03759d8f5521627fdbbcad28c795.zip
Sema: check for slices in packed and extern type validation
Closes #12930
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index be53c99f24..d0ddbdbfec 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -20841,9 +20841,9 @@ fn validateExternType(
.Opaque,
.Bool,
.Float,
- .Pointer,
.AnyFrame,
=> return true,
+ .Pointer => return !ty.isSlice(),
.Int => switch (ty.intInfo(sema.mod.getTarget()).bits) {
8, 16, 32, 64, 128 => return true,
else => return false,
@@ -20886,7 +20886,6 @@ fn explainWhyTypeIsNotExtern(
.Opaque,
.Bool,
.Float,
- .Pointer,
.AnyFrame,
=> return,
@@ -20902,6 +20901,7 @@ fn explainWhyTypeIsNotExtern(
.Frame,
=> return,
+ .Pointer => try mod.errNoteNonLazy(src_loc, msg, "slices have no guaranteed in-memory representation", .{}),
.Void => try mod.errNoteNonLazy(src_loc, msg, "'void' is a zero bit type; for C 'void' use 'anyopaque'", .{}),
.NoReturn => try mod.errNoteNonLazy(src_loc, msg, "'noreturn' is only allowed as a return type", .{}),
.Int => if (ty.intInfo(sema.mod.getTarget()).bits > 128) {
@@ -20960,11 +20960,11 @@ fn validatePackedType(ty: Type) bool {
.Void,
.Bool,
.Float,
- .Pointer,
.Int,
.Vector,
.Enum,
=> return true,
+ .Pointer => return !ty.isSlice(),
.Struct, .Union => return ty.containerLayout() == .Packed,
}
}
@@ -20980,7 +20980,6 @@ fn explainWhyTypeIsNotPacked(
.Void,
.Bool,
.Float,
- .Pointer,
.Int,
.Vector,
.Enum,
@@ -21001,6 +21000,7 @@ fn explainWhyTypeIsNotPacked(
.Optional,
.Array,
=> try mod.errNoteNonLazy(src_loc, msg, "type has no guaranteed in-memory representation", .{}),
+ .Pointer => try mod.errNoteNonLazy(src_loc, msg, "slices have no guaranteed in-memory representation", .{}),
.Fn => {
try mod.errNoteNonLazy(src_loc, msg, "type has no guaranteed in-memory representation", .{});
try mod.errNoteNonLazy(src_loc, msg, "use '*const ' to make a function pointer type", .{});