Skip to content

llvm::parseIR does not handle extractValue correctly #49436

@andrew-wja

Description

@andrew-wja
Bugzilla Link 50092
Version trunk
OS Linux
Attachments minimized test case

Extended Description

I have seen #​3465 (#3465 ) -- this bug is not that bug.

The attached simple module is handled fine by llvm-as but causes a signal to be raised when parsed via llvm::parseIR. No parse error message is returned in the user-supplied char**, we just go straight to throwing an exception. I can't see a throw in the code in llvm::parseIR so I assume it is coming from deeper in the machinery.

I am calling llvm::parseIR via LLVMParseIRInContext in the C interface.

It handles many other instructions just fine -- this specific case is the one breaking. It also handle parse failures of other instructions just fine -- we get an error message describing what went wrong in the user-supplied char**. In the case of extractValue, we get no error message -- just a crash.

This attached IR fragment is actually from the extractValue description in the LLVM language reference. If any fragment should parse successfully, I'd think it should be that one :)

I'm one of the maintainers of the downstream LLVM Haskell bindings (https://github.com/llvm-hs/llvm-hs), and we have been tracking this problem since LLVM 3.2 according to one of our commented-out test cases. It would be great to see a fix so we can test our generation of extractValue instructions properly.

Any fix can be tested as follows:

Check out llvm-hs from github (you'll have to uncomment the crashing test here: https://github.com/llvm-hs/llvm-hs/blob/llvm-9/llvm-hs/test/LLVM/Test/Constants.hs#L158)

cd llvm-hs

LD_LIBRARY_PATH=$(realpath ../llvm-9.0.1-root/lib) PATH=$(realpath ../llvm-9.0.1-root/bin):$PATH stack test

replacing those settings for PATH and LD_LIBRARY_PATH appropriately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions