/*1* Copyright 2010-2011 PathScale, Inc. All rights reserved.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions are met:5*6* 1. Redistributions of source code must retain the above copyright notice,7* this list of conditions and the following disclaimer.8*9* 2. Redistributions in binary form must reproduce the above copyright notice,10* this list of conditions and the following disclaimer in the documentation11* and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS14* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,15* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR16* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR17* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,18* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,19* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;20* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,21* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR22* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF23* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.24*/2526/**27* aux.cc - Compiler helper functions.28*29* The functions declared in this file are intended to be called only by code30* that is automatically generated by C++ compilers for some common cases.31*/3233#include <stdlib.h>34#include "stdexcept.h"3536namespace {37/**38* Throw an exception if we're compiling with exceptions, otherwise abort.39*/40template<typename T>41void throw_exception()42{43#if !defined(_CXXRT_NO_EXCEPTIONS)44throw T();45#else46abort();47#endif48}49}5051/**52* Called to generate a bad cast exception. This function is intended to allow53* compilers to insert code generating this exception without needing to54* duplicate the code for throwing the exception in every call site.55*/56extern "C" void __cxa_bad_cast()57{58throw_exception<std::bad_cast>();59}6061/**62* Called to generate a bad typeid exception. This function is intended to63* allow compilers to insert code generating this exception without needing to64* duplicate the code for throwing the exception in every call site.65*/66extern "C" void __cxa_bad_typeid()67{68throw_exception<std::bad_typeid>();69}7071/**72* Compilers may (but are not required to) set any pure-virtual function's73* vtable entry to this function. This makes debugging slightly easier, as74* users can add a breakpoint on this function to tell if they've accidentally75* called a pure-virtual function.76*/77extern "C" void __cxa_pure_virtual()78{79abort();80}8182/**83* Compilers may (but are not required to) set any deleted-virtual function's84* vtable entry to this function. This makes debugging slightly easier, as85* users can add a breakpoint on this function to tell if they've accidentally86* called a deleted-virtual function.87*/88extern "C" void __cxa_deleted_virtual()89{90abort();91}9293extern "C" void __cxa_throw_bad_array_new_length()94{95throw_exception<std::bad_array_new_length>();96}979899