[llvm] ffaca14 - [IR] Value: Fix OpCode checks
Nick Desaulniers via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 10 16:46:42 PDT 2021
Author: Sami Tolvanen
Date: 2021-06-10T16:46:33-07:00
New Revision: ffaca140d01b0b93723c3322b08351b03b95831f
URL: https://github.com/llvm/llvm-project/commit/ffaca140d01b0b93723c3322b08351b03b95831f
DIFF: https://github.com/llvm/llvm-project/commit/ffaca140d01b0b93723c3322b08351b03b95831f.diff
LOG: [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
Added:
Modified:
llvm/lib/IR/Value.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index 33b61c900e70..c3796f134922 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()) &&
More information about the llvm-commits
mailing list