diff options
author | Bernd Edlinger <bernd.edlinger@hotmail.de> | 2018-07-16 18:03:15 +0000 |
---|---|---|
committer | Bernd Edlinger <edlinger@gcc.gnu.org> | 2018-07-16 18:03:15 +0000 |
commit | 5828c09abe00cce5ddff7eefef274c48021c72c9 (patch) | |
tree | 02407fe16cba02310f6f45f81b7d684f739a7be5 /gcc | |
parent | b8c9cad352b8c40693dd7f6b15aec17bfb37c2a1 (diff) | |
download | gcc-5828c09abe00cce5ddff7eefef274c48021c72c9.zip gcc-5828c09abe00cce5ddff7eefef274c48021c72c9.tar.gz gcc-5828c09abe00cce5ddff7eefef274c48021c72c9.tar.bz2 |
re PR middle-end/86528 (strlen of constant string malfunction -- had to back out fix for PR middle-end/77357)
gcc:
2018-07-16 Bernd Edlinger <bernd.edlinger@hotmail.de>
PR middle-end/86528
* builtins.c (check_access): Bail out if range[0] is no INTEGER_CST.
* expr.c (string_constant): Fix the element size of ARRAY_TYPE.
testsuite:
2018-07-16 Bernd Edlinger <bernd.edlinger@hotmail.de>
PR middle-end/86528
* gcc.c-torture/execute/pr86528.c: New test.
* gcc.dg/Wrestrict-10.c (test_arr_strcat_2): Fix typo.
From-SVN: r262742
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/builtins.c | 4 | ||||
-rw-r--r-- | gcc/expr.c | 4 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/execute/pr86528.c | 20 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wrestrict-10.c | 3 |
6 files changed, 40 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b5b8a0e0..8fe8dfc 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-07-16 Bernd Edlinger <bernd.edlinger@hotmail.de> + + PR middle-end/86528 + * builtins.c (check_access): Bail out if range[0] is no INTEGER_CST. + * expr.c (string_constant): Fix the element size of ARRAY_TYPE. + 2018-07-16 Kelvin Nilsen <kelvin@gcc.gnu.org> * doc/extend.texi (PowerPC AltiVec Built-in Functions): diff --git a/gcc/builtins.c b/gcc/builtins.c index 839a818..c041641 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -3192,6 +3192,10 @@ check_access (tree exp, tree, tree, tree dstwrite, if (dstwrite) get_size_range (dstwrite, range); + /* This can happen at -O0. */ + if (range[0] && TREE_CODE (range[0]) != INTEGER_CST) + return false; + tree func = get_callee_fndecl (exp); /* First check the number of bytes to be written against the maximum @@ -11341,7 +11341,9 @@ string_constant (tree arg, tree *ptr_offset) tree offset = wide_int_to_tree (sizetype, base_off); if (varidx) { - if (tree eltsize = TYPE_SIZE_UNIT (TREE_TYPE (array))) + if (TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE) + return NULL_TREE; + if (tree eltsize = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (array)))) { /* Add the scaled variable index to the constant offset. */ tree eltoff = fold_build2 (MULT_EXPR, TREE_TYPE (offset), diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4abf541..854d28e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-07-16 Bernd Edlinger <bernd.edlinger@hotmail.de> + + PR middle-end/86528 + * gcc.c-torture/execute/pr86528.c: New test. + * gcc.dg/Wrestrict-10.c (test_arr_strcat_2): Fix typo. + 2018-07-16 Paolo Carlini <paolo.carlini@oracle.com> * g++.dg/template/spec40.C: New. diff --git a/gcc/testsuite/gcc.c-torture/execute/pr86528.c b/gcc/testsuite/gcc.c-torture/execute/pr86528.c new file mode 100644 index 0000000..2a7b011 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr86528.c @@ -0,0 +1,20 @@ +/* PR middle-end/86528 */ + +void __attribute__((noinline, noclone)) +test(char *data, __SIZE_TYPE__ len) +{ + static char const appended[] = "/./"; + char *buf = __builtin_alloca (len + sizeof appended); + __builtin_memcpy (buf, data, len); + __builtin_strcpy (buf + len, &appended[data[len - 1] == '/']); + if (__builtin_strcmp(buf, "test1234/./")) + __builtin_abort(); +} + +int +main() +{ + char *arg = "test1234/"; + test(arg, __builtin_strlen(arg)); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/Wrestrict-10.c b/gcc/testsuite/gcc.dg/Wrestrict-10.c index c412e42..8bdabdb 100644 --- a/gcc/testsuite/gcc.dg/Wrestrict-10.c +++ b/gcc/testsuite/gcc.dg/Wrestrict-10.c @@ -39,8 +39,7 @@ test_arr_strcat_1 (void) void __attribute__ ((noclone, noinline)) test_arr_strcat_2 (void) { - /* This probably deserves a warning. */ - strcpy (b.a, &b.a[i]); + strcat (b.a, &b.a[i]); /* { dg-warning "\\\[-Wrestrict" } */ } void __attribute__ ((noclone, noinline)) |