From 8c1d1e65b3b11b20131da9a6a24566cab26f0083 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Wed, 23 Oct 2024 11:06:00 -0400 Subject: [PATCH] ReadConstant handling of null pointers --- IDEHelper/Compiler/BfIRBuilder.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/IDEHelper/Compiler/BfIRBuilder.cpp b/IDEHelper/Compiler/BfIRBuilder.cpp index 5c73e89e..8d5dc23b 100644 --- a/IDEHelper/Compiler/BfIRBuilder.cpp +++ b/IDEHelper/Compiler/BfIRBuilder.cpp @@ -1413,6 +1413,22 @@ BfIRValue BfIRConstHolder::ReadConstant(void* ptr, BfType* type) return CreateConst(BfTypeCode_StringId, *(int32*)ptr); } + if (type->IsPointer()) + { + bool isZero = false; + if (mModule->mSystem->mPtrSize == 4) + isZero = *(int32*)ptr == 0; + else + isZero = *(int64*)ptr == 0; + if (isZero) + { + BfIRType irType; + irType.mKind = BfIRTypeData::TypeKind_TypeId; + irType.mId = type->mTypeId; + return CreateConstNull(irType); + } + } + return BfIRValue(); }