Skip to content

Commit e778223

Browse files
Constrain target of addrof operator to PTR (#380)
Adds an edge PTR -> x for expressions &x. Previously, only the result of the addrof expression had this constraint, but CheckedC prohibits taking the address of pointers with bounds. It is possible to take the address of an _Array_ptr when the pointer doesn't have bounds declared. With this constraint added however, 3C will not let this happen.
1 parent 2078016 commit e778223

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

clang/lib/3C/ConstraintResolver.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,18 @@ CVarSet ConstraintResolver::getExprConstraintVars(Expr *E) {
373373
dyn_cast<ArraySubscriptExpr>(UOExpr)) {
374374
Ret = getExprConstraintVars(ASE->getBase());
375375
} else {
376-
// add a VarAtom to UOExpr's PVConstraint, for &
377376
CVarSet T = getExprConstraintVars(UOExpr);
378377
assert("Empty constraint vars in AddrOf!" && !T.empty());
378+
// CheckedC prohibits taking the address of a variable with bounds. To
379+
// avoid doing this, constrain the target of AddrOf expressions to
380+
// PTR. This prevents it from solving to either ARR or NTARR. CheckedC
381+
// does permit taking the address of an _Array_ptr when the array
382+
// pointer has no declared bounds. With this constraint added however,
383+
// 3C will not generate such code.
384+
for (auto *CV : T)
385+
if (auto *PCV = dyn_cast<PVConstraint>(CV))
386+
PCV->constrainOuterTo(CS, CS.getPtr(), true);
387+
// add a VarAtom to UOExpr's PVConstraint, for &
379388
Ret = addAtomAll(T, CS.getPtr(), CS);
380389
}
381390
break;

0 commit comments

Comments
 (0)