@@ -1328,16 +1328,22 @@ std::shared_ptr<ExecutableCode> LLVMCodeBuilder::finalize()
13281328 break ;
13291329
13301330 case Compiler::CodeType::Reporter: {
1331- // Use last instruction return value and create a ValueData instance
1332- assert (!m_instructions.empty ());
1333- LLVMRegister *ret = m_instructions.back ()->functionReturnReg ;
1334- m_builder.CreateRet (m_builder.CreateLoad (m_valueDataType, createNewValue (ret))); // return copy
1331+ // Use last instruction return value (or last constant) and create a ValueData instance
1332+ assert (!m_instructions.empty () || m_lastConstValue);
1333+ LLVMRegister *ret = m_instructions.empty () ? m_lastConstValue : m_instructions.back ()->functionReturnReg ;
1334+ llvm::Value *copy = createNewValue (ret);
1335+ m_builder.CreateRet (m_builder.CreateLoad (m_valueDataType, copy));
13351336 break ;
13361337 }
1338+
13371339 case Compiler::CodeType::HatPredicate:
1338- // Use last instruction return value
1339- assert (!m_instructions.empty ());
1340- m_builder.CreateRet (m_instructions.back ()->functionReturnReg ->value );
1340+ // Use last instruction return value (or last constant)
1341+ assert (!m_instructions.empty () || m_lastConstValue);
1342+
1343+ if (m_instructions.empty ())
1344+ m_builder.CreateRet (castValue (m_lastConstValue, Compiler::StaticType::Bool));
1345+ else
1346+ m_builder.CreateRet (castValue (m_instructions.back ()->functionReturnReg , Compiler::StaticType::Bool));
13411347 break ;
13421348 }
13431349
@@ -1403,6 +1409,7 @@ CompilerConstant *LLVMCodeBuilder::addConstValue(const Value &value)
14031409{
14041410 auto constReg = std::make_shared<LLVMConstantRegister>(TYPE_MAP[value.type ()], value);
14051411 auto reg = std::reinterpret_pointer_cast<LLVMRegister>(constReg);
1412+ m_lastConstValue = reg.get ();
14061413 return static_cast <CompilerConstant *>(static_cast <CompilerValue *>(addReg (reg, nullptr )));
14071414}
14081415
@@ -3154,6 +3161,7 @@ llvm::Value *LLVMCodeBuilder::createStringComparison(LLVMRegister *arg1, LLVMReg
31543161 std::string str1 = arg1->constValue ().toString ();
31553162 std::string str2 = arg2->constValue ().toString ();
31563163 result = strcasecmp (str1.c_str (), str2.c_str ()) == 0 ;
3164+ result = string_compare_case_insensitive (str1, str2) == 0 ;
31573165 }
31583166
31593167 return m_builder.getInt1 (result);
0 commit comments