bool isDeclCandidate(FunctionDecl * FDecl) { if (m_NonNullArgIndexs.count(FDecl)) return true; if (llvm::isa<CXXRecordDecl>(FDecl)) return true; std::bitset<32> ArgIndexs; for (specific_attr_iterator<NonNullAttr> I = FDecl->specific_attr_begin<NonNullAttr>(), E = FDecl->specific_attr_end<NonNullAttr>(); I != E; ++I) { NonNullAttr *NonNull = *I; for (NonNullAttr::args_iterator i = NonNull->args_begin(), e = NonNull->args_end(); i != e; ++i) { ArgIndexs.set(*i); } } if (ArgIndexs.any()) { m_NonNullArgIndexs.insert(std::make_pair(FDecl, ArgIndexs)); return true; } return false; }
// Deal with all the call expr in the transaction. bool VisitCallExpr(CallExpr* TheCall) { if (FunctionDecl* FDecl = TheCall->getDirectCallee()) { std::bitset<32> ArgIndexs; for (FunctionDecl::redecl_iterator RI = FDecl->redecls_begin(), RE = FDecl->redecls_end(); RI != RE; ++RI) { for (specific_attr_iterator<NonNullAttr> I = RI->specific_attr_begin<NonNullAttr>(), E = RI->specific_attr_end<NonNullAttr>(); I != E; ++I) { NonNullAttr *NonNull = *I; // Store all the null attr argument's index into "ArgIndexs". for (NonNullAttr::args_iterator i = NonNull->args_begin(), e = NonNull->args_end(); i != e; ++i) { // Get the argument with the nonnull attribute. const Expr* Arg = TheCall->getArg(*i); // Check whether we can get the argument'value. If the argument is // not null, then ignore this argument and continue to deal with the // next argument with the nonnull attribute.ArgIndexs.set(*i); bool Result; ASTContext& Context = m_Sema->getASTContext(); if (Arg->EvaluateAsBooleanCondition(Result, Context) && Result) { continue; } ArgIndexs.set(*i); } break; } } if (ArgIndexs.any()) { // Get the function decl's name. std::string FName = getMangledName(FDecl); // Store the function decl's name into the vector. m_NonNullDeclNames.push_back(FName); // Store the function decl's name with its null attr args' indexes // into the map. m_NonNullArgIndexs.insert(std::make_pair(FName, ArgIndexs)); } // FIXME: For now we will only work/check on declarations that are not // deserialized. We want to avoid our null deref transaformer to // deserialize all the contents of a PCH/PCM. // We have to think of a better way to find the annotated // declarations, without that to cause too much deserialization. Stmt* S = (FDecl->isFromASTFile()) ? 0 : FDecl->getBody(); if (S) { for (Stmt::child_iterator II = S->child_begin(), EE = S->child_end(); II != EE; ++II) { CallExpr* child = dyn_cast<CallExpr>(*II); if (child && child->getDirectCallee() != FDecl) VisitCallExpr(child); } } } return true; // returning false will abort the in-depth traversal. }