Skip to content

Commit 128c8b8

Browse files
Fix bug in PR #380
CheckedC does let you take the address of constant size checked arrays. The previous commit would not let this happen, causing the ptrtoconstarr.c test to fail. It also caused ptrptr.c to fail, but this was because the -alltypes behavior expected in that test generated code that did not compile (because it took the address of an _Array_ptr). Both tests are now passing.
1 parent e778223 commit 128c8b8

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

clang/lib/3C/ConstraintResolver.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,10 @@ CVarSet ConstraintResolver::getExprConstraintVars(Expr *E) {
383383
// 3C will not generate such code.
384384
for (auto *CV : T)
385385
if (auto *PCV = dyn_cast<PVConstraint>(CV))
386-
PCV->constrainOuterTo(CS, CS.getPtr(), true);
386+
// On the other hand, CheckedC does let you take the address of
387+
// constant sized arrays.
388+
if (!PCV->getArrPresent())
389+
PCV->constrainOuterTo(CS, CS.getPtr(), true);
387390
// add a VarAtom to UOExpr's PVConstraint, for &
388391
Ret = addAtomAll(T, CS.getPtr(), CS);
389392
}

clang/test/3C/ptrptr.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: 3c -alltypes -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_ALL","CHECK" %s
22
// RUN: 3c -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_NOALL","CHECK" %s
3-
// RUN: 3c -addcr %s -- | %clang -c -fcheckedc-extension -x c -o /dev/null -
3+
// RUN: 3c -addcr -alltypes %s -- | %clang -c -fcheckedc-extension -x c -o /dev/null -
44
// RUN: 3c -output-postfix=checked -alltypes %s
55
// RUN: 3c -alltypes %S/ptrptr.checked.c -- | count 0
66
// RUN: rm %S/ptrptr.checked.c
@@ -27,17 +27,13 @@ void f() {
2727

2828
void g() {
2929
int *x = malloc(sizeof(int)*1);
30-
//CHECK_NOALL: int *x = malloc<int>(sizeof(int)*1);
31-
//CHECK_ALL: _Array_ptr<int> x : count(1) = malloc<int>(sizeof(int)*1);
30+
//CHECK: int *x = malloc<int>(sizeof(int)*1);
3231
int y[5];
33-
//CHECK_NOALL: int y[5];
34-
//CHECK_ALL: int y _Checked[5];
32+
//CHECK: int y[5];
3533
int **p = &x;
36-
//CHECK_NOALL: _Ptr<int *> p = &x;
37-
//CHECK_ALL: _Ptr<_Array_ptr<int>> p = &x;
34+
//CHECK: _Ptr<int *> p = &x;
3835
int **r = 0;
39-
//CHECK_NOALL: _Ptr<int *> r = 0;
40-
//CHECK_ALL: _Ptr<_Array_ptr<int>> r = 0;
36+
//CHECK: _Ptr<int *> r = 0;
4137
*p = y;
4238
(*p)[0] = 1;
4339
r = p;

0 commit comments

Comments
 (0)