Page MenuHomeFreeBSD

[tests] Fix "unused variable" warning-to-error on gcc-6.4
ClosedPublic

Authored by adrian on Oct 15 2020, 4:46 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Jan 18, 3:59 PM
Unknown Object (File)
Dec 13 2024, 1:59 PM
Unknown Object (File)
Dec 7 2024, 2:38 PM
Unknown Object (File)
Nov 28 2024, 4:10 AM
Unknown Object (File)
Nov 24 2024, 5:11 PM
Unknown Object (File)
Nov 24 2024, 5:33 AM
Unknown Object (File)
Nov 12 2024, 5:43 PM
Unknown Object (File)
Oct 18 2024, 3:25 PM
Subscribers

Details

Summary

This fixes a dummy variable unused warning-to-error on gcc-6.4.

Test Plan
  • 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.

cem added inline comments.
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

This revision is now accepted and ready to land.Nov 13 2020, 6:45 PM
This revision was automatically updated to reflect the committed changes.

Does anybody looked at the resulting asm to confirm that memory access is indeed generated ?

In D26792#607459, @kib wrote:

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);
In D26792#607459, @kib wrote:

Does anybody looked at the resulting asm to confirm that memory access is indeed generated ?

I verified it when I made the suggestion.