Description
In the following example, 3C makes the type of b
in foo
_Ptr<int>
because it is used safely inside the function. The function is called from inside the macro BAR
with an argument that cannot be rewritten to a checked type (because the argument is declared in the same macro). 3C want to insert a cast from int*
to _Ptr<int>
to make the call correct, but it cannot do this inside the macro.
#define BAR \
void bar(int *a) {\
foo(a);\
}
void foo(int *b) {}
BAR
After the changes in PR #434 a warning is emitted indicating where the rewriting fails. and suggesting what cast should be inserted.
/home/cc/checkedc-examples/cast_fail.c:7:1: warning: Unable to surround expression with cast.
Intended cast: "_Assume_bounds_cast<_Ptr<int>>()"
FOO
^~~
/home/cc/checkedc-examples/cast_fail.c:3:9: note: expanded from macro 'FOO'
foo(a);\
^
Since programs should compile without manual fixes when compiling without --alltypes
, 3C should rewrite the code so that this cast does not need to be placed. For instance, 3C could notice that foo
is called from an non-rewritable source range, and based on this information constrain the functions parameter types equal to the type of any arguments.
The fix for this issue should be verified against Lua.