/ Check-in [8681750e]
Login

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

Overview
Comment:Improved comments on the VDBE branch coverage testing logic. Fix the VDBE branch coverage measurement on the OP_MustBeInt opcode.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8681750e855a020ee374cb9f973f701a72068e33f97d0101a4fab3a228e5ebda
User & Date: drh 2019-04-01 14:01:21
Context
2019-04-01
14:30
Improved VDBE branch coverage in the run-time frame-spec error detection logic of window functions. check-in: f56d305a user: drh tags: trunk
14:01
Improved comments on the VDBE branch coverage testing logic. Fix the VDBE branch coverage measurement on the OP_MustBeInt opcode. check-in: 8681750e user: drh tags: trunk
13:06
Fix a defect in the VDBE branch coverage testing logic. check-in: 1fcf3307 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

   118    118   #endif
   119    119   
   120    120   /*
   121    121   ** Invoke the VDBE coverage callback, if that callback is defined.  This
   122    122   ** feature is used for test suite validation only and does not appear an
   123    123   ** production builds.
   124    124   **
   125         -** M is an integer between 2 and 4.  2 indicates a ordinary two-way
   126         -** branch (I=0 means fall through and I=1 means taken).  3 indicates
   127         -** a 3-way branch where the third way is when one of the operands is
   128         -** NULL.  4 indicates the OP_Jump instruction which has three destinations
   129         -** depending on whether the first operand is less than, equal to, or greater
   130         -** than the second. 
          125  +** M is the type of branch.  I is the direction taken for this instance of
          126  +** the branch.
          127  +**
          128  +**   M: 2 - two-way branch (I=0: fall-thru   1: jump                )
          129  +**      3 - two-way + NULL (I=0: fall-thru   1: jump      2: NULL   )
          130  +**      4 - OP_Jump        (I=0: jump p1     1: jump p2   2: jump p3)
          131  +**
          132  +** In other words, if M is 2, then I is either 0 (for fall-through) or
          133  +** 1 (for when the branch is taken).  If M is 3, the I is 0 for an
          134  +** ordinary fall-through, I is 1 if the branch was taken, and I is 2 
          135  +** if the result of comparison is NULL.  For M=3, I=2 the jump may or
          136  +** may not be taken, depending on the SQLITE_JUMPIFNULL flags in p5.
          137  +** When M is 4, that means that an OP_Jump is being run.  I is 0, 1, or 2
          138  +** depending on if the operands are less than, equal, or greater than.
   131    139   **
   132    140   ** iSrcLine is the source code line (from the __LINE__ macro) that
   133    141   ** generated the VDBE instruction combined with flag bits.  The source
   134    142   ** code line number is in the lower 24 bits of iSrcLine and the upper
   135    143   ** 8 bytes are flags.  The lower three bits of the flags indicate
   136    144   ** values for I that should never occur.  For example, if the branch is
   137    145   ** always taken, the flags should be 0x05 since the fall-through and
   138    146   ** alternate branch are never taken.  If a branch is never taken then
   139    147   ** flags should be 0x06 since only the fall-through approach is allowed.
   140    148   **
   141         -** Bit 0x04 of the flags indicates an OP_Jump opcode that is only
          149  +** Bit 0x08 of the flags indicates an OP_Jump opcode that is only
   142    150   ** interested in equal or not-equal.  In other words, I==0 and I==2
   143         -** should be treated the same.
          151  +** should be treated as equivalent
   144    152   **
   145    153   ** Since only a line number is retained, not the filename, this macro
   146    154   ** only works for amalgamation builds.  But that is ok, since these macros
   147    155   ** should be no-ops except for special builds used to measure test coverage.
   148    156   */
   149    157   #if !defined(SQLITE_VDBE_COVERAGE)
   150    158   # define VdbeBranchTaken(I,M)
................................................................................
   160    168       /* The upper 8 bits of iSrcLine are flags.  The lower three bits of
   161    169       ** the flags indicate directions that the branch can never go.  If
   162    170       ** a branch really does go in one of those directions, assert right
   163    171       ** away. */
   164    172       mNever = iSrcLine >> 24;
   165    173       assert( (I & mNever)==0 );
   166    174       if( sqlite3GlobalConfig.xVdbeBranch==0 ) return;  /*NO_TEST*/
          175  +    /* Invoke the branch coverage callback with three arguments:
          176  +    **    iSrcLine - the line number of the VdbeCoverage() macro, with
          177  +    **               flags removed.
          178  +    **    I        - Mask of bits 0x07 indicating which cases are are
          179  +    **               fulfilled by this instance of the jump.  0x01 means
          180  +    **               fall-thru, 0x02 means taken, 0x04 means NULL.  Any
          181  +    **               impossible cases (ex: if the comparison is never NULL)
          182  +    **               are filled in automatically so that the coverage
          183  +    **               measurement logic does not flag those impossible cases
          184  +    **               as missed coverage.
          185  +    **    M        - Type of jump.  Same as M argument above
          186  +    */
   167    187       I |= mNever;
   168    188       if( M==2 ) I |= 0x04;
   169    189       if( M==4 ){
   170    190         I |= 0x08;
   171    191         if( (mNever&0x08)!=0 && (I&0x05)!=0) I |= 0x05; /*NO_TEST*/
   172    192       }
   173    193       sqlite3GlobalConfig.xVdbeBranch(sqlite3GlobalConfig.pVdbeBranchArg,
................................................................................
  1730   1750   ** without data loss, then jump immediately to P2, or if P2==0
  1731   1751   ** raise an SQLITE_MISMATCH exception.
  1732   1752   */
  1733   1753   case OP_MustBeInt: {            /* jump, in1 */
  1734   1754     pIn1 = &aMem[pOp->p1];
  1735   1755     if( (pIn1->flags & MEM_Int)==0 ){
  1736   1756       applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
  1737         -    VdbeBranchTaken((pIn1->flags&MEM_Int)==0, 2);
  1738   1757       if( (pIn1->flags & MEM_Int)==0 ){
         1758  +      VdbeBranchTaken(1, 2);
  1739   1759         if( pOp->p2==0 ){
  1740   1760           rc = SQLITE_MISMATCH;
  1741   1761           goto abort_due_to_error;
  1742   1762         }else{
  1743   1763           goto jump_to_p2;
  1744   1764         }
  1745   1765       }
  1746   1766     }
         1767  +  VdbeBranchTaken(0, 2);
  1747   1768     MemSetTypeFlag(pIn1, MEM_Int);
  1748   1769     break;
  1749   1770   }
  1750   1771   
  1751   1772   #ifndef SQLITE_OMIT_FLOATING_POINT
  1752   1773   /* Opcode: RealAffinity P1 * * * *
  1753   1774   **