This fixes a dummy variable unused warning-to-error on gcc-6.4.
Details
- Reviewers
kib markj jilles - Commits
- rS367647: [tests] Fix unused variable warning in gcc
- compiled on gcc-6.4 amd64
Diff Detail
- Repository
- rS FreeBSD src repository - subversion
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
tests/sys/vm/page_fault_signal.c | ||
---|---|---|
119 ↗ | (On Diff #78248) | This isn't the right way to cope with this issue. Please get kib@ or markj@ to sign off on this review. |
tests/sys/vm/page_fault_signal.c | ||
---|---|---|
119 ↗ | (On Diff #78248) | Yeah, I've added them, I'll see how it goes! |
tests/sys/vm/page_fault_signal.c | ||
---|---|---|
119 ↗ | (On Diff #78248) | I think you could get rid of dummy and write (void)*(volatile int *)p; If the compiler elides the load, I believe the test will fail. |
tests/sys/vm/page_fault_signal.c | ||
---|---|---|
119 ↗ | (On Diff #78248) | Doesn't volatile int *p; and (void)*p; work fine? The other references do not dereference the pointer, and it isn't volatile int * volatile p. |
tests/sys/vm/page_fault_signal.c | ||
---|---|---|
119 ↗ | (On Diff #78248) | I think the compiler will raise an error around munmap(p, sz); if p is volatile. |
tests/sys/vm/page_fault_signal.c | ||
---|---|---|
119 ↗ | (On Diff #78248) | Maybe? munmap's first argument is void *; the behavior is well-defined, I don't know if GCC warns about that specific implicit cast to void *. |
tests/sys/vm/page_fault_signal.c | ||
---|---|---|
119 ↗ | (On Diff #78248) | Ah, Clang gives a -Wincompatible-pointer-types-discards-qualifiers warning and GCC -Wdiscarded-qualifiers. Ok |
Does anybody looked at the resulting asm to confirm that memory access is indeed generated ?
I confirmed on Godbolt:
Clang 11 amd64 -O3
main: # @main pushq %rax callq my_mmap movl (%rax), %ecx <<< access movq %rax, %rdi callq my_unmap xorl %eax, %eax popq %rcx retq
GCC 10 amd64 -O3
main: subq $8, %rsp call my_mmap movq %rax, %rdi movl (%rdi), %eax <<< access call my_unmap xorl %eax, %eax addq $8, %rsp ret
void *my_mmap(void); void my_unmap(void *p); int main(int argc, char **argv) { int *p; p = my_mmap(); (void)*(volatile int *)p; my_unmap(p);