From 58f8744af4fb3494ca8cc305c2d1a0eb3fb9d35a Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Mon, 19 Mar 2018 17:28:51 -0700 Subject: [PATCH] JIT: tolerate nonzero constant byrefs in impCheckForNullPointer (#17042) With the advent of #16966 we may now see constant nonzero byrefs from things like RVA statics. Tolerate these in `impCheckForNullPointer`. Note previously we'd type these as ints/longs and so bail out of `impCheckForNullPointer` after the first check. Closes #17008. --- src/jit/compiler.hpp | 8 +++++++- tests/src/JIT/Directed/RVAInit/oddsize.ilproj | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/jit/compiler.hpp b/src/jit/compiler.hpp index 2a6fd861536a..93db46bfef17 100644 --- a/src/jit/compiler.hpp +++ b/src/jit/compiler.hpp @@ -4355,7 +4355,13 @@ inline GenTree* Compiler::impCheckForNullPointer(GenTree* obj) if (obj->gtOper == GT_CNS_INT) { assert(obj->gtType == TYP_REF || obj->gtType == TYP_BYREF); - assert(obj->gtIntCon.gtIconVal == 0); + + // We can see non-zero byrefs for RVA statics. + if (obj->gtIntCon.gtIconVal != 0) + { + assert(obj->gtType == TYP_BYREF); + return obj; + } unsigned tmp = lvaGrabTemp(true DEBUGARG("CheckForNullPointer")); diff --git a/tests/src/JIT/Directed/RVAInit/oddsize.ilproj b/tests/src/JIT/Directed/RVAInit/oddsize.ilproj index 39d8bfaf0d96..7e22d9ffb4f8 100644 --- a/tests/src/JIT/Directed/RVAInit/oddsize.ilproj +++ b/tests/src/JIT/Directed/RVAInit/oddsize.ilproj @@ -10,7 +10,6 @@ Exe {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} ..\..\ - 1