Skip to content

Commit 1ebc2c1

Browse files
author
Aaron Eline
committed
Fixes and test cases
1 parent 2456705 commit 1ebc2c1

File tree

4 files changed

+47
-33
lines changed

4 files changed

+47
-33
lines changed

clang/include/clang/CConv/ConstraintVariables.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,7 @@ typedef PointerVariableConstraint PVConstraint;
364364

365365
typedef struct {
366366
PersistentSourceLoc PL;
367-
ASTContext *C;
368-
FunctionDecl *TFD;
369-
std::vector<std::pair<CVarSet, Expr*>> PS;
367+
std::vector<CVarSet> PS;
370368
} ParamDeferment;
371369

372370

@@ -419,9 +417,7 @@ class FunctionVariableConstraint : public ConstraintVariable {
419417
{ return deferredParams; }
420418

421419
void addDeferredParams(PersistentSourceLoc PL,
422-
ASTContext *C,
423-
FunctionDecl *TFD,
424-
std::vector<std::pair<CVarSet, Expr*>> Ps);
420+
std::vector<CVarSet> Ps);
425421

426422
size_t numParams() { return paramVars.size(); }
427423

clang/lib/CConv/ConstraintBuilder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class FunctionVisitor : public RecursiveASTVisitor<FunctionVisitor> {
194194
:
195195
false;
196196

197-
std::vector<std::pair<CVarSet, Expr*>> deferred;
197+
std::vector<CVarSet> deferred;
198198
for (const auto &A : E->arguments()) {
199199
CVarSet ArgumentConstraints;
200200
if(TFD != nullptr && i < TFD->getNumParams()) {
@@ -212,7 +212,7 @@ class FunctionVisitor : public RecursiveASTVisitor<FunctionVisitor> {
212212

213213

214214
if (callUntyped) {
215-
deferred.push_back(make_pair(ArgumentConstraints, A));
215+
deferred.push_back(ArgumentConstraints);
216216
} else if (i < TargetFV->numParams()) {
217217
// constrain the arg CV to the param CV
218218
CVarSet ParameterDC =
@@ -250,7 +250,7 @@ class FunctionVisitor : public RecursiveASTVisitor<FunctionVisitor> {
250250
i++;
251251
}
252252
if (callUntyped)
253-
TargetFV->addDeferredParams(PL, Context, TFD, deferred);
253+
TargetFV->addDeferredParams(PL, deferred);
254254

255255
}
256256
}

clang/lib/CConv/ConstraintVariables.cpp

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,7 @@ Atom *PointerVariableConstraint::getAtom(unsigned AtomIdx, Constraints &CS) {
16241624
// Brain Transplant params and returns in [FromCV], recursively.
16251625
void FunctionVariableConstraint::brainTransplant(ConstraintVariable *FromCV,
16261626
ProgramInfo &I) {
1627+
llvm::errs() << "Brain Transplanting\n";
16271628
FVConstraint *From = dyn_cast<FVConstraint>(FromCV);
16281629
assert (From != nullptr);
16291630
// Transplant returns.
@@ -1639,6 +1640,7 @@ void FunctionVariableConstraint::brainTransplant(ConstraintVariable *FromCV,
16391640

16401641
void FunctionVariableConstraint::mergeDeclaration(ConstraintVariable *FromCV,
16411642
ProgramInfo &I) {
1643+
llvm::errs() << "Merging\n";
16421644
FVConstraint *From = dyn_cast<FVConstraint>(FromCV);
16431645
assert (From != nullptr);
16441646
// Transplant returns.
@@ -1663,8 +1665,8 @@ void FunctionVariableConstraint::handle_params
16631665
// The only case where the params are not equal, and it's not
16641666
// an untype call, is a variadic call. Variadic calls wil not
16651667
// generate deferments.
1666-
if (paramsEq && To->getDeferredParams().size() == 0
1667-
&& From->getDeferredParams().size() == 0 ) {
1668+
if (paramsEq || (To->getDeferredParams().size() == 0
1669+
&& From->getDeferredParams().size() == 0 )) {
16681670
for (unsigned i = 0; i < From->numParams(); i++) {
16691671
CVarSet &FromP = From->getParamVar(i);
16701672
CVarSet &P = To->getParamVar(i);
@@ -1676,29 +1678,24 @@ void FunctionVariableConstraint::handle_params
16761678
FVConstraint *Empty = fromEmpty ? From : To;
16771679
FVConstraint *Typed = fromEmpty ? To : From;
16781680
auto &CS = I.getConstraints();
1681+
// Copy constraint variables over the empty declaration
1682+
for(unsigned i = 0; i < Typed->numParams(); i++) {
1683+
CVarSet &TypedP = Typed->getParamVar(i);
1684+
auto TypedV = getOnly(TypedP);
1685+
CVarSet EmptyP;
1686+
ConstraintVariable *NewV = TypedV->getCopy(CS);
1687+
f(TypedV, NewV);
1688+
EmptyP.insert(NewV);
1689+
Empty->paramVars.push_back(EmptyP);
1690+
constrainConsVarGeq(EmptyP, TypedP, CS, nullptr, Wild_to_Safe, false, &I);
1691+
}
1692+
// Constraint the deffered parameters
16791693
for (auto deferred : Empty->getDeferredParams()) {
1680-
ConstraintResolver CB(I, deferred.C);
16811694
assert(Typed->numParams() == deferred.PS.size());
16821695
for(unsigned i = 0; i < deferred.PS.size(); i++) {
16831696
CVarSet ParamDC = Typed->getParamVar(i);
1684-
CVarSet ArgDC = deferred.PS[i].first;
1685-
Empty->paramVars.push_back(ParamDC);
1686-
auto TFD = deferred.TFD;
1697+
CVarSet ArgDC = deferred.PS[i];
16871698
constrainConsVarGeq(ParamDC, ArgDC, CS, &(deferred.PL), Wild_to_Safe, false, &I);
1688-
if (AllTypes && TFD != nullptr &&
1689-
!CB.containsValidCons(ParamDC) &&
1690-
!CB.containsValidCons(ArgDC)) {
1691-
auto *PVD = TFD->getParamDecl(i);
1692-
auto &ABI = I.getABoundsInfo();
1693-
BoundsKey PVKey, AGKey;
1694-
if ((CB.resolveBoundsKey(ParamDC, PVKey) ||
1695-
ABI.tryGetVariable(PVD, PVKey)) &&
1696-
(CB.resolveBoundsKey(ArgDC, AGKey) ||
1697-
ABI.tryGetVariable(deferred.PS[i].second,
1698-
*(deferred.C), AGKey))) {
1699-
ABI.addAssignment(PVKey, AGKey);
1700-
}
1701-
}
17021699
}
17031700
}
17041701
}
@@ -1708,11 +1705,9 @@ void FunctionVariableConstraint::handle_params
17081705
void
17091706
FunctionVariableConstraint::addDeferredParams
17101707
(PersistentSourceLoc PL,
1711-
ASTContext *C,
1712-
FunctionDecl *TFD,
1713-
std::vector<std::pair<CVarSet, Expr*>> Ps)
1708+
std::vector<CVarSet> Ps)
17141709
{
1715-
ParamDeferment P = { PL, C, TFD, Ps };
1710+
ParamDeferment P = { PL, Ps };
17161711
deferredParams.push_back(P);
17171712
return;
17181713
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: cconv-standalone -alltypes %s -- | FileCheck -match-full-lines --check-prefixes="CHECK" %s
2+
3+
int foo();
4+
//CHECK: int foo(_Array_ptr<int> x : count(y), int y);
5+
6+
int bar(int *x, int c) {
7+
//CHECK: int bar(_Array_ptr<int> x : count(c), int c) {
8+
return foo(x, 1) + 3;
9+
}
10+
11+
int foo(int *x, int y);
12+
//CHECK: int foo(_Array_ptr<int> x : count(y), int y);
13+
14+
int foo(int *x, int y) {
15+
//CHECK: int foo(_Array_ptr<int> x : count(y), int y) {
16+
int sum = 0;
17+
for(int i = 0; i < y; i++) {
18+
sum += x[i];
19+
}
20+
return sum;
21+
}
22+
23+

0 commit comments

Comments
 (0)