blob: a59483f3229f33b51bcc4ee70d3c50b81a1d597d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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
|