clang does not know fno-delete-null-pointer-checks#664
clang does not know fno-delete-null-pointer-checks#664mehlis merged 1 commit intoRIOT-OS:masterfrom Kijewski:conditional-fno-delete-null-pointer-checks
Conversation
|
See clang bug 9251 - Support -fno-delete-null-pointer-checks. The feature request is staled since 2011-12-02. But clang does not seem to use the delete-null-pointer-checks optimization, so it's safe to omit the argument. But I'm not sure how to probe whether the supplied $(CC) supports Test input: #include <stdio.h>
int main(void)
{
unsigned *volatile x_ = NULL;
unsigned *x = x_;
printf("%u\n", *x);
if (x) {
return 0;
}
return 1;
}gcc: 08048300 <main>:
8048300: 55 push %ebp
8048301: 89 e5 mov %esp,%ebp
8048303: 83 e4 f0 and $0xfffffff0,%esp
8048306: 83 ec 20 sub $0x20,%esp
8048309: c7 44 24 1c 00 00 00 movl $0x0,0x1c(%esp)
8048310: 00
8048311: 8b 44 24 1c mov 0x1c(%esp),%eax
8048315: 8b 00 mov (%eax),%eax
8048317: c7 04 24 b0 84 04 08 movl $0x80484b0,(%esp)
804831e: 89 44 24 04 mov %eax,0x4(%esp)
8048322: e8 a9 ff ff ff call 80482d0 <printf@plt>
8048327: 31 c0 xor %eax,%eax // set result to zero w/o any check
8048329: c9 leave
804832a: c3 retclang: 08048420 <main>:
8048420: 56 push %esi
8048421: 83 ec 18 sub $0x18,%esp
8048424: c7 44 24 14 00 00 00 movl $0x0,0x14(%esp)
804842b: 00
804842c: 8b 74 24 14 mov 0x14(%esp),%esi
8048430: 8b 06 mov (%esi),%eax
8048432: 89 44 24 04 mov %eax,0x4(%esp)
8048436: c7 04 24 e0 84 04 08 movl $0x80484e0,(%esp)
804843d: e8 ae fe ff ff call 80482f0 <printf@plt>
8048442: 85 f6 test %esi,%esi // ← test if x == NULL
8048444: 0f 94 c0 sete %al // ← set result accordingly
8048447: 0f b6 c0 movzbl %al,%eax
804844a: 83 c4 18 add $0x18,%esp
804844d: 5e pop %esi
804844e: c3 ret |
|
nice analyses, so we get useful results with clang without having this switch implemented in clang |
|
I wrapped the |
Makefile.include
Outdated
There was a problem hiding this comment.
please write two lines:
- why this switch is needed (gcc)
- why it is not enabled in all cases (clang)
|
@Kijewski you can copy the content of the issues, just one sentence: what is the motivation for the switch, what is the reason to not enable it in every case.:) I think it's best to have a short version directly in the file, and a link to the discussion is always a benefit. |
seems not to work with that command line... |
|
hello-world and default work for me with that command line. |
|
I'm on current master with this commit cherry picked in and I get: |
Only use -fno-delete-null-pointer-checks if the supplied compiler knows the flag. Clang does not understand the flag, and does not need it.
|
You have an old clang version. I amended my commit to check if the output on STDERR was empty when testing if the flag is known. |
|
Ah I see. I'm on oldstable fedora. going to test this tomorrow with stable. |
|
tested with clang 3.4. it works. ACK. can someone else test this too? |
|
Successfully tested that building yields no warnings with: and |
…nter-checks clang does not know fno-delete-null-pointer-checks
Only use -fno-delete-null-pointer-checks if the supplied compiler knows the flag. Clang does not understand the flag, and does not need it.
Only use -fno-delete-null-pointer-checks if the supplied compiler knows the flag. Clang does not understand the flag, and does not need it.
In RIOT-OS#664 I added a test that determines if the supplied compiler understands the `-fno-delete-null-pointer-checks` flag. The problem is that the `$(CC)` supplied on command line or in the application's Makefile is used, but not the one the `$(BOARD)`'s Makefile sets. That problem was overlooked as all the boards use GCC, and GCC happens to know the flag. But if some future board does not use GCC, then the wrong order of the checks could pose a problem.
as introduced in #628 the parameter "-fno-delete-null-pointer-checks" is handed over to the compiler.
clang throws a warning and ignores it.
task: try to find a way to get the desired functionality in clang, and or try to find a way to get rid of this warning.