LLVMLinux: Remove warning about returning an uninitialized variable
PATCH 1/1 LLVMLinux: Remove warning about returning an uninitialized variable
From: Behan Webster <[email protected]>
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.
--- include/asm-generic/cmpxchg-local.h | 1 + 1 file changed, 1 insertion(+)
include/asm-generic/cmpxchg-local.h +1 -0
@@ -41,6 +41,7 @@ static inline unsigned long __cmpxchg_local_generic(volatile void *ptr,break ;default :wrong_size_cmpxchg (ptr); + prev =0 ; }raw_local_irq_restore (flags);return prev;
Signature · 1 line
1.8.3.2
Arnd Bergmann
maintainerinclude/asm-generic/cmpxchg-local.h static inline unsigned long __cmpxchg_local_generic(volatile void *ptr, · line 47
Quoted 12 lines · On Saturday 22 March 2014, [email protected] wrote:
include/asm-generic/cmpxchg-local.h +1
-0@@ -41,6 +41,7 @@ static inline unsigned long __cmpxchg_local_generic(volatile void *ptr,break ;default :wrong_size_cmpxchg (ptr); + prev =0 ; }raw_local_irq_restore (flags);return prev;
How about using __unreachable() instead to annotate the fact that you won't get here?
Arnd
Quoted 16 lines · Arnd Bergmann
include/asm-generic/cmpxchg-local.h static inline unsigned long __cmpxchg_local_generic(volatile void *ptr, · line 47
Quoted 12 lines · On Saturday 22 March 2014, [email protected] wrote:
include/asm-generic/cmpxchg-local.h +1
-0@@ -41,6 +41,7 @@ static inline unsigned long __cmpxchg_local_generic(volatile void *ptr,break ;default :wrong_size_cmpxchg (ptr); + prev =0 ; }raw_local_irq_restore (flags);return prev;How about using
__unreachable()instead to annotate the fact that you won't get here?
Yours is a _much_ better idea. Will fix.
Thanks,
Behan
Signature · 2 lines
Behan Webster [email protected]
PATCH v2 1/1 LLVMLinux: Remove warning about returning an uninitialized variable
In reply to Arnd BergmannFrom: Behan Webster <[email protected]>
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.
--- include/asm-generic/cmpxchg-local.h | 1 + 1 file changed, 1 insertion(+)
include/asm-generic/cmpxchg-local.h +1 -0
@@ -41,6 +41,7 @@ static inline unsigned long __cmpxchg_local_generic(volatile void *ptr,break ;default :wrong_size_cmpxchg (ptr); +__builtin_unreachable (); }raw_local_irq_restore (flags);return prev;
Signature · 1 line
1.8.3.2
Quoted 19 lines · On Sat, Mar 22, 2014 at 08:48:19AM -0700, [email protected] wrote:
From: Behan Webster <[email protected]>
Fix uninitialized return code in default case in
cmpxchg-local.hThis 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 <[email protected]>Signed-off-by Mark Charlebois <[email protected]>--- include/asm-generic/cmpxchg-local.h | 1 + 1 file changed, 1 insertion(+)include/asm-generic/cmpxchg-local.h +0
-0
include/asm-generic/cmpxchg-local.h static inline unsigned long __cmpxchg_local_generic(volatile void *ptr, · line 44
Quoted 4 lines
include/asm-generic/cmpxchg-local.h +1
-0@@ -41,6 +41,7 @@ static inline unsigned long __cmpxchg_local_generic(volatile void *ptr,break ;default :wrong_size_cmpxchg (ptr); +__builtin_unreachable ();
It is unreachable() - see compiler.h
Sam
Quoted 15 lines · Sam Ravnborg
Quoted 14 lines · On Sat, Mar 22, 2014 at 08:48:19AM -0700, [email protected] wrote:
From: Behan Webster <[email protected]>
Fix uninitialized return code in default case in
cmpxchg-local.hThis 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 <[email protected]>Signed-off-by Mark Charlebois <[email protected]>--- include/asm-generic/cmpxchg-local.h | 1 + 1 file changed, 1 insertion(+)
Quoted 10 lines
include/asm-generic/cmpxchg-local.h static inline unsigned long __cmpxchg_local_generic(volatile void *ptr, · line 44
Quoted 9 lines
include/asm-generic/cmpxchg-local.h +1
-0@@ -41,6 +41,7 @@ static inline unsigned long __cmpxchg_local_generic(volatile void *ptr,break ;default :wrong_size_cmpxchg (ptr); +__builtin_unreachable ();It is
unreachable()- seecompiler.h
Oh I see.
Behan
Signature · 2 lines
Behan Webster [email protected]
PATCH v3 1/1 LLVMLinux: Remove warning about returning an uninitialized variable
In reply to Sam RavnborgFrom: Behan Webster <[email protected]>
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.
--- include/asm-generic/cmpxchg-local.h | 1 + 1 file changed, 1 insertion(+)
include/asm-generic/cmpxchg-local.h +1 -0
@@ -41,6 +41,7 @@ static inline unsigned long __cmpxchg_local_generic(volatile void *ptr,break ;default :wrong_size_cmpxchg (ptr); +unreachable (); }raw_local_irq_restore (flags);return prev;
Signature · 1 line
1.8.3.2
Quoted 19 lines · On Sat, 2014-03-22 at 08:48 -0700, [email protected] wrote:
From: Behan Webster <[email protected]>
Fix uninitialized return code in default case in
cmpxchg-local.hThis 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 <[email protected]>Signed-off-by Mark Charlebois <[email protected]>--- include/asm-generic/cmpxchg-local.h | 1 + 1 file changed, 1 insertion(+)include/asm-generic/cmpxchg-local.h +0
-0
include/asm-generic/cmpxchg-local.h static inline unsigned long __cmpxchg_local_generic(volatile void *ptr, · line 44
Quoted 4 lines
include/asm-generic/cmpxchg-local.h +1
-0@@ -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).
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.
James
Quoted 15 lines · James Bottomley
Quoted 14 lines · On Sat, 2014-03-22 at 08:48 -0700, [email protected] wrote:
From: Behan Webster <[email protected]>
Fix uninitialized return code in default case in
cmpxchg-local.hThis 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 <[email protected]>Signed-off-by Mark Charlebois <[email protected]>--- include/asm-generic/cmpxchg-local.h | 1 + 1 file changed, 1 insertion(+)
Quoted 11 lines
include/asm-generic/cmpxchg-local.h static inline unsigned long __cmpxchg_local_generic(volatile void *ptr, · line 44
Quoted 9 lines
include/asm-generic/cmpxchg-local.h +1
-0@@ -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_unreachableis a gcc-4 ism).
It is also supported by clang.
Quoted 3 lines
Got to say this still looks wrong. If
wrong_size_cmpxchg()cannot return, the function should be annotated as such with__noreturn(likepanic()) so theunreachable()should be superfluous.
Okay. I can try that instead.
Thanks,
Behan
Signature · 2 lines
Behan Webster [email protected]
Quoted 27 lines · Behan Webster
Quoted 15 lines · James Bottomley
Quoted 14 lines · On Sat, 2014-03-22 at 08:48 -0700, [email protected] wrote:
From: Behan Webster <[email protected]>
Fix uninitialized return code in default case in
cmpxchg-local.hThis 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 <[email protected]>Signed-off-by Mark Charlebois <[email protected]>--- include/asm-generic/cmpxchg-local.h | 1 + 1 file changed, 1 insertion(+)Quoted 11 lines
include/asm-generic/cmpxchg-local.h static inline unsigned long __cmpxchg_local_generic(volatile void *ptr, · line 44
Quoted 9 lines
include/asm-generic/cmpxchg-local.h +1
-0@@ -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_unreachableis a gcc-4 ism).
Quoted 1 line
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.
Quoted 4 lines
Quoted 3 lines
Got to say this still looks wrong. If
wrong_size_cmpxchg()cannot return, the function should be annotated as such with__noreturn(likepanic()) so theunreachable()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
---
include/asm-generic/cmpxchg-local.h +2 -1
@@ -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
Quoted 28 lines · James Bottomley
Quoted 27 lines · Behan Webster
Quoted 26 lines · James Bottomley
Quoted 19 lines · On Sat, 2014-03-22 at 08:48 -0700, [email protected] wrote:
From: Behan Webster <[email protected]>
Fix uninitialized return code in default case in
cmpxchg-local.hThis 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 <[email protected]>Signed-off-by Mark Charlebois <[email protected]>--- include/asm-generic/cmpxchg-local.h | 1 + 1 file changed, 1 insertion(+)include/asm-generic/cmpxchg-local.h +0
-0include/asm-generic/cmpxchg-local.h static inline unsigned long __cmpxchg_local_generic(volatile void *ptr, · line 44
Quoted 4 lines
include/asm-generic/cmpxchg-local.h +1
-0@@ -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_unreachableis a gcc-4 ism).
Quoted 3 lines
Quoted 1 line
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.
Quoted 15 lines
Quoted 4 lines
Quoted 3 lines
Got to say this still looks wrong. If
wrong_size_cmpxchg()cannot return, the function should be annotated as such with__noreturn(likepanic()) so theunreachable()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
---
include/asm-generic/cmpxchg-local.h +0
-0
include/asm-generic/cmpxchg-local.h line 11
Quoted 9 lines
include/asm-generic/cmpxchg-local.h +2
-1@@ -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
Signature · 2 lines
Behan Webster [email protected]
PATCH v4 1/1 LLVMLinux: Remove warning about returning an uninitialized variable
In reply to James BottomleyFrom: Behan Webster <[email protected]>
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.
--- include/asm-generic/cmpxchg-local.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/asm-generic/cmpxchg-local.h +2 -1
@@ -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
Signature · 1 line
1.8.3.2
Quoted 10 lines · [email protected] wrote:
From: Behan Webster <[email protected]>
Fix uninitialized return code in default case in
cmpxchg-local.hThis 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 <[email protected]>Signed-off-by Mark Charlebois <[email protected]>
Quoted 11 lines · On Monday 24 March 2014, [email protected] wrote:
From: Behan Webster <[email protected]>
Fix uninitialized return code in default case in
cmpxchg-local.hThis 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 <[email protected]>Signed-off-by Mark Charlebois <[email protected]>
Quoted 20 lines · On 03/21/2014 11:38 PM, [email protected] wrote:
From: Behan Webster <[email protected]>
Fix uninitialized return code in default case in
cmpxchg-local.hThis 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 <[email protected]>Signed-off-by Mark Charlebois <[email protected]>--- include/asm-generic/cmpxchg-local.h | 1 + 1 file changed, 1 insertion(+)include/asm-generic/cmpxchg-local.h +0
-0
include/asm-generic/cmpxchg-local.h static inline unsigned long __cmpxchg_local_generic(volatile void *ptr, · line 47
Quoted 7 lines
include/asm-generic/cmpxchg-local.h +1
-0@@ -41,6 +41,7 @@ static inline unsigned long __cmpxchg_local_generic(volatile void *ptr,break ;default :wrong_size_cmpxchg (ptr); + prev =0 ; }raw_local_irq_restore (flags);return prev;
Shouldn't this be a build time assert (__compiletime_error())?
-hpa
Quoted 15 lines · H. Peter Anvin
Quoted 14 lines · On 03/21/2014 11:38 PM, [email protected] wrote:
From: Behan Webster <[email protected]>
Fix uninitialized return code in default case in
cmpxchg-local.hThis 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 <[email protected]>Signed-off-by Mark Charlebois <[email protected]>--- include/asm-generic/cmpxchg-local.h | 1 + 1 file changed, 1 insertion(+)
Quoted 14 lines
include/asm-generic/cmpxchg-local.h static inline unsigned long __cmpxchg_local_generic(volatile void *ptr, · line 47
Quoted 13 lines
include/asm-generic/cmpxchg-local.h +1
-0@@ -41,6 +41,7 @@ static inline unsigned long __cmpxchg_local_generic(volatile void *ptr,break ;default :wrong_size_cmpxchg (ptr); + prev =0 ; }raw_local_irq_restore (flags);return prev;Shouldn't this be a build time assert (
__compiletime_error())?
I changed it to a __noreturn on wrong_size_cmpxchg thanks to James Bottomley.
Which would be better?
Behan
Signature · 2 lines
Behan Webster [email protected]
Quoted 17 lines · Behan Webster
Quoted 17 lines
Quoted 14 lines
include/asm-generic/cmpxchg-local.h +1
-0@@ -41,6 +41,7 @@ static inline unsigned long __cmpxchg_local_generic(volatile void *ptr, break;default :wrong_size_cmpxchg (ptr); + prev =0 ; }raw_local_irq_restore (flags);Quoted 2 lines
return prev;Shouldn't this be a build time assert (
__compiletime_error())?
Quoted 5 lines
I changed it to a
__noreturnonwrong_size_cmpxchgthanks to James Bottomley.Which would be better?
__compiletime_error traps at compile time rather than link time, which is what you want.
-hpa
Quoted 17 lines · H. Peter Anvin
Quoted 16 lines · Behan Webster
Quoted 16 lines
Quoted 13 lines
include/asm-generic/cmpxchg-local.h +1
-0@@ -41,6 +41,7 @@ static inline unsigned long __cmpxchg_local_generic(volatile void *ptr, break;default :wrong_size_cmpxchg (ptr); + prev =0 ; }raw_local_irq_restore (flags);Quoted 2 lines
return prev;Shouldn't this be a build time assert (
__compiletime_error())?
Quoted 7 lines
Quoted 5 lines
I changed it to a
__noreturnonwrong_size_cmpxchgthanks to James Bottomley.Which would be better?
__compiletime_errortraps at compile time rather than link time, which is what you want.
The idea is to remove the compile time warning that the return code "prev" isn't initialized in the default case. Indicating that wrong_size_cmpxchg doesn't return fixes that false positive.
Behan
Signature · 2 lines
Behan Webster [email protected]
Quoted 7 lines · Behan Webster
Quoted 3 lines
Quoted 1 line
__compiletime_errortraps at compile time rather than link time, which is what you want.The idea is to remove the compile time warning that the return code "prev" isn't initialized in the default case. Indicating that
wrong_size_cmpxchgdoesn't return fixes that false positive.
Perhaps __compiletime_error() should have __noreturn built in?
-hpa