diff options
author | Anders Waldenborg <anders@0x63.nu> | 2013-10-17 10:25:24 +0000 |
---|---|---|
committer | Anders Waldenborg <anders@0x63.nu> | 2013-10-17 10:25:24 +0000 |
commit | 2fee43f9b210859f46fdb279baabb96a61a774af (patch) | |
tree | 3447b808cafd24998e91fd85fc1e1ea21091f405 /lib | |
parent | 4ef1999d61f955917f86320f3b1c6e3352fd0b49 (diff) | |
download | llvm-2fee43f9b210859f46fdb279baabb96a61a774af.tar.gz llvm-2fee43f9b210859f46fdb279baabb96a61a774af.tar.bz2 llvm-2fee43f9b210859f46fdb279baabb96a61a774af.tar.xz |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Target/TargetMachineC.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/Target/TargetMachineC.cpp b/lib/Target/TargetMachineC.cpp index 741912200d..9fccfcd9e2 100644 --- a/lib/Target/TargetMachineC.cpp +++ b/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()); |