gdb_index_test.cc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // gdb_index_test.cc -- a test case for the --gdb-index option.
  2. // Copyright (C) 2012-2022 Free Software Foundation, Inc.
  3. // Written by Cary Coutant <ccoutant@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 source file defines a number of symbols of different forms
  18. // to exercise the DWARF scanner in gold.
  19. namespace
  20. {
  21. int c1_count;
  22. int c2_count;
  23. };
  24. namespace one
  25. {
  26. enum G
  27. {
  28. G_A,
  29. G_B,
  30. G_C
  31. };
  32. class c1
  33. {
  34. public:
  35. static int count;
  36. c1()
  37. { ++c1_count; }
  38. ~c1()
  39. {
  40. --c1_count;
  41. }
  42. enum E
  43. {
  44. E_A,
  45. E_B,
  46. E_C,
  47. };
  48. int
  49. val()
  50. { return E_A; }
  51. };
  52. c1 c1v;
  53. };
  54. namespace two
  55. {
  56. const int ci = 3;
  57. template <typename T>
  58. class c2
  59. {
  60. public:
  61. c2(T t)
  62. : t_(t)
  63. {
  64. ++c2_count;
  65. }
  66. ~c2()
  67. { --c2_count; }
  68. T
  69. val()
  70. { return this->t_; }
  71. T t_;
  72. };
  73. c2<int> c2v1(1);
  74. c2<double> c2v2(2.0);
  75. c2<int const*> c2v3(&ci);
  76. };
  77. enum F
  78. {
  79. F_A,
  80. F_B,
  81. F_C
  82. };
  83. template <class C>
  84. bool
  85. check(C* c)
  86. { return c->val() == 0; }
  87. bool
  88. check_enum(int i)
  89. { return i > 0; }
  90. struct anonymous_union_container {
  91. union {
  92. struct astruct {
  93. int a;
  94. };
  95. int b;
  96. } u;
  97. };
  98. anonymous_union_container anonymous_union_var;
  99. #ifdef __GNUC__
  100. #define ALWAYS_INLINE __attribute__((always_inline))
  101. #else
  102. #define ALWAYS_INLINE
  103. #endif
  104. static inline ALWAYS_INLINE int
  105. inline_func_1(int i)
  106. { return i * 17; }
  107. int
  108. main()
  109. {
  110. F f = F_A;
  111. one::G g = one::G_A;
  112. check_enum(f);
  113. check_enum(g);
  114. check(&one::c1v);
  115. check(&two::c2v1);
  116. check(&two::c2v2);
  117. check(&two::c2v3);
  118. anonymous_union_var.u.b = inline_func_1(3) - 51;
  119. return anonymous_union_var.u.b;
  120. }