#!/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" <"$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