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
This commit is contained in:
Anders Waldenborg 2013-10-17 10:25:24 +00:00
parent 81857f0bcb
commit a89c1e3145
1 changed files with 6 additions and 2 deletions

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