Index: llvm/tools/llvm-c-test/attributes.c =================================================================== --- llvm/tools/llvm-c-test/attributes.c +++ llvm/tools/llvm-c-test/attributes.c @@ -29,9 +29,12 @@ for (Idx = LLVMAttributeFunctionIndex, ParamCount = LLVMCountParams(F); Idx <= ParamCount; ++Idx) { int AttrCount = LLVMGetAttributeCountAtIndex(F, Idx); - LLVMAttributeRef *Attrs = - (LLVMAttributeRef *)malloc(AttrCount * sizeof(LLVMAttributeRef)); - assert(Attrs); + LLVMAttributeRef *Attrs = 0; + if (AttrCount) { + Attrs = + (LLVMAttributeRef *)malloc(AttrCount * sizeof(LLVMAttributeRef)); + assert(Attrs); + } LLVMGetAttributesAtIndex(F, Idx, Attrs); free(Attrs); } @@ -61,9 +64,12 @@ ParamCount = LLVMCountParams(F); Idx <= ParamCount; ++Idx) { int AttrCount = LLVMGetCallSiteAttributeCount(I, Idx); - LLVMAttributeRef *Attrs = (LLVMAttributeRef *)malloc( - AttrCount * sizeof(LLVMAttributeRef)); - assert(Attrs); + LLVMAttributeRef *Attrs = 0; + if (AttrCount) { + Attrs = (LLVMAttributeRef *)malloc( + AttrCount * sizeof(LLVMAttributeRef)); + assert(Attrs); + } LLVMGetCallSiteAttributes(I, Idx, Attrs); free(Attrs); }