/ Check-in [924d63b2]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Remove unreachable code, replacing it in most cases with assert() or NEVER() macros.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 924d63b283a3d059838114c95d42c6feaf913529
User & Date: drh 2013-11-11 16:55:52
Context
2013-11-11
19:01
Add a way for virtual tables to return the expected number of rows for a scan (not just the overall cost) to SQLite. Have the rtree module make use of this. check-in: 5a3cfd74 user: dan tags: trunk
16:55
Remove unreachable code, replacing it in most cases with assert() or NEVER() macros. check-in: 924d63b2 user: drh tags: trunk
03:37
Fix issue with several memory allocation tests due to KeyInfo allocations now being shared. check-in: 569fedd6 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

  4176   4176       }else{
  4177   4177         pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
  4178   4178       }
  4179   4179       if( pKey ){
  4180   4180         assert( sqlite3KeyInfoIsWriteable(pKey) );
  4181   4181         for(i=0; i<nCol; i++){
  4182   4182           char *zColl = pIdx->azColl[i];
  4183         -        if( zColl==0 ) zColl = "BINARY";
         4183  +        if( NEVER(zColl==0) ) zColl = "BINARY";
  4184   4184           pKey->aColl[i] = sqlite3LocateCollSeq(pParse, zColl);
  4185   4185           pKey->aSortOrder[i] = pIdx->aSortOrder[i];
  4186   4186         }
  4187   4187         if( pParse->nErr ){
  4188   4188           sqlite3KeyInfoUnref(pKey);
  4189   4189         }else{
  4190   4190           pIdx->pKeyInfo = pKey;
  4191   4191         }
  4192   4192       }
  4193   4193     }
  4194   4194     return sqlite3KeyInfoRef(pIdx->pKeyInfo);
  4195   4195   }

Changes to src/insert.c.

  1580   1580       if( regR!=regIdx ) sqlite3ReleaseTempRange(pParse, regR, nPkField);
  1581   1581     }
  1582   1582     if( ipkTop ){
  1583   1583       sqlite3VdbeAddOp2(v, OP_Goto, 0, ipkTop+1);
  1584   1584       sqlite3VdbeJumpHere(v, ipkBottom);
  1585   1585     }
  1586   1586     
  1587         -  if( pbMayReplace ){
  1588         -    *pbMayReplace = seenReplace;
  1589         -  }
         1587  +  *pbMayReplace = seenReplace;
  1590   1588     VdbeModuleComment((v, "END: GenCnstCks(%d)", seenReplace));
  1591   1589   }
  1592   1590   
  1593   1591   /*
  1594   1592   ** This routine generates code to finish the INSERT or UPDATE operation
  1595   1593   ** that was started by a prior call to sqlite3GenerateConstraintChecks.
  1596   1594   ** A consecutive range of registers starting at regNewData contains the
................................................................................
  1624   1622       if( aRegIdx[i]==0 ) continue;
  1625   1623       if( pIdx->pPartIdxWhere ){
  1626   1624         sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
  1627   1625       }
  1628   1626       sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i]);
  1629   1627       pik_flags = 0;
  1630   1628       if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT;
  1631         -    if( pIdx->autoIndex==2 && !HasRowid(pTab) && pParse->nested==0 ){
         1629  +    if( pIdx->autoIndex==2 && !HasRowid(pTab) ){
         1630  +      assert( pParse->nested==0 );
  1632   1631         pik_flags |= OPFLAG_NCHANGE;
  1633   1632       }
  1634   1633       if( pik_flags )  sqlite3VdbeChangeP5(v, pik_flags);
  1635   1634     }
  1636   1635     if( !HasRowid(pTab) ) return;
  1637   1636     regData = regNewData + 1;
  1638   1637     regRec = sqlite3GetTempReg(pParse);

Changes to src/update.c.

   416    416           }
   417    417         }
   418    418       }
   419    419       for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
   420    420         int iThisCur = iIdxCur+i;
   421    421         assert( aRegIdx );
   422    422         if( (openAll || aRegIdx[i]>0)
   423         -       && iThisCur!=aiCurOnePass[0]
   424    423          && iThisCur!=aiCurOnePass[1]
   425    424         ){
          425  +        assert( iThisCur!=aiCurOnePass[0] );
   426    426           sqlite3VdbeAddOp3(v, OP_OpenWrite, iThisCur, pIdx->tnum, iDb);
   427    427           sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
   428    428           assert( pParse->nTab>iThisCur );
   429    429           VdbeComment((v, "%s", pIdx->zName));
   430    430           if( okOnePass && pPk && iThisCur==iDataCur ){
   431    431             sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak,
   432    432                                  regKey, nKey);

Changes to src/vdbe.c.

   884    884         testcase( pOp->p5==2 );
   885    885         testcase( pOp->p5==3 );
   886    886         testcase( pOp->p5==4 );
   887    887         zType = azType[pOp->p5-1];
   888    888       }else{
   889    889         zType = 0;
   890    890       }
          891  +    assert( zType!=0 || pOp->p4.z!=0 );
   891    892       zLogFmt = "abort at %d in [%s]: %s";
   892    893       if( zType && pOp->p4.z ){
   893    894         sqlite3SetString(&p->zErrMsg, db, "%s constraint failed: %s", 
   894    895                          zType, pOp->p4.z);
   895    896       }else if( pOp->p4.z ){
   896    897         sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
   897         -    }else if( zType ){
          898  +    }else{
   898    899         sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType);
   899         -    }else{
   900         -      zLogFmt = "abort at %d in [%s]";
   901    900       }
   902    901       sqlite3_log(pOp->p1, zLogFmt, pc, p->zSql, p->zErrMsg);
   903    902     }
   904    903     rc = sqlite3VdbeHalt(p);
   905    904     assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
   906    905     if( rc==SQLITE_BUSY ){
   907    906       p->rc = rc = SQLITE_BUSY;
................................................................................
  4609   4608         assert( pC->deferredMoveto==0 );
  4610   4609         pC->cacheStatus = CACHE_STALE;
  4611   4610       }
  4612   4611     }
  4613   4612     break;
  4614   4613   }
  4615   4614   
  4616         -/* Opcode: IdxDelete P1 P2 P3 * P5
         4615  +/* Opcode: IdxDelete P1 P2 P3 * *
  4617   4616   ** Synopsis: key=r[P2@P3]
  4618   4617   **
  4619   4618   ** The content of P3 registers starting at register P2 form
  4620   4619   ** an unpacked index key. This opcode removes that entry from the 
  4621   4620   ** index opened by cursor P1.
  4622   4621   */
  4623   4622   case OP_IdxDelete: {
................................................................................
  4629   4628     assert( pOp->p3>0 );
  4630   4629     assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem-p->nCursor)+1 );
  4631   4630     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  4632   4631     pC = p->apCsr[pOp->p1];
  4633   4632     assert( pC!=0 );
  4634   4633     pCrsr = pC->pCursor;
  4635   4634     assert( pCrsr!=0 );
  4636         -  if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
         4635  +  assert( pOp->p5==0 );
  4637   4636     r.pKeyInfo = pC->pKeyInfo;
  4638   4637     r.nField = (u16)pOp->p3;
  4639   4638     r.flags = UNPACKED_PREFIX_MATCH;
  4640   4639     r.aMem = &aMem[pOp->p2];
  4641   4640   #ifdef SQLITE_DEBUG
  4642   4641     { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
  4643   4642   #endif

Changes to src/vdbeaux.c.

   533    533       int i;
   534    534       VdbeOpList const *pIn = aOp;
   535    535       for(i=0; i<nOp; i++, pIn++){
   536    536         int p2 = pIn->p2;
   537    537         VdbeOp *pOut = &p->aOp[i+addr];
   538    538         pOut->opcode = pIn->opcode;
   539    539         pOut->p1 = pIn->p1;
   540         -      if( p2<0 && (sqlite3OpcodeProperty[pOut->opcode] & OPFLG_JUMP)!=0 ){
          540  +      if( p2<0 ){
          541  +        assert( sqlite3OpcodeProperty[pOut->opcode] & OPFLG_JUMP );
   541    542           pOut->p2 = addr + ADDR(p2);
   542    543         }else{
   543    544           pOut->p2 = p2;
   544    545         }
   545    546         pOut->p3 = pIn->p3;
   546    547         pOut->p4type = P4_NOTUSED;
   547    548         pOut->p4.p = 0;

Changes to src/where.c.

  6063   6063       }else{
  6064   6064         sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
  6065   6065       }
  6066   6066       if( pLoop->wsFlags & WHERE_INDEXED ){
  6067   6067         Index *pIx = pLoop->u.btree.pIndex;
  6068   6068         int iIndexCur;
  6069   6069         int op = OP_OpenRead;
  6070         -      if( pWInfo->okOnePass && iIdxCur ){
         6070  +      /* iIdxCur is always set if to a positive value if ONEPASS is possible */
         6071  +      assert( iIdxCur!=0 || (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0 );
         6072  +      if( pWInfo->okOnePass ){
  6071   6073           Index *pJ = pTabItem->pTab->pIndex;
  6072   6074           iIndexCur = iIdxCur;
  6073   6075           assert( wctrlFlags & WHERE_ONEPASS_DESIRED );
  6074   6076           while( ALWAYS(pJ) && pJ!=pIx ){
  6075   6077             iIndexCur++;
  6076   6078             pJ = pJ->pNext;
  6077   6079           }