debug_msg.cc 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // debug_msg.cc -- a test case for printing debug info for missing symbols.
  2. // Copyright (C) 2006-2015 Free Software Foundation, Inc.
  3. // Written by Ian Lance Taylor <iant@google.com>.
  4. // This file is part of gold.
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 3 of the License, or
  8. // (at your option) any later version.
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. // MA 02110-1301, USA.
  17. // This file is constructed to have undefined references. In
  18. // debug_msg.sh, we will try to link this file, and analyze the
  19. // error messages that are produced.
  20. extern int undef_int;
  21. extern float undef_float;
  22. extern void undef_fn1();
  23. extern void undef_fn2();
  24. int* badref1 = &undef_int;
  25. static float* badref2 = &undef_float;
  26. void (*fn_array[])() =
  27. {
  28. undef_fn1,
  29. undef_fn2
  30. };
  31. template<class Foo>
  32. int testfn(Foo x)
  33. {
  34. undef_fn1();
  35. undef_fn2();
  36. return undef_int;
  37. }
  38. class Base
  39. {
  40. virtual void virtfn() { undef_fn1(); }
  41. };
  42. class Derived : public Base
  43. {
  44. virtual void virtfn() { undef_fn2(); }
  45. };
  46. // This tests One Definition Rule (ODR) violations.
  47. void SortAscending(int array[], int size); // in odr_violation1.cc
  48. void SortDescending(int array[], int size); // in odr_violation2.cc
  49. // This tests One Definition Rule (ODR) non-violations.
  50. #include "odr_header2.h"
  51. OdrBase* CreateOdrDerived1(); // in odr_violation1.cc
  52. OdrBase* CreateOdrDerived2(); // in odr_violation2.cc
  53. extern "C" int OverriddenCFunction(int i); // in odr_violation*.cc
  54. inline int SometimesInlineFunction(int i) { // strong in odr_violation2.cc.
  55. return i * i * 3;
  56. }
  57. int main()
  58. {
  59. testfn(5);
  60. testfn(4.0);
  61. Base b;
  62. Derived d;
  63. int kInput1[] = {1, 6, 9, 7, 3, 4, 2, 10, 5, 8};
  64. int kSize1 = sizeof(kInput1) / sizeof(int);
  65. SortAscending(kInput1, kSize1);
  66. int kInput2[] = {1, 6, 9, 7, 3, 4, 2, 10, 5, 8};
  67. int kSize2 = sizeof(kInput2) / sizeof(int);
  68. SortDescending(kInput2, kSize2);
  69. OverriddenCFunction(3);
  70. SometimesInlineFunction(3);
  71. delete CreateOdrDerived1();
  72. delete CreateOdrDerived2();
  73. return 0;
  74. }