22 #include "llvm/Support/raw_ostream.h" 24 using namespace clang;
92 class GTestChecker :
public Checker<check::PostCall> {
100 void checkPostCall(
const CallEvent &Call, CheckerContext &C)
const;
104 bool IsRef, CheckerContext &C)
const;
107 CheckerContext &C)
const;
109 void initIdentifierInfo(
ASTContext &Ctx)
const;
112 getAssertionResultSuccessFieldValue(
const CXXRecordDecl *AssertionResultDecl,
122 GTestChecker::GTestChecker() : AssertionResultII(nullptr), SuccessII(nullptr) {}
130 void GTestChecker::modelAssertionResultBoolConstructor(
135 SVal BooleanArgVal = Call->getArgSVal(0);
138 if (!BooleanArgVal.getAs<Loc>())
140 BooleanArgVal = C.getState()->getSVal(BooleanArgVal.castAs<Loc>());
145 SVal ThisSuccess = getAssertionResultSuccessFieldValue(
148 State = assumeValuesEqual(ThisSuccess, BooleanArgVal, State, C);
149 C.addTransition(State);
159 void GTestChecker::modelAssertionResultCopyConstructor(
165 SVal OtherVal = Call->getArgSVal(0);
171 SVal ThisSuccess = getAssertionResultSuccessFieldValue(AssertResultClassDecl,
173 SVal OtherSuccess = getAssertionResultSuccessFieldValue(AssertResultClassDecl,
176 State = assumeValuesEqual(ThisSuccess, OtherSuccess, State, C);
177 C.addTransition(State);
181 void GTestChecker::checkPostCall(
const CallEvent &Call,
182 CheckerContext &C)
const {
187 initIdentifierInfo(C.getASTContext());
205 modelAssertionResultCopyConstructor(CtorCall, C);
225 modelAssertionResultBoolConstructor(CtorCall,
false, C);
228 if (ParamCount == 2){
231 RefTy->getPointeeType()->getCanonicalTypeUnqualified() == BoolTy) {
233 modelAssertionResultBoolConstructor(CtorCall,
true, C);
239 void GTestChecker::initIdentifierInfo(
ASTContext &Ctx)
const {
240 if (AssertionResultII)
243 AssertionResultII = &Ctx.
Idents.
get(
"AssertionResult");
249 SVal GTestChecker::getAssertionResultSuccessFieldValue(
262 State->getLValue(SuccessField, Instance).getAs<Loc>();
263 if (!FieldLoc.hasValue())
266 return State->getSVal(*FieldLoc);
273 if (!Val1.getAs<DefinedOrUnknownSVal>() ||
274 !Val2.getAs<DefinedOrUnknownSVal>())
278 C.getSValBuilder().evalEQ(State, Val1.castAs<DefinedOrUnknownSVal>(),
279 Val2.castAs<DefinedOrUnknownSVal>());
281 if (!ValuesEqual.getAs<DefinedSVal>())
284 State = C.getConstraintManager().assume(
285 State, ValuesEqual.castAs<DefinedSVal>(),
true);
290 void ento::registerGTestChecker(CheckerManager &Mgr) {
291 Mgr.registerChecker<GTestChecker>();
294 bool ento::shouldRegisterGTestChecker(
const LangOptions &LO) {
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
Return 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.