OSDN Git Service

PR c++/40502
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 10 Jul 2009 11:56:55 +0000 (11:56 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 10 Jul 2009 11:56:55 +0000 (11:56 +0000)
* error.c (cp_print_error_function): Check for NULL block.

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

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@149470 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/error.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/strncpy-chk1.C [new file with mode: 0644]

index 604ba46..c29e32d 100644 (file)
@@ -1,5 +1,10 @@
+2009-07-10  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/40502
+       * error.c (cp_print_error_function): Check for NULL block.
+
 2008-07-09  Simon Martin  <simartin@users.sourceforge.net>
-       Jason Merrill  <jason@redhat.com>
+           Jason Merrill  <jason@redhat.com>
 
        * pt.c (perform_typedefs_access_check, get_types_needing_access_check,
        append_type_to_template_for_access_check_1): Use CLASS_TYPE_P.
index 850f406..a0ba51a 100644 (file)
@@ -2603,7 +2603,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;
                }
index 4cb3306..7e7be11 100644 (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-10  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/40496
diff --git a/gcc/testsuite/g++.dg/ext/strncpy-chk1.C b/gcc/testsuite/g++.dg/ext/strncpy-chk1.C
new file mode 100644 (file)
index 0000000..7770ba9
--- /dev/null
@@ -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);
+}