From: Jonathan Rajotte Date: Tue, 23 Jul 2019 21:58:29 +0000 (-0400) Subject: `ctf` plugin: Use CTF_BYTE_ORDER_UNKNOWN in place of -1 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=e2bd7d40c86a2209c18c594b391b2d4c7ea59740 `ctf` plugin: Use CTF_BYTE_ORDER_UNKNOWN in place of -1 Seen on clang-3.9, 4.0 and clang-1001.0.46.4. Comparison of constant -1 with expression of type 'enum *****' is always false [-Wtautological-constant-out-of-range-compare] Note that the enum underlying type is implementation defined and left to the choice of the compiler by the standard [1] (6.7.2.2 4). Most compiler default to unsigned int. The use of -1 is not a problem per see since wrap around of unsigned int behaviour is not undefined. Using -1 is the equivalent of assigning UINT_MAX here. This warning was removed for later clang for these specific cases since the effect of always being false is erroneous. Still, it make more sense to use a specific enum for such case instead of relying on the compiler type. Signed-off-by: Jonathan Rajotte Change-Id: I5dcbaa2066cbab8c429ff54e8d8b8b295fc8baf1 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1764 CI-Build: Philippe Proulx Reviewed-by: Philippe Proulx --- diff --git a/src/plugins/ctf/common/bfcr/bfcr.c b/src/plugins/ctf/common/bfcr/bfcr.c index fc9b6699..89e83ca4 100644 --- a/src/plugins/ctf/common/bfcr/bfcr.c +++ b/src/plugins/ctf/common/bfcr/bfcr.c @@ -116,8 +116,8 @@ struct bt_bfcr { * classes for which the common boundary is not the boundary of * a byte cannot have different byte orders. * - * This is set to -1 on reset and when the last basic field class - * was a string class. + * This is set to CTF_BYTE_ORDER_UNKNOWN on reset and when the last + * basic field class was a string class. */ enum ctf_byte_order last_bo; @@ -517,12 +517,12 @@ enum bt_bfcr_status validate_contiguous_bo(struct bt_bfcr *bfcr, } /* Always valid if last byte order is unknown */ - if (bfcr->last_bo == -1) { + if (bfcr->last_bo == CTF_BYTE_ORDER_UNKNOWN) { goto end; } /* Always valid if next byte order is unknown */ - if (next_bo == -1) { + if (next_bo == CTF_BYTE_ORDER_UNKNOWN) { goto end; } @@ -1241,7 +1241,7 @@ void reset(struct bt_bfcr *bfcr) stack_clear(bfcr->stack); stitch_reset(bfcr); bfcr->buf.addr = NULL; - bfcr->last_bo = -1; + bfcr->last_bo = CTF_BYTE_ORDER_UNKNOWN; } static diff --git a/src/plugins/ctf/common/metadata/ctf-meta.h b/src/plugins/ctf/common/metadata/ctf-meta.h index 8db2dee4..5924346d 100644 --- a/src/plugins/ctf/common/metadata/ctf-meta.h +++ b/src/plugins/ctf/common/metadata/ctf-meta.h @@ -50,6 +50,7 @@ enum ctf_field_class_meaning { }; enum ctf_byte_order { + CTF_BYTE_ORDER_UNKNOWN, CTF_BYTE_ORDER_DEFAULT, CTF_BYTE_ORDER_LITTLE, CTF_BYTE_ORDER_BIG, @@ -1636,7 +1637,7 @@ struct ctf_trace_class *ctf_trace_class_create(void) struct ctf_trace_class *tc = g_new0(struct ctf_trace_class, 1); BT_ASSERT(tc); - tc->default_byte_order = -1; + tc->default_byte_order = CTF_BYTE_ORDER_UNKNOWN; tc->clock_classes = g_ptr_array_new_with_free_func( (GDestroyNotify) ctf_clock_class_destroy); BT_ASSERT(tc->clock_classes); diff --git a/src/plugins/ctf/common/metadata/visitor-generate-ir.c b/src/plugins/ctf/common/metadata/visitor-generate-ir.c index 9b0f16e6..0799ba19 100644 --- a/src/plugins/ctf/common/metadata/visitor-generate-ir.c +++ b/src/plugins/ctf/common/metadata/visitor-generate-ir.c @@ -1009,7 +1009,7 @@ enum ctf_byte_order byte_order_from_unary_expr(struct ctx *ctx, struct ctf_node *unary_expr) { const char *str; - enum ctf_byte_order bo = -1; + enum ctf_byte_order bo = CTF_BYTE_ORDER_UNKNOWN; if (unary_expr->u.unary_expression.type != UNARY_STRING) { _BT_COMP_LOGE_NODE(unary_expr, @@ -2329,7 +2329,7 @@ int visit_integer_decl(struct ctx *ctx, } byte_order = get_real_byte_order(ctx, right); - if (byte_order == -1) { + if (byte_order == CTF_BYTE_ORDER_UNKNOWN) { _BT_COMP_LOGE_NODE(right, "Invalid `byte_order` attribute in integer field class: " "ret=%d", ret); @@ -2676,7 +2676,7 @@ int visit_floating_point_number_decl(struct ctx *ctx, } byte_order = get_real_byte_order(ctx, right); - if (byte_order == -1) { + if (byte_order == CTF_BYTE_ORDER_UNKNOWN) { _BT_COMP_LOGE_NODE(right, "Invalid `byte_order` attribute in floating point number field class: " "ret=%d", ret); @@ -3986,7 +3986,7 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set) goto error; } - BT_ASSERT(ctx->ctf_tc->default_byte_order != -1); + BT_ASSERT(ctx->ctf_tc->default_byte_order != CTF_BYTE_ORDER_UNKNOWN); _SET(set, _TRACE_BYTE_ORDER_SET); } else if (strcmp(left, "packet.header") == 0) { if (_IS_SET(set, _TRACE_PACKET_HEADER_SET)) { @@ -4232,7 +4232,7 @@ int set_trace_byte_order(struct ctx *ctx, struct ctf_node *trace_node) struct ctf_node, siblings); bo = byte_order_from_unary_expr(ctx, right_node); - if (bo == -1) { + if (bo == CTF_BYTE_ORDER_UNKNOWN) { _BT_COMP_LOGE_NODE(node, "Invalid `byte_order` attribute in trace (`trace` block): " "expecting `le`, `be`, or `network`."); @@ -4782,7 +4782,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, * have the native byte order yet, and we don't have any * trace block yet, then fail with EINCOMPLETE. */ - if (ctx->ctf_tc->default_byte_order == -1) { + if (ctx->ctf_tc->default_byte_order == CTF_BYTE_ORDER_UNKNOWN) { bt_list_for_each_entry(iter, &node->u.root.trace, siblings) { if (got_trace_decl) { _BT_COMP_LOGE_NODE(node,