File: m_compiler.c

package info (click to toggle)
valgrind 1%3A3.24.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 176,332 kB
  • sloc: ansic: 795,029; exp: 26,134; xml: 23,472; asm: 14,393; cpp: 9,397; makefile: 7,464; sh: 6,122; perl: 5,446; python: 1,498; javascript: 981; awk: 166; csh: 1
file content (319 lines) | stat: -rw-r--r-- 7,433 bytes parent folder | download | duplicates (3)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/* -*- mode: C; c-basic-offset: 3; -*- */

/*--------------------------------------------------------------------*/
/*--- Compiler specific stuff.                        m_compiler.c ---*/
/*--------------------------------------------------------------------*/
 
/*
   This file is part of Valgrind, a dynamic binary instrumentation
   framework.

   Copyright (C) 2014-2017 Florian Krohm
      florian@eich-krohm.de

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, see <http://www.gnu.org/licenses/>.

   The GNU General Public License is contained in the file COPYING.
*/

/* Currently, this file provides definitions for builtins that not all
   compilers or compiler versions provide.

   Missing builtins are rare. Therefore, no attempt has been made to
   provide efficient implementations.
 */

#include "config.h"
#include "pub_core_basics.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
#include "pub_core_debuglog.h"

#ifndef HAVE_BUILTIN_POPCOUT

/* From the GCC documentation:
   Returns the number of 1-bits in x. */

UInt
__builtin_popcount(UInt x)
{
   UInt i, count = 0;

   for (i = 0; i < 32; ++i) {
      count += x & 1;
      x >>= 1;
   }
   return count;
}

UInt
__builtin_popcountll(ULong x)
{
   UInt i, count = 0;

   for (i = 0; i < 64; ++i) {
      count += x & 1;
      x >>= 1;
   }
   return count;
}
#endif

#ifndef HAVE_BUILTIN_CLZ

/* From the GCC documentation:
   Returns the number of leading 0-bits in x, starting at the most
   significant position. If x is 0, the result is undefined. */

UInt
__builtin_clz(UInt x)
{
   UInt count = 32;
   UInt y;

   y = x >> 16; if (y != 0) { count -= 16; x = y; }
   y = x >> 8;  if (y != 0) { count -= 8;  x = y; }
   y = x >> 4;  if (y != 0) { count -= 4;  x = y; }
   y = x >> 2;  if (y != 0) { count -= 2;  x = y; }
   y = x >> 1;  if (y != 0) return count - 2;
   return count - x;
}

UInt
__builtin_clzll(ULong x)
{
   UInt count = 64;
   ULong y;

   y = x >> 32; if (y != 0) { count -= 32; x = y; }
   y = x >> 16; if (y != 0) { count -= 16; x = y; }
   y = x >> 8;  if (y != 0) { count -= 8;  x = y; }
   y = x >> 4;  if (y != 0) { count -= 4;  x = y; }
   y = x >> 2;  if (y != 0) { count -= 2;  x = y; }
   y = x >> 1;  if (y != 0) return count - 2;
   return count - x;
}
#endif

#ifndef HAVE_BUILTIN_CTZ

/* From the GCC documentation:
   Returns the number of trailing 0-bits in x, starting at the least
   significant bit position. If x is 0, the result is undefined. */

UInt
__builtin_ctz(UInt x)
{
   UInt i, count = 0;

   for (i = 0; i < 32; ++i) {
      if (x & 1) break;
      ++count;
      x >>= 1;
   }
   return count;
}

UInt
__builtin_ctzll(ULong x)
{
   UInt i, count = 0;

   for (i = 0; i < 64; ++i) {
      if (x & 1) break;
      ++count;
      x >>= 1;
   }
   return count;
}
#endif


#ifdef __INTEL_COMPILER

/* Provide certain functions Intel's ICC compiler expects to be defined. */

void *
__intel_memcpy(void *dest, const void *src, SizeT sz)
{
   return VG_(memcpy)( dest, src, sz );
}

