Re: [PATCH v2] LLVMLinux: Remove warning about returning an uninitialized variable

From: Behan Webster
Date: Sun Mar 23 2014 - 02:33:12 EST


On 03/22/14 09:42, James Bottomley wrote:
On Sat, 2014-03-22 at 09:37 -0700, Behan Webster wrote:
On 03/22/14 09:29, James Bottomley wrote:
On Sat, 2014-03-22 at 08:48 -0700, behanw@xxxxxxxxxxxxxxxxxx wrote:
From: Behan Webster <behanw@xxxxxxxxxxxxxxxxxx>

Fix uninitialized return code in default case in cmpxchg-local.h

This patch fixes the code to prevent an uninitialized return value that is detected
when compiling with clang. The bug produces numerous warnings when compiling the
Linux kernel with clang.

Signed-off-by: Behan Webster <behanw@xxxxxxxxxxxxxxxxxx>
Signed-off-by: Mark Charlebois <charlebm@xxxxxxxxx>
---
include/asm-generic/cmpxchg-local.h | 1 +
1 file changed, 1 insertion(+)

diff --git a/include/asm-generic/cmpxchg-local.h b/include/asm-generic/cmpxchg-local.h
index d8d4c89..9112111 100644
--- a/include/asm-generic/cmpxchg-local.h
+++ b/include/asm-generic/cmpxchg-local.h
@@ -41,6 +41,7 @@ static inline unsigned long __cmpxchg_local_generic(volatile void *ptr,
break;
default:
wrong_size_cmpxchg(ptr);
+ __builtin_unreachable();
No, that's got to be unreachable() so that it works in all compilers,
(__builtin_unreachable is a gcc-4 ism).
It is also supported by clang.
OK, but it's not supported by gcc-3. So gcc-3 would crap out seeing the
statement, which is why we have to wrapper it.
Sorry. I wasn't clear. It is not merely a gcc-4 ism; it is also supported by clang.

I'm not arguing it should be used. I understand (and agree with) your objection to its use since it isn't supported before gcc-4.

Got to say this still looks wrong. If wrong_size_cmpxchg() cannot
return, the function should be annotated as such with __noreturn (like
panic()) so the unreachable() should be superfluous.
Okay. I can try that instead.
Great; This seems to work for me (but then my compiler doesn't see the
unreachable problem).

James

---
diff --git a/include/asm-generic/cmpxchg-local.h b/include/asm-generic/cmpxchg-local.h
index d8d4c89..70bef78 100644
--- a/include/asm-generic/cmpxchg-local.h
+++ b/include/asm-generic/cmpxchg-local.h
@@ -4,7 +4,8 @@
#include <linux/types.h>
#include <linux/irqflags.h>
-extern unsigned long wrong_size_cmpxchg(volatile void *ptr);
+extern unsigned long wrong_size_cmpxchg(volatile void *ptr)
+ __noreturn;
/*
* Generic version of __cmpxchg_local (disables interrupts). Takes an unsigned
Nice. I'll give it a try. It looks like a much better solution.

Behan

--
Behan Webster
behanw@xxxxxxxxxxxxxxxxxx

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/