[llvm-bugs] [Bug 51682] New: -Warray-bounds warning with asm goto in impossible switch cases

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Aug 30 15:32:15 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51682

            Bug ID: 51682
           Summary: -Warray-bounds warning with asm goto in impossible
                    switch cases
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C
          Assignee: unassignedclangbugs at nondot.org
          Reporter: natechancellor at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Created attachment 25206
  --> https://bugs.llvm.org/attachment.cgi?id=25206&action=edit
False positive -Warray-bounds reproducer

A piece of code in the Linux kernel triggers -Warray-bounds when it appears
that it should not [1]. Attached is a small reproducer, which has been derived
from arch/powerpc/kernel/signal_32.c [2].

$ clang -fsyntax-only -Weverything warray-bounds.c
warray-bounds.c:12:27: warning: array index 3 is past the end of the array
(which contains 1 element) [-Warray-bounds]
                __asm__ goto("" : : "r"(oldset->sig[3] >> 32) : : failed);
                                        ^           ~
warray-bounds.c:4:2: note: array 'sig' declared here
        unsigned long sig[NSIG_WORDS];
        ^
warray-bounds.c:16:27: warning: array index 2 is past the end of the array
(which contains 1 element) [-Warray-bounds]
                __asm__ goto("" : : "r"(oldset->sig[2] >> 32) : : failed);
                                        ^           ~
warray-bounds.c:4:2: note: array 'sig' declared here
        unsigned long sig[NSIG_WORDS];
        ^
warray-bounds.c:20:27: warning: array index 1 is past the end of the array
(which contains 1 element) [-Warray-bounds]
                __asm__ goto("" : : "r"(oldset->sig[1] >> 32) : : failed);
                                        ^           ~
warray-bounds.c:4:2: note: array 'sig' declared here
        unsigned long sig[NSIG_WORDS];
        ^
3 warnings generated.

$ gcc -fsyntax-only -Wall -Wextra -Wpedantic warray-bounds.c

This appears similar to PR36115 but the second function appears to do the right
thing and not warn so I do not think that it is the same situation.

[1]: https://lore.kernel.org/r/YS0nJtNDCwfbaubZ@Ryzen-9-3900X.localdomain/
[2]:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/powerpc/kernel/signal_32.c?h=v5.14

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210830/3eb091e5/attachment.html>


More information about the llvm-bugs mailing list