summaryrefslogtreecommitdiff
path: root/tests/t0041-integer-width-suffix.sh
diff options
context:
space:
mode:
authorkx <kx@radix-linux.su>2026-10-01 12:02:28 +0300
committerkx <kx@radix-linux.su>2026-10-01 12:02:28 +0300
commitba1b04d64bdfaf377915b22f77520216ebe47674 (patch)
tree044343035c28b2b04ca9725f26e9b7c39342d19c /tests/t0041-integer-width-suffix.sh
parent124b140798456778e2a96851cc7268aa9a726698 (diff)
downloadmcpu-cpp-1.0.2.tar.xz
Version 1.0.21.0.2
Diffstat (limited to 'tests/t0041-integer-width-suffix.sh')
-rwxr-xr-xtests/t0041-integer-width-suffix.sh95
1 files changed, 95 insertions, 0 deletions
diff --git a/tests/t0041-integer-width-suffix.sh b/tests/t0041-integer-width-suffix.sh
new file mode 100755
index 0000000..a59483f
--- /dev/null
+++ b/tests/t0041-integer-width-suffix.sh
@@ -0,0 +1,95 @@
+#!/bin/sh
+set -eu
+base="${TMPDIR-/tmp}/mcpu-cpp-integer-width-suffix-$$"
+mkdir -p "$base"
+trap 'rm -rf "$base"' EXIT HUP INT TERM
+
+cat > "$base/main.c" <<'EOT'
+#if 0x7fz8 == 127
+z8_positive
+#endif
+#if 0x80z8 == -128
+z8_sign_extend
+#endif
+#if 0xffz8 == -1
+z8_minus_one
+#endif
+#if 0xffz8u == 255
+z8_zero_extend
+#endif
+#if 0x1ffz8 == -1 && 0x1ffz8U == 255
+z8_truncate
+#endif
+#if 0x8000z16 == -32768 && 0xffffz16U == 65535
+z16_ok
+#endif
+#if 0x80000000z32 < 0 && 0xffffffffz32u == 4294967295U
+z32_ok
+#endif
+#if 0xffffffffffffffffz64 == -1
+z64_signed
+#endif
+#if 0xffffffffffffffffZ064U > 0
+z64_unsigned_leading_zero_width
+#endif
+#if 0x7fz8 + 1 == 128
+operations_are_64_bit
+#endif
+#if (~0xffz8u) == 0xffffffffffffff00U
+compl_is_64_bit
+#endif
+#if (0x80z8 >> 1) == -64 && (0x80z8u >> 1) == 64
+shift_uses_promoted_value
+#endif
+#if 1z24 == 1
+invalid_width_ignored
+#endif
+#if 1z024U == 1U
+invalid_width_u_preserved
+#endif
+#if 1U == 1 && 1u == 1
+plain_u_ok
+#endif
+EOT
+
+"$MCPU_CPP" --no-config "$base/main.c" -o "$base/out" 2>"$base/err"
+
+for word in \
+ z8_positive z8_sign_extend z8_minus_one z8_zero_extend z8_truncate \
+ z16_ok z32_ok z64_signed z64_unsigned_leading_zero_width \
+ operations_are_64_bit compl_is_64_bit shift_uses_promoted_value \
+ invalid_width_ignored invalid_width_u_preserved plain_u_ok; do
+ test "`grep -c "^${word}$" "$base/out"`" -eq 1
+done
+
+test "`grep -c 'warning: invalid zNNN integer-width suffix; suffix ignored' "$base/err"`" -eq 2
+
+for bad in \
+ '1z128' \
+ '1z256u' \
+ '1z32undefined' \
+ '1z32ufoo' \
+ '1z32$foo' \
+ '1L' \
+ '1LL' \
+ '18446744073709551616'; do
+ cat > "$base/bad.c" <<EOT
+#if $bad
+bad
+#endif
+EOT
+ if "$MCPU_CPP" --no-config "$base/bad.c" -o "$base/bad-out" 2>"$base/bad-err"; then
+ echo "accepted invalid integer constant: $bad" >&2
+ exit 1
+ fi
+done
+
+cat > "$base/wide.c" <<'EOT'
+#if 1z128
+bad
+#endif
+EOT
+if "$MCPU_CPP" --no-config "$base/wide.c" -o "$base/bad-out" 2>"$base/wide.err"; then
+ exit 1
+fi
+grep 'error: integer constants wider than 64 bits are not allowed in conditional directives' "$base/wide.err" >/dev/null