re PR middle-end/40502 (crash in cp_diagnostic_starter)

PR c++/40502
	* error.c (cp_print_error_function): Check for NULL block.

	* g++.dg/ext/strncpy-chk1.C: New test.

From-SVN: r149499
This commit is contained in:
Jakub Jelinek 2009-07-11 00:31:34 +02:00 committed by Jakub Jelinek
parent 3f9305d000
commit 51fca017fa
4 changed files with 42 additions and 1 deletions

View File

@ -1,3 +1,8 @@
2009-07-10 Jakub Jelinek <jakub@redhat.com>
PR c++/40502
* error.c (cp_print_error_function): Check for NULL block.
2009-07-09 Dodji Seketeli <dodji@redhat.com>
PR c++/40684

View File

@ -2458,7 +2458,7 @@ cp_print_error_function (diagnostic_context *context,
while (block && TREE_CODE (block) == BLOCK)
block = BLOCK_SUPERCONTEXT (block);
if (TREE_CODE (block) == FUNCTION_DECL)
if (block && TREE_CODE (block) == FUNCTION_DECL)
fndecl = block;
abstract_origin = NULL;
}

View File

@ -1,3 +1,8 @@
2009-07-10 Jakub Jelinek <jakub@redhat.com>
PR c++/40502
* g++.dg/ext/strncpy-chk1.C: New test.
2009-07-09 Paul Thomas <pault@gcc.gnu.org>
PR fortran/40440

View File

@ -0,0 +1,31 @@
// PR c++/40502
// { dg-do compile }
// { dg-options "-O2" }
struct A { char x[12], y[35]; };
struct B { char z[50]; };
inline void
foo (char *dest, const char *__restrict src, __SIZE_TYPE__ n)
{
__builtin___strncpy_chk (dest, src, n, __builtin_object_size (dest, 0)); // { dg-warning "will always overflow" }
}
void bar (const char *, int);
inline void
baz (int i)
{
char s[128], t[32];
bar (s, 0);
bar (t, i);
A a;
B b;
foo (a.y, b.z, 36);
}
void
test ()
{
baz (0);
}