22#include "llvm/Support/raw_ostream.h"
93class GTestChecker :
public Checker<check::PostCall> {
110 void initIdentifierInfo(
ASTContext &Ctx)
const;
113 getAssertionResultSuccessFieldValue(
const CXXRecordDecl *AssertionResultDecl,
123GTestChecker::GTestChecker() : AssertionResultII(nullptr), SuccessII(nullptr) {}
131void GTestChecker::modelAssertionResultBoolConstructor(
133 assert(
Call->getNumArgs() >= 1 &&
Call->getNumArgs() <= 2);
136 SVal BooleanArgVal =
Call->getArgSVal(0);
139 if (!isa<Loc>(BooleanArgVal))
141 BooleanArgVal =
C.getState()->getSVal(BooleanArgVal.
castAs<
Loc>());
144 SVal ThisVal =
Call->getCXXThisVal();
146 SVal ThisSuccess = getAssertionResultSuccessFieldValue(
147 Call->getDecl()->getParent(), ThisVal, State);
149 State = assumeValuesEqual(ThisSuccess, BooleanArgVal, State,
C);
150 C.addTransition(State);
160void GTestChecker::modelAssertionResultCopyConstructor(
162 assert(
Call->getNumArgs() == 1);
166 SVal OtherVal =
Call->getArgSVal(0);
167 SVal ThisVal =
Call->getCXXThisVal();
172 SVal ThisSuccess = getAssertionResultSuccessFieldValue(AssertResultClassDecl,
174 SVal OtherSuccess = getAssertionResultSuccessFieldValue(AssertResultClassDecl,
177 State = assumeValuesEqual(ThisSuccess, OtherSuccess, State,
C);
178 C.addTransition(State);
182void GTestChecker::checkPostCall(
const CallEvent &Call,
188 initIdentifierInfo(
C.getASTContext());
190 auto *CtorCall = dyn_cast<CXXConstructorCall>(&Call);
206 modelAssertionResultCopyConstructor(CtorCall,
C);
226 modelAssertionResultBoolConstructor(CtorCall,
false,
C);
229 if (ParamCount == 2){
232 RefTy->getPointeeType()->getCanonicalTypeUnqualified() == BoolTy) {
234 modelAssertionResultBoolConstructor(CtorCall,
true,
C);
240void GTestChecker::initIdentifierInfo(
ASTContext &Ctx)
const {
241 if (AssertionResultII)
244 AssertionResultII = &Ctx.
Idents.
get(
"AssertionResult");
250SVal GTestChecker::getAssertionResultSuccessFieldValue(
258 auto *SuccessField = dyn_cast<FieldDecl>(Result.front());
262 std::optional<Loc> FieldLoc =
263 State->getLValue(SuccessField, Instance).getAs<
Loc>();
267 return State->getSVal(*FieldLoc);
276 if (!DVal1 || !DVal2)
280 C.getSValBuilder().evalEQ(State, *DVal1, *DVal2).getAs<
DefinedSVal>();
284 State =
C.getConstraintManager().assume(State, *ValuesEqual,
true);
Defines the clang::LangOptions interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Represents a C++ constructor within a class.
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.
Represents a C++ struct/union/class.
The results of name lookup within a DeclContext.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
const ParmVarDecl * getParamDecl(unsigned i) const
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
One of these records is kept for each identifier that is lexed.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Base for LValueReferenceType and RValueReferenceType.
const T * getAs() const
Member-template getAs<specific type>'.
Represents a call to a C++ constructor.
Represents an abstract call to a function or method along a particular path.
CHECKER * registerChecker(AT &&... Args)
Used to register checkers.
const LangOptions & getLangOpts() const
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
std::optional< T > getAs() const
Convert to the specified SVal type, returning std::nullopt if this SVal is not of the desired type.
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
bool Call(InterpState &S, CodePtr OpPC, const Function *Func)
@ C
Languages that the frontend can parse and compile.