aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2024-07-11 21:36:34 -0400
committerAndrew Kelley <andrew@ziglang.org>2024-07-12 00:43:38 -0700
commit3ad81c40c01649551b4ad3d2c450d8b5f7934362 (patch)
tree56775cdd64157a6756c6544f36ed58b00e9f627a /src
parentca752c61c08eaa06458bdc6fa3cc724c09a62f77 (diff)
downloadzig-3ad81c40c01649551b4ad3d2c450d8b5f7934362.tar.gz
zig-3ad81c40c01649551b4ad3d2c450d8b5f7934362.zip
Zcu: allow atomic operations on packed structs
Same validation rules as the backing integer would have.
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig4
-rw-r--r--src/Zcu.zig54
2 files changed, 26 insertions, 32 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 1062ece2be..896d18d21f 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -23950,7 +23950,7 @@ fn checkAtomicPtrOperand(
error.BadType => return sema.fail(
block,
elem_ty_src,
- "expected bool, integer, float, enum, or pointer type; found '{}'",
+ "expected bool, integer, float, enum, packed struct, or pointer type; found '{}'",
.{elem_ty.fmt(pt)},
),
};
@@ -24279,7 +24279,7 @@ fn zirCmpxchg(
return sema.fail(
block,
elem_ty_src,
- "expected bool, integer, enum, or pointer type; found '{}'",
+ "expected bool, integer, enum, packed struct, or pointer type; found '{}'",
.{elem_ty.fmt(pt)},
);
}
diff --git a/src/Zcu.zig b/src/Zcu.zig
index a9d80b4fdf..5179225fc1 100644
--- a/src/Zcu.zig
+++ b/src/Zcu.zig
@@ -3305,37 +3305,31 @@ pub fn atomicPtrAlignment(
.spirv => @panic("TODO what should this value be?"),
};
- const int_ty = switch (ty.zigTypeTag(mod)) {
- .Int => ty,
- .Enum => ty.intTagType(mod),
- .Float => {
- const bit_count = ty.floatBits(target);
- if (bit_count > max_atomic_bits) {
- diags.* = .{
- .bits = bit_count,
- .max_bits = max_atomic_bits,
- };
- return error.FloatTooBig;
- }
- return .none;
- },
- .Bool => return .none,
- else => {
- if (ty.isPtrAtRuntime(mod)) return .none;
- return error.BadType;
- },
- };
-
- const bit_count = int_ty.intInfo(mod).bits;
- if (bit_count > max_atomic_bits) {
- diags.* = .{
- .bits = bit_count,
- .max_bits = max_atomic_bits,
- };
- return error.IntTooBig;
+ if (ty.toIntern() == .bool_type) return .none;
+ if (ty.isRuntimeFloat()) {
+ const bit_count = ty.floatBits(target);
+ if (bit_count > max_atomic_bits) {
+ diags.* = .{
+ .bits = bit_count,
+ .max_bits = max_atomic_bits,
+ };
+ return error.FloatTooBig;
+ }
+ return .none;
+ }
+ if (ty.isAbiInt(mod)) {
+ const bit_count = ty.intInfo(mod).bits;
+ if (bit_count > max_atomic_bits) {
+ diags.* = .{
+ .bits = bit_count,
+ .max_bits = max_atomic_bits,
+ };
+ return error.IntTooBig;
+ }
+ return .none;
}
-
- return .none;
+ if (ty.isPtrAtRuntime(mod)) return .none;
+ return error.BadType;
}
pub fn declFileScope(mod: *Module, decl_index: Decl.Index) *File {