Skip to content

Commit

Permalink
test: Add XFAIL placeholder: DTrace internal integer representation
Browse files Browse the repository at this point in the history
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@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
euloh authored and kvanhees committed Aug 4, 2022
1 parent 0c5bf3e commit 69a5549
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
71 changes: 71 additions & 0 deletions test/unittest/arithmetic/tst.bug-casting.d
Original file line number Diff line number Diff line change
@@ -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);
}
13 changes: 13 additions & 0 deletions test/unittest/arithmetic/tst.bug-casting.r
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 69a5549

Please sign in to comment.