From: jakub Date: Wed, 8 Aug 2018 08:31:40 +0000 (+0000) Subject: PR c++/86738 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2b1749c4ab52eda4733612528f612f756546c312;p=thirdparty%2Fgcc.git PR c++/86738 * constexpr.c (cxx_eval_binary_expression): For arithmetics involving NULL pointer set *non_constant_p to true. (cxx_eval_component_reference): For dereferencing of a NULL pointer, set *non_constant_p to true and return t. * g++.dg/opt/pr86738.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@263390 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 0d4377c2d6ae..ed3ad71a94ac 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2018-08-08 Jakub Jelinek + + PR c++/86738 + * constexpr.c (cxx_eval_binary_expression): For arithmetics involving + NULL pointer set *non_constant_p to true. + (cxx_eval_component_reference): For dereferencing of a NULL pointer, + set *non_constant_p to true and return t. + 2018-08-07 Paolo Carlini PR c++/59480, DR 136 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 79039ff2b791..d796e8b1626a 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -2082,6 +2082,7 @@ cxx_eval_binary_expression (const constexpr_ctx *ctx, tree t, { if (!ctx->quiet) error ("arithmetic involving a null pointer in %qE", lhs); + *non_constant_p = true; return t; } else if (code == POINTER_PLUS_EXPR) @@ -2522,9 +2523,13 @@ cxx_eval_component_reference (const constexpr_ctx *ctx, tree t, lval, non_constant_p, overflow_p); if (INDIRECT_REF_P (whole) - && integer_zerop (TREE_OPERAND (whole, 0)) - && !ctx->quiet) - error ("dereferencing a null pointer in %qE", orig_whole); + && integer_zerop (TREE_OPERAND (whole, 0))) + { + if (!ctx->quiet) + error ("dereferencing a null pointer in %qE", orig_whole); + *non_constant_p = true; + return t; + } if (TREE_CODE (whole) == PTRMEM_CST) whole = cplus_expand_constant (whole); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c4aaa448fa13..6eb02bb3dece 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-08-08 Jakub Jelinek + + PR c++/86738 + * g++.dg/opt/pr86738.C: New test. + 2018-08-07 Richard Sandiford PR target/86838 diff --git a/gcc/testsuite/g++.dg/opt/pr86738.C b/gcc/testsuite/g++.dg/opt/pr86738.C new file mode 100644 index 000000000000..f5079ffde831 --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/pr86738.C @@ -0,0 +1,12 @@ +// PR c++/86738 +// { dg-do compile } + +struct S { int s; }; +unsigned char a[20]; +unsigned char *p = &a[(__UINTPTR_TYPE__) &((S *) 0)->s]; + +void +foo () +{ + __builtin_memcpy (&a[15], &a[(__UINTPTR_TYPE__) &((S *) 0)->s], 2); +}