From 4f3535815e039b0593297e17ce03715b6afa93b1 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 9 Nov 2016 17:21:45 +0100 Subject: [PATCH] re PR middle-end/77718 (expand_builtin_memcmp swaps args) PR target/77718 * builtins.c (expand_builtin_memcmp): Formatting fix. * gcc.c-torture/execute/pr77718.c: New test. From-SVN: r242007 --- gcc/ChangeLog | 6 ++++- gcc/builtins.c | 2 +- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/gcc.c-torture/execute/pr77718.c | 25 +++++++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr77718.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 355148b2c72..d5616524c0d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,8 @@ 2016-11-09 Jakub Jelinek + PR target/77718 + * builtins.c (expand_builtin_memcmp): Formatting fix. + * flag-types.h (enum sanitize_code): Add SANITIZE_SHIFT_BASE and SANITIZE_SHIFT_EXPONENT, change SANITIZE_SHIFT to bitwise or of them, renumber other enumerators. @@ -5059,7 +5062,8 @@ 2016-09-29 Bernd Schmidt - * builtins.c (expand_builtin_memcmp): don't swap args unless + PR target/77718 + * builtins.c (expand_builtin_memcmp): Don't swap args unless result is only being compared with zero. 2016-09-29 Marek Polacek diff --git a/gcc/builtins.c b/gcc/builtins.c index cc711a0f843..3ac2d441484 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -3754,7 +3754,7 @@ expand_builtin_memcmp (tree exp, rtx target, bool result_eq) { src_str = c_getstr (arg1); if (src_str != NULL) - std::swap (arg1_rtx, arg2_rtx); + std::swap (arg1_rtx, arg2_rtx); } /* If SRC is a string constant and block move would be done diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dd221bbb136..7a3b6c5ffc6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2016-11-09 Jakub Jelinek + PR target/77718 + * gcc.c-torture/execute/pr77718.c: New test. + * gcc.dg/ubsan/c99-shift-3.c: New test. * gcc.dg/ubsan/c99-shift-4.c: New test. * gcc.dg/ubsan/c99-shift-5.c: New test. diff --git a/gcc/testsuite/gcc.c-torture/execute/pr77718.c b/gcc/testsuite/gcc.c-torture/execute/pr77718.c new file mode 100644 index 00000000000..a76effef801 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr77718.c @@ -0,0 +1,25 @@ +/* PR middle-end/77718 */ + +char a[64] __attribute__((aligned (8))); + +__attribute__((noinline, noclone)) int +foo (void) +{ + return __builtin_memcmp ("bbbbbb", a, 6); +} + +__attribute__((noinline, noclone)) int +bar (void) +{ + return __builtin_memcmp (a, "bbbbbb", 6); +} + +int +main () +{ + __builtin_memset (a, 'a', sizeof (a)); + if (((foo () < 0) ^ ('a' > 'b')) + || ((bar () < 0) ^ ('a' < 'b'))) + __builtin_abort (); + return 0; +} -- 2.30.2