From a89c1e314545d7a2c079551cee81ca09cfac3160 Mon Sep 17 00:00:00 2001 From: Anders Waldenborg Date: Thu, 17 Oct 2013 10:25:24 +0000 Subject: llvm-c: Return NULL from LLVMGetFirstTarget instead of asserting If no targets are registered, LLVMGetFirstTarget currently fails with an assertion. This patch makes it return NULL instead, similarly to how LLVMGetNextTarget would. Patch by Peter Zotov Differential Revision: http://llvm-reviews.chandlerc.com/D1908 llvm-svn: 192878 --- llvm/lib/Target/TargetMachineC.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'llvm/lib') diff --git a/llvm/lib/Target/TargetMachineC.cpp b/llvm/lib/Target/TargetMachineC.cpp index 741912200da..9fccfcd9e22 100644 --- a/llvm/lib/Target/TargetMachineC.cpp +++ b/llvm/lib/Target/TargetMachineC.cpp @@ -60,8 +60,12 @@ inline LLVMTargetRef wrap(const Target * P) { } LLVMTargetRef LLVMGetFirstTarget() { - const Target* target = &*TargetRegistry::begin(); - return wrap(target); + if(TargetRegistry::begin() == TargetRegistry::end()) { + return NULL; + } + + const Target* target = &*TargetRegistry::begin(); + return wrap(target); } LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T) { return wrap(unwrap(T)->getNext()); -- cgit v1.2.3