[llvm] r286704 - [C API] Fix several null pointer dereferences.

whitequark via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 11 19:38:23 PST 2016


Author: whitequark
Date: Fri Nov 11 21:38:23 2016
New Revision: 286704

URL: http://llvm.org/viewvc/llvm-project?rev=286704&view=rev
Log:
[C API] Fix several null pointer dereferences.

Modified:
    llvm/trunk/lib/IR/Core.cpp

Modified: llvm/trunk/lib/IR/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Core.cpp?rev=286704&r1=286703&r2=286704&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Core.cpp (original)
+++ llvm/trunk/lib/IR/Core.cpp Fri Nov 11 21:38:23 2016
@@ -1842,12 +1842,16 @@ void LLVMAddAttributeAtIndex(LLVMValueRe
 
 unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx) {
   auto *ASN = AttributeSetNode::get(unwrap<Function>(F)->getAttributes(), Idx);
+  if (!ASN)
+    return 0;
   return ASN->getNumAttributes();
 }
 
 void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
                               LLVMAttributeRef *Attrs) {
   auto *ASN = AttributeSetNode::get(unwrap<Function>(F)->getAttributes(), Idx);
+  if (!ASN)
+    return;
   for (auto A: make_range(ASN->begin(), ASN->end()))
     *Attrs++ = wrap(A);
 }
@@ -2173,6 +2177,8 @@ unsigned LLVMGetCallSiteAttributeCount(L
                                        LLVMAttributeIndex Idx) {
   auto CS = CallSite(unwrap<Instruction>(C));
   auto *ASN = AttributeSetNode::get(CS.getAttributes(), Idx);
+  if (!ASN)
+    return 0;
   return ASN->getNumAttributes();
 }
 
@@ -2180,6 +2186,8 @@ void LLVMGetCallSiteAttributes(LLVMValue
                                LLVMAttributeRef *Attrs) {
   auto CS = CallSite(unwrap<Instruction>(C));
   auto *ASN = AttributeSetNode::get(CS.getAttributes(), Idx);
+  if (!ASN)
+    return;
   for (auto A: make_range(ASN->begin(), ASN->end()))
     *Attrs++ = wrap(A);
 }




More information about the llvm-commits mailing list