1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
Patch that fixes toplevel.{c,h} defines of {floor,exact}_log2
aur-general discussion: https://lists.archlinux.org/pipermail/aur-general/2015-June/031034.html
Made by 'carstene1ns'
References, taken from above mail:
[1]: https://paste.xinu.at/f32k/ # This patch
[2]: https://gcc.gnu.org/gcc-5/porting_to.html ("Different semantics for
inline functions")
[3]: https://github.com/gcc-mirror/gcc/commit/4345dfaa7260253cb0d3b10b4b466f586e9d28dc
diff -Npur a/gcc/toplev.c b/gcc/toplev.c
--- a/gcc/toplev.c 2010-03-31 04:51:31.000000000 +0200
+++ b/gcc/toplev.c 2015-06-21 20:23:54.025339943 +0200
@@ -523,11 +523,11 @@ read_integral_parameter (const char *p,
return atoi (p);
}
-/* When compiling with a recent enough GCC, we use the GNU C "extern inline"
- for floor_log2 and exact_log2; see toplev.h. That construct, however,
- conflicts with the ISO C++ One Definition Rule. */
+/* The functions floor_log2 and exact_log2 are defined as inline
+ functions in toplev.h if GCC_VERSION >= 3004. The definitions here
+ are used for older versions of gcc. */
-#if GCC_VERSION < 3004 || !defined (__cplusplus)
+#if GCC_VERSION < 3004
/* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
If X is 0, return -1. */
@@ -540,9 +540,6 @@ floor_log2 (unsigned HOST_WIDE_INT x)
if (x == 0)
return -1;
-#ifdef CLZ_HWI
- t = HOST_BITS_PER_WIDE_INT - 1 - (int) CLZ_HWI (x);
-#else
if (HOST_BITS_PER_WIDE_INT > 64)
if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64))
t += 64;
@@ -559,7 +556,6 @@ floor_log2 (unsigned HOST_WIDE_INT x)
t += 2;
if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
t += 1;
-#endif
return t;
}
@@ -572,14 +568,10 @@ exact_log2 (unsigned HOST_WIDE_INT x)
{
if (x != (x & -x))
return -1;
-#ifdef CTZ_HWI
- return x ? CTZ_HWI (x) : -1;
-#else
return floor_log2 (x);
-#endif
}
-#endif /* GCC_VERSION < 3004 || !defined (__cplusplus) */
+#endif /* GCC_VERSION < 3004 */
/* Handler for fatal signals, such as SIGSEGV. These are transformed
into ICE messages, which is much more user friendly. In case the
diff -Npur a/gcc/toplev.h b/gcc/toplev.h
--- a/gcc/toplev.h 2009-02-20 16:20:38.000000000 +0100
+++ b/gcc/toplev.h 2015-06-21 20:24:35.142568303 +0200
@@ -167,14 +167,17 @@ extern void decode_d_option (const char
extern bool fast_math_flags_set_p (void);
extern bool fast_math_flags_struct_set_p (struct cl_optimization *);
+#if GCC_VERSION < 3004
+
/* Return log2, or -1 if not exact. */
extern int exact_log2 (unsigned HOST_WIDE_INT);
/* Return floor of log2, with -1 for zero. */
extern int floor_log2 (unsigned HOST_WIDE_INT);
+#else /* GCC_VERSION >= 3004 */
+
/* Inline versions of the above for speed. */
-#if GCC_VERSION >= 3004
# if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
# define CLZ_HWI __builtin_clzl
# define CTZ_HWI __builtin_ctzl
@@ -186,17 +189,18 @@ extern int floor_log2 (
# define CTZ_HWI __builtin_ctz
# endif
-extern inline int
+static inline int
floor_log2 (unsigned HOST_WIDE_INT x)
{
return x ? HOST_BITS_PER_WIDE_INT - 1 - (int) CLZ_HWI (x) : -1;
}
-extern inline int
+static inline int
exact_log2 (unsigned HOST_WIDE_INT x)
{
return x == (x & -x) && x ? (int) CTZ_HWI (x) : -1;
}
+
#endif /* GCC_VERSION >= 3004 */
/* Functions used to get and set GCC's notion of in what directory
|