22#include "llvm/Support/raw_ostream.h"
93class GTestChecker :
public Checker<check::PostCall> {
99 GTestChecker() =
default;
110 void initIdentifierInfo(
ASTContext &Ctx)
const;
113 getAssertionResultSuccessFieldValue(
const CXXRecordDecl *AssertionResultDecl,
129void GTestChecker::modelAssertionResultBoolConstructor(
131 assert(
Call->getNumArgs() >= 1 &&
Call->getNumArgs() <= 2);
134 SVal BooleanArgVal =
Call->getArgSVal(0);
137 if (!isa<Loc>(BooleanArgVal))
139 BooleanArgVal =
C.getState()->getSVal(BooleanArgVal.
castAs<
Loc>());
142 SVal ThisVal =
Call->getCXXThisVal();
144 SVal ThisSuccess = getAssertionResultSuccessFieldValue(
145 Call->getDecl()->getParent(), ThisVal, State);
147 State = assumeValuesEqual(ThisSuccess, BooleanArgVal, State,
C);
148 C.addTransition(State);
158void GTestChecker::modelAssertionResultCopyConstructor(
160 assert(
Call->getNumArgs() == 1);
164 SVal OtherVal =
Call->getArgSVal(0);
165 SVal ThisVal =
Call->getCXXThisVal();
170 SVal ThisSuccess = getAssertionResultSuccessFieldValue(AssertResultClassDecl,
172 SVal OtherSuccess = getAssertionResultSuccessFieldValue(AssertResultClassDecl,
175 State = assumeValuesEqual(ThisSuccess, OtherSuccess, State,
C);
176 C.addTransition(State);
186 initIdentifierInfo(
C.getASTContext());
188 auto *CtorCall = dyn_cast<CXXConstructorCall>(&
Call);
204 modelAssertionResultCopyConstructor(CtorCall,
C);
224 modelAssertionResultBoolConstructor(CtorCall,
false,
C);
227 if (ParamCount == 2){
230 RefTy->getPointeeType()->getCanonicalTypeUnqualified() == BoolTy) {
232 modelAssertionResultBoolConstructor(CtorCall,
true,
C);
238void GTestChecker::initIdentifierInfo(
ASTContext &Ctx)
const {
239 if (AssertionResultII)
242 AssertionResultII = &Ctx.
Idents.
get(
"AssertionResult");
248SVal GTestChecker::getAssertionResultSuccessFieldValue(
256 auto *SuccessField = dyn_cast<FieldDecl>(Result.front());
260 std::optional<Loc> FieldLoc =
261 State->getLValue(SuccessField, Instance).getAs<
Loc>();
265 return State->getSVal(*FieldLoc);
274 if (!DVal1 || !DVal2)
278 C.getSValBuilder().evalEQ(State, *DVal1, *DVal2).getAs<
DefinedSVal>();
282 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.
The JSON file list parser is used to communicate input to InstallAPI.