This is an archive of the discontinued LLVM Phabricator instance.

[IR Verifier] didn't check if switch case is constant, align IR Verifier's check with LLParser.
ClosedPublic

Authored by Peter on Oct 24 2022, 7:11 PM.

Details

Summary

If a programmer incorrectly Switch->setOperand() and Verifier will pass, causing problems when dumping this Module
This patch aligns SwitchInst's check with LLParser. It also includes a test to justify the patch.

Diff Detail

Event Timeline

Peter created this revision.Oct 24 2022, 7:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 24 2022, 7:11 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
Peter requested review of this revision.Oct 24 2022, 7:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 24 2022, 7:11 PM
arsenm added a subscriber: arsenm.Oct 24 2022, 7:31 PM
arsenm added inline comments.
llvm/lib/IR/Verifier.cpp
2882

Is this missing a check for a consistent number of operands, or is that hidden somewhere else?

Peter added inline comments.Oct 24 2022, 8:52 PM
llvm/lib/IR/Verifier.cpp
2882

I don't think there is a check for operand number consistency.

The Index * 2 + 2 is getCaseValue()'s default behavior. I believe SwitchInst manages operand number consistency when you addCase().

arsenm accepted this revision.Oct 31 2022, 7:26 PM
arsenm added inline comments.
llvm/lib/IR/Verifier.cpp
2882

But the verifier's job is to ensure like that is followed. Not sure there's another way to bypass that

This revision is now accepted and ready to land.Oct 31 2022, 7:26 PM
Peter marked 2 inline comments as done.Oct 31 2022, 8:34 PM
Peter added inline comments.
llvm/lib/IR/Verifier.cpp
2882

I reviewed the SwitchInst definition again and couldn't find a bypass. Will merge tomorrow.

This revision was automatically updated to reflect the committed changes.
Peter marked an inline comment as done.