clang: lib/StaticAnalyzer/Core/CallEvent.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

50#include "llvm/ADT/ArrayRef.h"

51#include "llvm/ADT/DenseMap.h"

52#include "llvm/ADT/ImmutableList.h"

53#include "llvm/ADT/PointerIntPair.h"

54#include "llvm/ADT/SmallSet.h"

55#include "llvm/ADT/SmallVector.h"

56#include "llvm/ADT/StringExtras.h"

57#include "llvm/ADT/StringRef.h"

58#include "llvm/Support/Casting.h"

59#include "llvm/Support/Compiler.h"

60#include "llvm/Support/Debug.h"

61#include "llvm/Support/ErrorHandling.h"

62#include "llvm/Support/raw_ostream.h"

63#include

64#include

65#include

66

67#define DEBUG_TYPE "static-analyzer-call-event"

68

69using namespace clang;

70using namespace ento;

71

75 if (E)

78}

79

81

85 return true;

86

87

88

89

92

95 for (const auto *I : RD->fields()) {

96 QualType FieldT = I->getType();

98 return true;

99 }

100 }

101 return false;

102}

103

108 return false;

110 } else

111 return false;

112}

113

116

117

118

119

121 return false;

122

123 unsigned Idx = 0;

126 I != E && Idx < NumOfArgs; ++I, ++Idx) {

127

129 continue;

130

132 return true;

133 }

134 return false;

135}

136

139}

140

143}

144

146 const auto *FD = dyn_cast_or_null(getDecl());

147 if (!FD)

148 return false;

149

151}

152

155 if (D)

156 return nullptr;

157

160

161 return ADC;

162}

163

167 if (!ADC)

168 return nullptr;

169

171 if (E)

172 return nullptr;

173

174

175

176

177

178

181 assert(B);

182

183

184 unsigned Idx = 0, Sz = B->size();

185 for (; Idx < Sz; ++Idx)

186 if (auto StmtElem = (*B)[Idx].getAs())

187 if (StmtElem->getStmt() == E)

188 break;

189 assert(Idx < Sz);

190

192}

193

197

198 if (!SFC)

199 return nullptr;

200

202 State->getStateManager().getRegionManager().getParamVarRegion(

204 return PVR;

205}

206

207

208

212 return false;

214 return false;

216 return false;

217 return true;

218}

219

220

221

222

225 unsigned Idx = 0;

227 E = Call.param_type_end();

228 I != E; ++I, ++Idx) {

230 PreserveArgs.insert(Idx);

231 }

232}

233

237

238

240 if (callee->hasAttr() || callee->hasAttr())

242

245

247

248

249 llvm::SmallSet<unsigned, 4> PreserveArgs;

252

253 for (unsigned Idx = 0, Count = getNumArgs(); Idx != Count; ++Idx) {

254

255

256 if (PreserveArgs.count(Idx))

258 ETraits.setTrait(MR->getBaseRegion(),

260

261

262 ValuesToInvalidate.push_back(getArgSVal(Idx));

263

264

265

266

267

268

269

270

271

278 }

279

280

281

282

285 true,

286 nullptr, this, &ETraits);

287}

288

291

293 if (IsPreVisit)

296 }

297

299 assert(D && "Cannot get a program point without a statement or decl");

300 assert(ElemRef.getParent() &&

301 "Cannot get a program point without a CFGElementRef");

302

304 if (IsPreVisit)

307}

308

311 if (!ArgE)

314}

315

318 if (!ArgE)

319 return {};

321}

322

325 if (E)

328}

329

331

336 return;

337 }

338

340 Out << "Call to ";

342 return;

343 }

344

345 Out << "Unknown call (type " << getKindAsString() << ")";

346}

347

349 return isa<CallExpr, ObjCMessageExpr, CXXConstructExpr, CXXNewExpr>(S);

350}

351

353 assert(D);

354 if (const auto *FD = dyn_cast(D))

355 return FD->getReturnType();

356 if (const auto *MD = dyn_cast(D))

357 return MD->getReturnType();

358 if (const auto *BD = dyn_cast(D)) {

359

360

361

362

363

364

365

366

367 if (const TypeSourceInfo *TSI = BD->getSignatureAsWritten()) {

368 QualType Ty = TSI->getType();

370 Ty = FT->getReturnType();

372 return Ty;

373 }

374

375 return {};

376 }

377

378 llvm_unreachable("unknown callable kind");

379}

380

382 assert(D);

383

384 if (const auto *FD = dyn_cast(D))

385 return FD->isVariadic();

386 if (const auto *MD = dyn_cast(D))

387 return MD->isVariadic();

388 if (const auto *BD = dyn_cast(D))

389 return BD->isVariadic();

390

391 llvm_unreachable("unknown callable kind");

392}

393

396 return UT && UT->getDecl()->hasAttr();

397}

398

399

400

405

406

407

408

409

410

411

412

413

414

416

419

420 llvm::ImmutableList CompoundSVals = BVF.getEmptySValList();

422

423

425 }

426

428}

429

430

431

432

433

434

435

438 const auto *CallExprDecl = dyn_cast_or_null(Call.getDecl());

439 if (!CallExprDecl)

440 return ArgVal;

441

444

445

446

447

448

449 if (CallExprDecl->hasPrototype() || Definition->hasPrototype())

450 return ArgVal;

451

452

453

456

457 const Expr *ArgExpr = Call.getArgExpr(ArgIdx);

460}

461

468

469

470

471 unsigned NumArgs = Call.getNumArgs();

472 unsigned Idx = 0;

