Problems with IR Builder


I am finding that I can happily add this instruction to with the IR Builder API.
%reg010 = add i32 %reg007, i64 %reg001

Then when I do a "verify" pass I get this:
Both operands to a binary operator are not of the same type!
  %reg010 = add i32 %reg007, i64 %reg001

Now, why doesn't it catch this error when I add the instruction,
instead of waiting till the verify pass to catch it?

I have found other cases, where it passes the verify pass, I can write
the .bc bitcode to a file.
Then when I use llvm-dis to convert the .bc to .ll format, llvm-dis
fails to load it.
So, why aren't the tests done at the "verify" pass the same as the
tests done by llvm-dis ?

I need my program to have sufficient tests in it to ensure that
whatever bitcode it tries to write, it will be valid bitcode that can
be read by all other llvm tools.
I.e. I wish to catch the error at creation time.

Is this expected behaviour, or a bug?

Kind Regards


It should be checked at creation if you have assertions enabled. It’s checked in BinaryOperator::init which is called by the BinaryOperator constructor.

I’m sure it’s done this way for performance of release builds. Development is done with assertions enabled to flush out all the issues then release builds don’t have to pay the cost of the checks.