Skip to content

Commit 1d20c18

Browse files
committed
For __builtin_bit_cast, we just need to evalLocation for the second argument instead of evalLoad.
1 parent 95ac7cf commit 1d20c18

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -285,23 +285,27 @@ void ExprEngine::VisitCast(const CastExpr *CastE, const Expr *Ex,
285285
ExplodedNodeSet dstPreStmt;
286286
getCheckerManager().runCheckersForPreStmt(dstPreStmt, Pred, CastE, *this);
287287

288-
if (CastE->getCastKind() == CK_LValueToRValue ||
289-
CastE->getCastKind() == CK_LValueToRValueBitCast) {
288+
if (CastE->getCastKind() == CK_LValueToRValue) {
289+
for (ExplodedNode *subExprNode : dstPreStmt) {
290+
ProgramStateRef state = subExprNode->getState();
291+
const LocationContext *LCtx = subExprNode->getLocationContext();
292+
evalLoad(Dst, CastE, CastE, subExprNode, state, state->getSVal(Ex, LCtx));
293+
}
294+
return;
295+
}
296+
if (CastE->getCastKind() == CK_LValueToRValueBitCast) {
297+
// Handle `__builtin_bit_cast`:
290298
ExplodedNodeSet dstEvalLoad;
291299

300+
// Simulate the lvalue-to-rvalue conversion on `Ex`:
292301
for (ExplodedNode *subExprNode : dstPreStmt) {
293302
ProgramStateRef state = subExprNode->getState();
294303
const LocationContext *LCtx = subExprNode->getLocationContext();
295-
evalLoad(dstEvalLoad, CastE, CastE, subExprNode, state,
296-
state->getSVal(Ex, LCtx));
297-
}
298-
if (CastE->getCastKind() == CK_LValueToRValue) {
299-
Dst.insert(dstEvalLoad);
300-
return;
304+
evalLocation(dstEvalLoad, CastE, Ex, subExprNode, state,
305+
state->getSVal(Ex, LCtx), true);
301306
}
302-
assert(CastE->getCastKind() == CK_LValueToRValueBitCast &&
303-
"unexpected cast kind");
304-
// Need to simulate the actual cast operation:
307+
// Simulate the operation that actually casts the original value to a new
308+
// value of the destination type :
305309
StmtNodeBuilder Bldr(dstEvalLoad, Dst, *currBldrCtx);
306310

307311
for (ExplodedNode *Node : dstEvalLoad) {

0 commit comments

Comments
 (0)