474 for (; I != E && Idx < NumArgs; ++I, ++Idx) {

475 assert(*I && "Formal parameter has no decl?");

476

477

479 if (Call.isArgumentConstructedDirectly(Call.getASTArgumentIndex(Idx)))

480 continue;

481

482

483

484

485 SVal ArgVal = Call.getArgSVal(Idx);

486 const Expr *ArgExpr = Call.getArgExpr(Idx);

487

489 continue;

490

491

492

494

498 std::make_pair(ParamLoc, processArgument(ArgVal, ArgExpr, *I, SVB)));

499 }

500

501

502}

503

506 if (!StackFrame)

507 return nullptr;

508

511 return Ctor->getConstructionContext();

512 }

513

515 return RecCall->getConstructionContext();

516 }

517

518 return nullptr;

519}

520

523 if (!CallLocationContext || CallLocationContext->inTopFrame())

524 return nullptr;

525

526 const auto *CallStackFrameContext = CallLocationContext->getStackFrame();

527 if (!CallStackFrameContext)

528 return nullptr;

529

530 CallEventManager &CEMgr = State->getStateManager().getCallEventManager();

531 return CEMgr.getCaller(CallStackFrameContext, State);

532}

533

536 return Caller->isInSystemHeader();

537

538 return false;

539}

540

543 if (!CC)

544 return std::nullopt;

545

547 ExprEngine &Engine = getState()->getStateManager().getOwningEngine();

551 return RetVal;

552}

553

556 if (D)

557 return {};

558 return D->parameters();

559}

560

563 if (!FD)

564 return {};

565

566

567

570 getManager()->getContext(FD);

571 bool IsAutosynthesized;

572 Stmt* Body = AD->getBody(IsAutosynthesized);

573 LLVM_DEBUG({

574 if (IsAutosynthesized)

575 llvm::dbgs() << "Using autosynthesized body for " << FD->getName()

576 << "\n";

577 });

578

579 ExprEngine &Engine = getState()->getStateManager().getOwningEngine();

581 *Engine.getCrossTranslationUnitContext();

582

583 AnalyzerOptions &Opts = Engine.getAnalysisManager().options;

584

585 if (Body) {

588

590 return {};

592 }

594 }

595

596

597 if (!Opts.IsNaiveCTUEnabled)

598 return {};

599

602 Opts.DisplayCTUProgress);

603

604 if (!CTUDeclOrError) {

605 handleAllErrors(CTUDeclOrError.takeError(),

607 CTUCtx.emitCrossTUDiagnostics(IE);

608 });

609 return {};

610 }

611

613}

614

618 const auto *D = cast(CalleeCtx->getDecl());

621 D->parameters());

622}

623

626 return true;

627

629 if (D)

630 return true;

631

633 if (!II)

634 return false;

635

636

637

638

639

640

641

642 if (II->isStr("pthread_setspecific"))

643 return true;

644

645

646

647 if (II->isStr("xpc_connection_set_context"))

648 return true;

649

650

651 if (II->isStr("funopen"))

652 return true;

653

654

655

656 if (II->isStr("__cxa_demangle"))

657 return true;

658

659 StringRef FName = II->getName();

660

661

662

663 if (FName.ends_with("NoCopy"))

664 return true;

665

666

667

668 if (FName.starts_with("NS") && FName.contains("Insert"))

669 return true;

670

671

672

673 if (FName.starts_with("CF") || FName.starts_with("CG")) {

674 return StrInStrNoCase(FName, "InsertValue") != StringRef::npos ||

675 StrInStrNoCase(FName, "AddValue") != StringRef::npos ||

676 StrInStrNoCase(FName, "SetValue") != StringRef::npos ||

677 StrInStrNoCase(FName, "WithData") != StringRef::npos ||

678 StrInStrNoCase(FName, "AppendValue") != StringRef::npos ||

679 StrInStrNoCase(FName, "SetAttribute") != StringRef::npos;

680 }

681

682 return false;

683}

684

687 if (D)

688 return D;

689

691}

692

694 const auto *CE = cast_or_null(getOriginExpr());

695 if (!CE)

697

699 if (D)

700 return D;

701

703}

704

708 Values.push_back(ThisVal);

709

710

711 if (const auto *D = cast_or_null(getDecl())) {

712 if (D->isConst())

713 return;

714

715

716

717

719 if (!ParentRecord || !ParentRecord->hasDefinition())

720 return;

721

723 return;

724

725

727 if (!ThisRegion)

728 return;

729

732 }

733}

734

737

739

740 if (isa(ThisVal)) {

743 return SVB.evalCast(ThisVal, Base->getType(), OriginalTy);

744 }

745

747 return ThisVal;

748}

749

750std::pair<const CXXRecordDecl *, bool>

753 if (!R)

754 return {};

755

758 return {};

759

763}

764

766

768 if (D)

769 return {};

770

771

772 const auto *MD = cast(D);

773 if (!MD->isVirtual())

775

777 if (!RD || !RD->hasDefinition())

778 return {};

779

780

781 const CXXMethodDecl *Result = MD->getCorrespondingMethodInClass(RD, true);

783

784

785

786

787 assert(!RD->isDerivedFrom(MD->getParent()) && "Couldn't find known method");

788

789

790

791

792

793

794

795

796

797 return {};

798 }

799

800

803 if (!CanBeSubClass)

805 return {};

806 }

807

808

809

810

811 if (CanBeSubClass)

815}

816

821

822

827

828 const auto *MD = cast(CalleeCtx->getDecl());

830

831

832

837

838

839 std::optional V =

841 if (V) {

842

843

844

848 ThisVal = SVB.evalCast(ThisVal, Ty, StaticTy);

849 } else

850 ThisVal = *V;

851 }

852

854 Bindings.push_back(std::make_pair(ThisLoc, ThisVal));

855 }

856}

857

860}

