[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <fe282f58-1627-480b-8f01-71d0effd5da8@linux.intel.com>
Date: Mon, 30 Jun 2025 16:24:26 -0700
From: Marc Herbert <marc.herbert@...ux.intel.com>
To: Kent Overstreet <kent.overstreet@...ux.dev>
Cc: Dan Williams <dan.j.williams@...el.com>,
Greg KH <gregkh@...uxfoundation.org>, Miguel Ojeda <ojeda@...nel.org>,
Benjamin.Cheatham@....com, Jonathan.Cameron@...wei.com, dakr@...nel.org,
linux-acpi@...r.kernel.org, linux-cxl@...r.kernel.org,
linux-kernel@...r.kernel.org, rafael.j.wysocki@...el.com, rafael@...nel.org,
sudeep.holla@....com, Dan Carpenter <dan.carpenter@...aro.org>,
Kees Cook <kees@...nel.org>
Subject: Re: [PATCH] driver core: faux: fix Undefined Behavior in
faux_device_destroy()
On 2025-06-25 17:55, Kent Overstreet wrote:
> the big con:
> - they interact badly with gotos, you can get undefined behaviour from
> using a variable that wasn't actually defined _and the compiler will
> not warn you_
> [...]
> But the issue with gotos is worth highlighting. Be careful when using
> them in code that hasn't been converted to __cleanup.
Thanks Kent for sharing this.
I got curious and found that clang -Wall is actually able to warn,
at least in simple cases:
int goto_uninitialized_C99(int *ptr)
{
if (!ptr)
goto cleanup;
const int i = 42;
cleanup:
// clang warning, no gcc warning
printf("fin: i=%d\n", i);
warning: variable 'i' is used uninitialized whenever 'if' condition
is true [-Wsometimes-uninitialized]
gcc -Wall -Wextra does not say anything.
Tested with clang version 18.1.3 and gcc 13.3.0
Interestingly, there is no warning difference between C89 and C99 code
for such a simple example. gcc warns for neither C89 code nor C99 code
and clang warns for both.
int goto_uninitialized_C89(int *ptr)
{
int i;
if (!ptr)
goto cleanup;
i = 42
cleanup:
/* clang warning, no gcc warning */
printf("fin: i=%d\n", i);
(finally getting rid of gotos is one of the main purposes of RAII)
Powered by blists - more mailing lists