@@ -23,7 +23,7 @@ using namespace clang;
2323unsigned int lastRecordLocation = -1 ;
2424
2525void processRecordDecl (RecordDecl *Declaration, ProgramInfo &Info,
26- ASTContext *Context, ConstraintResolver CB) {
26+ ASTContext *Context, ConstraintResolver CB, bool inFunc ) {
2727 if (RecordDecl *Definition = Declaration->getDefinition ()) {
2828 // store current record's location to cross-ref later in a VarDecl
2929 lastRecordLocation = Definition->getBeginLoc ().getRawEncoding ();
@@ -36,13 +36,24 @@ void processRecordDecl(RecordDecl *Declaration, ProgramInfo &Info,
3636 // We only want to re-write a record if it contains
3737 // any pointer types, to include array types.
3838 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+ }
4450 }
4551 }
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+ }
4657 }
4758 }
4859 }
@@ -66,7 +77,7 @@ class FunctionVisitor : public RecursiveASTVisitor<FunctionVisitor> {
6677 // Introduce variables as needed.
6778 for (const auto &D : S->decls ()) {
6879 if (RecordDecl *RD = dyn_cast<RecordDecl>(D)) {
69- processRecordDecl (RD, Info, Context, CB);
80+ processRecordDecl (RD, Info, Context, CB, true );
7081 }
7182 if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
7283 if (VD->isLocalVarDecl ()) {
@@ -459,7 +470,7 @@ class ConstraintGenVisitor : public RecursiveASTVisitor<ConstraintGenVisitor> {
459470 }
460471
461472 bool VisitRecordDecl (RecordDecl *Declaration) {
462- processRecordDecl (Declaration, Info, Context, CB);
473+ processRecordDecl (Declaration, Info, Context, CB, false );
463474 return true ;
464475 }
465476
0 commit comments