Skip to content

Issues with DeclRewriter::buildDeclVar handling of existing bounds / itypes #694

Open
@mattmccutchen-cci

Description

@mattmccutchen-cci

Some issues with the following code:

SourceRange Range = PVD->getSourceRange();
if (PVD->hasBoundsExpr())
Range.setEnd(PVD->getBoundsExpr()->getEndLoc());
if (Range.isValid() && !inParamMultiDecl(PVD)) {
Type = getSourceText(Range, *Context);
if (!Type.empty()) {
IType = getExistingIType(CV->getExternal()) + BoundsStr;
return;
}
}

(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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions