check for valid IL offsets before computing block ILsize
authorAndy Ayers <andya@microsoft.com>
Tue, 8 Jan 2019 23:19:42 +0000 (15:19 -0800)
committerAndy Ayers <andya@microsoft.com>
Tue, 8 Jan 2019 23:19:42 +0000 (15:19 -0800)
src/jit/flowgraph.cpp

index 2df3cce..eedb1aa 100644 (file)
@@ -6835,8 +6835,14 @@ void Compiler::fgImport()
             // Assume if we generate any IR for the block we generate IR for the entire block.
             if (!block->isEmpty())
             {
-                unsigned blockILSize = blockILSize = block->bbCodeOffsEnd - block->bbCodeOffs;
-                importedILSize += blockILSize;
+                IL_OFFSET beginOffset = block->bbCodeOffs;
+                IL_OFFSET endOffset   = block->bbCodeOffsEnd;
+
+                if ((beginOffset != BAD_IL_OFFSET) && (endOffset != BAD_IL_OFFSET) && (endOffset > beginOffset))
+                {
+                    unsigned blockILSize = endOffset - beginOffset;
+                    importedILSize += blockILSize;
+                }
             }
         }
     }