Created attachment 44465 [details] g++ hugo.cc ---> causes internal compiler error /home/jdanne/gnu2/bin/g++ hugo.cc hugo.cc: In member function 'int FooBarEvent::showFooBar()': hugo.cc:38:108: internal compiler error: Segmentation fault memcpy(formatId, &(remoteInvDataString[((unsigned int) (unsigned long)&((FooBarData *)0)->FormateID)]), 2); ^ 0xbb58ef crash_signal ../../gcc/toplev.c:325 0xe4c1b3 selt ../../gcc/wide-int.cc:404 0xe4c1b3 wi::lts_p_large(long const*, unsigned int, unsigned int, long const*, unsigned int) ../../gcc/wide-int.cc:480 0x67032b bool wi::les_p<generic_wide_int<wi::extended_tree<192> >, generic_wide_int<wi::extended_tree<192> > >(generic_wide_int<wi::extended_tree<192> > const&, generic_wide_int<wi::extended_tree<192> > const&) ../../gcc/wide-int.h:1917 0x67032b wi::binary_traits<generic_wide_int<wi::extended_tree<192> >, generic_wide_int<wi::extended_tree<192> >, wi::int_traits<generic_wide_int<wi::extended_tree<192> > >::precision_type, wi::int_traits<generic_wide_int<wi::extended_tree<192> > >::precision_type>::signed_predicate_result operator<=<generic_wide_int<wi::extended_tree<192> >, generic_wide_int<wi::extended_tree<192> > >(generic_wide_int<wi::extended_tree<192> > const&, generic_wide_int<wi::extended_tree<192> > const&) ../../gcc/wide-int.h:3171 0x67032b tree_int_cst_le(tree_node const*, tree_node const*) ../../gcc/tree.h:5737 0x67032b cxx_eval_array_reference ../../gcc/cp/constexpr.c:2429 0x67032b cxx_eval_constant_expression ../../gcc/cp/constexpr.c:4504 0x66e334 cxx_eval_constant_expression ../../gcc/cp/constexpr.c:4366 0x66df00 cxx_eval_constant_expression ../../gcc/cp/constexpr.c:4598 0x671e79 cxx_eval_outermost_constant_expr ../../gcc/cp/constexpr.c:4861 0x673dae maybe_constant_value(tree_node*, tree_node*) ../../gcc/cp/constexpr.c:5079 0x67d9fa cp_fully_fold(tree_node*) ../../gcc/cp/cp-gimplify.c:2110 0x6835a7 cp_convert_and_check(tree_node*, tree_node*, int) ../../gcc/cp/cvt.c:651 0x64e134 convert_like_real ../../gcc/cp/call.c:7126 0x6518d9 build_over_call ../../gcc/cp/call.c:7999 0x653ab7 build_new_function_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**, int) ../../gcc/cp/call.c:4319 0x75f4ad finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool, bool, int) ../../gcc/cp/semantics.c:2537 0x711e91 cp_parser_postfix_expression ../../gcc/cp/parser.c:7238 0x7125d1 cp_parser_unary_expression ../../gcc/cp/parser.c:8317 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions. =================== /home/jdanne/gnu2/bin/g++ -v Using built-in specs. COLLECT_GCC=/home/jdanne/gnu2/bin/g++ COLLECT_LTO_WRAPPER=/home/jdanne/gnu2/libexec/gcc/x86_64-linux-gnu/8.2.0/lto-wrapper Target: x86_64-linux-gnu Configured with: ../configure --enable-languages=c,c++ --enable-multiarch --enable-shared --enable-threads=posix --with-arch-32=i686 --disable-bootstrap --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-checking=release --prefix=/home/jdanne/gnu2 --with-cpu=generic --enable-multilib --enable-nls Thread model: posix gcc version 8.2.0 (GCC) =================================== Code which caused the internal compiler error: ---------------------------------------------- typedef unsigned int size_t; extern void *memcpy (void *__restrict __dest, __const void *__restrict __src, size_t __n) throw () __attribute__ ((__nonnull__ (1, 2))); typedef struct { char FormateID[2]; char x1[4]; char x2[8]; char x3[10]; char x4[14]; char x5[14]; char x6[4]; char x7[16]; char x8[2]; char x9[6]; char x10[46]; }FooBarData; class FooBarEvent { public: int showFooBar(); }; int FooBarEvent::showFooBar() { char dbgBuf[256]; unsigned char remoteInvDataString[10]; unsigned char formatId[2+1]; memcpy(formatId, &(remoteInvDataString[((unsigned int) (unsigned long)&((FooBarData *)0)->FormateID)]), 2); return 0; }
Confirmed.
Bisection points to r259458: PR c++/84463 * typeck.c (cp_build_addr_expr_1): Move handling of offsetof-like tricks from here to ... * cp-gimplify.c (cp_fold) <case ADDR_EXPR>: ... here. Only use it if INDIRECT_REF's operand is INTEGER_CST cast to pointer type.
Reduced testcase: struct S { int s; }; unsigned char a[20]; void foo () { __builtin_memcpy (&a[15], &a[(unsigned) (__UINTPTR_TYPE__) &((S *) 0)->s], 2); // __builtin_memcpy (&a[15], &a[(unsigned) __builtin_offsetof (S, s)], 2); } You really should just use offsetof, instead of poor man's attempts at it. That said, g++ should not crash on it.
Created attachment 44501 [details] gcc9-pr86738.patch Untested fix.
Author: jakub Date: Wed Aug 8 08:31:40 2018 New Revision: 263390 URL: https://gcc.gnu.org/viewcvs?rev=263390&root=gcc&view=rev Log: 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. Added: trunk/gcc/testsuite/g++.dg/opt/pr86738.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/constexpr.c trunk/gcc/testsuite/ChangeLog
Fixed on the trunk so far.
Author: jakub Date: Wed Sep 5 07:19:27 2018 New Revision: 264104 URL: https://gcc.gnu.org/viewcvs?rev=264104&root=gcc&view=rev Log: Backported from mainline 2018-08-08 Jakub Jelinek <jakub@redhat.com> 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. Added: branches/gcc-8-branch/gcc/testsuite/g++.dg/opt/pr86738.C Modified: branches/gcc-8-branch/gcc/cp/ChangeLog branches/gcc-8-branch/gcc/cp/constexpr.c branches/gcc-8-branch/gcc/testsuite/ChangeLog
Fixed for 8.3+ too.