[llvm] r192878 - llvm-c: Return NULL from LLVMGetFirstTarget instead of asserting
Anders Waldenborg
anders at 0x63.nu
Thu Oct 17 03:25:24 PDT 2013
Author: andersg
Date: Thu Oct 17 05:25:24 2013
New Revision: 192878
URL: http://llvm.org/viewvc/llvm-project?rev=192878&view=rev
Log:
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
Modified:
llvm/trunk/lib/Target/TargetMachineC.cpp
Modified: llvm/trunk/lib/Target/TargetMachineC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetMachineC.cpp?rev=192878&r1=192877&r2=192878&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetMachineC.cpp (original)
+++ llvm/trunk/lib/Target/TargetMachineC.cpp Thu Oct 17 05:25:24 2013
@@ -60,8 +60,12 @@ inline LLVMTargetRef wrap(const Target *
}
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());
More information about the llvm-commits
mailing list