861

863

864

865

866

867 if (const auto *ME = dyn_cast(getOriginExpr()->getCallee()))

868 if (ME->hasQualifier())

870

872}

873

876}

877

881

882 return dyn_cast_or_null(DataReg);

883}

884

887 if (D)

888 return {};

889 return D->parameters();

890}

891

894

897}

898

904 auto *LambdaOperatorDecl = cast(CalleeCtx->getDecl());

905 Params = LambdaOperatorDecl->parameters();

906

907

908

909

912 Loc ThisLoc = SVB.getCXXThis(LambdaOperatorDecl, CalleeCtx);

913 Bindings.push_back(std::make_pair(ThisLoc, ThisVal));

914 } else {

915 Params = cast(CalleeCtx->getDecl())->parameters();

916 }

917

919 Params);

920}

921

926}

927

931 if (SymbolRef Sym = V.getAsSymbol(true))

934

935

937 if (const MemRegion *Obj = V.getAsRegion(); Obj && IsStdClassCtor) {

940 }

941

942 Values.push_back(V);

943}

944

949

953 const auto *MD = cast(CalleeCtx->getDecl());

955 Bindings.push_back(std::make_pair(ThisLoc, ThisVal));

956 }

957}

958

962 while (isa(SFC->getCallSite()))

964 return SFC;

965}

966

971}

972

974

975

978

980}

981

984 if (D)

985 return {};

986 return D->parameters();

987}

988

991

992

993

994

996 if (const ObjCIvarDecl *PropIvar = PropDecl->getPropertyIvarDecl()) {

1000 IvarRegion,

1003 IvarRegion,

1005 Values.push_back(IvarLVal);

1006 }

1007 return;

1008 }

1009 }

1010

1012}

1013

1015

1018

1021

1022

1023

1026 assert(SelfVal.isValid() && "Calling super but not in ObjC method");

1027 return SelfVal;

1028}

1029

1033 return true;

1034

1036 return false;

1037

1040

1041 return (RecVal == SelfVal);

1042}

1043

1050 return getContainingPseudoObjectExpr()->getSourceRange();

1051 }

1052 llvm_unreachable("unknown message kind");

1053}

1054

1056

1057const PseudoObjectExpr *ObjCMethodCall::getContainingPseudoObjectExpr() const {

1058 assert(Data && "Lazy lookup not yet performed.");

1060 return ObjCMessageDataTy::getFromOpaqueValue(Data).getPointer();

1061}

1062

1063static const Expr *

1066

1067

1068

1069 if (const auto *BO = dyn_cast(Syntactic))

1071

1072 return Syntactic;

1073}

1074

1076 if (Data) {

1077

1080

1081

1082 if (const auto *POE = dyn_cast_or_null(S)) {

1084

1087 case Stmt::ObjCPropertyRefExprClass:

1089 break;

1090 case Stmt::ObjCSubscriptRefExprClass:

1092 break;

1093 default:

1094

1096 break;

1097 }

1098

1103 return K;

1104 }

1105 }

1106

1111 }

1112

1114 if (!Info.getPointer())

1117}

1118

1120

1122 const PseudoObjectExpr *POE = getContainingPseudoObjectExpr();

1123 assert(POE && "Property access without PseudoObjectExpr?");

1124

1126 auto *RefExpr = cast(Syntactic);

1127

1128 if (RefExpr->isExplicitProperty())

1129 return RefExpr->getExplicitProperty();

1130 }

1131

1132

1135 return nullptr;

1136

1137

1139}

1140

1143 assert(IDecl);

1145 getState()->getStateManager().getOwningEngine().getAnalysisManager();

1146

1147

1148

1149

1152 return false;

1153

1154

1156 return false;

1157

1158

1159

1160

1161

1162

1163

1165 while (true) {

1167

1168

1169 if (D)

1170 return false;

1171

1172

1174 return true;

1175

1176 if (D->isOverriding()) {

1177

1178 IDecl = D->getClassInterface();

1179 if (!IDecl)

1180 return false;

1181

1183 if (!IDecl)

1184 return false;

1185

1186 continue;

1187 }

1188

1189 return false;

1190 };

1191

1192 llvm_unreachable("The while loop should always terminate.");

1193}

1194

1196 if (!MD)

1197 return MD;

1198

1199

1201 for (auto *I : MD->redecls())

1202 if (I->hasBody())

1203 MD = cast(I);

1204 }

1205 return MD;

1206}

1207

1212};

1213

1214namespace llvm {

1218

1220 return {InterfaceInfo::getEmptyKey(), SelectorInfo::getEmptyKey(), false};

1221 }

1222

1224 return {InterfaceInfo::getTombstoneKey(), SelectorInfo::getTombstoneKey(),

1225 true};

1226 }

1227

1229 return llvm::hash_combine(

1230 llvm::hash_code(InterfaceInfo::getHashValue(Key.Interface)),

1231 llvm::hash_code(SelectorInfo::getHashValue(Key.LookupSelector)),

1233 }

1234

1240 }

1241};

1242}

1243

1246 Selector LookupSelector, bool InstanceMethod) {

1247

1248

1249

1250

1251

1252

1253

1254

1255

1256

1257

1258

1259

1260

1261 using PrivateMethodCache =

1262 llvm::DenseMap<PrivateMethodKey, std::optional<const ObjCMethodDecl *>>;

1263

1264 static PrivateMethodCache PMC;

1265 std::optional<const ObjCMethodDecl *> &Val =

1266 PMC[{Interface, LookupSelector, InstanceMethod}];

1267

1268

1269 if (!Val) {

1270 Val = Interface->lookupPrivateMethod(LookupSelector, InstanceMethod);

1271

1272 if (!*Val) {

1273

1274 Val = Interface->lookupMethod(LookupSelector, InstanceMethod);

1275 }

1276 }

1277

1278 return *Val;

1279}

