Hi TinyCC maintainers,
I'm a student working on a compiler project. Recently I used the
TinyCC testcases in `tests/tests2` for validation. Those testcases are
excellently designed and helped me uncover a series of bugs in my
compiler implementation.
However, while testing with `55_lshift_type`, I noticed that the
debug output lacks sufficient clarity when the compiler has incorrect
type promotion behavior. This makes it harder to pinpoint the root
cause, despite the testcase's effectiveness in validating type promotion
rules.
To address this, I propose improving the debug hints by including
shift type information. Here is the proposed patch:
```
--- 55_lshift_type.c 2025-04-09 16:04:53.346290150 +0800
+++ 55_lshift_type_new.c 2025-04-09 16:04:24.756266205 +0800
@@ -10,7 +10,7 @@
#include <stdio.h>
#define PTYPE(M) ((M) < 0 || -(M) < 0 ? -1 : 1) * (int) sizeof((M)+0)
-#define CHECK(X,T) check(#X, PTYPE(X), PTYPE((X) << (T) 1))
+#define CHECK(X,T) check(#X " << " #T, PTYPE(X), PTYPE((X) << (T) 1))
#define TEST1(X,T) do { CHECK(X,T); CHECK(X,unsigned T); } while (0)
#define TEST2(X) \
do \
@@ -38,7 +38,7 @@
{
int failed = arg1 != shift;
if (debug || failed)
- printf ("%s %d %d\n", s, arg1, shift);
+ printf ("%s, %d %d\n", s, arg1, shift);
nfailed += failed;
}
```
The previous debug information output looks like:
```
((short)((1))) -4 -4
((short)((1))) -4 -4
((short)((1))) -4 -4
((short)((1))) -4 -4
```
After path, it looks like:
```
((short)((1))) << short, -4 -4
((short)((1))) << unsigned short, -4 -4
((short)((1))) << int, -4 -4
((short)((1))) << unsigned int, -4 -4
((short)((1))) << long, -4 -4
((short)((1))) << unsigned long, -4 -4
((short)((1))) << long long, -4 -4
```
This modification helped me quickly locate the type promotion
problem precisely, so I believe this improvement could benefit other
developers working on type system validation.
Thank you for considering this change.
Sincerely,
Jinghao Dang
_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel