diff options
author | whitequark <whitequark@whitequark.org> | 2019-04-24 13:30:03 +0000 |
---|---|---|
committer | whitequark <whitequark@whitequark.org> | 2019-04-24 13:30:03 +0000 |
commit | 50392a3b1b84beea67bb294f6855d5fb1facd35e (patch) | |
tree | 92674af471cec2be760785175af827a21927be40 /llvm/lib/IR/Core.cpp | |
parent | f96b6d927088db90286844a472d45a5ac9d3f3d6 (diff) | |
download | bcm5719-llvm-50392a3b1b84beea67bb294f6855d5fb1facd35e.tar.gz bcm5719-llvm-50392a3b1b84beea67bb294f6855d5fb1facd35e.zip |
[LLVM-C] Use dyn_cast instead of unwrap in LLVMGetDebugLoc functions
Summary:
The `unwrap<Type>` calls can assert with:
```
Assertion failed: (isa<X>(Val) && "cast<Ty>() argument of incompatible type!"), function cast
```
so replace them with `dyn_cast`.
Reviewers: whitequark, abdulras, hiraditya, compnerd
Reviewed By: whitequark
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60473
llvm-svn: 359093
Diffstat (limited to 'llvm/lib/IR/Core.cpp')
-rw-r--r-- | llvm/lib/IR/Core.cpp | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index 2a4ea8d5246..354921dc43e 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -1199,15 +1199,17 @@ void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char *Name, const char *LLVMGetDebugLocDirectory(LLVMValueRef Val, unsigned *Length) { if (!Length) return nullptr; StringRef S; - if (const auto *I = unwrap<Instruction>(Val)) { - S = I->getDebugLoc()->getDirectory(); - } else if (const auto *GV = unwrap<GlobalVariable>(Val)) { + if (const auto *I = dyn_cast<Instruction>(unwrap(Val))) { + if (const auto &DL = I->getDebugLoc()) { + S = DL->getDirectory(); + } + } else if (const auto *GV = dyn_cast<GlobalVariable>(unwrap(Val))) { SmallVector<DIGlobalVariableExpression *, 1> GVEs; GV->getDebugInfo(GVEs); if (GVEs.size()) if (const DIGlobalVariable *DGV = GVEs[0]->getVariable()) S = DGV->getDirectory(); - } else if (const auto *F = unwrap<Function>(Val)) { + } else if (const auto *F = dyn_cast<Function>(unwrap(Val))) { if (const DISubprogram *DSP = F->getSubprogram()) S = DSP->getDirectory(); } else { @@ -1221,15 +1223,17 @@ const char *LLVMGetDebugLocDirectory(LLVMValueRef Val, unsigned *Length) { const char *LLVMGetDebugLocFilename(LLVMValueRef Val, unsigned *Length) { if (!Length) return nullptr; StringRef S; - if (const auto *I = unwrap<Instruction>(Val)) { - S = I->getDebugLoc()->getFilename(); - } else if (const auto *GV = unwrap<GlobalVariable>(Val)) { + if (const auto *I = dyn_cast<Instruction>(unwrap(Val))) { + if (const auto &DL = I->getDebugLoc()) { + S = DL->getFilename(); + } + } else if (const auto *GV = dyn_cast<GlobalVariable>(unwrap(Val))) { SmallVector<DIGlobalVariableExpression *, 1> GVEs; GV->getDebugInfo(GVEs); if (GVEs.size()) if (const DIGlobalVariable *DGV = GVEs[0]->getVariable()) S = DGV->getFilename(); - } else if (const auto *F = unwrap<Function>(Val)) { + } else if (const auto *F = dyn_cast<Function>(unwrap(Val))) { if (const DISubprogram *DSP = F->getSubprogram()) S = DSP->getFilename(); } else { @@ -1242,15 +1246,17 @@ const char *LLVMGetDebugLocFilename(LLVMValueRef Val, unsigned *Length) { unsigned LLVMGetDebugLocLine(LLVMValueRef Val) { unsigned L = 0; - if (const auto *I = unwrap<Instruction>(Val)) { - L = I->getDebugLoc()->getLine(); - } else if (const auto *GV = unwrap<GlobalVariable>(Val)) { + if (const auto *I = dyn_cast<Instruction>(unwrap(Val))) { + if (const auto &DL = I->getDebugLoc()) { + L = DL->getLine(); + } + } else if (const auto *GV = dyn_cast<GlobalVariable>(unwrap(Val))) { SmallVector<DIGlobalVariableExpression *, 1> GVEs; GV->getDebugInfo(GVEs); if (GVEs.size()) if (const DIGlobalVariable *DGV = GVEs[0]->getVariable()) L = DGV->getLine(); - } else if (const auto *F = unwrap<Function>(Val)) { + } else if (const auto *F = dyn_cast<Function>(unwrap(Val))) { if (const DISubprogram *DSP = F->getSubprogram()) L = DSP->getLine(); } else { @@ -1262,9 +1268,9 @@ unsigned LLVMGetDebugLocLine(LLVMValueRef Val) { unsigned LLVMGetDebugLocColumn(LLVMValueRef Val) { unsigned C = 0; - if (const auto *I = unwrap<Instruction>(Val)) - if (const auto &L = I->getDebugLoc()) - C = L->getColumn(); + if (const auto *I = dyn_cast<Instruction>(unwrap(Val))) + if (const auto &DL = I->getDebugLoc()) + C = DL->getColumn(); return C; } |