1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-10 01:02:56 +03:00

In the byte-code, when the result of an expression needs to be in a particular

register, always use the sqlite3ExprCode() routine because it has the smarts
to know whether to use OP_Copy or OP_SCopy.  Do not try to OP_SCopy inline
because an OP_Copy might be required.  Fix for the problem identified by
[forum:/forumpost/5522082cfc|forum post 5522082cfc].

FossilOrigin-Name: c104e5c6eeb89575319d9f94f49446142b06912fa8b283c19d46aa2ccddc5bda
This commit is contained in:
drh
2023-03-25 19:44:25 +00:00
parent 52786ec185
commit 28ae195658
3 changed files with 14 additions and 24 deletions

View File

@@ -4397,11 +4397,8 @@ expr_code_doover:
#ifndef SQLITE_OMIT_CAST
case TK_CAST: {
/* Expressions of the form: CAST(pLeft AS token) */
inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
if( inReg!=target ){
sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
inReg = target;
}
sqlite3ExprCode(pParse, pExpr->pLeft, target);
assert( inReg==target );
assert( !ExprHasProperty(pExpr, EP_IntValue) );
sqlite3VdbeAddOp2(v, OP_Cast, target,
sqlite3AffinityType(pExpr->u.zToken, 0));
@@ -4740,13 +4737,9 @@ expr_code_doover:
** Clear subtypes as subtypes may not cross a subquery boundary.
*/
assert( pExpr->pLeft );
inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
if( inReg!=target ){
sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
inReg = target;
}
sqlite3VdbeAddOp1(v, OP_ClrSubtype, inReg);
return inReg;
sqlite3ExprCode(pParse, pExpr->pLeft, target);
sqlite3VdbeAddOp1(v, OP_ClrSubtype, target);
return target;
}else{
pExpr = pExpr->pLeft;
goto expr_code_doover; /* 2018-04-28: Prevent deep recursion. */
@@ -4856,12 +4849,9 @@ expr_code_doover:
** "target" and not someplace else.
*/
pParse->okConstFactor = 0; /* note (1) above */
inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
sqlite3ExprCode(pParse, pExpr->pLeft, target);
assert( target==inReg );
pParse->okConstFactor = okConstFactor;
if( inReg!=target ){ /* note (2) above */
sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
inReg = target;
}
sqlite3VdbeJumpHere(v, addrINR);
break;
}