1280

1283 assert(E);

1284 Selector Sel = E->getSelector();

1285

1286 if (E->isInstanceMessage()) {

1287

1289 bool CanBeSubClassed = false;

1290 bool LookingForInstanceMethod = true;

1291 QualType SupersType = E->getSuperType();

1292 const MemRegion *Receiver = nullptr;

1293

1294 if (!SupersType.isNull()) {

1295

1296

1297

1298 ReceiverT = cast(SupersType)->getObjectType();

1299 } else {

1301 if (!Receiver)

1302 return {};

1303

1306 assert(isa(Receiver) &&

1307 "Unhandled untyped region class!");

1308 return {};

1309 }

1310

1313

1314 const auto *ReceiverDynT =

1315 dyn_cast(DynType.getCanonicalType());

1316

1317 if (ReceiverDynT) {

1318 ReceiverT = ReceiverDynT->getObjectType();

1319

1320

1321

1322

1324

1326

1327 if (Receiver == SelfVal.getAsRegion()) {

1329 }

1330

1331

1332

1337

1338 ReceiverT =

1340

1342

1343 LookingForInstanceMethod = false;

1344 }

1345 }

1346 }

1347

1348 if (CanBeSubClassed)

1350

1351

1352

1354 }

1355 }

1356

1357

1358 if (ReceiverT)

1362

1363 if (MD && !MD->hasBody())

1365

1366 if (CanBeSubClassed)

1368 else

1370 }

1371 } else {

1372

1373

1374

1376

1378 }

1379 }

1380

1381 return {};

1382}

1383

1389 return true;

1390 }

1391

1393}

1394

1398 const auto *D = cast(CalleeCtx->getDecl());

1401 D->parameters());

1402

1408 Bindings.push_back(std::make_pair(SelfLoc, SelfVal));

1409 }

1410}

1411

1416 if (const auto *MCE = dyn_cast(CE))

1417 return create(MCE, State, LCtx, ElemRef);

1418

1419 if (const auto *OpCE = dyn_cast(CE)) {

1420 const FunctionDecl *DirectCallee = OpCE->getDirectCallee();

1421 if (const auto *MD = dyn_cast(DirectCallee)) {

1422 if (MD->isImplicitObjectMemberFunction())

1423 return create(OpCE, State, LCtx, ElemRef);

1424 if (MD->isStatic())

1425 return create(OpCE, State, LCtx, ElemRef);

1426 }

1427

1429 return create(CE, State, LCtx, ElemRef);

1430 }

1431

1432

1433

1434 return create(CE, State, LCtx, ElemRef);

1435}

1436

1444 assert(CallerCtx && "This should not be used for top-level stack frames");

1445

1447

1448 if (CallSite) {

1450 return Out;

1451

1452 SValBuilder &SVB = State->getStateManager().getSValBuilder();

1453 const auto *Ctor = cast(CalleeCtx->getDecl());

1455 SVal ThisVal = State->getSVal(ThisPtr);

1456

1457 if (const auto *CE = dyn_cast(CallSite))

1459 ElemRef);

1460 else if (const auto *CIE = dyn_cast(CallSite))

1462 CallerCtx, ElemRef);

1463 else {

1464

1465 llvm_unreachable("This is not an inlineable statement");

1466 }

1467 }

1468

1469

1470

1474 "All other CFG elements should have exprs");

1475

1476 SValBuilder &SVB = State->getStateManager().getSValBuilder();

1477 const auto *Dtor = cast(CalleeCtx->getDecl());

1479 SVal ThisVal = State->getSVal(ThisPtr);

1480

1481 const Stmt *Trigger;

1482 if (std::optional AutoDtor =

1484 Trigger = AutoDtor->getTriggerStmt();

1485 else if (std::optional DeleteDtor = E.getAs<CFGDeleteDtor>())

1486 Trigger = DeleteDtor->getDeleteExpr();

1487 else

1488 Trigger = Dtor->getBody();

1489

1492 CallerCtx, ElemRef);

1493}

1494

1498 if (const auto *CE = dyn_cast(S)) {

1500 } else if (const auto *NE = dyn_cast(S)) {

1502 } else if (const auto *DE = dyn_cast(S)) {

1504 } else if (const auto *ME = dyn_cast(S)) {

1506 } else {

1507 return nullptr;

1508 }

1509}

Defines the clang::ASTContext interface.

This file defines AnalysisDeclContext, a class that manages the analysis context data for context sen...

static bool isZeroConstant(const llvm::Value *Value)

static bool isVoidPointerToNonConst(QualType T)

static const ObjCMethodDecl * findDefiningRedecl(const ObjCMethodDecl *MD)

static const ObjCMethodDecl * lookupRuntimeDefinition(const ObjCInterfaceDecl *Interface, Selector LookupSelector, bool InstanceMethod)

static void addParameterValuesToBindings(const StackFrameContext *CalleeCtx, CallEvent::BindingsTy &Bindings, SValBuilder &SVB, const CallEvent &Call, ArrayRef< ParmVarDecl * > parameters)

static const Expr * getSyntacticFromForPseudoObjectExpr(const PseudoObjectExpr *POE)

static bool isTransparentUnion(QualType T)

llvm::PointerIntPair< const PseudoObjectExpr *, 2 > ObjCMessageDataTy

static bool isCallback(QualType T)

static SVal castArgToParamTypeIfNeeded(const CallEvent &Call, unsigned ArgIdx, SVal ArgVal, SValBuilder &SVB)

Cast the argument value to the type of the parameter at the function declaration.

