[DTrace-devel] [PATCH 24/61] test: Add XFAIL placeholder: DTrace internal integer representation

eugene.loh at oracle.com eugene.loh at oracle.com
Fri Jul 8 14:45:08 UTC 2022


From: Eugene Loh <eugene.loh at oracle.com>

When DTrace performs integer operations, it assumes integers (of
all widths and signedness) are internally represented in 64 bits
and do not need frequent typecasting.  This breaks the documented
behavior.  Recent patches have addressed a number of these problems.

A few problems remain.  Notably, arithmetic operations can change
the sign bit of a narrow integer.  This should result in the high
bits of the 64-bit representation changing.  The DTrace code generator
should typecast appropriately.

Add a placeholder test that XFAILs to indicate that work remains.

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 test/unittest/arithmetic/tst.bug-casting.d | 71 ++++++++++++++++++++++
 test/unittest/arithmetic/tst.bug-casting.r | 13 ++++
 2 files changed, 84 insertions(+)
 create mode 100644 test/unittest/arithmetic/tst.bug-casting.d
 create mode 100644 test/unittest/arithmetic/tst.bug-casting.r

diff --git a/test/unittest/arithmetic/tst.bug-casting.d b/test/unittest/arithmetic/tst.bug-casting.d
new file mode 100644
index 00000000..82e4bd68
--- /dev/null
+++ b/test/unittest/arithmetic/tst.bug-casting.d
@@ -0,0 +1,71 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * DTrace has an intrinsically broken integer model.  Internally, it
+ * represents all integers in 64-bit registers -- importantly, it assumes
+ * that integers are represented in 64 bits and do not frequently need
+ * type casting.  Recent patches have fixed some of the problems, but
+ * other issues will remain until code generation becomes much more
+ * diligent about type casting.  This test is an XFAIL placeholder
+ * illustrating a few problems until these issues are addressed.
+ *
+ * Specifically, when signed integers are represented as 64-bit sign-extended
+ * values, results of their operations are sometimes improperly represented --
+ * say, when the uppermost bit flips.  The uppermost bits need to refilled.
+ *
+ * Check with a similar C program, albeit with the format string "%llx".
+ */
+/* @@xfail: broken DTrace integer model */
+
+#pragma D option quiet
+
+int x, y;
+long long z;
+
+BEGIN
+{
+	/* if x=1<<30, then x+x fills the uppermost bit */
+	x = (1 << 30 );
+	z =            (x + x); printf("%x\n", z);
+	z = (long long)(x + x); printf("%x\n", z);
+
+	/* here is another way of examining the uppermost bits */
+	z = 1;
+	z <<= 32;
+	printf("%x\n",             (x + x)  & z);
+	printf("%x\n", ((long long)(x + x)) & z);
+
+	/* if x=1, then x<<31 fills the uppermost bit */
+	x = 1;
+	z =            (x << 31); printf("%x\n", z);
+	z = (long long)(x << 31); printf("%x\n", z);
+
+	/* if x=1<<30, then x<<5 should zero out */
+	x = 1 << 30;
+	z =            (x << 5); printf("%x\n", z);
+	z = (long long)(x << 5); printf("%x\n", z);
+
+	/* if we flip the sign bit, the sign should change */
+	x = +1;
+	y = 1;
+	z = (x ^ (y << 31));
+	printf("flip sign bit of +1, result is %s\n",
+	                  z > 0 ? "positive" : "negative");
+	printf("flip sign bit of +1, result is %s\n",
+	    (x ^ (y << 31)) > 0 ? "positive" : "negative");
+
+	x = -1;
+	y = 1;
+	z = (x ^ (y << 31));
+	printf("flip sign bit of -1, result is %s\n",
+	                  z > 0 ? "positive" : "negative");
+	printf("flip sign bit of -1, result is %s\n",
+	    (x ^ (y << 31)) > 0 ? "positive" : "negative");
+
+	exit (0);
+}
diff --git a/test/unittest/arithmetic/tst.bug-casting.r b/test/unittest/arithmetic/tst.bug-casting.r
new file mode 100644
index 00000000..b1585632
--- /dev/null
+++ b/test/unittest/arithmetic/tst.bug-casting.r
@@ -0,0 +1,13 @@
+ffffffff80000000
+ffffffff80000000
+100000000
+100000000
+ffffffff80000000
+ffffffff80000000
+0
+0
+flip sign bit of +1, result is negative
+flip sign bit of +1, result is negative
+flip sign bit of -1, result is positive
+flip sign bit of -1, result is positive
+
-- 
2.18.4




More information about the DTrace-devel mailing list