Skip to contentSkip to conversation

eal: silence unreachable code warning

PATCH In review Stephen Hemminger 2 participants 3 messages Nov 17

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eal: silence unreachable code warning

Clang evalutes strlen of constant string at compile time, then complains about unreachable code. Use extra parenthesis to mark code as explcitly dead.

Bugzilla ID: 2135

---
 lib/eal/common/rte_version.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/eal/common/rte_version.c +3 -1
index 627b89d4a8..62572428fc 100644
@@ -36,7 +36,9 @@ rte_version(void)
 	static char version[32];
 	if (version[0] != 0)
 		return version;
-	if (strlen(RTE_VER_SUFFIX) == 0)
+
+	/* extra paren to silence unreachable warnings */
+	if ((strlen(RTE_VER_SUFFIX) == 0))
 		snprintf(version, sizeof(version), "%s %d.%02d.%d",
 				RTE_VER_PREFIX,
 				RTE_VER_YEAR,
Signature · 1 line
2.53.0
#1 lore raw
Quoted 17 lines · Stephen Hemminger

Clang evalutes strlen of constant string at compile time, then complains about unreachable code. Use extra parenthesis to mark code as explcitly dead.

Bugzilla ID: 2135

---
 lib/eal/common/rte_version.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/eal/common/rte_version.c +0 -0
index 627b89d4a8..62572428fc 100644

lib/eal/common/rte_version.c rte_version(void) · line 44

Quoted 10 lines
lib/eal/common/rte_version.c +3 -1
@@ -36,7 +36,9 @@ rte_version(void)
 	static char version[32];
 	if (version[0] != 0)
 		return version;
-	if (strlen(RTE_VER_SUFFIX) == 0)
+
+	/* extra paren to silence unreachable warnings */
+	if ((strlen(RTE_VER_SUFFIX) == 0))
 		snprintf(version, sizeof(version), "%s %d.%02d.%d",
 				RTE_VER_PREFIX,
 				RTE_VER_YEAR,

Is it guaranteed that the checker won't look inside the double brackets? An alternative suggestion is to change RTE_VER_SUFFIX to the function call to the (public) API rte_version_suffix() and use strlen on that. We can even mark the function as __rte_noinline to avoid optimizer getting rid of the call in future and reintroducing the warning.

Also, when fixing this, I think it would be nice to also fix the indent of the else leg.

/Bruce

#2 lore raw
Quoted 35 lines · On Tue, 17 Nov 2026 19:17:12 +0000 Bruce Richardson…
Quoted 17 lines · Stephen Hemminger

Clang evalutes strlen of constant string at compile time, then complains about unreachable code. Use extra parenthesis to mark code as explcitly dead.

Bugzilla ID: 2135

---
 lib/eal/common/rte_version.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/eal/common/rte_version.c +0 -0
index 627b89d4a8..62572428fc 100644

lib/eal/common/rte_version.c rte_version(void) · line 44

Quoted 10 lines
lib/eal/common/rte_version.c +3 -1
@@ -36,7 +36,9 @@ rte_version(void)
 	static char version[32];
 	if (version[0] != 0)
 		return version;
-	if (strlen(RTE_VER_SUFFIX) == 0)
+
+	/* extra paren to silence unreachable warnings */
+	if ((strlen(RTE_VER_SUFFIX) == 0))
 		snprintf(version, sizeof(version), "%s %d.%02d.%d",
 				RTE_VER_PREFIX,
 				RTE_VER_YEAR,

Is it guaranteed that the checker won't look inside the double brackets? An alternative suggestion is to change RTE_VER_SUFFIX to the function call to the (public) API rte_version_suffix() and use strlen on that. We can even mark the function as __rte_noinline to avoid optimizer getting rid of the call in future and reintroducing the warning.

Quoted 4 lines

Also, when fixing this, I think it would be nice to also fix the indent of the else leg.

/Bruce

Clang suggests it as a fix so I think that should always work. Gcc unreachable flag is a noop, the compiler structure makes it too hard for them to do the analysis.

Ok, can fix the indent as well.