Is there any way to check if metadata has been correctly set?


I’m trying to check if metadata has been corrrectly set in a certain backend pass for UT purpose, but cannot found anyway could work. I have limit experience on IR and MIR test, but neither of them could check metadata. So is there any way could do that?

Thanks in advance!


There’s a “Verifier” check that happens every time IR is loaded or emitted, or it can be run as a pass, which checks whether the module (including metadata) is structured correctly. Take a look at llvm/lib/IR/Verifier.cpp. That gives a basic assurance that metadata is in the right format, but it’s still possible that the metadata might not mean what it’s supposed to (you have to write your own tests for that).

For backend / MIR things it’s less clear, and depends on what kind of metadata is present. I think most of the metadata remains in the IR module.

Thanks your kindly reply. Sorry for didn’t make it clear, I intend to do it in IR test, so Verifier.cpp might not help.

If it’s an IR test that’s run using the “opt” tool, then opt automatically runs the Verifier at the end of all the other passes it runs [0], so that will be happening automatically.

If you’re doing this in IR tests, is that because you’re aiming to test something deeper than just the basic formatting of metadata? If that’s the case, then you’ll need to think about the different inputs your metadata might encounter and produce test files, Then when you know what the behaviour should be with that input, write FileCheck lines to check that the output metadata is correct.


Case #1 is what I tried to find, that’s really helpful, many thanks!