From ce9bb1097dc2ce3babed2c4ff1795ffe269104b0 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 12 Nov 2016 03:38:23 +0000 Subject: [PATCH] [C API] Fix several null pointer dereferences. llvm-svn: 286704 --- llvm/lib/IR/Core.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index 1cf17b1..a969e08 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -1842,12 +1842,16 @@ void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx) { auto *ASN = AttributeSetNode::get(unwrap(F)->getAttributes(), Idx); + if (!ASN) + return 0; return ASN->getNumAttributes(); } void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, LLVMAttributeRef *Attrs) { auto *ASN = AttributeSetNode::get(unwrap(F)->getAttributes(), Idx); + if (!ASN) + return; for (auto A: make_range(ASN->begin(), ASN->end())) *Attrs++ = wrap(A); } @@ -2173,6 +2177,8 @@ unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C, LLVMAttributeIndex Idx) { auto CS = CallSite(unwrap(C)); auto *ASN = AttributeSetNode::get(CS.getAttributes(), Idx); + if (!ASN) + return 0; return ASN->getNumAttributes(); } @@ -2180,6 +2186,8 @@ void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx, LLVMAttributeRef *Attrs) { auto CS = CallSite(unwrap(C)); auto *ASN = AttributeSetNode::get(CS.getAttributes(), Idx); + if (!ASN) + return; for (auto A: make_range(ASN->begin(), ASN->end())) *Attrs++ = wrap(A); } -- 2.7.4