diff options
author | Sami Tolvanen <samitolvanen@google.com> | 2021-06-10 16:18:57 -0700 |
---|---|---|
committer | Nick Desaulniers <ndesaulniers@google.com> | 2021-06-10 16:46:33 -0700 |
commit | ffaca140d01b0b93723c3322b08351b03b95831f (patch) | |
tree | 879b006447f068ab6d712390d97e0d020969a69b /llvm/lib/IR/Value.cpp | |
parent | 5a1589fc6d1131e6d73c498cc5987433d1c5e098 (diff) | |
download | llvm-ffaca140d01b0b93723c3322b08351b03b95831f.zip llvm-ffaca140d01b0b93723c3322b08351b03b95831f.tar.gz llvm-ffaca140d01b0b93723c3322b08351b03b95831f.tar.bz2 |
[IR] Value: Fix OpCode checks
Value::SubclassID cannot be directly compared to Instruction enums, such as
Instruction::{Call,Invoke,CallBr}. We have to first subtract InstructionVal
from the SubclassID to get the OpCode, similar to Instruction::getOpCode().
Reviewed By: nickdesaulniers
Differential Revision: https://reviews.llvm.org/D104043
Diffstat (limited to 'llvm/lib/IR/Value.cpp')
-rw-r--r-- | llvm/lib/IR/Value.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp index 33b61c9..c3796f1 100644 --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -58,10 +58,13 @@ Value::Value(Type *ty, unsigned scid) // FIXME: Why isn't this in the subclass gunk?? // Note, we cannot call isa<CallInst> before the CallInst has been // constructed. - if (SubclassID == Instruction::Call || SubclassID == Instruction::Invoke || - SubclassID == Instruction::CallBr) + unsigned OpCode = 0; + if (SubclassID >= InstructionVal) + OpCode = SubclassID - InstructionVal; + if (OpCode == Instruction::Call || OpCode == Instruction::Invoke || + OpCode == Instruction::CallBr) assert((VTy->isFirstClassType() || VTy->isVoidTy() || VTy->isStructTy()) && - "invalid CallInst type!"); + "invalid CallBase type!"); else if (SubclassID != BasicBlockVal && (/*SubclassID < ConstantFirstVal ||*/ SubclassID > ConstantLastVal)) assert((VTy->isFirstClassType() || VTy->isVoidTy()) && |