Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-exhaustive patterns #73

Closed
fduxiao opened this issue Nov 12, 2019 · 6 comments
Closed

Non-exhaustive patterns #73

fduxiao opened this issue Nov 12, 2019 · 6 comments

Comments

@fduxiao
Copy link

fduxiao commented Nov 12, 2019

src/LLVM/Pretty.hs:530:13-48: Non-exhaustive patterns in PointerType argTy _

I got this error when buiding some IR with llvm-hs-pretty

@cocreature
Copy link
Member

Can you show us the IR? Is this a compile error or a runtime error?

@sdiehl
Copy link
Member

sdiehl commented Nov 12, 2019

There are cases where you can construct llvm-hs ASTs that are invalid IR and they can't be printed. Thus the non-exhaustive patterns. Make sure that your IR passes the verifier first and then post it here.

@fduxiao
Copy link
Author

fduxiao commented Nov 12, 2019

Here's my code. I'm following this guide generating them.

module Main where

import Data.Text.Lazy (unpack)
import Data.String
import LLVM.AST
import LLVM.Pretty
import LLVM.AST.Global


printModule :: Module -> IO ()
printModule = putStr. unpack . ppllvm

double :: Type
double = FloatingPointType DoubleFP

makeName :: String -> Name
makeName = Name . fromString

local ::  Name -> Operand
local = LocalReference double

ret :: Operand -> Named Terminator
ret val = Do $ Ret (Just val) []

func :: Definition
func = GlobalDefinition $ functionDefaults {
    name          = makeName "foo"
    , parameters  = ([Parameter double (makeName "a") []], False)
    , returnType  = double
    , basicBlocks = [
        BasicBlock (makeName "entry") [
            UnName 1 := Alloca double Nothing 0 []
            , UnName 2 := Store False (local $ UnName 1) (local $ makeName "a") Nothing 0 []
            , UnName 3 := Load False (local $ UnName 1) Nothing 0 []
        ] (ret . local $ UnName 3)
    ]
}


main :: IO ()
main = printModule $ defaultModule {
    moduleName = fromString "some name"
    , moduleDefinitions = [func]
}

@sdiehl
Copy link
Member

sdiehl commented Nov 18, 2019

Your load instruction needs to be loading from a pointer type double* instead of double.

@fduxiao
Copy link
Author

fduxiao commented Nov 20, 2019

@sdiehl I finally found how the problem happened. I think it might be the problem with your tutorial of kaleidoscope. I opened another issue under that repo illustrating it.

@sdiehl
Copy link
Member

sdiehl commented Jan 1, 2020

Made a note about non-exhaustive pattern and tried to add some more informative error messages. I'm in the process of fixing the kaleidoscope tutorial so it's up to date as well. That's about all I can do so closing out this issue.

@sdiehl sdiehl closed this as completed Jan 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants