23 #include "llvm/Support/raw_ostream.h" 25 using namespace clang;
93 class GTestChecker :
public Checker<check::PostCall> {
101 void checkPostCall(
const CallEvent &Call, CheckerContext &C)
const;
105 bool IsRef, CheckerContext &C)
const;
108 CheckerContext &C)
const;
110 void initIdentifierInfo(
ASTContext &Ctx)
const;
113 getAssertionResultSuccessFieldValue(
const CXXRecordDecl *AssertionResultDecl,
123 GTestChecker::GTestChecker() : AssertionResultII(nullptr), SuccessII(nullptr) {}
131 void GTestChecker::modelAssertionResultBoolConstructor(
136 SVal BooleanArgVal = Call->getArgSVal(0);
139 if (!BooleanArgVal.getAs<Loc>())
141 BooleanArgVal = C.getState()->getSVal(BooleanArgVal.castAs<Loc>());
146 SVal ThisSuccess = getAssertionResultSuccessFieldValue(
149 State = assumeValuesEqual(ThisSuccess, BooleanArgVal, State, C);
150 C.addTransition(State);
160 void GTestChecker::modelAssertionResultCopyConstructor(
166 SVal OtherVal = Call->getArgSVal(0);
172 SVal ThisSuccess = getAssertionResultSuccessFieldValue(AssertResultClassDecl,
174 SVal OtherSuccess = getAssertionResultSuccessFieldValue(AssertResultClassDecl,
177 State = assumeValuesEqual(ThisSuccess, OtherSuccess, State, C);
178 C.addTransition(State);
182 void GTestChecker::checkPostCall(
const CallEvent &Call,
183 CheckerContext &C)
const {
188 initIdentifierInfo(C.getASTContext());
206 modelAssertionResultCopyConstructor(CtorCall, C);
226 modelAssertionResultBoolConstructor(CtorCall,
false, C);
229 if (ParamCount == 2){
232 RefTy->getPointeeType()->getCanonicalTypeUnqualified() == BoolTy) {
234 modelAssertionResultBoolConstructor(CtorCall,
true, C);
240 void GTestChecker::initIdentifierInfo(
ASTContext &Ctx)
const {
241 if (AssertionResultII)
244 AssertionResultII = &Ctx.
Idents.
get(
"AssertionResult");
250 SVal GTestChecker::getAssertionResultSuccessFieldValue(
263 State->getLValue(SuccessField, Instance).getAs<Loc>();
264 if (!FieldLoc.hasValue())
267 return State->getSVal(*FieldLoc);
274 if (!Val1.getAs<DefinedOrUnknownSVal>() ||
275 !Val2.getAs<DefinedOrUnknownSVal>())
279 C.getSValBuilder().evalEQ(State, Val1.castAs<DefinedOrUnknownSVal>(),
280 Val2.castAs<DefinedOrUnknownSVal>());
282 if (!ValuesEqual.getAs<DefinedSVal>())
285 State = C.getConstraintManager().assume(
286 State, ValuesEqual.castAs<DefinedSVal>(),
true);
291 void ento::registerGTestChecker(CheckerManager &Mgr) {
295 if (!LangOpts.CPlusPlus)
298 Mgr.registerChecker<GTestChecker>();
const CXXConstructorDecl * getDecl() const override
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
Represents a C++ constructor within a class.
const T * getAs() const
Member-template getAs<specific type>'.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
One of these records is kept for each identifier that is lexed.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
The results of name lookup within a DeclContext.
Represents a member of a struct/union/class.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Defines the clang::LangOptions interface.
unsigned getNumArgs() const override
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
const ParmVarDecl * getParamDecl(unsigned i) const
SVal getCXXThisVal() const
Returns the value of the implicit 'this' object.
Dataflow Directional Tag Classes.
bool isCopyConstructor(unsigned &TypeQuals) const
Whether this constructor is a copy constructor (C++ [class.copy]p2, which can be used to copy the cla...
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
Base for LValueReferenceType and RValueReferenceType.
Represents a C++ struct/union/class.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Represents a call to a C++ constructor.