diff mbox

[U-Boot,RFC,06/10] cc-option: make it work with clang

Message ID 1401568344-4441-7-git-send-email-jeroen@myspectrum.nl
State RFC
Delegated to: Tom Rini
Headers show

Commit Message

Jeroen Hofstee May 31, 2014, 8:32 p.m. UTC
By default clang will return echo a warning if an option is unknown.
Therefore turn warnings into errors when polling for options.
---
 scripts/Kbuild.include | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Masahiro Yamada June 10, 2014, 8:39 a.m. UTC | #1
Hi Jeroen,


On Sat, 31 May 2014 22:32:20 +0200
Jeroen Hofstee <jeroen@myspectrum.nl> wrote:

> By default clang will return echo a warning if an option is unknown.
> Therefore turn warnings into errors when polling for options.

As far as I tested with clang 3.5 on Ubuntu 14.04,
it looks different.

$ clang -fno-delete-null-pointer-checks  helloworld.c
clang: error: unknown argument: '-fno-delete-null-pointer-checks'
$ echo $?
1


Best Regards
Masahiro Yamada
Albert ARIBAUD June 10, 2014, 8:52 a.m. UTC | #2
Hi Masahiro,

On Tue, 10 Jun 2014 17:39:03 +0900, Masahiro Yamada
<yamada.m@jp.panasonic.com> wrote:

> Hi Jeroen,
> 
> 
> On Sat, 31 May 2014 22:32:20 +0200
> Jeroen Hofstee <jeroen@myspectrum.nl> wrote:
> 
> > By default clang will return echo a warning if an option is unknown.
> > Therefore turn warnings into errors when polling for options.
> 
> As far as I tested with clang 3.5 on Ubuntu 14.04,
> it looks different.
> 
> $ clang -fno-delete-null-pointer-checks  helloworld.c
> clang: error: unknown argument: '-fno-delete-null-pointer-checks'
> $ echo $?
> 1

Possibly it depends on how the clang/LLVM toolchain in use has been
built and configured. In any case, explicitly turning warnings into
errors fixes those toolchains which only emit warnings for unknown
options, and it won't harm those such as the one above which already
do "the right thing".

> Best Regards
> Masahiro Yamada

Amicalement,
Jeroen Hofstee July 5, 2014, 1:34 p.m. UTC | #3
Hello Masahiro,

On 10-06-14 10:39, Masahiro Yamada wrote:
> Hi Jeroen,
>
>
> On Sat, 31 May 2014 22:32:20 +0200
> Jeroen Hofstee <jeroen@myspectrum.nl> wrote:
>
>> By default clang will return echo a warning if an option is unknown.
>> Therefore turn warnings into errors when polling for options.
> As far as I tested with clang 3.5 on Ubuntu 14.04,
> it looks different.
>
> $ clang -fno-delete-null-pointer-checks  helloworld.c
> clang: error: unknown argument: '-fno-delete-null-pointer-checks'
> $ echo $?
> 1

Yes it seems to be restricted to warning options. The -Werror=date-time
causes a lot of noise e.g. when building with clang 3.4. With 3.5 this 
option
seems to be added, but behavior for unrecognized warnings flags remained
the same, see below.

Regards,
Jeroen

[jeroen@freebsd /usr/home/jeroen]$ clang -v
FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512
Target: x86_64-unknown-freebsd11.0
Thread model: posix
Selected GCC installation:
[jeroen@freebsd /usr/home/jeroen]$ clang -Werror=date-time a.c
warning: unknown warning option '-Werror=date-time' 
[-Wunknown-warning-option]
1 warning generated.
[jeroen@freebsd /usr/home/jeroen]$ echo $?
0
[jeroen@freebsd /usr/home/jeroen]$ clang -Werror -Werror=date-time a.c
error: unknown warning option '-Werror=date-time' 
[-Werror,-Wunknown-warning-option]
[jeroen@freebsd /usr/home/jeroen]$ echo $?
1

jeroen@yellow:~$ clang -v
clang version 3.5.0 (git@github.com:jhofstee/clang.git 
f533fd477a50467a0d96293d116f4059aa806b65) 
(git@github.com:jhofstee/llvm.git 6b7ff6be9c1bcf8ce440c7f1c7646fbf059562e4)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8.1
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.1
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Candidate multilib: .;@m64
Selected multilib: .;@m64
jeroen@yellow:~$ clang -Werror=date-time a.c
jeroen@yellow:~$ clang -Werror=date-time-newer a.c
warning: unknown warning option '-Werror=date-time-newer'; did you mean 
'-Werror=date-time'? [-Wunknown-warning-option]
1 warning generated.
jeroen@yellow:~$ echo $?
0
jeroen@yellow:~$ clang -Werror -Werror=date-time-newer a.c
error: unknown warning option '-Werror=date-time-newer'; did you mean 
'-Werror=date-time'? [-Werror,-Wunknown-warning-option]
jeroen@yellow:~$ echo $?
1
diff mbox

Patch

diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index c664e39..4c33359 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -113,12 +113,12 @@  as-instr = $(call try-run,\
 # Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
 
 cc-option = $(call try-run,\
-	$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
+	$(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
 
 # cc-option-yn
 # Usage: flag := $(call cc-option-yn,-march=winchip-c6)
 cc-option-yn = $(call try-run,\
-	$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
+	$(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
 
 # cc-option-align
 # Prefix align with either -falign or -malign