Dear TCC developers,
I pushed 205f264b9e01 to mob earlier. It adds -Wnull-to-nonoptional,
which warns when a null pointer constant is implicitly converted to a
pointer whose target type lacks the _Optional qualifier. The warning
is off by default because such conversions are commonplace; however,
in a program that uses _Optional, it is invaluable (equivalent to
-Wwrite-strings for conversions to a pointer whose target type lacks
the const qualifier).
Annex B of ISO/IEC DTS 26716 (WG14 N3951) lists this conversion as one
for which an implementation can usefully warn. For example, with the
warning enabled, "int *p = 0" is diagnosed and "_Optional int *p = 0"
is not.
The compiler changes are small: 1 line added in libtcc.c, 2 in tcc.h,
and 25 added and 2 removed in tccgen.c. Most of the work beyond the
check in verify_assign_cast() is there to get cases like this right:
_Optional int *f(int ready, int *p)
{
return ready ? p : 0;
}
Warning as soon as TCC sees the null pointer constant would be
premature because the return type is pointer-to-optional; if the
return type were "int *" then the same expression should trigger a
warning. TCC therefore remembers the null pointer conversion (nulls =
1) until it knows the destination type. Constant folding must preserve
the distinction between (void *)0, which is a null pointer constant
(nulls = 0), and (void *)(int *)0, which is not (nulls = -1).
If TCC has already cleared a local aggregate, it skips the store for
an explicit initialiser such as .p = 0, so the patch checks the
pointer conversion beforehand (by calling verify_assign_cast).
The tests add 95 lines and the documentation adds 8.
Thanks,
Christopher
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel