Description
Some issues with the following code:
checkedc-clang/clang/lib/3C/DeclRewriter.cpp
Lines 833 to 842 in fd4d8af
(Update 2021-09-08: The getCheckedCAnnotationsEnd
function being factored out in #702 might help.)
Duplication of bounds / itypes: 3C rewrites the following:
void foo_i(int *a, int *b : itype(_Array_ptr<int>)) { b = (int *)1; }
void foo_b(int *a, int *b : count(1)) { b = (int *)1; }
void foo_ib(int *a, int *b : itype(_Array_ptr<int>) count(1)) { b = (int *)1; }
void foo_bi(int *a, int *b : count(1) itype(_Array_ptr<int>)) { b = (int *)1; }
to:
void foo_i(_Ptr<int> a, int *b : itype(_Ptr<int>)) { b = (int *)1; }
void foo_b(_Ptr<int> a, int *b : count(1) : count(1)) { b = (int *)1; }
void foo_ib(_Ptr<int> a, int *b : itype(_Array_ptr<int>) count(1) : itype(_Array_ptr<int>) count(1)) { b = (int *)1; }
void foo_bi(_Ptr<int> a, int *b : count(1) : itype(_Array_ptr<int>) count(1)) { b = (int *)1; }
Unnecessary macro expansion: Currently, 3C fails an assertion if an existing itype is inside a macro. #693 will change 3C to regenerate the itype from the AST. But as seen in a test case there, this may unnecessarily expand a macro:
#define macro1 : itype(_Ptr<int>)
void fn(int *b macro1, int *c) {
//CHECK: void fn(int *b : itype(_Ptr<int>), _Ptr<int> c) {
b = 1;
}
The expansion could be avoided at least in this case by reading a source range for the parameter that is extended to include the itype instead of adding the itype separately, as the code tries to do for the bounds; here's a proof of concept. But this might cause other problems.