void *
__intel_mic_avx512f_memcpy(void *dest, const void *src, SizeT sz)
{
   return VG_(memcpy)( dest, src, sz );
}

void *
__intel_new_memcpy(void *dest, const void *src, SizeT sz)
{
   return VG_(memcpy)( dest, src, sz );
}

void *
__intel_ssse3_memcpy(void *dest, const void *src, SizeT sz)
{
   return VG_(memcpy)( dest, src, sz );
}

void *
__intel_ssse3_rep_memcpy(void *dest, const void *src, SizeT sz)
{
   return VG_(memcpy)( dest, src, sz );
}

void *
_intel_fast_memcpy(void *dest, const void *src, SizeT sz)
{
   return VG_(memcpy)( dest, src, sz );
}

void *
__intel_lrb_memcpy(void *dest, const void *src, SizeT sz)
{
   return VG_(memcpy)( dest, src, sz );
}

void *
__intel_memset(void *dest, int value, SizeT num)
{
   return VG_(memset)( dest, value, num );    
}

void *
__intel_new_memset(void *dest, int value, SizeT num)
{
   return VG_(memset)( dest, value, num );    
}

void *
__intel_mic_avx512f_memset(void *dest, int value, SizeT num)
{
   return VG_(memset)( dest, value, num );    
}

void *
__intel_lrb_memset(void *dest, int value, SizeT num)
{
   return VG_(memset)( dest, value, num );    
}

void *
_intel_fast_memset(void *dest, int value, SizeT num)
{
   return VG_(memset)( dest, value, num );    
}

#endif


/*====================================================================*/
/*=== gcc -fsanitize=undefined helper function support             ===*/
/*====================================================================*/

void __ubsan_handle_type_mismatch ( void );
void __ubsan_handle_type_mismatch ( void )
{
   VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
   vg_assert(0);
}

void __ubsan_handle_type_mismatch_v1 ( void );
void __ubsan_handle_type_mismatch_v1 ( void )
{
   VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
   vg_assert(0);
}

void __ubsan_handle_mul_overflow ( void );
void __ubsan_handle_mul_overflow ( void )
{
   VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
   vg_assert(0);
}

void __ubsan_handle_add_overflow ( void );
void __ubsan_handle_add_overflow ( void )
{
   VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
   vg_assert(0);
}

void __ubsan_handle_sub_overflow ( void );
void __ubsan_handle_sub_overflow ( void )
{
   VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
   vg_assert(0);
}

void __ubsan_handle_divrem_overflow ( void );
void __ubsan_handle_divrem_overflow ( void )
{
   VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
   vg_assert(0);
}

void __ubsan_handle_negate_overflow ( void );
void __ubsan_handle_negate_overflow ( void )
{
   VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
   vg_assert(0);
}

void __ubsan_handle_pointer_overflow ( void );
void __ubsan_handle_pointer_overflow ( void )
{
   VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
   vg_assert(0);
}

void __ubsan_handle_out_of_bounds ( void );
void __ubsan_handle_out_of_bounds ( void )
{
   VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
   vg_assert(0);
}

void __ubsan_handle_shift_out_of_bounds ( void );
void __ubsan_handle_shift_out_of_bounds ( void )
{
   VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
   vg_assert(0);
}

void __ubsan_handle_vla_bound_not_positive ( void );
void __ubsan_handle_vla_bound_not_positive ( void )
{
   VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
   vg_assert(0);
}

void __ubsan_handle_nonnull_arg ( void );
void __ubsan_handle_nonnull_arg ( void )
{
   VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
   vg_assert(0);
}

void __ubsan_handle_invalid_builtin ( void );
void __ubsan_handle_invalid_builtin ( void )
{
   VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
   vg_assert(0);
}

/*--------------------------------------------------------------------*/
/*--- end                                                          ---*/
/*--------------------------------------------------------------------*/