static SVal processArgument(SVal Value, const Expr *ArgumentExpr, const ParmVarDecl *Parameter, SValBuilder &SVB)

static void findPtrToConstParams(llvm::SmallSet< unsigned, 4 > &PreserveArgs, const CallEvent &Call)

Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....

Defines the clang::Expr interface and subclasses for C++ expressions.

Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.

static const Decl * getCanonicalDecl(const Decl *D)

Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.

Defines the clang::SourceLocation class and associated facilities.

Defines the SourceManager interface.

Defines various enumerations that describe declaration and type specifiers.

C Language Family Type Representation.

static bool isPointerToConst(const QualType &QT)

Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...

QualType getRecordType(const RecordDecl *Decl) const

QualType getPointerType(QualType T) const

Return the uniqued reference to the type for a pointer to the specified type.

QualType getReferenceQualifiedType(const Expr *e) const

getReferenceQualifiedType - Given an expr, will return the type for that expression,...

const clang::PrintingPolicy & getPrintingPolicy() const

AnalysisDeclContext * getContext(const Decl *D)

const StackFrameContext * getStackFrame(const Decl *D)

Obtain the beginning context of the analysis.

AnalysisDeclContext contains the context data for the function, method or block under analysis.

CFGStmtMap * getCFGStmtMap()

const Decl * getDecl() const

const ImplicitParamDecl * getSelfDecl() const

AnalysisDeclContextManager * getManager() const

Stores options for the analyzer from the command line.

Represents a block literal declaration, which is like an unnamed FunctionDecl.

Represents C++ object destructor implicitly generated for automatic object or temporary bound to cons...

Represents C++ object destructor implicitly generated for base object in destructor.

Represents a single basic block in a source-level CFG.

ElementRefImpl< true > ConstCFGElementRef

Represents a function call that returns a C++ object by value.

Represents C++ constructor call.

Represents C++ object destructor generated from a call to delete.

Represents a top-level expression in a basic block.

std::optional< T > getAs() const

Convert to the specified CFGElement type, returning std::nullopt if this CFGElement is not of the des...

Represents C++ object destructor implicitly generated by compiler on various occasions.

CFGBlock * getBlock(Stmt *S)

Returns the CFGBlock the specified Stmt* appears in.

Represents C++ object destructor implicitly generated at the end of full expression for temporary obj...

Expr * getImplicitObjectArgument() const

Retrieve the implicit object argument for the member call.

Represents a static or instance method of a struct/union/class.

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.

bool hasMutableFields() const

Determine whether this class, or any of its class subobjects, contains a mutable field.

bool hasDefinition() const

CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).

Expr * getArg(unsigned Arg)

getArg - Return the specified argument.

FunctionDecl * getDirectCallee()

If the callee is a FunctionDecl, return it. Otherwise return null.

ConstructionContext's subclasses describe different ways of constructing an object in C++.

Decl - This represents one declaration (or definition), e.g.

SourceLocation getLocation() const

redecl_range redecls() const

Returns an iterator range for all the redeclarations of the same decl.

void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const

This represents one expression.

Expr * IgnoreParens() LLVM_READONLY

Skip past any parentheses which might surround this expression until reaching a fixed point.

Represents a function declaration or definition.

FunctionType - C99 6.7.5.3 - Function Declarators.

One of these records is kept for each identifier that is lexed.

bool isStr(const char(&Str)[StrLen]) const

Return true if this is the identifier for the specified string.

StringRef getName() const

Return the actual identifier string.

It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...

const Decl * getDecl() const

const ParentMap & getParentMap() const

LLVM_ATTRIBUTE_RETURNS_NONNULL AnalysisDeclContext * getAnalysisDeclContext() const

const LocationContext * getParent() const

It might return null.

const StackFrameContext * getStackFrame() const

StringRef getName() const

Get the name of identifier for this declaration as a StringRef.

Represents an ObjC class declaration.

ObjCMethodDecl * lookupMethod(Selector Sel, bool isInstance, bool shallowCategoryLookup=false, bool followSuper=true, const ObjCCategoryDecl *C=nullptr) const

lookupMethod - This method returns an instance/class method by looking in the class,...

SourceLocation getEndOfDefinitionLoc() const

ObjCInterfaceDecl * getSuperClass() const

ObjCIvarDecl - Represents an ObjC instance variable.

An expression that sends a message to the given Objective-C object or class.

@ SuperInstance

The receiver is the instance of the superclass object.

@ SuperClass

The receiver is a superclass.

ObjCMethodDecl - Represents an instance or class method declaration.

bool hasBody() const override

Determine whether this method has a body.

bool isPropertyAccessor() const

const ObjCPropertyDecl * findPropertyDecl(bool CheckOverrides=true) const

Returns the property associated with this method's selector.

ObjCMethodDecl * getCanonicalDecl() override

Retrieves the "canonical" declaration of the given declaration.

Represents a class type in Objective C.

ObjCInterfaceDecl * getInterface() const

Gets the interface declaration for this object type, if the base type really is an interface.

Represents one property declaration in an Objective-C interface.

Stmt * getParentIgnoreParenCasts(Stmt *) const

Represents a parameter to a function.

PointerType - C99 6.7.5.1 - Pointer Declarators.

Represents a program point just after an implicit call event.

Represents a program point just before an implicit call event.

ProgramPoints can be "tagged" as representing points specific to a given analysis entity.

PseudoObjectExpr - An expression which accesses a pseudo-object l-value.

Expr * getSyntacticForm()

Return the syntactic form of this expression, i.e.

A (possibly-)qualified type.

bool isNull() const

Return true if this QualType doesn't point to a type yet.

QualType getCanonicalType() const

bool isConstQualified() const

