clang 24.0.0git
ExprEngineC.cpp
Go to the documentation of this file.
1//=-- ExprEngineC.cpp - ExprEngine support for C expressions ----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines ExprEngine's support for C expressions.
10//
11//===----------------------------------------------------------------------===//
12
13#include "clang/AST/DeclCXX.h"
14#include "clang/AST/ExprCXX.h"
17#include <optional>
18
19using namespace clang;
20using namespace ento;
21using llvm::APSInt;
22
24 ExplodedNode *Pred,
25 ExplodedNodeSet &Dst) {
26 const StackFrame *SF = Pred->getStackFrame();
27
28 Expr *LHS = B->getLHS()->IgnoreParens();
29 Expr *RHS = B->getRHS()->IgnoreParens();
30
31 // FIXME: Prechecks eventually go in ::Visit().
32 ExplodedNodeSet CheckedSet;
33 ExplodedNodeSet Tmp2;
34 getCheckerManager().runCheckersForPreStmt(CheckedSet, Pred, B, *this);
35
36 // With both the LHS and RHS evaluated, process the operation itself.
37 for (ExplodedNode *N : CheckedSet) {
38 ProgramStateRef State = N->getState();
39 SVal LeftV = State->getSVal(LHS, SF);
40 SVal RightV = State->getSVal(RHS, SF);
41
43
44 if (Op == BO_Assign) {
45 if (RightV.isUnknown()) {
46 unsigned Count = getNumVisitedCurrent();
47 RightV = svalBuilder.conjureSymbolVal(nullptr, getCFGElementRef(), SF,
48 Count);
49 }
50 // Simulate the effects of a "store": bind the value of the RHS
51 // to the L-Value represented by the LHS.
52 SVal ExprVal = B->isGLValue() ? LeftV : RightV;
53 evalStore(Tmp2, B, LHS, N, State->BindExpr(B, SF, ExprVal), LeftV,
54 RightV);
55 continue;
56 }
57
58 if (!B->isAssignmentOp()) {
59 if (B->isAdditiveOp()) {
60 // Ensure that if `p` is a pointer and `i` is an integer with Unknown
61 // value, then `p+i`, `i+p` and `p-i` are evaluated to element regions
62 // (with a symbolic offset) instead of Unknown.
63 auto ConjureIfNeeded = [this, SF](SVal &V, SVal Other, QualType VTy) {
64 if (isa<Loc>(Other) && VTy->isIntegralOrEnumerationType() &&
65 V.isUnknown()) {
66 V = svalBuilder.conjureSymbolVal(getCFGElementRef(), SF, VTy,
68 }
69 };
70 ConjureIfNeeded(RightV, LeftV, RHS->getType());
71 ConjureIfNeeded(LeftV, RightV, LHS->getType());
72 }
73
74 // Although we don't yet model pointers-to-members, we do need to make
75 // sure that the members of temporaries have a valid 'this' pointer for
76 // other checks.
77 if (B->getOpcode() == BO_PtrMemD)
78 State = createTemporaryRegionIfNeeded(State, SF, LHS);
79
80 // Process non-assignments except commas or short-circuited
81 // logical expressions (LAnd and LOr).
82 SVal Result = evalBinOp(State, Op, LeftV, RightV, B->getType());
83 if (!Result.isUnknown()) {
84 State = State->BindExpr(B, SF, Result);
85 } else {
86 // If we cannot evaluate the operation escape the operands.
87 State = escapeValues(State, LeftV, PSK_EscapeOther);
88 State = escapeValues(State, RightV, PSK_EscapeOther);
89 }
90
91 Tmp2.insert(Engine.makePostStmtNode(B, State, N));
92 continue;
93 }
94
95 assert (B->isCompoundAssignmentOp());
96
97 switch (Op) {
98 default:
99 llvm_unreachable("Invalid opcode for compound assignment.");
100 case BO_MulAssign: Op = BO_Mul; break;
101 case BO_DivAssign: Op = BO_Div; break;
102 case BO_RemAssign: Op = BO_Rem; break;
103 case BO_AddAssign: Op = BO_Add; break;
104 case BO_SubAssign: Op = BO_Sub; break;
105 case BO_ShlAssign: Op = BO_Shl; break;
106 case BO_ShrAssign: Op = BO_Shr; break;
107 case BO_AndAssign: Op = BO_And; break;
108 case BO_XorAssign: Op = BO_Xor; break;
109 case BO_OrAssign: Op = BO_Or; break;
110 }
111
112 // Perform a load (the LHS). This performs the checks for
113 // null dereferences, and so on.
114 ExplodedNodeSet Tmp;
115 evalLoad(Tmp, B, LHS, N, State, LeftV);
116
117 for (ExplodedNode *N : Tmp) {
118 State = N->getState();
119 SVal V = State->getSVal(LHS, SF);
120
121 // Determine the relevant types.
122 const ASTContext &ACtx = getContext();
123 const auto *CAOpB = cast<CompoundAssignOperator>(B);
124 QualType CTy = ACtx.getCanonicalType(CAOpB->getComputationResultType());
125 QualType CLHSTy = ACtx.getCanonicalType(CAOpB->getComputationLHSType());
126 QualType LTy = ACtx.getCanonicalType(LHS->getType());
127
128 // Promote LHS.
129 V = svalBuilder.evalCast(V, CLHSTy, LTy);
130
131 // Compute the result of the operation.
132 SVal Result = svalBuilder.evalCast(evalBinOp(State, Op, V, RightV, CTy),
133 B->getType(), CTy);
134
135 SVal StoredInLeftV;
136
137 if (Result.isUnknown()) {
138 // The symbolic value is actually for the type of the left-hand side
139 // expression, not the computation type, as this is the value the
140 // LValue on the LHS will bind to.
141 StoredInLeftV = svalBuilder.conjureSymbolVal(
142 /*symbolTag=*/nullptr, getCFGElementRef(), SF, LTy,
144 // However, we need to convert the symbol to the computation type.
145 Result = svalBuilder.evalCast(StoredInLeftV, CTy, LTy);
146 } else {
147 // The left-hand side may bind to a different value then the
148 // computation type.
149 StoredInLeftV = svalBuilder.evalCast(Result, LTy, CTy);
150 }
151
152 // In C++, assignment and compound assignment operators return an
153 // lvalue.
154 if (B->isGLValue())
155 State = State->BindExpr(B, SF, LeftV);
156 else
157 State = State->BindExpr(B, SF, Result);
158
159 evalStore(Tmp2, B, LHS, N, State, LeftV, StoredInLeftV);
160 }
161 }
162
163 ExplodedNodeSet AssumedSet;
164 if (AMgr.options.ShouldEagerlyAssume &&
165 (B->isRelationalOp() || B->isEqualityOp())) {
166 evalEagerlyAssumeBifurcation(AssumedSet, Tmp2, B);
167 } else {
168 AssumedSet.insert(Tmp2);
169 }
170 // FIXME: postvisits eventually go in ::Visit()
171 getCheckerManager().runCheckersForPostStmt(Dst, AssumedSet, B, *this);
172}
173
175 ExplodedNodeSet &Dst) {
176
178
179 const BlockDecl *BD = BE->getBlockDecl();
180 // Get the value of the block itself.
181 SVal V = svalBuilder.getBlockPointer(BD, T, Pred->getStackFrame(),
183
184 ProgramStateRef State = Pred->getState();
185
186 // If we created a new MemRegion for the block, we should explicitly bind
187 // the captured variables.
188 if (const BlockDataRegion *BDR =
189 dyn_cast_or_null<BlockDataRegion>(V.getAsRegion())) {
190
191 auto ReferencedVars = BDR->referenced_vars();
192 auto CI = BD->capture_begin();
193 auto CE = BD->capture_end();
194 for (auto Var : ReferencedVars) {
195 const VarRegion *capturedR = Var.getCapturedRegion();
196 const TypedValueRegion *originalR = Var.getOriginalRegion();
197
198 // If the capture had a copy expression, use the result of evaluating
199 // that expression, otherwise use the original value.
200 // We rely on the invariant that the block declaration's capture variables
201 // are a prefix of the BlockDataRegion's referenced vars (which may include
202 // referenced globals, etc.) to enable fast lookup of the capture for a
203 // given referenced var.
204 const Expr *copyExpr = nullptr;
205 if (CI != CE) {
206 assert(CI->getVariable() == capturedR->getDecl());
207 copyExpr = CI->getCopyExpr();
208 CI++;
209 }
210
211 if (capturedR != originalR) {
212 SVal originalV;
213 const StackFrame *SF = Pred->getStackFrame();
214 if (copyExpr) {
215 originalV = State->getSVal(copyExpr, SF);
216 } else {
217 originalV = State->getSVal(loc::MemRegionVal(originalR));
218 }
219 State = State->bindLoc(loc::MemRegionVal(capturedR), originalV, SF);
220 }
221 }
222 }
223
224 Dst.insert(Engine.makeNodeWithBinding(Pred, BE, V, State,
226}
227
229 const StackFrame *SF, QualType T,
230 QualType ExTy, const CastExpr *CastE,
231 ExplodedNodeSet &Dst, ExplodedNode *Pred) {
232 if (T->isLValueReferenceType()) {
233 assert(!CastE->getType()->isLValueReferenceType());
234 ExTy = getContext().getLValueReferenceType(ExTy);
235 } else if (T->isRValueReferenceType()) {
236 assert(!CastE->getType()->isRValueReferenceType());
237 ExTy = getContext().getRValueReferenceType(ExTy);
238 }
239 // Delegate to SValBuilder to process.
240 SVal OrigV = state->getSVal(Ex, SF);
241 SVal SimplifiedOrigV = svalBuilder.simplifySVal(state, OrigV);
242 SVal V = svalBuilder.evalCast(SimplifiedOrigV, T, ExTy);
243 // Negate the result if we're treating the boolean as a signed i1
244 if (CastE->getCastKind() == CK_BooleanToSignedIntegral && V.isValid())
245 V = svalBuilder.evalMinus(V.castAs<NonLoc>());
246
247 state = state->BindExpr(CastE, SF, V);
248 if (V.isUnknown() && !OrigV.isUnknown()) {
249 state = escapeValues(state, OrigV, PSK_EscapeOther);
250 }
251 Dst.insert(Engine.makePostStmtNode(CastE, state, Pred));
252}
253
255 ExplodedNodeSet &Dst) {
256 const Expr *Ex = CastE->getSubExpr();
257 ProgramStateRef State = Pred->getState();
258 const StackFrame *SF = Pred->getStackFrame();
259
260 if (CastE->getCastKind() == CK_LValueToRValue) {
261 evalLoad(Dst, CastE, CastE, Pred, State, State->getSVal(Ex, SF));
262 return;
263 }
264 if (CastE->getCastKind() == CK_LValueToRValueBitCast) {
265 // Handle `__builtin_bit_cast`:
266 ExplodedNodeSet DstEvalLoc;
267
268 // Simulate the lvalue-to-rvalue conversion on `Ex`:
269 evalLocation(DstEvalLoc, CastE, Ex, Pred, State, State->getSVal(Ex, SF),
270 true);
271 // Simulate the operation that actually casts the original value to a new
272 // value of the destination type :
273
274 for (ExplodedNode *Node : DstEvalLoc) {
275 ProgramStateRef State = Node->getState();
276 const StackFrame *SF = Node->getStackFrame();
277 // Although `Ex` is an lvalue, it could have `Loc::ConcreteInt` kind
278 // (e.g., `(int *)123456`). In such cases, there is no MemRegion
279 // available and we can't get the value to be casted.
280 SVal CastedV = UnknownVal();
281
282 if (const MemRegion *MR = State->getSVal(Ex, SF).getAsRegion()) {
283 SVal OrigV = State->getSVal(MR);
284 CastedV = svalBuilder.evalCast(svalBuilder.simplifySVal(State, OrigV),
285 CastE->getType(), Ex->getType());
286 }
287 Dst.insert(Engine.makeNodeWithBinding(Node, CastE, CastedV));
288 }
289 return;
290 }
291
292 // All other casts.
293 QualType T = CastE->getType();
294 QualType ExTy = Ex->getType();
295
296 if (const ExplicitCastExpr *ExCast=dyn_cast_or_null<ExplicitCastExpr>(CastE))
297 T = ExCast->getTypeAsWritten();
298
299 switch (CastE->getCastKind()) {
300 case CK_LValueToRValue:
301 case CK_LValueToRValueBitCast:
302 llvm_unreachable("LValueToRValue casts handled earlier.");
303 case CK_ToVoid:
304 Dst.insert(Pred);
305 return;
306 // The analyzer doesn't do anything special with these casts,
307 // since it understands retain/release semantics already.
308 case CK_ARCProduceObject:
309 case CK_ARCConsumeObject:
310 case CK_ARCReclaimReturnedObject:
311 case CK_ARCExtendBlockObject: // Fall-through.
312 case CK_CopyAndAutoreleaseBlockObject:
313 // The analyser can ignore atomic casts for now, although some future
314 // checkers may want to make certain that you're not modifying the same
315 // value through atomic and nonatomic pointers.
316 case CK_AtomicToNonAtomic:
317 case CK_NonAtomicToAtomic:
318 // True no-ops.
319 case CK_NoOp:
320 case CK_ConstructorConversion:
321 case CK_UserDefinedConversion:
322 case CK_FunctionToPointerDecay:
323 case CK_BuiltinFnToFnPtr:
324 case CK_HLSLArrayRValue: {
325 // Copy the SVal of Ex to CastE.
326 SVal V = State->getSVal(Ex, SF);
327 Dst.insert(Engine.makeNodeWithBinding(Pred, CastE, V));
328 return;
329 }
330 case CK_MemberPointerToBoolean:
331 case CK_PointerToBoolean: {
332 SVal V = State->getSVal(Ex, SF);
333 auto PTMSV = V.getAs<nonloc::PointerToMember>();
334 if (PTMSV)
335 V = svalBuilder.makeTruthVal(!PTMSV->isNullMemberPointer(), ExTy);
336 if (V.isUndef() || PTMSV) {
337 Dst.insert(Engine.makeNodeWithBinding(Pred, CastE, V));
338 return;
339 }
340 handleLValueBitCast(State, Ex, SF, T, ExTy, CastE, Dst, Pred);
341 return;
342 }
343 case CK_Dependent:
344 case CK_ArrayToPointerDecay:
345 case CK_BitCast:
346 case CK_AddressSpaceConversion:
347 case CK_BooleanToSignedIntegral:
348 case CK_IntegralToPointer:
349 case CK_PointerToIntegral: {
350 SVal V = State->getSVal(Ex, SF);
352 Dst.insert(Engine.makeNodeWithBinding(Pred, CastE, UnknownVal()));
353 return;
354 }
355 handleLValueBitCast(State, Ex, SF, T, ExTy, CastE, Dst, Pred);
356 return;
357 }
358 case CK_IntegralToBoolean:
359 case CK_IntegralToFloating:
360 case CK_FloatingToIntegral:
361 case CK_FloatingToBoolean:
362 case CK_FloatingCast:
363 case CK_FloatingRealToComplex:
364 case CK_FloatingComplexToReal:
365 case CK_FloatingComplexToBoolean:
366 case CK_FloatingComplexCast:
367 case CK_FloatingComplexToIntegralComplex:
368 case CK_IntegralRealToComplex:
369 case CK_IntegralComplexToReal:
370 case CK_IntegralComplexToBoolean:
371 case CK_IntegralComplexCast:
372 case CK_IntegralComplexToFloatingComplex:
373 case CK_CPointerToObjCPointerCast:
374 case CK_BlockPointerToObjCPointerCast:
375 case CK_AnyPointerToBlockPointerCast:
376 case CK_ObjCObjectLValueCast:
377 case CK_ZeroToOCLOpaqueType:
378 case CK_IntToOCLSampler:
379 case CK_LValueBitCast:
380 case CK_FloatingToFixedPoint:
381 case CK_FixedPointToFloating:
382 case CK_FixedPointCast:
383 case CK_FixedPointToBoolean:
384 case CK_FixedPointToIntegral:
385 case CK_IntegralToFixedPoint: {
386 handleLValueBitCast(State, Ex, SF, T, ExTy, CastE, Dst, Pred);
387 return;
388 }
389 case CK_IntegralCast: {
390 // Delegate to SValBuilder to process.
391 SVal V = State->getSVal(Ex, SF);
392 if (AMgr.options.analyzerSymbolicIntegerCasts())
393 V = svalBuilder.evalCast(V, T, ExTy);
394 else
395 V = svalBuilder.evalIntegralCast(State, V, T, ExTy);
396 Dst.insert(Engine.makeNodeWithBinding(Pred, CastE, V));
397 return;
398 }
399 case CK_DerivedToBase:
400 case CK_UncheckedDerivedToBase: {
401 // For DerivedToBase cast, delegate to the store manager.
402 SVal val = State->getSVal(Ex, SF);
403 val = getStoreManager().evalDerivedToBase(val, CastE);
404 Dst.insert(Engine.makeNodeWithBinding(Pred, CastE, val));
405 return;
406 }
407 // Handle C++ dyn_cast.
408 case CK_Dynamic: {
409 SVal val = State->getSVal(Ex, SF);
410
411 // Compute the type of the result.
412 QualType resultType = CastE->getType();
413 if (CastE->isGLValue())
414 resultType = getContext().getPointerType(resultType);
415
416 bool Failed = true;
417
418 // Check if the value being cast does not evaluates to 0.
419 if (!val.isZeroConstant())
420 if (std::optional<SVal> V =
421 StateMgr.getStoreManager().evalBaseToDerived(val, T)) {
422 val = *V;
423 Failed = false;
424 }
425
426 if (Failed) {
427 if (T->isReferenceType()) {
428 // A bad_cast exception is thrown if input value is a reference.
429 // Currently, we model this, by generating a sink.
430 Engine.makePostStmtNode(CastE, State, Pred, /*MarkAsSink=*/true);
431 return;
432 } else {
433 // If the cast fails on a pointer, bind to 0.
434 State = State->BindExpr(CastE, SF,
435 svalBuilder.makeNullWithType(resultType));
436 }
437 } else {
438 // If we don't know if the cast succeeded, conjure a new symbol.
439 if (val.isUnknown()) {
440 DefinedOrUnknownSVal NewSym = svalBuilder.conjureSymbolVal(
441 /*symbolTag=*/nullptr, getCFGElementRef(), SF, resultType,
443 State = State->BindExpr(CastE, SF, NewSym);
444 } else
445 // Else, bind to the derived region value.
446 State = State->BindExpr(CastE, SF, val);
447 }
448 Dst.insert(Engine.makePostStmtNode(CastE, State, Pred));
449 return;
450 }
451 case CK_BaseToDerived: {
452 SVal val = State->getSVal(Ex, SF);
453 QualType resultType = CastE->getType();
454 if (CastE->isGLValue())
455 resultType = getContext().getPointerType(resultType);
456
457 if (!val.isConstant()) {
458 std::optional<SVal> V = getStoreManager().evalBaseToDerived(val, T);
459 val = V ? *V : UnknownVal();
460 }
461
462 // Failed to cast or the result is unknown, fall back to conservative.
463 if (val.isUnknown()) {
464 val = svalBuilder.conjureSymbolVal(
465 /*symbolTag=*/nullptr, getCFGElementRef(), SF, resultType,
467 }
468 Dst.insert(Engine.makeNodeWithBinding(Pred, CastE, val));
469 return;
470 }
471 case CK_NullToPointer: {
472 SVal V = svalBuilder.makeNullWithType(CastE->getType());
473 Dst.insert(Engine.makeNodeWithBinding(Pred, CastE, V));
474 return;
475 }
476 case CK_NullToMemberPointer: {
477 SVal V = svalBuilder.getMemberPointer(nullptr);
478 Dst.insert(Engine.makeNodeWithBinding(Pred, CastE, V));
479 return;
480 }
481 case CK_DerivedToBaseMemberPointer:
482 case CK_BaseToDerivedMemberPointer:
483 case CK_ReinterpretMemberPointer: {
484 SVal V = State->getSVal(Ex, SF);
485 if (auto PTMSV = V.getAs<nonloc::PointerToMember>()) {
486 SVal CastedPTMSV =
487 svalBuilder.makePointerToMember(getBasicVals().accumCXXBase(
488 CastE->path(), *PTMSV, CastE->getCastKind()));
489 Dst.insert(Engine.makeNodeWithBinding(Pred, CastE, CastedPTMSV));
490 return;
491 }
492 // Explicitly proceed with default handler for this case cascade.
493 }
494 [[fallthrough]];
495 // Various C++ casts that are not handled yet.
496 case CK_ToUnion:
497 case CK_MatrixCast:
498 case CK_CoopMatrixCast:
499 case CK_VectorSplat:
500 case CK_HLSLElementwiseCast:
501 case CK_HLSLAggregateSplatCast:
502 case CK_HLSLMatrixTruncation:
503 case CK_HLSLVectorTruncation: {
504 QualType resultType = CastE->getType();
505 if (CastE->isGLValue())
506 resultType = getContext().getPointerType(resultType);
507 SVal result = svalBuilder.conjureSymbolVal(
508 /*symbolTag=*/nullptr, getCFGElementRef(), SF, resultType,
510 Dst.insert(Engine.makeNodeWithBinding(Pred, CastE, result));
511 return;
512 }
513 }
514}
515
517 ExplodedNode *Pred,
518 ExplodedNodeSet &Dst) {
519 ProgramStateRef State = Pred->getState();
520 const StackFrame *SF = Pred->getStackFrame();
521
522 const Expr *Init = CL->getInitializer();
523 SVal V = State->getSVal(CL->getInitializer(), SF);
524
526 // No work needed. Just pass the value up to this expression.
527 } else {
528 assert(isa<InitListExpr>(Init));
529 Loc CLLoc = State->getLValue(CL, SF);
530 State = State->bindLoc(CLLoc, V, SF);
531
532 if (CL->isGLValue())
533 V = CLLoc;
534 }
535
536 Dst.insert(Engine.makeNodeWithBinding(Pred, CL, V, State));
537}
538
540 ExplodedNodeSet &Dst) {
541 if (isa<TypedefNameDecl>(*DS->decl_begin())) {
542 // C99 6.7.7 "Any array size expressions associated with variable length
543 // array declarators are evaluated each time the declaration of the typedef
544 // name is reached in the order of execution."
545 // The checkers should know about typedef to be able to handle VLA size
546 // expressions.
547 ExplodedNodeSet DstPre;
548 getCheckerManager().runCheckersForPreStmt(DstPre, Pred, DS, *this);
549 getCheckerManager().runCheckersForPostStmt(Dst, DstPre, DS, *this);
550 return;
551 }
552
553 // Assumption: The CFG has one DeclStmt per Decl.
554 const VarDecl *VD = dyn_cast_or_null<VarDecl>(*DS->decl_begin());
555
556 if (!VD) {
557 //TODO:AZ: remove explicit insertion after refactoring is done.
558 Dst.insert(Pred);
559 return;
560 }
561
562 // Self-assignment initialization in variable declaration,
563 // i.e., `int x = x;`,
564 // is a C idiom to suppress warnings of unused variables.
565 // This filter will not match variables of C++ record types, but will match
566 // C++ references. Allow references continuing here to make the undefined
567 // value checker report self-assignments of C++ references.
568 if (const Expr *EI = VD->getInit()) {
569 // Ignore InitListExpr if exists.
570 if (const auto *IL = dyn_cast<InitListExpr>(EI);
571 IL && IL->getNumInits() == 1)
572 EI = IL->getInit(0);
573
574 // Ignore parentheses and implict casts.
575 if (const auto *DR = dyn_cast<DeclRefExpr>(EI->IgnoreParenImpCasts())) {
576 if (VD == DR->getDecl() && !VD->getType()->isReferenceType()) {
577 Dst.insert(Pred);
578 return;
579 }
580 }
581 }
582
583 // FIXME: all pre/post visits should eventually be handled by ::Visit().
584 ExplodedNodeSet dstPreVisit;
585 getCheckerManager().runCheckersForPreStmt(dstPreVisit, Pred, DS, *this);
586
587 ExplodedNodeSet dstEvaluated;
588 for (ExplodedNodeSet::iterator I = dstPreVisit.begin(), E = dstPreVisit.end();
589 I!=E; ++I) {
590 ExplodedNode *N = *I;
591 ProgramStateRef state = N->getState();
592 const StackFrame *SF = N->getStackFrame();
593
594 // Decls without InitExpr are not initialized explicitly.
595 if (const Expr *InitEx = VD->getInit()) {
596
597 // Note in the state that the initialization has occurred.
598 ExplodedNode *UpdatedN = N;
599 SVal InitVal = state->getSVal(InitEx, SF);
600
601 assert(DS->isSingleDecl());
602 if (getObjectUnderConstruction(state, DS, SF)) {
603 state = finishObjectConstruction(state, DS, SF);
604 // We constructed the object directly in the variable.
605 // No need to bind anything.
606 dstEvaluated.insert(Engine.makePostStmtNode(DS, state, UpdatedN));
607 } else {
608 // Recover some path-sensitivity if a scalar value evaluated to
609 // UnknownVal.
610 if (InitVal.isUnknown()) {
611 QualType Ty = InitEx->getType();
612 if (InitEx->isGLValue()) {
613 Ty = getContext().getPointerType(Ty);
614 }
615
616 InitVal = svalBuilder.conjureSymbolVal(
617 /*symbolTag=*/nullptr, getCFGElementRef(), SF, Ty,
619 }
620
621 evalBind(dstEvaluated, DS, UpdatedN, state->getLValue(VD, SF), InitVal,
622 true);
623 }
624 }
625 else {
626 dstEvaluated.insert(Engine.makePostStmtNode(DS, state, N));
627 }
628 }
629
630 getCheckerManager().runCheckersForPostStmt(Dst, dstEvaluated, DS, *this);
631}
632
634 ExplodedNodeSet &Dst) {
635 // This method acts upon CFG elements for logical operators && and ||
636 // and attaches the value (true or false) to them as expressions.
637 // It doesn't produce any state splits.
638 // If we made it that far, we're past the point when we modeled the short
639 // circuit. It means that we should have precise knowledge about whether
640 // we've short-circuited. If we did, we already know the value we need to
641 // bind. If we didn't, the value of the RHS (casted to the boolean type)
642 // is the answer.
643 // Currently this method tries to figure out whether we've short-circuited
644 // by looking at the ExplodedGraph. This method is imperfect because there
645 // could inevitably have been merges that would have resulted in multiple
646 // potential path traversal histories. We bail out when we fail.
647 // Due to this ambiguity, a more reliable solution would have been to
648 // track the short circuit operation history path-sensitively until
649 // we evaluate the respective logical operator.
650 assert(B->getOpcode() == BO_LAnd ||
651 B->getOpcode() == BO_LOr);
652
653 ProgramStateRef state = Pred->getState();
654
655 if (B->getType()->isVectorType()) {
656 // FIXME: We do not model vector arithmetic yet. When adding support for
657 // that, note that the CFG-based reasoning below does not apply, because
658 // logical operators on vectors are not short-circuit. Currently they are
659 // modeled as short-circuit in Clang CFG but this is incorrect.
660 // Do not set the value for the expression. It'd be UnknownVal by default.
661 Dst.insert(Engine.makePostStmtNode(B, state, Pred));
662 return;
663 }
664
665 ExplodedNode *N = Pred;
666 while (!N->getLocation().getAs<BlockEdge>()) {
667 ProgramPoint P = N->getLocation();
668 assert(P.getAs<PreStmt>() || P.getAs<PreStmtPurgeDeadSymbols>() ||
669 P.getAs<BlockEntrance>());
670 (void) P;
671 if (N->pred_size() != 1) {
672 // We failed to track back where we came from.
673 Dst.insert(Engine.makePostStmtNode(B, state, Pred));
674 return;
675 }
676 N = *N->pred_begin();
677 }
678
679 if (N->pred_size() != 1) {
680 // We failed to track back where we came from.
681 Dst.insert(Engine.makePostStmtNode(B, state, Pred));
682 return;
683 }
684
686 SVal X;
687
688 // Determine the value of the expression by introspecting how we
689 // got this location in the CFG. This requires looking at the previous
690 // block we were in and what kind of control-flow transfer was involved.
691 const CFGBlock *SrcBlock = BE.getSrc();
692 // The only terminator (if there is one) that makes sense is a logical op.
693 CFGTerminator T = SrcBlock->getTerminator();
694 if (const BinaryOperator *Term = cast_or_null<BinaryOperator>(T.getStmt())) {
695 (void) Term;
696 assert(Term->isLogicalOp());
697 assert(SrcBlock->succ_size() == 2);
698 // Did we take the true or false branch?
699 unsigned constant = (*SrcBlock->succ_begin() == BE.getDst()) ? 1 : 0;
700 X = svalBuilder.makeIntVal(constant, B->getType());
701 }
702 else {
703 // If there is no terminator, by construction the last statement
704 // in SrcBlock is the value of the enclosing expression.
705 // However, we still need to constrain that value to be 0 or 1.
706 assert(!SrcBlock->empty());
707 CFGStmt Elem = SrcBlock->rbegin()->castAs<CFGStmt>();
708 const Expr *RHS = cast<Expr>(Elem.getStmt());
709 SVal RHSVal = N->getState()->getSVal(RHS, Pred->getStackFrame());
710
711 if (RHSVal.isUndef()) {
712 X = RHSVal;
713 } else {
714 // We evaluate "RHSVal != 0" expression which result in 0 if the value is
715 // known to be false, 1 if the value is known to be true and a new symbol
716 // when the assumption is unknown.
717 X = evalBinOp(N->getState(), BO_NE, RHSVal,
718 svalBuilder.makeZeroVal(RHS->getType()), B->getType());
719 }
720 }
721 Dst.insert(Engine.makeNodeWithBinding(Pred, B, X));
722}
723
725 const Expr *L,
726 const Expr *R,
727 ExplodedNode *Pred,
728 ExplodedNodeSet &Dst) {
729 assert(L && R);
730
731 ProgramStateRef state = Pred->getState();
732 const StackFrame *SF = Pred->getStackFrame();
733 const CFGBlock *SrcBlock = nullptr;
734
735 // Find the predecessor block.
736 ProgramStateRef SrcState = state;
737 for (const ExplodedNode *N = Pred ; N ; N = *N->pred_begin()) {
738 auto Edge = N->getLocationAs<BlockEdge>();
739 if (!Edge.has_value()) {
740 // If the state N has multiple predecessors P, it means that successors
741 // of P are all equivalent.
742 // In turn, that means that all nodes at P are equivalent in terms
743 // of observable behavior at N, and we can follow any of them.
744 // FIXME: a more robust solution which does not walk up the tree.
745 continue;
746 }
747 SrcBlock = Edge->getSrc();
748 SrcState = N->getState();
749 break;
750 }
751
752 assert(SrcBlock && "missing function entry");
753
754 // Find the last expression in the predecessor block. That is the
755 // expression that is used for the value of the ternary expression.
756 bool hasValue = false;
757 SVal V;
758
759 for (CFGElement CE : llvm::reverse(*SrcBlock)) {
760 if (std::optional<CFGStmt> CS = CE.getAs<CFGStmt>()) {
761 const Expr *ValEx = cast<Expr>(CS->getStmt());
762 ValEx = ValEx->IgnoreParens();
763
764 // For GNU extension '?:' operator, the left hand side will be an
765 // OpaqueValueExpr, so get the underlying expression.
766 if (const OpaqueValueExpr *OpaqueEx = dyn_cast<OpaqueValueExpr>(L))
767 L = OpaqueEx->getSourceExpr();
768
769 // If the last expression in the predecessor block matches true or false
770 // subexpression, get its the value.
771 if (ValEx == L->IgnoreParens() || ValEx == R->IgnoreParens()) {
772 hasValue = true;
773 V = SrcState->getSVal(ValEx, SF);
774 }
775 break;
776 }
777 }
778
779 if (!hasValue)
780 V = svalBuilder.conjureSymbolVal(nullptr, getCFGElementRef(), SF,
782
783 // Generate a new node with the binding from the appropriate path.
784 Dst.insert(Engine.makeNodeWithBinding(Pred, Ex, V));
785}
786
788 ExplodedNodeSet &Dst) {
790 if (OOE->EvaluateAsInt(Result, getContext())) {
791 APSInt IV = Result.Val.getInt();
792 assert(IV.getBitWidth() == getContext().getTypeSize(OOE->getType()));
793 assert(OOE->getType()->castAs<BuiltinType>()->isInteger());
794 assert(IV.isSigned() == OOE->getType()->isSignedIntegerType());
795 SVal X = svalBuilder.makeIntVal(IV);
796 Dst.insert(Engine.makeNodeWithBinding(Pred, OOE, X));
797 } else {
798 // FIXME: Handle the case where __builtin_offsetof is not a constant.
799 Dst.insert(Pred);
800 }
801}
802
804 const UnaryExprOrTypeTraitExpr *Ex, ExplodedNode *Pred,
805 ExplodedNodeSet &Dst) {
806 QualType T = Ex->getTypeOfArgument();
807
808 if (Ex->getKind() == UETT_SizeOf || Ex->getKind() == UETT_DataSizeOf ||
809 Ex->getKind() == UETT_CountOf) {
810 if (!T->isIncompleteType() && !T->isConstantSizeType()) {
811 assert(T->isVariableArrayType() && "Unknown non-constant-sized type.");
812
813 // FIXME: Add support for VLA type arguments and VLA expressions.
814 // When that happens, we should probably refactor VLASizeChecker's code.
815 Dst.insert(Pred);
816 return;
817 } else if (T->getAs<ObjCObjectType>()) {
818 // Some code tries to take the sizeof an ObjCObjectType, relying that
819 // the compiler has laid out its representation. Just report Unknown
820 // for these.
821 Dst.insert(Pred);
822 return;
823 }
824 }
825
826 APSInt Value = Ex->EvaluateKnownConstInt(getContext());
827 CharUnits amt = CharUnits::fromQuantity(Value.getZExtValue());
828
829 SVal V = svalBuilder.makeIntVal(amt.getQuantity(), Ex->getType());
830 Dst.insert(Engine.makeNodeWithBinding(Pred, Ex, V));
831}
832
834 ExplodedNodeSet &Dst) {
835 if (SE->getSubStmt()->body_empty()) {
836 // Empty statement expression.
837 assert(SE->getType() == getContext().VoidTy &&
838 "Empty statement expression must have void type.");
839 } else if (const auto *LastExpr =
840 dyn_cast<Expr>(*SE->getSubStmt()->body_rbegin())) {
841 SVal Val = Pred->getState()->getSVal(LastExpr, Pred->getStackFrame());
842 Pred = Engine.makeNodeWithBinding(Pred, SE, Val);
843 }
844 Dst.insert(Pred);
845}
846
848 ExplodedNodeSet &Dst) {
849 // FIXME: Prechecks eventually go in ::Visit().
850 ExplodedNodeSet CheckedSet;
851 getCheckerManager().runCheckersForPreStmt(CheckedSet, Pred, U, *this);
852
853 ExplodedNodeSet EvalSet;
854
855 // Lambda for handling the case when the operand is returned unchanged.
856 auto MakeNodeForIdentityOp = [U, &Engine = Engine](ExplodedNode *N) {
857 const Expr *Ex = U->getSubExpr()->IgnoreParens();
858 SVal SV = N->getState()->getSVal(Ex, N->getStackFrame());
859 return Engine.makeNodeWithBinding(N, U, SV);
860 };
861
862 for (ExplodedNode *N : CheckedSet) {
863 switch (U->getOpcode()) {
864 default: {
865 ExplodedNodeSet Tmp;
867 EvalSet.insert(Tmp);
868 break;
869 }
870 case UO_Real: {
871 const Expr *Ex = U->getSubExpr()->IgnoreParens();
872
873 // FIXME: We don't have complex SValues yet.
874 if (Ex->getType()->isAnyComplexType()) {
875 // Just report "Unknown."
876 EvalSet.insert(N);
877 break;
878 }
879
880 // For all other types, UO_Real is an identity operation.
881 assert (U->getType() == Ex->getType());
882 EvalSet.insert(MakeNodeForIdentityOp(N));
883 break;
884 }
885
886 case UO_Imag: {
887 const Expr *Ex = U->getSubExpr()->IgnoreParens();
888 // FIXME: We don't have complex SValues yet.
889 if (Ex->getType()->isAnyComplexType()) {
890 // Just report "Unknown."
891 EvalSet.insert(N);
892 break;
893 }
894 // For all other types, UO_Imag returns 0.
895 SVal X = svalBuilder.makeZeroVal(Ex->getType());
896 EvalSet.insert(Engine.makeNodeWithBinding(N, U, X));
897 break;
898 }
899
900 case UO_AddrOf: {
901 // Process pointer-to-member address operation.
902 const Expr *Ex = U->getSubExpr()->IgnoreParens();
903 if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Ex)) {
904 const ValueDecl *VD = DRE->getDecl();
905
907 SVal SV = svalBuilder.getMemberPointer(cast<NamedDecl>(VD));
908 EvalSet.insert(Engine.makeNodeWithBinding(N, U, SV));
909 break;
910 }
911 }
912 // Explicitly proceed with default handler for this case cascade.
913 EvalSet.insert(MakeNodeForIdentityOp(N));
914 break;
915 }
916 case UO_Plus:
917 assert(!U->isGLValue());
918 [[fallthrough]];
919 case UO_Deref:
920 case UO_Extension: {
921 EvalSet.insert(MakeNodeForIdentityOp(N));
922 break;
923 }
924
925 case UO_LNot:
926 case UO_Minus:
927 case UO_Not: {
928 assert (!U->isGLValue());
929 const Expr *Ex = U->getSubExpr()->IgnoreParens();
930 ProgramStateRef state = N->getState();
931 const StackFrame *SF = N->getStackFrame();
932
933 // Get the value of the subexpression.
934 SVal V = state->getSVal(Ex, SF);
935
936 if (V.isUnknownOrUndef()) {
937 EvalSet.insert(Engine.makeNodeWithBinding(N, U, V));
938 break;
939 }
940
941 switch (U->getOpcode()) {
942 default:
943 llvm_unreachable("Invalid Opcode.");
944 case UO_Not:
945 // FIXME: Do we need to handle promotions?
946 state = state->BindExpr(
947 U, SF, svalBuilder.evalComplement(V.castAs<NonLoc>()));
948 break;
949 case UO_Minus:
950 // FIXME: Do we need to handle promotions?
951 state =
952 state->BindExpr(U, SF, svalBuilder.evalMinus(V.castAs<NonLoc>()));
953 break;
954 case UO_LNot:
955 // C99 6.5.3.3: "The expression !E is equivalent to (0==E)."
956 //
957 // Note: technically we do "E == 0", but this is the same in the
958 // transfer functions as "0 == E".
959 SVal Result;
960 if (std::optional<Loc> LV = V.getAs<Loc>()) {
961 Loc X = svalBuilder.makeNullWithType(Ex->getType());
962 Result = evalBinOp(state, BO_EQ, *LV, X, U->getType());
963 } else if (Ex->getType()->isFloatingType()) {
964 // FIXME: handle floating point types.
965 Result = UnknownVal();
966 } else {
967 nonloc::ConcreteInt X(getBasicVals().getValue(0, Ex->getType()));
968 Result = evalBinOp(state, BO_EQ, V.castAs<NonLoc>(), X, U->getType());
969 }
970
971 state = state->BindExpr(U, SF, Result);
972 break;
973 }
974 EvalSet.insert(Engine.makePostStmtNode(U, state, N));
975 break;
976 }
977 }
978 }
979
980 ExplodedNodeSet AssumedSet;
981 if (AMgr.options.ShouldEagerlyAssume && (U->getOpcode() == UO_LNot)) {
982 evalEagerlyAssumeBifurcation(AssumedSet, EvalSet, U);
983 } else {
984 AssumedSet.insert(EvalSet);
985 }
986 getCheckerManager().runCheckersForPostStmt(Dst, AssumedSet, U, *this);
987}
988
990 ExplodedNode *Pred,
991 ExplodedNodeSet &Dst) {
992 SVal V = UnknownVal();
993 if (const Expr *Result = PE->getResultExpr())
994 V = Pred->getState()->getSVal(Result, Pred->getStackFrame());
995 Dst.insert(Engine.makeNodeWithBinding(Pred, PE, V));
996}
997
1000 ExplodedNodeSet &Dst) {
1001 // ObjCIndirectCopyRestoreExpr implies passing a temporary for
1002 // correctness of lifetime management. Due to limited analysis
1003 // of ARC, this is implemented as direct arg passing.
1004 const Expr *E = OIE->getSubExpr();
1005 SVal V = Pred->getState()->getSVal(E, Pred->getStackFrame());
1006 Dst.insert(Engine.makeNodeWithBinding(Pred, OIE, V));
1007}
1008
1010 ExplodedNode *Pred,
1011 ExplodedNodeSet &Dst) {
1012 // Handle ++ and -- (both pre- and post-increment).
1013 assert (U->isIncrementDecrementOp());
1014 const Expr *Ex = U->getSubExpr()->IgnoreParens();
1015
1016 const StackFrame *SF = Pred->getStackFrame();
1017 ProgramStateRef state = Pred->getState();
1018 SVal loc = state->getSVal(Ex, SF);
1019
1020 // Perform a load.
1021 ExplodedNodeSet Tmp;
1022 evalLoad(Tmp, U, Ex, Pred, state, loc);
1023
1024 ExplodedNodeSet Dst2;
1025 for (ExplodedNode *N : Tmp) {
1026 state = N->getState();
1027 assert(SF == N->getStackFrame());
1028 SVal V2_untested = state->getSVal(Ex, SF);
1029
1030 // Propagate unknown and undefined values.
1031 if (V2_untested.isUnknownOrUndef()) {
1032 state = state->BindExpr(U, SF, V2_untested);
1033
1034 // Perform the store, so that the uninitialized value detection happens.
1035 evalStore(Dst2, U, Ex, N, state, loc, V2_untested);
1036 continue;
1037 }
1038 DefinedSVal V2 = V2_untested.castAs<DefinedSVal>();
1039
1040 // Handle all other values.
1041 BinaryOperator::Opcode Op = U->isIncrementOp() ? BO_Add : BO_Sub;
1042
1043 // If the UnaryOperator has non-location type, use its type to create the
1044 // constant value. If the UnaryOperator has location type, create the
1045 // constant with int type and pointer width.
1046 SVal RHS;
1047 SVal Result;
1048
1049 if (U->getType()->isAnyPointerType())
1050 RHS = svalBuilder.makeArrayIndex(1);
1051 else if (U->getType()->isIntegralOrEnumerationType())
1052 RHS = svalBuilder.makeIntVal(1, U->getType());
1053 else
1054 RHS = UnknownVal();
1055
1056 // The use of an operand of type bool with the ++ operators is deprecated
1057 // but valid until C++17. And if the operand of the ++ operator is of type
1058 // bool, it is set to true until C++17. Note that for '_Bool', it is also
1059 // set to true when it encounters ++ operator.
1060 if (U->getType()->isBooleanType() && U->isIncrementOp())
1061 Result = svalBuilder.makeTruthVal(true, U->getType());
1062 else
1063 Result = evalBinOp(state, Op, V2, RHS, U->getType());
1064
1065 // Conjure a new symbol if necessary to recover precision.
1066 if (Result.isUnknown()){
1067 DefinedOrUnknownSVal SymVal = svalBuilder.conjureSymbolVal(
1068 /*symbolTag=*/nullptr, getCFGElementRef(), SF,
1070 Result = SymVal;
1071
1072 // If the value is a location, ++/-- should always preserve
1073 // non-nullness. Check if the original value was non-null, and if so
1074 // propagate that constraint.
1075 if (Loc::isLocType(U->getType())) {
1076 DefinedOrUnknownSVal Constraint =
1077 svalBuilder.evalEQ(state, V2,svalBuilder.makeZeroVal(U->getType()));
1078
1079 if (!state->assume(Constraint, true)) {
1080 // It isn't feasible for the original value to be null.
1081 // Propagate this constraint.
1082 Constraint = svalBuilder.evalEQ(state, SymVal,
1083 svalBuilder.makeZeroVal(U->getType()));
1084
1085 state = state->assume(Constraint, false);
1086 assert(state);
1087 }
1088 }
1089 }
1090
1091 // Since the lvalue-to-rvalue conversion is explicit in the AST,
1092 // we bind an l-value if the operator is prefix and an lvalue (in C++).
1093 if (U->isGLValue())
1094 state = state->BindExpr(U, SF, loc);
1095 else
1096 state = state->BindExpr(U, SF, U->isPostfix() ? V2 : Result);
1097
1098 // Perform the store.
1099 evalStore(Dst2, U, Ex, N, state, loc, Result);
1100 }
1101 Dst.insert(Dst2);
1102}
#define V(N, I)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::Expr interface and subclasses for C++ expressions.
#define X(type, name)
Definition Value.h:97
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:246
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type.
static CanQualType getCanonicalType(QualType T)
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4107
Expr * getLHS() const
Definition Expr.h:4157
static bool isRelationalOp(Opcode Opc)
Definition Expr.h:4201
Expr * getRHS() const
Definition Expr.h:4159
static bool isAdditiveOp(Opcode Opc)
Definition Expr.h:4193
static bool isAssignmentOp(Opcode Opc)
Definition Expr.h:4243
static bool isCompoundAssignmentOp(Opcode Opc)
Definition Expr.h:4248
Opcode getOpcode() const
Definition Expr.h:4152
static bool isEqualityOp(Opcode Opc)
Definition Expr.h:4204
BinaryOperatorKind Opcode
Definition Expr.h:4112
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition Decl.h:4862
capture_const_iterator capture_begin() const
Definition Decl.h:4994
capture_const_iterator capture_end() const
Definition Decl.h:4995
const CFGBlock * getSrc() const
const CFGBlock * getDst() const
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition Expr.h:6758
const BlockDecl * getBlockDecl() const
Definition Expr.h:6770
This class is used for builtin types like 'int'.
Definition TypeBase.h:3246
bool isInteger() const
Definition TypeBase.h:3313
Represents a single basic block in a source-level CFG.
Definition CFG.h:651
reverse_iterator rbegin()
Definition CFG.h:970
bool empty() const
Definition CFG.h:1008
CFGTerminator getTerminator() const
Definition CFG.h:1145
succ_iterator succ_begin()
Definition CFG.h:1045
unsigned succ_size() const
Definition CFG.h:1063
Represents a top-level expression in a basic block.
Definition CFG.h:55
T castAs() const
Convert to the specified CFGElement type, asserting that this CFGElement is of the desired type.
Definition CFG.h:103
const Stmt * getStmt() const
Definition CFG.h:143
Represents CFGBlock terminator statement.
Definition CFG.h:578
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3745
CastKind getCastKind() const
Definition Expr.h:3789
llvm::iterator_range< path_iterator > path()
Path through the class hierarchy taken by casts between base and derived classes (see implementation ...
Definition Expr.h:3832
Expr * getSubExpr()
Definition Expr.h:3795
This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
QuantityType getQuantity() const
Get the raw integer representation of this quantity.
Definition CharUnits.h:155
static constexpr CharUnits fromQuantity(QuantityType Quantity)
Construct a CharUnits quantity from a raw integer type.
Definition CharUnits.h:58
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3674
bool body_empty() const
Definition Stmt.h:1795
reverse_body_iterator body_rbegin()
Definition Stmt.h:1846
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1315
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1642
bool isSingleDecl() const
isSingleDecl - This method returns true if this DeclStmt refers to a single Decl.
Definition Stmt.h:1655
decl_iterator decl_begin()
Definition Stmt.h:1696
ExplicitCastExpr - An explicit cast written in the source code.
Definition Expr.h:3997
This represents one expression.
Definition Expr.h:114
bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects, bool InConstantContext=false) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer,...
bool isGLValue() const
Definition Expr.h:289
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3126
QualType getType() const
Definition Expr.h:146
ObjCIndirectCopyRestoreExpr - Represents the passing of a function argument by indirect copy-restore ...
Definition ExprObjC.h:1614
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition Expr.h:2596
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1223
Represents a point after we ran remove dead bindings BEFORE processing the given statement.
T castAs() const
Convert to the specified ProgramPoint type, asserting that this ProgramPoint is of the desired type.
std::optional< T > getAs() const
Convert to the specified ProgramPoint type, returning std::nullopt if this ProgramPoint is not of the...
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6890
Expr * getResultExpr()
Return the result-bearing expression, or null if there is none.
Definition Expr.h:6938
A (possibly-)qualified type.
Definition TypeBase.h:938
It represents a stack frame of the call stack.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition Expr.h:4664
CompoundStmt * getSubStmt()
Definition Expr.h:4681
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
Definition Type.cpp:2410
bool isRValueReferenceType() const
Definition TypeBase.h:8949
const T * castAs() const
Member-template castAs<specific type>.
Definition TypeBase.h:9604
bool isReferenceType() const
Definition TypeBase.h:8941
bool isLValueReferenceType() const
Definition TypeBase.h:8945
bool isAnyComplexType() const
Definition TypeBase.h:9052
bool isVectorType() const
Definition TypeBase.h:9056
bool isFloatingType() const
Definition Type.cpp:2535
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2694
QualType getTypeOfArgument() const
Gets the argument type, or the type of the argument expression, whichever is appropriate.
Definition Expr.h:2763
UnaryExprOrTypeTrait getKind() const
Definition Expr.h:2726
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2313
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:714
QualType getType() const
Definition Decl.h:725
Represents a variable declaration or definition.
Definition Decl.h:934
const Expr * getInit() const
Definition Decl.h:1393
BlockDataRegion - A region that represents a block instance.
Definition MemRegion.h:713
void runCheckersForPostStmt(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const Stmt *S, ExprEngine &Eng, bool wasInlined=false)
Run checkers for post-visiting Stmts.
void runCheckersForPreStmt(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const Stmt *S, ExprEngine &Eng)
Run checkers for pre-visiting Stmts.
ExplodedNodeSet is a set of ExplodedNode * elements with the invariant that its elements cannot be nu...
void insert(ExplodedNode *N)
const ProgramStateRef & getState() const
SVal getSVal(const Expr *E) const
Get the value of an arbitrary expression at this node.
ProgramPoint getLocation() const
getLocation - Returns the edge associated with the given node.
unsigned pred_size() const
const StackFrame * getStackFrame() const
void VisitBinaryOperator(const BinaryOperator *B, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitBinaryOperator - Transfer function logic for binary operators.
void VisitGuardedExpr(const Expr *Ex, const Expr *L, const Expr *R, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitGuardedExpr - Transfer function logic for ?, __builtin_choose.
BasicValueFactory & getBasicVals()
Definition ExprEngine.h:471
void VisitLogicalExpr(const BinaryOperator *B, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitLogicalExpr - Transfer function logic for '&&', '||'.
void evalEagerlyAssumeBifurcation(ExplodedNodeSet &Dst, ExplodedNodeSet &Src, const Expr *Ex)
evalEagerlyAssumeBifurcation - Given the nodes in 'Src', eagerly assume concrete boolean values for '...
SVal evalBinOp(ProgramStateRef ST, BinaryOperator::Opcode Op, SVal LHS, SVal RHS, QualType T)
Definition ExprEngine.h:679
void VisitObjCIndirectCopyRestoreExpr(const ObjCIndirectCopyRestoreExpr *OIE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void VisitUnaryOperator(const UnaryOperator *B, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitUnaryOperator - Transfer function logic for unary operators.
void VisitDeclStmt(const DeclStmt *DS, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitDeclStmt - Transfer function logic for DeclStmts.
void VisitBlockExpr(const BlockExpr *BE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitBlockExpr - Transfer function logic for BlockExprs.
void VisitIncrementDecrementOperator(const UnaryOperator *U, ExplodedNode *Pred, ExplodedNodeSet &Dst)
Handle ++ and – (both pre- and post-increment).
ASTContext & getContext() const
getContext - Return the ASTContext associated with this analysis.
Definition ExprEngine.h:196
StoreManager & getStoreManager()
Definition ExprEngine.h:458
ConstCFGElementRef getCFGElementRef() const
If the current analysis step is the analysis of a CFGElement, return a reference to it; otherwise ret...
Definition ExprEngine.h:261
void VisitStmtExpr(const StmtExpr *SE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Ex, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitUnaryExprOrTypeTraitExpr - Transfer function for sizeof.
ProgramStateRef escapeValues(ProgramStateRef State, ArrayRef< SVal > Vs, PointerEscapeKind K, const CallEvent *Call=nullptr) const
A simple wrapper when you only need to notify checkers of pointer-escape of some values.
CheckerManager & getCheckerManager() const
Definition ExprEngine.h:205
static std::optional< SVal > getObjectUnderConstruction(ProgramStateRef State, const ConstructionContextItem &Item, const StackFrame *SF)
By looking at a certain item that may be potentially part of an object's ConstructionContext,...
unsigned getNumVisitedCurrent() const
Definition ExprEngine.h:271
void VisitOffsetOfExpr(const OffsetOfExpr *Ex, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitOffsetOfExpr - Transfer function for offsetof.
void evalLoad(ExplodedNodeSet &Dst, const Expr *NodeEx, const Expr *BoundExpr, ExplodedNode *Pred, ProgramStateRef St, SVal location, const ProgramPointTag *tag=nullptr, QualType LoadTy=QualType())
Simulate a read of the result of Ex.
void VisitCompoundLiteralExpr(const CompoundLiteralExpr *CL, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitCompoundLiteralExpr - Transfer function logic for compound literals.
void evalStore(ExplodedNodeSet &Dst, const Expr *AssignE, const Expr *StoreE, ExplodedNode *Pred, ProgramStateRef St, SVal TargetLV, SVal Val, const ProgramPointTag *tag=nullptr)
evalStore - Handle the semantics of a store via an assignment.
void VisitCastExpr(const CastExpr *CastE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitCastExpr - Transfer function logic for all casts (implicit and explicit).
void VisitPseudoObjectExpr(const PseudoObjectExpr *PE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void handleLValueBitCast(ProgramStateRef state, const Expr *Ex, const StackFrame *SF, QualType T, QualType ExTy, const CastExpr *CastE, ExplodedNodeSet &Dst, ExplodedNode *Pred)
static bool isLocType(QualType T)
Definition SVals.h:265
MemRegion - The root abstract class for all memory regions.
Definition MemRegion.h:97
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
Definition SVals.h:57
bool isUndef() const
Definition SVals.h:113
bool isZeroConstant() const
Definition SVals.cpp:257
bool isUnknownOrUndef() const
Definition SVals.h:115
bool isConstant() const
Definition SVals.cpp:245
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
Definition SVals.h:84
bool isUnknown() const
Definition SVals.h:111
SVal evalDerivedToBase(SVal Derived, const CastExpr *Cast)
Evaluates a chain of derived-to-base casts through the path specified in Cast.
Definition Store.cpp:254
std::optional< SVal > evalBaseToDerived(SVal Base, QualType DerivedPtrType)
Attempts to do a down cast.
Definition Store.cpp:318
TypedValueRegion - An abstract class representing regions having a typed value.
Definition MemRegion.h:570
const VarDecl * getDecl() const override=0
Value representing integer constant.
Definition SVals.h:303
Value representing pointer-to-member.
Definition SVals.h:437
Definition SPIR.cpp:35
@ PSK_EscapeOther
The reason for pointer escape is unknown.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
Top level wrappers for InstallAPI frontend operations.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
bool isa(CodeGen::Address addr)
Definition Address.h:330
@ Result
The result type of a method or function.
Definition TypeBase.h:906
U cast(CodeGen::Address addr)
Definition Address.h:327
EvalResult is a struct with detailed info about an evaluated expression.
Definition Expr.h:667