@@ -23,7 +23,7 @@ using namespace clang;
23
23
unsigned int lastRecordLocation = -1 ;
24
24
25
25
void processRecordDecl (RecordDecl *Declaration, ProgramInfo &Info,
26
- ASTContext *Context, ConstraintResolver CB) {
26
+ ASTContext *Context, ConstraintResolver CB, bool inFunc ) {
27
27
if (RecordDecl *Definition = Declaration->getDefinition ()) {
28
28
// store current record's location to cross-ref later in a VarDecl
29
29
lastRecordLocation = Definition->getBeginLoc ().getRawEncoding ();
@@ -36,13 +36,24 @@ void processRecordDecl(RecordDecl *Declaration, ProgramInfo &Info,
36
36
// We only want to re-write a record if it contains
37
37
// any pointer types, to include array types.
38
38
for (const auto &D : Definition->fields ()) {
39
- if (D->getType ()->isPointerType () || D->getType ()->isArrayType ()) {
40
- if (FL.isInSystemHeader () || Definition->isUnion ()) {
41
- CVarSet C = Info.getVariable (D, Context);
42
- std::string Rsn = " External struct field or union encountered" ;
43
- CB.constraintAllCVarsToWild (C, Rsn, nullptr );
39
+ bool mark_wild = ((D->getType ()->isPointerType () || D->getType ()->isArrayType ()) &&
40
+ (FL.isInSystemHeader () || Definition->isUnion ()));
41
+ if (!mark_wild && inFunc) {
42
+ Decl *D = Declaration->getNextDeclInContext ();
43
+ if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
44
+ if (!VD->getType ()->isPointerType () && !VD->getType ()->isArrayType ()) {
45
+ unsigned int BeginLoc = VD->getBeginLoc ().getRawEncoding ();
46
+ unsigned int EndLoc = VD->getEndLoc ().getRawEncoding ();
47
+ mark_wild = (lastRecordLocation >= BeginLoc &&
48
+ lastRecordLocation <= EndLoc);
49
+ }
44
50
}
45
51
}
52
+ if (mark_wild) {
53
+ CVarSet C = Info.getVariable (D, Context);
54
+ std::string Rsn = " External struct field or union encountered" ;
55
+ CB.constraintAllCVarsToWild (C, Rsn, nullptr );
56
+ }
46
57
}
47
58
}
48
59
}
@@ -66,7 +77,7 @@ class FunctionVisitor : public RecursiveASTVisitor<FunctionVisitor> {
66
77
// Introduce variables as needed.
67
78
for (const auto &D : S->decls ()) {
68
79
if (RecordDecl *RD = dyn_cast<RecordDecl>(D)) {
69
- processRecordDecl (RD, Info, Context, CB);
80
+ processRecordDecl (RD, Info, Context, CB, true );
70
81
}
71
82
if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
72
83
if (VD->isLocalVarDecl ()) {
@@ -459,7 +470,7 @@ class ConstraintGenVisitor : public RecursiveASTVisitor<ConstraintGenVisitor> {
459
470
}
460
471
461
472
bool VisitRecordDecl (RecordDecl *Declaration) {
462
- processRecordDecl (Declaration, Info, Context, CB);
473
+ processRecordDecl (Declaration, Info, Context, CB, false );
463
474
return true ;
464
475
}
465
476
0 commit comments