23 #include "llvm/Support/raw_ostream.h" 25 using namespace clang;
93 class GTestChecker :
public Checker<check::PostCall> {
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);
146 SVal ThisSuccess = getAssertionResultSuccessFieldValue(
149 State = assumeValuesEqual(ThisSuccess, BooleanArgVal, State, C);
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);
182 void GTestChecker::checkPostCall(
const CallEvent &Call,
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);
295 if (!LangOpts.CPlusPlus)
virtual ProgramStateRef assume(ProgramStateRef state, DefinedSVal Cond, bool Assumption)=0
const CXXConstructorDecl * getDecl() const override
ExplodedNode * addTransition(ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)
Generates a new transition in the program state graph (ExplodedGraph).
Represents a C++ constructor within a class.
const T * getAs() const
Member-template getAs<specific type>'.
const bool wasInlined
If we are post visiting a call, this flag will be set if the call was inlined.
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
Optional< T > getAs() const
Convert to the specified SVal type, returning None if this SVal is not of the desired type...
CHECKER * registerChecker(AT... Args)
Used to register checkers.
ConstraintManager & getConstraintManager()
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
const ParmVarDecl * getParamDecl(unsigned i) const
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
SVal getCXXThisVal() const
Returns the value of the implicit 'this' object.
Dataflow Directional Tag Classes.
ASTContext & getASTContext()
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...
SVal evalEQ(ProgramStateRef state, SVal lhs, SVal rhs)
Represents an abstract call to a function or method along a particular path.
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
const ProgramStateRef & getState() const
Base for LValueReferenceType and RValueReferenceType.
Represents a C++ struct/union/class.
SValBuilder & getSValBuilder()
const LangOptions & getLangOpts() const
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Represents a call to a C++ constructor.