`ctf` plugin: Use is_log_level_set to infer ctf_event_class log_level validity
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Tue, 23 Jul 2019 19:23:02 +0000 (15:23 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 29 Jul 2019 14:45:17 +0000 (10:45 -0400)
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.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Change-Id: I6ce97c2481f36573d1a221b59e2459f1fe35ded9
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1761
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/plugins/ctf/common/metadata/ctf-meta-translate.c
src/plugins/ctf/common/metadata/ctf-meta.h
src/plugins/ctf/common/metadata/visitor-generate-ir.c

index c79e0d943f5dc715f9b0bd15a71a3eb39de62299..7d0d966acc0fada002887d520aa22f6630bce880 100644 (file)
@@ -543,7 +543,7 @@ void ctf_event_class_to_ir(struct ctx *ctx)
                BT_ASSERT(ret == 0);
        }
 
-       if (ctx->ec->log_level != -1) {
+       if (ctx->ec->is_log_level_set) {
                bt_event_class_set_log_level(ir_ec, ctx->ec->log_level);
        }
 
index 68ad988e2177e934fcab199b35224d84a49d3f34..c5874ad1f5b4b5676065130f8f85114bc02b81d1 100644 (file)
@@ -221,6 +221,7 @@ struct ctf_event_class {
        GString *emf_uri;
        bt_event_class_log_level log_level;
        bool is_translated;
+       bool is_log_level_set;
 
        /* Owned by this */
        struct ctf_field_class *spec_context_fc;
@@ -1485,10 +1486,19 @@ struct ctf_event_class *ctf_event_class_create(void)
        BT_ASSERT(ec->name);
        ec->emf_uri = g_string_new(NULL);
        BT_ASSERT(ec->emf_uri);
-       ec->log_level = -1;
+       ec->is_log_level_set = false;
        return ec;
 }
 
+static inline
+void ctf_event_class_set_log_level(struct ctf_event_class *ec,
+               enum bt_event_class_log_level log_level)
+{
+       BT_ASSERT(ec);
+       ec->log_level = log_level;
+       ec->is_log_level_set = true;
+}
+
 static inline
 void ctf_event_class_destroy(struct ctf_event_class *ec)
 {
index b7831a86019e1a2510392e8ba9b77839ea070e97..9b0f16e674406ba319c698b660665395d5b4d613 100644 (file)
@@ -3173,6 +3173,7 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node,
                        _SET(set, _EVENT_FIELDS_SET);
                } else if (strcmp(left, "loglevel") == 0) {
                        uint64_t loglevel_value;
+                       bool is_log_level_known = true;
                        bt_event_class_log_level log_level = -1;
 
                        if (_IS_SET(set, _EVENT_LOG_LEVEL_SET)) {
@@ -3238,12 +3239,13 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node,
                                log_level = BT_EVENT_CLASS_LOG_LEVEL_DEBUG;
                                break;
                        default:
+                               is_log_level_known = false;
                                _BT_COMP_LOGW_NODE(node, "Not setting event class's log level because its value is unknown: "
                                        "log-level=%" PRIu64, loglevel_value);
                        }
 
-                       if (log_level != -1) {
-                               event_class->log_level = log_level;
+                       if (is_log_level_known) {
+                               ctf_event_class_set_log_level(event_class, log_level);
                        }
 
                        _SET(set, _EVENT_LOG_LEVEL_SET);
This page took 0.028051 seconds and 4 git commands to generate.