Determine whether this type is const-qualified.

Represents a struct/union/class.

field_range fields() const

A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...

RecordDecl * getDecl() const

Smart pointer class that efficiently represents Objective-C method names.

const IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const

Retrieve the identifier at a given position in the selector.

unsigned getNumArgs() const

Encodes a location in the source.

bool isValid() const

Return true if this is a valid SourceLocation object.

A trivial tuple used to represent a source range.

SourceLocation getBegin() const

It represents a stack frame of the call stack (based on CallEvent).

unsigned getIndex() const

CFGElement getCallSiteCFGElement() const

const Stmt * getCallSite() const

const CFGBlock * getCallSiteBlock() const

Stmt - This represents one statement.

void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const

StmtClass getStmtClass() const

SourceRange getSourceRange() const LLVM_READONLY

SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...

A container of type source information.

bool isBlockPointerType() const

const RecordType * getAsUnionType() const

NOTE: getAs*ArrayType are methods on ASTContext.

bool isFunctionPointerType() const

bool isObjCSelType() const

bool isReferenceType() const

const CXXRecordDecl * getPointeeCXXRecordDecl() const

If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to.

QualType getPointeeType() const

If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.

bool isDependentType() const

Whether this type is a dependent type, meaning that its definition somehow depends on a template para...

const RecordType * getAsStructureType() const

bool isAnyPointerType() const

const T * getAs() const

Member-template getAs'.

Represents a variable declaration or definition.

This class is used for tools that requires cross translation unit capability.

llvm::Expected< const FunctionDecl * > getCrossTUDefinition(const FunctionDecl *FD, StringRef CrossTUDir, StringRef IndexName, bool DisplayCTUProgress=false)

This function loads a function or variable definition from an external AST file and merges it into th...

bool hasError(const Decl *ToDecl) const

Returns true if the given Decl is mapped (or created) during an import but there was an unrecoverable...

bool isImportedAsNew(const Decl *ToDecl) const

Returns true if the given Decl is newly created during the import.

static bool isInCodeFile(SourceLocation SL, const SourceManager &SM)

void getInitialStackFrameContents(const StackFrameContext *CalleeCtx, BindingsTy &Bindings) const override

Populates the given SmallVector with the bindings in the callee's stack frame at the start of this ca...

void getExtraInvalidatedValues(ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const override

Used to specify non-argument regions that will be invalidated as a result of this call.

SVal getCXXThisVal() const

Returns the value of the implicit 'this' object.

const FunctionDecl * getDecl() const override

Returns the declaration of the function or method that will be called.

ArrayRef< ParmVarDecl * > parameters() const override

Return call's formal parameters.

void getInitialStackFrameContents(const StackFrameContext *CalleeCtx, BindingsTy &Bindings) const override

Populates the given SmallVector with the bindings in the callee's stack frame at the start of this ca...

bool argumentsMayEscape() const override

Returns true if any of the arguments are known to escape to long- term storage, even if this method w...

RuntimeDefinition getRuntimeDefinition() const override

Returns the definition of the function or method that will be called.

llvm::ImmutableList< SVal > getEmptySValList()

llvm::ImmutableList< SVal > prependSVal(SVal X, llvm::ImmutableList< SVal > L)

const BlockDecl * getDecl() const override

Returns the declaration of the function or method that will be called.

const BlockDataRegion * getBlockRegion() const

Returns the region associated with this instance of the block.

bool isConversionFromLambda() const

ArrayRef< ParmVarDecl * > parameters() const override

Return call's formal parameters.

void getExtraInvalidatedValues(ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const override

Used to specify non-argument regions that will be invalidated as a result of this call.

const VarRegion * getRegionStoringCapturedLambda() const

For a block converted from a C++ lambda, returns the block VarRegion for the variable holding the cap...

void getInitialStackFrameContents(const StackFrameContext *CalleeCtx, BindingsTy &Bindings) const override

Populates the given SmallVector with the bindings in the callee's stack frame at the start of this ca...

const CallExpr * getOriginExpr() const override

Returns the expression whose value will be the result of this call.

BlockDataRegion - A region that represents a block instance.

SVal getCXXThisVal() const override

Returns the value of the implicit 'this' object.

RuntimeDefinition getRuntimeDefinition() const override

Returns the definition of the function or method that will be called.

bool isBaseDestructor() const

Returns true if this is a call to a base class destructor.

const StackFrameContext * getInheritingStackFrame() const

Obtain the stack frame of the inheriting constructor.

std::pair< const CXXRecordDecl *, bool > getDeclForDynamicType() const

Returns the decl refered to by the "dynamic type" of the current object and if the class can be a sub...

void getExtraInvalidatedValues(ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const override

Used to specify non-argument regions that will be invalidated as a result of this call.

virtual SVal getCXXThisVal() const

Returns the value of the implicit 'this' object.

RuntimeDefinition getRuntimeDefinition() const override

Returns the definition of the function or method that will be called.

virtual const Expr * getCXXThisExpr() const

Returns the expression representing the implicit 'this' object.

const FunctionDecl * getDecl() const override

Returns the declaration of the function or method that will be called.

void getInitialStackFrameContents(const StackFrameContext *CalleeCtx, BindingsTy &Bindings) const override

Populates the given SmallVector with the bindings in the callee's stack frame at the start of this ca...

const CXXMemberCallExpr * getOriginExpr() const override

Returns the expression whose value will be the result of this call.

const Expr * getCXXThisExpr() const override

Returns the expression representing the implicit 'this' object.

RuntimeDefinition getRuntimeDefinition() const override

Returns the definition of the function or method that will be called.

const Expr * getCXXThisExpr() const override

Returns the expression representing the implicit 'this' object.

const CXXOperatorCallExpr * getOriginExpr() const override

Returns the expression whose value will be the result of this call.

Manages the lifetime of CallEvent objects.

CallEventRef< CXXDestructorCall > getCXXDestructorCall(const CXXDestructorDecl *DD, const Stmt *Trigger, const MemRegion *Target, bool IsBase, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)

CallEventRef getCall(const Stmt *S, ProgramStateRef State, const LocationContext *LC, CFGBlock::ConstCFGElementRef ElemRef)

Gets a call event for a function call, Objective-C method call, a 'new', or a 'delete' call.

CallEventRef< CXXDeallocatorCall > getCXXDeallocatorCall(const CXXDeleteExpr *E, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)

CallEventRef getSimpleCall(const CallExpr *E, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)

CallEventRef< ObjCMethodCall > getObjCMethodCall(const ObjCMessageExpr *E, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)

CallEventRef< CXXAllocatorCall > getCXXAllocatorCall(const CXXNewExpr *E, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)

CallEventRef< CXXConstructorCall > getCXXConstructorCall(const CXXConstructExpr *E, const MemRegion *Target, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)

CallEventRef< CXXInheritedConstructorCall > getCXXInheritedConstructorCall(const CXXInheritedCtorInitExpr *E, const MemRegion *Target, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)

CallEventRef getCaller(const StackFrameContext *CalleeCtx, ProgramStateRef State)

Gets an outside caller given a callee context.

Represents an abstract call to a function or method along a particular path.

virtual SourceRange getArgSourceRange(unsigned Index) const

Returns the source range for errors associated with this argument.

virtual void getExtraInvalidatedValues(ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const

Used to specify non-argument regions that will be invalidated as a result of this call.

virtual StringRef getKindAsString() const =0

virtual const Expr * getOriginExpr() const

Returns the expression whose value will be the result of this call.

static bool isCallStmt(const Stmt *S)

Returns true if this is a statement is a function or method call of some kind.

llvm::mapped_iterator< ArrayRef< ParmVarDecl * >::iterator, GetTypeFn > param_type_iterator

const ConstructionContext * getConstructionContext() const

Returns the construction context of the call, if it is a C++ constructor call or a call of a function...

param_type_iterator param_type_end() const

const ParamVarRegion * getParameterLocation(unsigned Index, unsigned BlockCount) const

Returns memory location for a parameter variable within the callee stack frame.

bool isCalledFromSystemHeader() const

AnalysisDeclContext * getCalleeAnalysisDeclContext() const

Returns AnalysisDeclContext for the callee stack frame.

ProgramStateRef invalidateRegions(unsigned BlockCount, ProgramStateRef Orig=nullptr) const

Returns a new state with all argument regions invalidated.

virtual std::optional< unsigned > getAdjustedParameterIndex(unsigned ASTArgumentIndex) const

Some calls have parameter numbering mismatched from argument numbering.

const ProgramStateRef & getState() const

The state in which the call is being evaluated.

QualType getResultType() const

Returns the result type, adjusted for references.

bool isInSystemHeader() const

Returns true if the callee is known to be from a system header.

bool isGlobalCFunction(StringRef SpecificName=StringRef()) const

Returns true if the callee is an externally-visible function in the top-level namespace,...

virtual bool argumentsMayEscape() const

Returns true if any of the arguments are known to escape to long- term storage, even if this method w...

param_type_iterator param_type_begin() const

Returns an iterator over the types of the call's formal parameters.

ProgramPoint getProgramPoint(bool IsPreVisit=false, const ProgramPointTag *Tag=nullptr) const

Returns an appropriate ProgramPoint for this call.

const StackFrameContext * getCalleeStackFrame(unsigned BlockCount) const

Returns the callee stack frame.

static QualType getDeclaredResultType(const Decl *D)

Returns the result type of a function or method declaration.

SVal getSVal(const Stmt *S) const

Get the value of arbitrary expressions at this point in the path.

static bool isVariadic(const Decl *D)

Returns true if the given decl is known to be variadic.

virtual SVal getArgSVal(unsigned Index) const

Returns the value of a given argument at the time of the call.

bool hasNonNullArgumentsWithType(bool(*Condition)(QualType)) const

Returns true if the type of any of the non-null arguments satisfies the condition.

std::optional< SVal > getReturnValueUnderConstruction() const

If the call returns a C++ record type then the region of its return value can be retrieved from its c...

virtual const Expr * getArgExpr(unsigned Index) const

Returns the expression associated with a given argument.

virtual unsigned getNumArgs() const =0

Returns the number of arguments (explicit and implicit).

bool hasVoidPointerToNonConstArg() const

Returns true if any of the arguments is void*.

const CallEventRef getCaller() const

bool isArgumentConstructedDirectly(unsigned Index) const

Returns true if on the current path, the argument was constructed by calling a C++ constructor over i...

SVal getReturnValue() const

Returns the return value of the call.

virtual const Decl * getDecl() const

Returns the declaration of the function or method that will be called.

const LocationContext * getLocationContext() const

The context in which the call is being evaluated.

bool hasNonZeroCallbackArg() const

Returns true if any of the arguments appear to represent callbacks.

virtual Kind getKind() const =0

Returns the kind of call this is.

virtual SourceRange getSourceRange() const

Returns a source range for the entire call, suitable for outputting in diagnostics.

static bool isCLibraryFunction(const FunctionDecl *FD, StringRef Name=StringRef())

Returns true if the given function is an externally-visible function in the top-level namespace,...

Stores the currently inferred strictest bound on the runtime type of a region in a given state along ...

bool canBeASubClass() const

Returns false if the type information is precise (the type 'DynTy' is the only type in the lattice),...

QualType getType() const

Returns the currently inferred upper bound on the runtime type.

bool isValid() const

Returns true if the dynamic type info is available.

SVal computeObjectUnderConstruction(const Expr *E, ProgramStateRef State, const NodeBuilderContext *BldrCtx, const LocationContext *LCtx, const ConstructionContext *CC, EvalCallOptions &CallOpts, unsigned Idx=0)

Find location of the object that is being constructed by a given constructor.

const NodeBuilderContext & getBuilderContext()

const VarRegion * getVarRegion(const VarDecl *VD, const LocationContext *LC)

getVarRegion - Retrieve or create the memory region associated with a specified VarDecl and LocationC...

const ParamVarRegion * getParamVarRegion(const Expr *OriginExpr, unsigned Index, const LocationContext *LC)

getParamVarRegion - Retrieve or create the memory region associated with a specified CallExpr,...

MemRegion - The root abstract class for all memory regions.

LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * getBaseRegion() const

Represents any expression that calls an Objective-C method.

const ObjCMethodDecl * getDecl() const override

Returns the declaration of the function or method that will be called.

void getExtraInvalidatedValues(ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const override

Used to specify non-argument regions that will be invalidated as a result of this call.

bool isInstanceMessage() const

ObjCMessageKind getMessageKind() const

Returns how the message was written in the source (property access, subscript, or explicit message se...

const ObjCMessageExpr * getOriginExpr() const override

Returns the expression whose value will be the result of this call.

ArrayRef< ParmVarDecl * > parameters() const override

Return call's formal parameters.

SourceRange getSourceRange() const override

Returns a source range for the entire call, suitable for outputting in diagnostics.

virtual bool canBeOverridenInSubclass(ObjCInterfaceDecl *IDecl, Selector Sel) const

Check if the selector may have multiple definitions (may have overrides).

bool argumentsMayEscape() const override

Returns true if any of the arguments are known to escape to long- term storage, even if this method w...

SVal getReceiverSVal() const

Returns the value of the receiver at the time of this call.

RuntimeDefinition getRuntimeDefinition() const override

Returns the definition of the function or method that will be called.

bool isReceiverSelfOrSuper() const

Checks if the receiver refers to 'self' or 'super'.

Selector getSelector() const

const ObjCPropertyDecl * getAccessedProperty() const

void getInitialStackFrameContents(const StackFrameContext *CalleeCtx, BindingsTy &Bindings) const override

Populates the given SmallVector with the bindings in the callee's stack frame at the start of this ca...

ParamVarRegion - Represents a region for paremters.

SValBuilder & getSValBuilder()

StoreManager & getStoreManager()

Information about invalidation for a particular region/symbol.

@ TK_PreserveContents

Tells that a region's contents is not changed.

@ TK_DoNotInvalidateSuperRegion

@ TK_SuppressEscape

Suppress pointer-escaping of a region.

void setTrait(SymbolRef Sym, InvalidationKinds IK)

Defines the runtime definition of the called function.

BasicValueFactory & getBasicValueFactory()

NonLoc makeCompoundVal(QualType type, llvm::ImmutableList< SVal > vals)

MemRegionManager & getRegionManager()

ASTContext & getContext()

loc::MemRegionVal makeLoc(SymbolRef sym)

SVal evalCast(SVal V, QualType CastTy, QualType OriginalTy)

Cast a given SVal to another SVal using given QualType's.

loc::MemRegionVal getCXXThis(const CXXMethodDecl *D, const StackFrameContext *SFC)

Return a memory region for the 'this' object reference.

SVal - This represents a symbolic expression, which can be either an L-value or an R-value.

bool isUnknownOrUndef() const

const FunctionDecl * getAsFunctionDecl() const

getAsFunctionDecl - If this SVal is a MemRegionVal and wraps a CodeTextRegion wrapping a FunctionDecl...

QualType getType(const ASTContext &) const

Try to get a reasonable type for the given value.

const MemRegion * getAsRegion() const

const CallExpr * getOriginExpr() const override

Returns the expression whose value will be the result of this call.

const FunctionDecl * getDecl() const override

Returns the declaration of the function or method that will be called.

std::optional< SVal > evalBaseToDerived(SVal Base, QualType DerivedPtrType)

Attempts to do a down cast.

TypedValueRegion - An abstract class representing regions having a typed value.

bool isWithinStdNamespace(const Decl *D)

Returns true if declaration D is in std namespace or any nested namespace or class scope.

DynamicTypeInfo getDynamicTypeInfo(ProgramStateRef State, const MemRegion *MR)

Get dynamic type information for the region MR.

ObjCMessageKind

Represents the ways an Objective-C message send can occur.

DynamicTypeInfo getClassObjectDynamicTypeInfo(ProgramStateRef State, SymbolRef Sym)

Get dynamic type information stored in a class object represented by Sym.

The JSON file list parser is used to communicate input to InstallAPI.

@ Parameter

The parameter type of a method or function.

@ Result

The result type of a method or function.

const FunctionProtoType * T

@ Interface

The "__interface" keyword introduces the elaborated-type-specifier.

@ Class

The "class" keyword introduces the elaborated-type-specifier.

Diagnostic wrappers for TextAPI types for error reporting.

const ObjCInterfaceDecl * Interface

Hints for figuring out of a call should be inlined during evalCall().

DenseMapInfo< Selector > SelectorInfo

static unsigned getHashValue(const PrivateMethodKey &Key)

static PrivateMethodKey getEmptyKey()

DenseMapInfo< const ObjCInterfaceDecl * > InterfaceInfo

static bool isEqual(const PrivateMethodKey &LHS, const PrivateMethodKey &RHS)

static PrivateMethodKey getTombstoneKey()