From: Jeroen Hofstee <jeroen@myspectrum.nl>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] arm, ubifs: fix gcc5.x compiler warning
Date: Tue, 1 Dec 2015 00:48:52 +0100 [thread overview]
Message-ID: <565CE064.9060306@myspectrum.nl> (raw)
In-Reply-To: <565C1F09.4090100@denx.de>
Hello Heiko,
On 30-11-15 11:03, Heiko Schocher wrote:
>
> Am 30.11.2015 um 10:20 schrieb Jeroen Hofstee:
>> Hello Heiko,
>>
>> On 30-11-15 08:47, Heiko Schocher wrote:
>>> compiling U-Boot for openrd_base_defconfig with
>>> gcc 5.x shows the following warning:
>>>
>>> CC fs/ubifs/super.o
>>> In file included from fs/ubifs/ubifs.h:35:0,
>>> from fs/ubifs/super.c:37:
>>> fs/ubifs/super.c: In function 'atomic_inc':
>>> ./arch/arm/include/asm/atomic.h:55:2: warning: 'flags' is used
>>> uninitialized in this function
>>> [-Wuninitialized]
>>> local_irq_save(flags);
>>
>> Since flags is an "out" argument, something else must be wrong.
>> There should be no need to initialize it, since local_irq_save should
>> do that afaik.
>
> yes, you are right, it should be, but gcc 5.x seems to have problems
> with it ... compiled code size for the openrd_base config is same with
> my patch ...
>
> Hmm... for the openrd_base compile local_irq_save() is used from:
> arch/arm/thumb1/include/asm/proc-armv/system.h
>
> with:
> static inline void local_irq_save(
> unsigned long flags __attribute__((unused)))
> {
> __asm__ __volatile__ ("" : : : "memory");
> }
>
> flasg marked as unused ... seems correct to me, but I have
> no idea, why gcc 5.x prints a warning ... any ideas?
>
Well, guessing, order of the passes inside the compiler matter, if the
inline is done first, and thereafter the sanity check is done, the latter
can't detect an uninitialized variable is passed, since it has already
been removed. If you do it the other way around, it will warn first
since it won't know the latter pass will remove it. If I have to guess,
I think that is what is happening. [ of course it can be made a bit
smarter, by e.g. looking at the __attribute__((unused)), but more
guessing, I think gcc5 just ignores that one ].
Even more funny is the fact that these functions are not macro's
to _prevent_ compiler warnings ;) So cc-ing Albert since he wrote it.
"
/*
* Redefine all original macros with static inline functions containing
* a simple memory barrier, so that they produce the same instruction
* ordering constraints as their original counterparts.
* We use static inline functions rather than macros so that we can tell
* the compiler to not complain about unused arguments.
*/
"
If we can find a version which doesn't pose other requirements then the
linux versions (like flags must be initialized) _and_ they don't warn
as well, I guess we can agree that would be preferred.
I am not sure to what extend though, some options below to modify
local_irq_save itself to prevent the warning.... 4 and 5 are warning free,
not sure it is a brilliant thing to do though .... Albert?
Regards,
Jeroen
--------------------------------------------------------------------------------------------
// triggers: "is used uninitialized in this function" with gcc5
static inline void my_argument_maybe_unused1(int flags
__attribute__((unused)))
{
}
// triggers -Wunused-variable
#define my_argument_maybe_unused2(flags) do {} while(0)
// triggers set but not used
#define my_argument_maybe_unused3(flags) do { flags = 0; } while(0)
// so, lets use flags instead, but clearly unused so it gets optimized
out later ;)
// no warnings with gcc 5, clang 3.4....
#define my_argument_maybe_unused4(flags) do { int dummy
__attribute__((unused)) = sizeof(flags); } while(0)
// combined preprocessor / compiler foodoo
static inline void _my_argument_maybe_unused5(int *flags
__attribute__((unused)))
{
}
#define my_argument_maybe_unused5(flags) do {
_my_argument_maybe_unused5(&flags); } while(0)
int main()
{
int i_am_used_in_linux_not_in_uboot1;
int i_am_used_in_linux_not_in_uboot2;
int i_am_used_in_linux_not_in_uboot3;
int i_am_used_in_linux_not_in_uboot4;
int i_am_used_in_linux_not_in_uboot5;
my_argument_maybe_unused1(i_am_used_in_linux_not_in_uboot1);
my_argument_maybe_unused2(i_am_used_in_linux_not_in_uboot2);
my_argument_maybe_unused3(i_am_used_in_linux_not_in_uboot3);
my_argument_maybe_unused4(i_am_used_in_linux_not_in_uboot4);
my_argument_maybe_unused5(i_am_used_in_linux_not_in_uboot5);
return 0;
}
/*
arm-linux-gnueabihf-gcc (Linaro GCC 5.1-2015.08) 5.1.1 20150608
arm-linux-gnueabihf-gcc -Wall -O2 warnings.c
good, no code generated..
000102c0 <main>:
102c0: 2000 movs r0, #0
102c2: 4770 bx lr
host, clang... guess this fine too, no idea what the nops are though...
00000000004004f0 <main>:
4004f0: 31 c0 xor %eax,%eax
4004f2: c3 retq
4004f3: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
4004fa: 00 00 00
4004fd: 0f 1f 00 nopl (%rax)
*/
next prev parent reply other threads:[~2015-11-30 23:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-30 7:47 [U-Boot] [PATCH] arm, ubifs: fix gcc5.x compiler warning Heiko Schocher
2015-11-30 9:20 ` Jeroen Hofstee
2015-11-30 10:03 ` Heiko Schocher
2015-11-30 16:28 ` Tom Rini
2015-12-01 7:56 ` Albert ARIBAUD
2015-12-02 14:39 ` Tom Rini
2015-11-30 23:48 ` Jeroen Hofstee [this message]
2016-01-20 21:00 ` [U-Boot] " Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=565CE064.9060306@myspectrum.nl \
--to=jeroen@myspectrum.nl \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox