/* DF-2242: db_shift_expr right-shift truncates the 64-bit ddb operand to
 * 32 bits: sys/ddb/db_expr.c:216  `lhs = (unsigned) lhs >> rhs;`
 * This reproduces the exact expression in userland to show the truncation. */
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <sys/types.h>

typedef intmax_t db_expr_t;

int main(void)
{
	db_expr_t lhs = (db_expr_t)0x123456789abcdef0LL;
	db_expr_t rhs = 4;
	db_expr_t buggy, correct;

	/* exact source expression */
	buggy = (unsigned) lhs >> rhs;
	/* fixed expression */
	correct = (uintmax_t) lhs >> rhs;

	printf("lhs              = %#018jx\n", (uintmax_t)lhs);
	printf("buggy (unsigned) = %#018jx   <-- truncated to 32 bits first\n",
	    (uintmax_t)buggy);
	printf("fixed (uintmax_t)= %#018jx\n", (uintmax_t)correct);
	printf("DDB session: 'x/s %#jx >> 4' evaluates to %#jx instead of %#jx\n",
	    (uintmax_t)lhs, (uintmax_t)buggy, (uintmax_t)correct);
	return 0;
}
