[DTrace-devel] [PATCH v3 3/5] Fix size for typecast tuple (and aggregation key) components

Kris Van Hees kris.van.hees at oracle.com
Thu Sep 8 21:18:00 UTC 2022


Components of a tuple (or aggregation key) were being typecast where
needed but if narrowing or widening took place, the storage size to store
the value was never updated.

Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
Reviewed-by: Nick Alcock <nick.alcock at oracle.com>
---
 libdtrace/dt_cg.c                     |  3 +++
 test/unittest/aggs/tst.typecast-key.d | 27 +++++++++++++++++++++++++++
 test/unittest/aggs/tst.typecast-key.r |  2 ++
 3 files changed, 32 insertions(+)
 create mode 100644 test/unittest/aggs/tst.typecast-key.d
 create mode 100644 test/unittest/aggs/tst.typecast-key.r

diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
index 06ab0974..c4e49129 100644
--- a/libdtrace/dt_cg.c
+++ b/libdtrace/dt_cg.c
@@ -2765,6 +2765,9 @@ empty_args:
 		dt_cg_typecast(dnp, &isp->dis_args[i], dlp, drp);
 		isp->dis_args[i].dn_reg = -1;
 
+		/* The typecast may have changed the size. */
+		size = dt_node_sizeof(&isp->dis_args[i]);
+
 		if (dt_node_is_scalar(dnp) || dt_node_is_float(dnp)) {
 			assert(size > 0 && size <= 8 &&
 			       (size & (size - 1)) == 0);
diff --git a/test/unittest/aggs/tst.typecast-key.d b/test/unittest/aggs/tst.typecast-key.d
new file mode 100644
index 00000000..77fe51c2
--- /dev/null
+++ b/test/unittest/aggs/tst.typecast-key.d
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+/*
+ * ASSERTION: Offset and alignment of an aggregation key element is defined by
+ *	      the prototype of the aggregation key and not the passed values.
+ *
+ * SECTION: Aggregations/Aggregations
+ */
+
+#pragma D option quiet
+
+BEGIN
+{
+	@[(int32_t)1, 2] = count();
+	@[(int64_t)1, 2] = count();
+	exit(0);
+}
+
+ERROR
+{
+	exit(1);
+}
diff --git a/test/unittest/aggs/tst.typecast-key.r b/test/unittest/aggs/tst.typecast-key.r
new file mode 100644
index 00000000..0d4ee55a
--- /dev/null
+++ b/test/unittest/aggs/tst.typecast-key.r
@@ -0,0 +1,2 @@
+
+        1        2                2
-- 
2.34.1




More information about the DTrace-devel mailing list