Skip to content

Commit 84a263d

Browse files
Remove conditional stopping creating of constraint variables (#445)
The removed conditional stopped constraint variables being created for fields of structures that were defined in macros. The original reason for adding this is unclear, but removing it seems to be correct.
1 parent 073606d commit 84a263d

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

clang/lib/3C/ConstraintBuilder.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -589,14 +589,9 @@ class VariableAdderVisitor : public RecursiveASTVisitor<VariableAdderVisitor> {
589589
assert("Declaration is a definition, but getDefinition() is null?" &&
590590
Definition);
591591
FullSourceLoc FL = Context->getFullLoc(Definition->getBeginLoc());
592-
if (FL.isValid()) {
593-
SourceManager &SM = Context->getSourceManager();
594-
FileID FID = FL.getFileID();
595-
const FileEntry *FE = SM.getFileEntryForID(FID);
596-
if (FE && FE->isValid())
597-
for (auto *const D : Definition->fields())
598-
addVariable(D);
599-
}
592+
if (FL.isValid())
593+
for (auto *const D : Definition->fields())
594+
addVariable(D);
600595
}
601596
return true;
602597
}

clang/test/3C/struct_macro.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: rm -rf %t*
2+
// RUN: 3c -base-dir=%S -alltypes -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_ALL","CHECK" %s
3+
// RUN: 3c -base-dir=%S -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_NOALL","CHECK" %s
4+
// RUN: 3c -base-dir=%S -addcr %s -- | %clang -c -fcheckedc-extension -x c -o /dev/null -
5+
// RUN: 3c -base-dir=%S -output-dir=%t.checked -alltypes %s --
6+
// RUN: 3c -base-dir=%t.checked -alltypes %t.checked/struct_macro.c -- | diff %t.checked/struct_macro.c -
7+
8+
9+
// 3C was failing to create constraint variables for fields of structure
10+
// defined by macros.
11+
// https://github.com/correctcomputation/checkedc-clang/issues/297
12+
13+
14+
// Fields is not in macro, so can be checked
15+
16+
#define b struct c
17+
b {int * a;};
18+
//CHECK: b {_Ptr<int> a;};
19+
void e(struct c x) {
20+
int *y = x.a;
21+
//CHECK: _Ptr<int> y = x.a;
22+
}
23+
24+
// Fields is in macro, so it can't be checked.
25+
// A constraint variable still must be created.
26+
#define foo struct bar { int * x };
27+
foo
28+
29+
void baz(struct bar buz) {
30+
int *x = buz.x;
31+
//CHECK: int *x = buz.x;
32+
}

0 commit comments

Comments
 (0)