Uninitialized _Bool: "faa = (faa == 1) ? 0 : 1" is allways != 0
Hello
Toggling (uninitialized _Bool -variable) seems give randomly allways "true". Compiler generate code that toggle only lowest bit, and not mask out waste bits. If uninitialized memory value is other than 0 or 1, is result then allways true (!= 0). Compiler gives warning only when optimization is turned on (example "-Os"). Is this bug?
-------
c:\test>type test.c
void foo2(_Bool);
void foo(void) {
_Bool bar;
while(1)
{
bar = (bar == 1) ? 0 : 1;
}
}
c:\test>
c:\test>
test.o: file format elf32-littlearm
Disassembly of section .text:
00000000 <foo>:
0: e92d4800 push {fp, lr}
4: e28db004 add fp, sp, #4
8: e24dd008 sub sp, sp, #8
c: e55b3005 ldrb r3, [fp, #-5]
10: e2233001 eor r3, r3, #1
14: e54b3005 strb r3, [fp, #-5]
18: e55b3005 ldrb r3, [fp, #-5]
1c: e1a00003 mov r0, r3
20: ebfffffe bl 0 <foo2>
24: eafffff8 b c <foo+0xc>
c:\test>
test.c: In function 'foo':
test.c:8:7: warning: 'bar' may be used uninitialized in this function [-Wmaybe-
bar = (bar == 1) ? 0 : 1;
~~~~
c:\test>
test.o: file format elf32-littlearm
Disassembly of section .text:
00000000 <foo>:
0: e92d4010 push {r4, lr}
4: e2244001 eor r4, r4, #1
8: e20440ff and r4, r4, #255 ; 0xff
c: e1a00004 mov r0, r4
10: ebfffffe bl 0 <foo2>
14: eafffffa b 4 <foo+0x4>
c:\test>
c:\test>
Using built-in specs.
COLLECT_
COLLECT_
Target: arm-none-eabi
Configured with: /tmp/jenkins-
Thread model: single
gcc version 6.3.1 20170620 (release) [ARM/embedded-
Question information
- Language:
- English Edit question
- Status:
- Solved
- Assignee:
- No assignee Edit question
- Solved by:
- Thomas Preud'homme
- Solved:
- Last query:
- Last reply: