on master help sign in
Check for nulls in ChkCase
commit4072b67ee2e462341919ff852d27cdc146e43fc1 authorBenjamin Saunders <besaunde@sfu.ca> dateTue 25 Jun 2013, 16:50 (13 years ago) parent9130dda
1 file changed+13−9
src/IRTS/CodegenLLVM.hs+13−9
src/IRTS/CodegenLLVM.hs+13−9
@@ -331,26 +331,30 @@ cgExpr (SChkCase inspect alts) = do
331331 case mval of
332332 Nothing -> return Nothing
333333 Just val ->
334− do ptr <- inst $ BitCast val (PointerType (IntegerType 8) (AddrSpace 0)) []
334+ do endBBN <- getName "endChkCase"
335+ notNullBBN <- getName "notNull"
336+ originBlock <- gets currentBlockName
337+ isNull <- inst $ ICmp IPred.EQ val (ConstantOperand nullValue) []
338+ terminate $ CondBr isNull endBBN notNullBBN []
339+ newBlock notNullBBN
340+ ptr <- inst $ BitCast val (PointerType (IntegerType 8) (AddrSpace 0)) []
335341 flag <- inst $ Load False ptr Nothing 0 []
336342 isVal <- inst $ ICmp IPred.EQ flag (ConstantOperand (C.Int 8 (-1))) []
337343 conBBN <- getName "constructor"
338− valBBN <- getName "value"
339− originBlock <- gets currentBlockName
340− terminate $ CondBr isVal valBBN conBBN []
344+ terminate $ CondBr isVal endBBN conBBN []
341345 newBlock conBBN
342346 result <- cgCase val alts
343347 caseExitBlock <- gets currentBlockName
344348 case result of
345349 Nothing -> do
346350 terminate $ Unreachable []
347− newBlock valBBN
351+ newBlock endBBN
348352 return $ Just val
349− Just r -> do
350− terminate $ Br valBBN []
351− newBlock valBBN
353+ Just caseVal -> do
354+ terminate $ Br endBBN []
355+ newBlock endBBN
352356 Just <$> (inst $ Phi (PointerType valueType (AddrSpace 0))
353− [(val, originBlock), (r, caseExitBlock)] [])
357+ [(val, originBlock), (val, notNullBBN), (caseVal, caseExitBlock)] [])
354358cgExpr (SProj conVar idx) = do
355359 val <- var conVar
356360 case val of