Commit d5fa9cc9 by Jakub Jelinek Committed by Jakub Jelinek

predict.h (PROB_LIKELY): Fix the value.

	* predict.h (PROB_LIKELY): Fix the value.
	* internal-fn.c (ubsan_expand_si_overflow_mul_check): Add support
	for overflow checking for modes without 2xwider supported mode,
	if the mode has 2xnarrower mode.

	* c-c++-common/ubsan/overflow-mul-3.c: New test.
	* c-c++-common/ubsan/overflow-mul-4.c: New test.

From-SVN: r206026
parent 97286431
2013-12-16 Jakub Jelinek <jakub@redhat.com>
* predict.h (PROB_LIKELY): Fix the value.
* internal-fn.c (ubsan_expand_si_overflow_mul_check): Add support
for overflow checking for modes without 2xwider supported mode,
if the mode has 2xnarrower mode.
* internal-fn.c: Include stringpool.h and tree-ssanames.h.
(ubsan_expand_si_overflow_addsub_check): In the generic expansion,
try to improve generated code if one of the arguments is constant
......@@ -28,7 +28,7 @@ along with GCC; see the file COPYING3. If not see
#define PROB_VERY_LIKELY (REG_BR_PROB_BASE - PROB_VERY_UNLIKELY)
#define PROB_ALWAYS (REG_BR_PROB_BASE)
#define PROB_UNLIKELY (REG_BR_PROB_BASE / 5 - 1)
#define PROB_LIKELY (PROB_ALWAYS - PROB_VERY_LIKELY)
#define PROB_LIKELY (REG_BR_PROB_BASE - PROB_UNLIKELY)
#define DEF_PREDICTOR(ENUM, NAME, HITRATE, FLAGS) ENUM,
enum br_predictor
......
2013-12-16 Jakub Jelinek <jakub@redhat.com>
* c-c++-common/ubsan/overflow-mul-3.c: New test.
* c-c++-common/ubsan/overflow-mul-4.c: New test.
PR libgomp/59337
* gfortran.dg/gomp/pr59337.f90: New test.
......
/* { dg-do run } */
/* { dg-options "-fsanitize=signed-integer-overflow" } */
/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */
__attribute__((noinline, noclone)) long long
mul (long long x, long long y)
{
return x * y;
}
long long tab[] = {
0x7fffffffLL, 0x7fffffffLL, 0x3fffffff00000001LL,
-0x80000000LL, -0x80000000LL, 0x4000000000000000LL,
0x7fffffffLL, -0x80000000LL, -0x3fffffff80000000LL,
-0x80000000LL, 0x7fffffffLL, -0x3fffffff80000000LL,
3LL, 5LL, 15LL,
-3LL, -9LL, 27LL,
6LL, -7LL, -42LL,
-12LL, 13LL, -156LL,
0x1555555555555555LL, 6LL, 0x7ffffffffffffffeLL,
-0x1555555555555555LL, -6LL, 0x7ffffffffffffffeLL,
0x1555555555555555LL, -6LL, -0x7ffffffffffffffeLL,
-0x1555555555555555LL, 6LL, -0x7ffffffffffffffeLL,
0x81234567LL, 0xfdbe971fLL, 0x7fffffffbea72879LL,
-0x81234567LL, -0xfdbe971fLL, 0x7fffffffbea72879LL,
0x81234567LL, -0xfdbe971fLL, -0x7fffffffbea72879LL,
-0x81234567LL, 0xfdbe971fLL, -0x7fffffffbea72879LL
};
int
main ()
{
unsigned int i;
for (i = 0; i < sizeof (tab) / sizeof (long long); i += 3)
if (mul (tab[i], tab[i + 1]) != tab[i + 2]
|| mul (tab[i + 1], tab[i]) != tab[i + 2])
__builtin_abort ();
return 0;
}
/* { dg-do run } */
/* { dg-options "-fsanitize=signed-integer-overflow" } */
/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */
int
main ()
{
#define MUL_WITH_CHECK(xv, yv, zv) \
do { \
long long x = xv; \
long long y = yv; \
long long z; \
asm ("" : "+g" (x)); \
asm ("" : "+g" (y)); \
z = x * y; \
asm ("" : "+g" (z)); \
if (z != zv) \
__builtin_abort (); \
} while (0)
MUL_WITH_CHECK (0x1555555555555556LL, 6LL, -0x7ffffffffffffffcLL);
MUL_WITH_CHECK (-0x1555555555555556LL, -6LL, -0x7ffffffffffffffcLL);
MUL_WITH_CHECK (0x1555555555555556LL, -6LL, 0x7ffffffffffffffcLL);
MUL_WITH_CHECK (-0x1555555555555556LL, 6LL, 0x7ffffffffffffffcLL);
MUL_WITH_CHECK (0x81234568LL, 0xfdbe971fLL, -0x7fffffff439a4068LL);
MUL_WITH_CHECK (-0x81234568LL, -0xfdbe971fLL, -0x7fffffff439a4068LL);
MUL_WITH_CHECK (0x81234568LL, -0xfdbe971fLL, 0x7fffffff439a4068LL);
MUL_WITH_CHECK (-0x81234568LL, 0xfdbe971fLL, 0x7fffffff439a4068LL);
MUL_WITH_CHECK (0x1555555555555555LL, 7LL, -0x6aaaaaaaaaaaaaadLL);
MUL_WITH_CHECK (-0x1555555555555555LL, -7LL, -0x6aaaaaaaaaaaaaadLL);
MUL_WITH_CHECK (0x1555555555555555LL, -7LL, 0x6aaaaaaaaaaaaaadLL);
MUL_WITH_CHECK (-0x1555555555555555LL, 7LL, 0x6aaaaaaaaaaaaaadLL);
MUL_WITH_CHECK (0x81234567LL, 0xfdbe9720LL, -0x7fffffffc0359220LL);
MUL_WITH_CHECK (-0x81234567LL, -0xfdbe9720LL, -0x7fffffffc0359220LL);
MUL_WITH_CHECK (0x81234567LL, -0xfdbe9720LL, 0x7fffffffc0359220LL);
MUL_WITH_CHECK (-0x81234567LL, 0xfdbe9720LL, 0x7fffffffc0359220LL);
MUL_WITH_CHECK (6LL, 0x1555555555555556LL, -0x7ffffffffffffffcLL);
MUL_WITH_CHECK (-6LL, -0x1555555555555556LL, -0x7ffffffffffffffcLL);
MUL_WITH_CHECK (-6LL, 0x1555555555555556LL, 0x7ffffffffffffffcLL);
MUL_WITH_CHECK (6LL, -0x1555555555555556LL, 0x7ffffffffffffffcLL);
MUL_WITH_CHECK (0xfdbe971fLL, 0x81234568LL, -0x7fffffff439a4068LL);
MUL_WITH_CHECK (-0xfdbe971fLL, -0x81234568LL, -0x7fffffff439a4068LL);
MUL_WITH_CHECK (-0xfdbe971fLL, 0x81234568LL, 0x7fffffff439a4068LL);
MUL_WITH_CHECK (0xfdbe971fLL, -0x81234568LL, 0x7fffffff439a4068LL);
MUL_WITH_CHECK (7LL, 0x1555555555555555LL, -0x6aaaaaaaaaaaaaadLL);
MUL_WITH_CHECK (-7LL, -0x1555555555555555LL, -0x6aaaaaaaaaaaaaadLL);
MUL_WITH_CHECK (-7LL, 0x1555555555555555LL, 0x6aaaaaaaaaaaaaadLL);
MUL_WITH_CHECK (7LL, -0x1555555555555555LL, 0x6aaaaaaaaaaaaaadLL);
MUL_WITH_CHECK (0xfdbe9720LL, 0x81234567LL, -0x7fffffffc0359220LL);
MUL_WITH_CHECK (-0xfdbe9720LL, -0x81234567LL, -0x7fffffffc0359220LL);
MUL_WITH_CHECK (-0xfdbe9720LL, 0x81234567LL, 0x7fffffffc0359220LL);
MUL_WITH_CHECK (0xfdbe9720LL, -0x81234567LL, 0x7fffffffc0359220LL);
return 0;
}
/* { dg-output "overflow-mul-4.c:20:\[^\n\r]*signed integer overflow: 1537228672809129302 \\* 6 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:21:\[^\n\r]*signed integer overflow: -1537228672809129302 \\* -6 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:22:\[^\n\r]*signed integer overflow: 1537228672809129302 \\* -6 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:23:\[^\n\r]*signed integer overflow: -1537228672809129302 \\* 6 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:24:\[^\n\r]*signed integer overflow: 2166572392 \\* 4257126175 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:25:\[^\n\r]*signed integer overflow: -2166572392 \\* -4257126175 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:26:\[^\n\r]*signed integer overflow: 2166572392 \\* -4257126175 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:27:\[^\n\r]*signed integer overflow: -2166572392 \\* 4257126175 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:28:\[^\n\r]*signed integer overflow: 1537228672809129301 \\* 7 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:29:\[^\n\r]*signed integer overflow: -1537228672809129301 \\* -7 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:30:\[^\n\r]*signed integer overflow: 1537228672809129301 \\* -7 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:31:\[^\n\r]*signed integer overflow: -1537228672809129301 \\* 7 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:32:\[^\n\r]*signed integer overflow: 2166572391 \\* 4257126176 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:33:\[^\n\r]*signed integer overflow: -2166572391 \\* -4257126176 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:34:\[^\n\r]*signed integer overflow: 2166572391 \\* -4257126176 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:35:\[^\n\r]*signed integer overflow: -2166572391 \\* 4257126176 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:36:\[^\n\r]*signed integer overflow: 6 \\* 1537228672809129302 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:37:\[^\n\r]*signed integer overflow: -6 \\* -1537228672809129302 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:38:\[^\n\r]*signed integer overflow: -6 \\* 1537228672809129302 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:39:\[^\n\r]*signed integer overflow: 6 \\* -1537228672809129302 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:40:\[^\n\r]*signed integer overflow: 4257126175 \\* 2166572392 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:41:\[^\n\r]*signed integer overflow: -4257126175 \\* -2166572392 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:42:\[^\n\r]*signed integer overflow: -4257126175 \\* 2166572392 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:43:\[^\n\r]*signed integer overflow: 4257126175 \\* -2166572392 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:44:\[^\n\r]*signed integer overflow: 7 \\* 1537228672809129301 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:45:\[^\n\r]*signed integer overflow: -7 \\* -1537228672809129301 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:46:\[^\n\r]*signed integer overflow: -7 \\* 1537228672809129301 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:47:\[^\n\r]*signed integer overflow: 7 \\* -1537228672809129301 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:48:\[^\n\r]*signed integer overflow: 4257126176 \\* 2166572391 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:49:\[^\n\r]*signed integer overflow: -4257126176 \\* -2166572391 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:50:\[^\n\r]*signed integer overflow: -4257126176 \\* 2166572391 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*overflow-mul-4.c:51:\[^\n\r]*signed integer overflow: 4257126176 \\* -2166572391 cannot be represented in type 'long long int'(\n|\r\n|\r)" } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment