authorgravatar for william@sengir.comWilliam Sengir <william@sengir.com> 2022-03-26 15:45:30-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-16 13:55:26-07:00
log6b5c87957b37df89d2ea53f1b39a7e4be0bf1326
treeb9b3760736e790a204745a42949b10bb1960570a
parentca1ab38d3a037239fc1399c2f9d5b2967acb6757

stage2: handle vectors in `Value.intFitsInType`


1 files changed, 11 insertions(+), 0 deletions(-)

src/value.zig+11
...@@ -1671,6 +1671,7 @@ pub const Value = extern union {...@@ -1671,6 +1671,7 @@ pub const Value = extern union {
1671 }1671 }
16721672
1673 /// Asserts the value is an integer, and the destination type is ComptimeInt or Int.1673 /// Asserts the value is an integer, and the destination type is ComptimeInt or Int.
1674 /// Vectors are also accepted. Vector results are reduced with AND.
1674 pub fn intFitsInType(self: Value, ty: Type, target: Target) bool {1675 pub fn intFitsInType(self: Value, ty: Type, target: Target) bool {
1675 switch (self.tag()) {1676 switch (self.tag()) {
1676 .zero,1677 .zero,
...@@ -1767,6 +1768,16 @@ pub const Value = extern union {...@@ -1767,6 +1768,16 @@ pub const Value = extern union {
1767 else => unreachable,1768 else => unreachable,
1768 },1769 },
17691770
1771 .aggregate => {
1772 assert(ty.zigTypeTag() == .Vector);
1773 for (self.castTag(.aggregate).?.data) |elem| {
1774 if (!elem.intFitsInType(ty.scalarType(), target)) {
1775 return false;
1776 }
1777 }
1778 return true;
1779 },
1780
1770 else => unreachable,1781 else => unreachable,
1771 }1782 }
1772 }1783 }