|
From: <sv...@va...> - 2005-07-06 19:02:06
|
Author: sewardj
Date: 2005-07-06 20:01:53 +0100 (Wed, 06 Jul 2005)
New Revision: 4116
Log:
Add a regression test for memcheck's ability do deal with partially
defined operands in equality comparisons.
Added:
trunk/memcheck/tests/partiallydefinedeq.c
trunk/memcheck/tests/partiallydefinedeq.stderr.exp
trunk/memcheck/tests/partiallydefinedeq.stdout.exp
trunk/memcheck/tests/partiallydefinedeq.vgtest
Modified:
trunk/memcheck/tests/Makefile.am
Modified: trunk/memcheck/tests/Makefile.am
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/Makefile.am 2005-07-06 18:48:59 UTC (rev 4115)
+++ trunk/memcheck/tests/Makefile.am 2005-07-06 19:01:53 UTC (rev 4116)
@@ -59,6 +59,8 @@
new_override.stderr.exp new_override.stdout.exp new_override.vgtest \
null_socket.stderr.exp null_socket.vgtest \
overlap.stderr.exp overlap.stdout.exp overlap.vgtest \
+ partiallydefinedeq.vgtest partiallydefinedeq.stderr.exp \
+ partiallydefinedeq.stdout.exp \
pointer-trace.vgtest \
pointer-trace.stderr.exp pointer-trace.stderr.exp64 \
post-syscall.stderr.exp post-syscall.stdout.exp post-syscall.vgtest \
@@ -101,6 +103,7 @@
memalign_test memalign2 memcmptest mempool mmaptest \
nanoleak new_nothrow \
null_socket overlap \
+ partiallydefinedeq \
pointer-trace \
post-syscall \
realloc1 realloc2 realloc3 \
Added: trunk/memcheck/tests/partiallydefinedeq.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/partiallydefinedeq.c 2005-07-06 18:48:59 UTC (re=
v 4115)
+++ trunk/memcheck/tests/partiallydefinedeq.c 2005-07-06 19:01:53 UTC (re=
v 4116)
@@ -0,0 +1,55 @@
+
+#include <stdio.h>
+#include <malloc.h>
+
+// Do a test comparison. By default memcheck does not use the
+// expensive EQ/NE scheme as it would be too expensive. The=20
+// assignment to *hack is a trick to fool memcheck's bogus-literal
+// spotter into thinking this is a bb which needs unusually careful
+// attention, and therefore the expensive EQ/NE scheme is used.
+
+__attribute__((noinline)) // keep your grubby hands off this fn
+void foo ( int* p1, int* p2, unsigned int * hack )
+{
+ *hack =3D 0x80808080;
+ if (*p1 =3D=3D *p2)
+ printf("foo\n");
+ else
+ printf("bar\n");
+}
+
+
+int main ( void )
+{
+
+ unsigned int hack;
+
+ int* junk1 =3D malloc(sizeof(int));
+ int* junk2 =3D malloc(sizeof(int));
+
+ short* ps1 =3D (short*)junk1;
+ short* ps2 =3D (short*)junk2;
+
+ int* pi1 =3D (int*)junk1;
+ int* pi2 =3D (int*)junk2;
+
+ // both words completely undefined. This should give an error.
+ foo(pi1,pi2, &hack);
+
+ // set half of the words, but to different values; so this should
+ // not give an error, since inspection of the defined parts=20
+ // shows the two values are not equal, and so the definedness of
+ // the conclusion is unaffected by the undefined halves.
+ *ps1 =3D 41;
+ *ps2 =3D 42;
+ foo(pi1,pi2, &hack);
+
+ // set half of the words, but to the same value, so this forces the
+ // result of the comparison to depend on the undefined halves.
+ // should give an error
+ *ps1 =3D 42;
+ *ps2 =3D 42;
+ foo(pi1,pi2, &hack);
+
+ return 0;
+}
Added: trunk/memcheck/tests/partiallydefinedeq.stderr.exp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/partiallydefinedeq.stderr.exp 2005-07-06 18:48:5=
9 UTC (rev 4115)
+++ trunk/memcheck/tests/partiallydefinedeq.stderr.exp 2005-07-06 19:01:5=
3 UTC (rev 4116)
@@ -0,0 +1,14 @@
+
+Conditional jump or move depends on uninitialised value(s)
+ at 0x........: foo (partiallydefinedeq.c:15)
+ by 0x........: main (partiallydefinedeq.c:37)
+
+Conditional jump or move depends on uninitialised value(s)
+ at 0x........: foo (partiallydefinedeq.c:15)
+ by 0x........: main (partiallydefinedeq.c:52)
+
+ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
+malloc/free: in use at exit: 8 bytes in 2 blocks.
+malloc/free: 2 allocs, 0 frees, 8 bytes allocated.
+For a detailed leak analysis, rerun with: --leak-check=3Dyes
+For counts of detected errors, rerun with: -v
Added: trunk/memcheck/tests/partiallydefinedeq.stdout.exp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/partiallydefinedeq.stdout.exp 2005-07-06 18:48:5=
9 UTC (rev 4115)
+++ trunk/memcheck/tests/partiallydefinedeq.stdout.exp 2005-07-06 19:01:5=
3 UTC (rev 4116)
@@ -0,0 +1,3 @@
+foo
+bar
+foo
Added: trunk/memcheck/tests/partiallydefinedeq.vgtest
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/partiallydefinedeq.vgtest 2005-07-06 18:48:59 UT=
C (rev 4115)
+++ trunk/memcheck/tests/partiallydefinedeq.vgtest 2005-07-06 19:01:53 UT=
C (rev 4116)
@@ -0,0 +1 @@
+prog: partiallydefinedeq
|