Skip to content

Remove conditional stopping creating of constraint variables #445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions clang/lib/3C/ConstraintBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,14 +589,9 @@ class VariableAdderVisitor : public RecursiveASTVisitor<VariableAdderVisitor> {
assert("Declaration is a definition, but getDefinition() is null?" &&
Definition);
FullSourceLoc FL = Context->getFullLoc(Definition->getBeginLoc());
if (FL.isValid()) {
SourceManager &SM = Context->getSourceManager();
FileID FID = FL.getFileID();
const FileEntry *FE = SM.getFileEntryForID(FID);
if (FE && FE->isValid())
for (auto *const D : Definition->fields())
addVariable(D);
}
if (FL.isValid())
for (auto *const D : Definition->fields())
addVariable(D);
}
return true;
}
Expand Down
32 changes: 32 additions & 0 deletions clang/test/3C/struct_macro.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// RUN: rm -rf %t*
// RUN: 3c -base-dir=%S -alltypes -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_ALL","CHECK" %s
// RUN: 3c -base-dir=%S -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_NOALL","CHECK" %s
// RUN: 3c -base-dir=%S -addcr %s -- | %clang -c -fcheckedc-extension -x c -o /dev/null -
// RUN: 3c -base-dir=%S -output-dir=%t.checked -alltypes %s --
// RUN: 3c -base-dir=%t.checked -alltypes %t.checked/struct_macro.c -- | diff %t.checked/struct_macro.c -


// 3C was failing to create constraint variables for fields of structure
// defined by macros.
// https://github.com/correctcomputation/checkedc-clang/issues/297


// Fields is not in macro, so can be checked

#define b struct c
b {int * a;};
//CHECK: b {_Ptr<int> a;};
void e(struct c x) {
int *y = x.a;
//CHECK: _Ptr<int> y = x.a;
}

// Fields is in macro, so it can't be checked.
// A constraint variable still must be created.
#define foo struct bar { int * x };
foo

void baz(struct bar buz) {
int *x = buz.x;
//CHECK: int *x = buz.x;
}