* [PATCH] eal: silence unreachable code warning
@ 2026-11-17 17:40 Stephen Hemminger
2026-11-17 19:17 ` Bruce Richardson
0 siblings, 1 reply; 3+ messages in thread
From: Stephen Hemminger @ 2026-11-17 17:40 UTC (permalink / raw)
To: dev; +Cc: 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
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
lib/eal/common/rte_version.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lib/eal/common/rte_version.c b/lib/eal/common/rte_version.c
index 627b89d4a8..62572428fc 100644
--- a/lib/eal/common/rte_version.c
+++ b/lib/eal/common/rte_version.c
@@ -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,
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] eal: silence unreachable code warning
2026-11-17 17:40 [PATCH] eal: silence unreachable code warning Stephen Hemminger
@ 2026-11-17 19:17 ` Bruce Richardson
2026-11-17 21:04 ` Stephen Hemminger
0 siblings, 1 reply; 3+ messages in thread
From: Bruce Richardson @ 2026-11-17 19:17 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: dev
On Tue, Nov 17, 2026 at 09:40:59AM -0800, Stephen Hemminger wrote:
> 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
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> lib/eal/common/rte_version.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/lib/eal/common/rte_version.c b/lib/eal/common/rte_version.c
> index 627b89d4a8..62572428fc 100644
> --- a/lib/eal/common/rte_version.c
> +++ b/lib/eal/common/rte_version.c
> @@ -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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] eal: silence unreachable code warning
2026-11-17 19:17 ` Bruce Richardson
@ 2026-11-17 21:04 ` Stephen Hemminger
0 siblings, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2026-11-17 21:04 UTC (permalink / raw)
To: Bruce Richardson; +Cc: dev
On Tue, 17 Nov 2026 19:17:12 +0000
Bruce Richardson <bruce.richardson@intel.com> wrote:
> On Tue, Nov 17, 2026 at 09:40:59AM -0800, Stephen Hemminger wrote:
> > 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
> >
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> > ---
> > lib/eal/common/rte_version.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/eal/common/rte_version.c b/lib/eal/common/rte_version.c
> > index 627b89d4a8..62572428fc 100644
> > --- a/lib/eal/common/rte_version.c
> > +++ b/lib/eal/common/rte_version.c
> > @@ -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
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-17 21:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 17:40 [PATCH] eal: silence unreachable code warning Stephen Hemminger
2026-11-17 19:17 ` Bruce Richardson
2026-11-17 21:04 ` Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox