This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa mudflap] more C++ support
- From: "Frank Ch. Eigler" <fche at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 22 Jan 2003 13:20:22 -0500
- Subject: [tree-ssa mudflap] more C++ support
Hi -
These patches tweak g++ -fmudflap support, and add the first few
actual C++ test cases. Building the older libmudflap C tests under
C++ showed some minor type-checking problems, so those are corrected.
[gcc/ChangeLog.tree-ssa]
2003-01-22 Frank Ch. Eigler <fche@redhat.com>
* tree-mudflap.c (mf_varname_tree): Conditionally invoke the C++
demangler in libiberty. Reduce function printing verbosity.
(mf_file_function_line_tree): Reduce function printing verbosity.
(mudflap_enqueue_decl): Use COMPLETE_TYPE_P to avoid trying to
register (get size of) void-typed objects.
[libmudflap/ChangeLog]
2003-01-22 Frank Ch. Eigler <fche@redhat.com>
* configure.in: Look for C++ compiler.
* test/*-frag.c, mf-driver.c: Reformatted with GNU indent and
fixed type warnings when built with C++.
* test/pass27-frag.cxx, pass28-frag.cxx: New C++ tests.
* Makefile.am (TESTS): Run them.
(*) Add new rules for building and running C++ tests.
(TESTFLAGS): Set new default to avoid libstdc++-v3 shlib issues.
* mf-runtime.h.in: Protect with extern "C".
* Makefile, configure: Regenerated.
Index: tree-mudflap.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-mudflap.c,v
retrieving revision 1.1.2.32
diff -u -p -r1.1.2.32 tree-mudflap.c
--- tree-mudflap.c 20 Jan 2003 21:20:06 -0000 1.1.2.32
+++ tree-mudflap.c 22 Jan 2003 18:02:43 -0000
@@ -42,6 +42,7 @@ Software Foundation, 59 Temple Place - S
#include "rtl.h"
#include "toplev.h"
#include "function.h"
+#include "demangle.h"
/* Internal function decls */
@@ -290,7 +291,7 @@ mf_varname_tree (decl)
{
const char *funcname = NULL;
if (DECL_NAME (current_function_decl))
- funcname = (*lang_hooks.decl_printable_name) (current_function_decl, 2);
+ funcname = (*lang_hooks.decl_printable_name) (current_function_decl, 1);
if (funcname == NULL)
funcname = "anonymous fn";
@@ -301,8 +302,26 @@ mf_varname_tree (decl)
else
output_add_string (buf, " ");
- /* Add <variable-declaration> */
- dump_generic_node (buf, decl, 0, 0);
+ /* Add <variable-declaration>, possibly demangled. */
+ {
+ char *declname = NULL;
+
+ if (strcmp ("GNU C++", lang_hooks.name) == 0)
+ {
+ /* The gcc/cp decl_printable_name hook doesn't do as good a job as
+ the libiberty demangler. */
+ declname = cplus_demangle (IDENTIFIER_POINTER (DECL_NAME (decl)),
+ DMGL_AUTO | DMGL_VERBOSE);
+ }
+
+ if (declname == NULL)
+ declname = (*lang_hooks.decl_printable_name) (decl, 3);
+
+ if (declname == NULL)
+ declname = "<unnamed variable>";
+
+ output_add_string (buf, declname);
+ }
/* Return the lot as a new STRING_CST. */
buf_contents = output_finalize_message (buf);
@@ -352,7 +371,7 @@ mf_file_function_line_tree (file, line)
{
const char *funcname = NULL;
if (DECL_NAME (current_function_decl))
- funcname = (*lang_hooks.decl_printable_name) (current_function_decl, 2);
+ funcname = (*lang_hooks.decl_printable_name) (current_function_decl, 1);
if (funcname == NULL)
funcname = "anonymous fn";
@@ -1114,7 +1133,7 @@ mudflap_enqueue_decl (obj, label)
fprintf (stderr, "' label=`%s'\n", label);
*/
- if (COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (obj)))
+ if (COMPLETE_TYPE_P (TREE_TYPE (obj)))
{
/* NB: the above condition doesn't require TREE_USED or
TREE_ADDRESSABLE. That's because this object may be a global
[libmudflap]
Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/Attic/Makefile.am,v
retrieving revision 1.1.2.18
diff -u -p -r1.1.2.18 Makefile.am
--- Makefile.am 8 Nov 2002 20:06:16 -0000 1.1.2.18
+++ Makefile.am 22 Jan 2003 18:11:08 -0000
@@ -7,7 +7,7 @@
AUTOMAKE_OPTIONS = 1.3 cygnus
MAINT_CHARSET = latin1
-TESTS_ENVIRONMENT = LD_LIBRARY_PATH='.libs:../../gcc' MUDFLAP_OPTIONS='-mode-check -viol-abort -no-heur-proc-map'
+TESTS_ENVIRONMENT = LD_LIBRARY_PATH='.libs:../../gcc:../libstdc++-v3/src/.libs' MUDFLAP_OPTIONS='-mode-check -viol-abort -no-heur-proc-map'
TESTS = test/fail1.x test/fail2.x test/fail3.x test/fail4.x test/fail5.x \
test/fail6.x test/fail7.x test/fail8.x test/fail9.x test/fail10.x \
@@ -19,7 +19,7 @@ TESTS = test/fail1.x test/fail2.x test/f
test/pass11.x test/pass12.x test/pass13.x test/pass14.x test/pass15.x \
test/pass16.x test/pass17.x test/pass18.x test/pass19.x test/pass20.x \
test/pass21.x test/pass22.x test/pass23.x test/pass24.x test/pass25.x \
- test/pass26.x \
+ test/pass26.x test/pass27.xx test/pass28.xx \
test/pass-stratcliff.x
test/%.c: test/%-frag.c test/mf-driver.c
@@ -30,13 +30,20 @@ test/%.c: test/%-frag.c test/mf-driver.c
@echo '}' >> $@
@echo created $@
+test/%.cxx: test/%-frag.cxx test/mf-driver.c
+ @mkdir -p test
+ @echo '#include "'$(srcdir)/test/mf-driver.c'"' > $@
+ @echo 'void test() {' >> $@
+ @echo '#include "'$<'"' >> $@
+ @echo '}' >> $@
+ @echo created $@
+
clean-local:
rm -f $(TESTS)
# Various possibilities
-TESTFLAGS=-rdynamic
-#TESTFLAGS=-static
-#TESTFLAGS=-fdisable-simple
+#TESTFLAGS=-rdynamic
+TESTFLAGS=-static -O2
#TESTFLAGS=-O3
test/fail%.x: test/fail%.c
@@ -44,6 +51,12 @@ test/fail%.x: test/fail%.c
test/pass%.x: test/pass%.c
$(CC) -DSHOULD_PASS -fmudflap $(TESTFLAGS) -g -o $@ $<
+
+test/fail%.xx: test/fail%.cxx
+ $(CXX) -DSHOULD_FAIL -fmudflap $(TESTFLAGS) -g -o $@ $<
+
+test/pass%.xx: test/pass%.cxx
+ $(CXX) -DSHOULD_PASS -fmudflap $(TESTFLAGS) -g -o $@ $<
$(TESTS): clean-tests $(lib_LTLIBRARIES)
Index: configure.in
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/Attic/configure.in,v
retrieving revision 1.1.2.4
diff -u -p -r1.1.2.4 configure.in
--- configure.in 6 Jan 2003 16:13:58 -0000 1.1.2.4
+++ configure.in 22 Jan 2003 18:11:08 -0000
@@ -14,6 +14,7 @@ AC_SUBST(libtool_VERSION)
dnl AM_ENABLE_MULTILIB
AM_MAINTAINER_MODE
AC_EXEEXT
+AC_PROG_CXX
target_alias=${target_alias-$target}
AC_SUBST(target_alias)
Index: mf-runtime.h.in
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/Attic/mf-runtime.h.in,v
retrieving revision 1.1.2.4
diff -u -p -r1.1.2.4 mf-runtime.h.in
--- mf-runtime.h.in 19 Dec 2002 20:41:44 -0000 1.1.2.4
+++ mf-runtime.h.in 22 Jan 2003 18:11:08 -0000
@@ -59,6 +59,10 @@ extern unsigned char __mf_lc_shift;
/* The public mudflap API */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
extern void __mf_check (uintptr_t ptr, uintptr_t sz, const char *location);
extern void __mf_register (uintptr_t ptr, uintptr_t sz, int type, const char *name);
extern void __mf_unregister (uintptr_t ptr, uintptr_t sz);
@@ -66,3 +70,7 @@ extern unsigned __mf_watch (uintptr_t pt
extern unsigned __mf_unwatch (uintptr_t ptr, uintptr_t sz);
extern void __mf_report ();
extern int __mf_set_options (const char *opts);
+
+#ifdef __cplusplus
+}
+#endif
Index: test/fail11-frag.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/test/Attic/fail11-frag.c,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 fail11-frag.c
--- test/fail11-frag.c 14 Aug 2002 17:35:59 -0000 1.1.2.1
+++ test/fail11-frag.c 22 Jan 2003 18:11:08 -0000
@@ -1,5 +1,5 @@
int i = 10;
-char *x = (void *)malloc(i * sizeof (char));
+char *x = (char *) malloc (i * sizeof (char));
while (i--)
{
Index: test/fail12-frag.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/test/Attic/fail12-frag.c,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 fail12-frag.c
--- test/fail12-frag.c 14 Aug 2002 17:35:59 -0000 1.1.2.1
+++ test/fail12-frag.c 22 Jan 2003 18:11:08 -0000
@@ -1,5 +1,5 @@
int i = 10;
-int *x = (void *)malloc(i * sizeof (int));
+int *x = (int *) malloc (i * sizeof (int));
while (i--)
{
Index: test/fail17-frag.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/test/Attic/fail17-frag.c,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 fail17-frag.c
--- test/fail17-frag.c 17 Aug 2002 00:52:35 -0000 1.1.2.1
+++ test/fail17-frag.c 22 Jan 2003 18:11:08 -0000
@@ -1,5 +1,7 @@
char * x;
-x = (char *)malloc (10);
+int foo;
+x = (char *) malloc (10);
strcpy (x, "123456789");
-strlen(x+10);
+foo = strlen (x+10);
+x [foo] = 1; /* we just just use foo to force execution of strlen */
Index: test/fail19-frag.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/test/Attic/fail19-frag.c,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 fail19-frag.c
--- test/fail19-frag.c 16 Oct 2002 18:51:59 -0000 1.1.2.1
+++ test/fail19-frag.c 22 Jan 2003 18:11:08 -0000
@@ -2,6 +2,6 @@ struct foo {
int bar [10];
};
-struct foo *k = (void *) malloc (2 * sizeof(int));
+struct foo *k = (struct foo *) malloc (2 * sizeof(int));
k->bar[5] = 9;
free (k);
Index: test/fail20-frag.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/test/Attic/fail20-frag.c,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 fail20-frag.c
--- test/fail20-frag.c 5 Nov 2002 21:21:04 -0000 1.1.2.1
+++ test/fail20-frag.c 22 Jan 2003 18:11:08 -0000
@@ -1,2 +1,2 @@
-char *p = (void *) 0;
+char *p = (char *) 0;
*p = 5;
Index: test/fail21-frag.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/test/Attic/fail21-frag.c,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 fail21-frag.c
--- test/fail21-frag.c 7 Nov 2002 19:39:29 -0000 1.1.2.1
+++ test/fail21-frag.c 22 Jan 2003 18:11:08 -0000
@@ -2,6 +2,6 @@ int foo = 5;
int *bar = & foo;
/* Make an access here to get &foo into the lookup cache. */
*bar = 5;
-__mf_watch (& foo, sizeof(foo));
+__mf_watch ((uintptr_t) & foo, sizeof(foo));
/* This access should trigger the watch violation. */
*bar = 10;
Index: test/mf-driver.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/test/Attic/mf-driver.c,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 mf-driver.c
--- test/mf-driver.c 6 Jan 2003 16:13:59 -0000 1.1.2.3
+++ test/mf-driver.c 22 Jan 2003 18:11:08 -0000
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
+#include <string.h>
/* this is a simplistic test driver for memory fault detection using
mudflap. you include this file in your mudflapped test case and define a
Index: test/pass-stratcliff.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/test/Attic/pass-stratcliff.c,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 pass-stratcliff.c
--- test/pass-stratcliff.c 5 Nov 2002 21:21:04 -0000 1.1.2.2
+++ test/pass-stratcliff.c 22 Jan 2003 18:11:08 -0000
@@ -19,6 +19,7 @@
02111-1307 USA. */
#define _GNU_SOURCE 1
+#define __USE_GNU
/* Make sure we don't test the optimized inline functions if we want to
test the real implementation. */
@@ -160,7 +161,7 @@ main (int argc, char *argv[])
char *cp;
adr[middle] = 'V';
- cp = rawmemchr (&adr[outer], 'V');
+ cp = (char *) rawmemchr (&adr[outer], 'V');
if (cp - &adr[outer] != middle - outer)
{
@@ -252,8 +253,6 @@ main (int argc, char *argv[])
{
for (inner = MAX (outer, size - 64); inner < size; ++inner)
{
- extern char *stpcpy(char *dest, const char *src);
-
adr[inner] = '\0';
if ((stpcpy (dest, &adr[outer]) - dest) != inner - outer)
@@ -276,8 +275,6 @@ main (int argc, char *argv[])
for (inner = 0; inner < size - outer; ++ inner)
{
- extern char *stpncpy(char *dest, const char *src, size_t n);
-
if ((stpncpy (dest, &adr[outer], inner) - dest)
!= MIN (inner, middle - outer))
{
Index: test/pass11-frag.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/test/Attic/pass11-frag.c,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 pass11-frag.c
--- test/pass11-frag.c 14 Aug 2002 17:35:59 -0000 1.1.2.1
+++ test/pass11-frag.c 22 Jan 2003 18:11:08 -0000
@@ -1,5 +1,5 @@
int i = 10;
-char *x = (void *)malloc(i * sizeof (char));
+char *x = (char *) malloc (i * sizeof (char));
while (--i)
{
Index: test/pass12-frag.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/test/Attic/pass12-frag.c,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 pass12-frag.c
--- test/pass12-frag.c 14 Aug 2002 17:35:59 -0000 1.1.2.1
+++ test/pass12-frag.c 22 Jan 2003 18:11:08 -0000
@@ -1,5 +1,5 @@
int i = 10;
-int *x = (void *)malloc(i * sizeof (int));
+int *x = (int *) malloc (i * sizeof (int));
while (--i)
{
Index: test/pass19-frag.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/test/Attic/pass19-frag.c,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 pass19-frag.c
--- test/pass19-frag.c 6 Sep 2002 19:04:44 -0000 1.1.2.1
+++ test/pass19-frag.c 22 Jan 2003 18:11:08 -0000
@@ -1,4 +1,4 @@
struct foo {int base; char variable[1]; }; /* a common idiom for variable-size structs */
-struct foo * b = malloc (sizeof (int)); /* enough for base */
+struct foo * b = (struct foo *) malloc (sizeof (int)); /* enough for base */
b->base = 4;
Index: test/pass20-frag.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/test/Attic/pass20-frag.c,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 pass20-frag.c
--- test/pass20-frag.c 16 Sep 2002 14:49:58 -0000 1.1.2.1
+++ test/pass20-frag.c 22 Jan 2003 18:11:08 -0000
@@ -1,6 +1,6 @@
struct bar {int stuff; int array[10]; };
-struct bar *foo = malloc (sizeof (struct bar));
+struct bar *foo = (struct bar *) malloc (sizeof (struct bar));
foo->array[5] = 4;
free (foo);
Index: test/pass21-frag.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/test/Attic/pass21-frag.c,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 pass21-frag.c
--- test/pass21-frag.c 30 Sep 2002 15:13:19 -0000 1.1.2.1
+++ test/pass21-frag.c 22 Jan 2003 18:11:08 -0000
@@ -1,5 +1,5 @@
char *boo, *foo;
-boo = alloca (100);
+boo = (char *) alloca (100);
boo[99] = 'a';
-foo = __builtin_alloca (200);
+foo = (char *) __builtin_alloca (200);
foo[44] = 'b';
Index: test/pass22-frag.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/test/Attic/pass22-frag.c,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 pass22-frag.c
--- test/pass22-frag.c 30 Sep 2002 15:13:19 -0000 1.1.2.1
+++ test/pass22-frag.c 22 Jan 2003 18:11:08 -0000
@@ -8,7 +8,7 @@ struct foo {
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
-struct foo* f = (void *) malloc (offsetof (struct foo, nothing));
+struct foo* f = (struct foo *) malloc (offsetof (struct foo, nothing));
f->base = 1;
f->flag1 = 1;
free (f);
Index: test/pass23-frag.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/test/Attic/pass23-frag.c,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 pass23-frag.c
--- test/pass23-frag.c 1 Oct 2002 19:52:56 -0000 1.1.2.1
+++ test/pass23-frag.c 22 Jan 2003 18:11:08 -0000
@@ -9,7 +9,7 @@ struct foo {
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
-struct foo* q = (void *) malloc (offsetof (struct foo, some_more_nothing));
+struct foo* q = (struct foo *) malloc (offsetof (struct foo, some_more_nothing));
/* The RHS of the following expression is meant to trigger a
fold-const.c mapping the expression to a BIT_FIELD_REF. It glues
together the accesses to the two non-neighbouring bitfields into a
Index: test/pass24-frag.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/test/Attic/pass24-frag.c,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 pass24-frag.c
--- test/pass24-frag.c 16 Oct 2002 18:51:59 -0000 1.1.2.1
+++ test/pass24-frag.c 22 Jan 2003 18:11:08 -0000
@@ -4,8 +4,8 @@ struct foo {
float baz;
};
-#define offsetof(S,F) (& (((S *) 0)->F))
+#define offsetof(S,F) ((size_t) & (((S *) 0)->F))
-struct foo *k = (void *) malloc (offsetof (struct foo, bar[4]));
+struct foo *k = (struct foo *) malloc (offsetof (struct foo, bar[4]));
k->bar[1] = 9;
free (k);
Index: test/pass25-frag.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/test/Attic/pass25-frag.c,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 pass25-frag.c
--- test/pass25-frag.c 7 Nov 2002 19:39:29 -0000 1.1.2.1
+++ test/pass25-frag.c 22 Jan 2003 18:11:08 -0000
@@ -2,6 +2,6 @@ int foo[10];
int *bar = & foo[3];
/* Watching occurs at the object granularity, which is in this case
the entire array. */
-__mf_watch (& foo[1], sizeof(foo[1]));
-__mf_unwatch (& foo[6], sizeof(foo[6]));
+__mf_watch ((uintptr_t) & foo[1], sizeof(foo[1]));
+__mf_unwatch ((uintptr_t) & foo[6], sizeof(foo[6]));
*bar = 10;
Index: test/pass27-frag.cxx
===================================================================
RCS file: test/pass27-frag.cxx
diff -N test/pass27-frag.cxx
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test/pass27-frag.cxx 22 Jan 2003 18:11:08 -0000
@@ -0,0 +1,9 @@
+class foo {
+ char z [10];
+public:
+ char *get_z () { return & this->z[0]; }
+};
+
+foo x;
+
+x.get_z()[9] = 'a';
Index: test/pass28-frag.cxx
===================================================================
RCS file: test/pass28-frag.cxx
diff -N test/pass28-frag.cxx
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test/pass28-frag.cxx 22 Jan 2003 18:11:08 -0000
@@ -0,0 +1,17 @@
+class foo {
+ char z [10];
+public:
+ virtual char *get_z () { return & this->z[0]; }
+};
+
+class bar: public foo {
+ char q [20];
+public:
+ char *get_z () { return & this->q[0]; }
+};
+
+foo *x = new bar ();
+
+x->get_z()[9] = 'a';
+
+delete x;
Index: test/pass4-frag.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/test/Attic/pass4-frag.c,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 pass4-frag.c
--- test/pass4-frag.c 14 Aug 2002 17:35:59 -0000 1.1.2.1
+++ test/pass4-frag.c 22 Jan 2003 18:11:08 -0000
@@ -1,2 +1,2 @@
-char foo [10];
-strcpy(foo, "123456789");
+char foo[10];
+strcpy (foo, "123456789");