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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192878 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Anders Waldenborg 2013-10-17 10:25:24 +00:00
parent 4ef1999d61
commit 2fee43f9b2

View File

@ -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());