auxhelper.cc 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright 2010-2011 PathScale, Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * 1. Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. *
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
  15. * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  16. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  18. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  21. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  22. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  23. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  24. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. /**
  27. * aux.cc - Compiler helper functions.
  28. *
  29. * The functions declared in this file are intended to be called only by code
  30. * that is automatically generated by C++ compilers for some common cases.
  31. */
  32. #include <stdlib.h>
  33. #include "stdexcept.h"
  34. namespace {
  35. /**
  36. * Throw an exception if we're compiling with exceptions, otherwise abort.
  37. */
  38. template<typename T>
  39. void throw_exception()
  40. {
  41. #if !defined(_CXXRT_NO_EXCEPTIONS)
  42. throw T();
  43. #else
  44. abort();
  45. #endif
  46. }
  47. }
  48. /**
  49. * Called to generate a bad cast exception. This function is intended to allow
  50. * compilers to insert code generating this exception without needing to
  51. * duplicate the code for throwing the exception in every call site.
  52. */
  53. extern "C" void __cxa_bad_cast()
  54. {
  55. throw_exception<std::bad_cast>();
  56. }
  57. /**
  58. * Called to generate a bad typeid exception. This function is intended to
  59. * allow compilers to insert code generating this exception without needing to
  60. * duplicate the code for throwing the exception in every call site.
  61. */
  62. extern "C" void __cxa_bad_typeid()
  63. {
  64. throw_exception<std::bad_typeid>();
  65. }
  66. /**
  67. * Compilers may (but are not required to) set any pure-virtual function's
  68. * vtable entry to this function. This makes debugging slightly easier, as
  69. * users can add a breakpoint on this function to tell if they've accidentally
  70. * called a pure-virtual function.
  71. */
  72. extern "C" void __cxa_pure_virtual()
  73. {
  74. abort();
  75. }
  76. /**
  77. * Compilers may (but are not required to) set any deleted-virtual function's
  78. * vtable entry to this function. This makes debugging slightly easier, as
  79. * users can add a breakpoint on this function to tell if they've accidentally
  80. * called a deleted-virtual function.
  81. */
  82. extern "C" void __cxa_deleted_virtual()
  83. {
  84. abort();
  85. }
  86. extern "C" void __cxa_throw_bad_array_new_length()
  87. {
  88. throw_exception<std::bad_array_new_length>();
  89. }