Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-Warray-bounds warning with asm goto in impossible switch cases #51024

Closed
nathanchance opened this issue Aug 30, 2021 · 2 comments
Closed

-Warray-bounds warning with asm goto in impossible switch cases #51024

nathanchance opened this issue Aug 30, 2021 · 2 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla c

Comments

@nathanchance
Copy link
Member

nathanchance commented Aug 30, 2021

Bugzilla Link 51682
Version trunk
OS Windows NT
Blocks #4440
Attachments False positive -Warray-bounds reproducer
CC @DougGregor,@efriedma-quic,@kees,@nickdesaulniers,@pageexec,@zygoloid

Extended Description

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

$ 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 #35463 but the second function appears to do the right thing and not warn so I do not think that it is the same situation.

@efriedma-quic
Copy link
Collaborator

It looks like something is going wrong with CFG analysis for asm goto, and we're treating the operand of the asm goto as "reachable" regardless of the surrounding CFG. The warning should be suppressed.

Briefly looked at it, but it's a bit more complicated than I thought. If someone wants to look, maybe start with AnalysisBasedWarnings::IssueWarnings and CFGBuilder::VisitGCCAsmStmt?

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@nickdesaulniers nickdesaulniers self-assigned this Dec 20, 2021
@nickdesaulniers
Copy link
Member

github-actions bot pushed a commit to tstellar/llvm-project that referenced this issue Jan 7, 2022
When performing CFG based analyses, don't forget to check the child
statements of an asm goto, such as the expressions used for
inputs+outputs.

Fixes: llvm#51024
Fixes: ClangBuiltLinux/linux#1439

Reviewed By: void, jyknight, jyu2, efriedma

Differential Revision: https://reviews.llvm.org/D116059

(cherry picked from commit 3a604fd)
tstellar pushed a commit that referenced this issue Jan 8, 2022
When performing CFG based analyses, don't forget to check the child
statements of an asm goto, such as the expressions used for
inputs+outputs.

Fixes: #51024
Fixes: ClangBuiltLinux/linux#1439

Reviewed By: void, jyknight, jyu2, efriedma

Differential Revision: https://reviews.llvm.org/D116059

(cherry picked from commit 3a604fd)
haoNoQ pushed a commit to swiftlang/llvm-project that referenced this issue Feb 23, 2022
When performing CFG based analyses, don't forget to check the child
statements of an asm goto, such as the expressions used for
inputs+outputs.

Fixes: llvm#51024
Fixes: ClangBuiltLinux/linux#1439

Reviewed By: void, jyknight, jyu2, efriedma

Differential Revision: https://reviews.llvm.org/D116059

(cherry picked from commit 3a604fd)
s194604 pushed a commit to s194604/patmos-llvm-project that referenced this issue Apr 10, 2022
When performing CFG based analyses, don't forget to check the child
statements of an asm goto, such as the expressions used for
inputs+outputs.

Fixes: llvm/llvm-project#51024
Fixes: ClangBuiltLinux/linux#1439

Reviewed By: void, jyknight, jyu2, efriedma

Differential Revision: https://reviews.llvm.org/D116059

(cherry picked from commit 3a604fd)
bryanpkc pushed a commit to flang-compiler/classic-flang-llvm-project that referenced this issue Apr 20, 2022
When performing CFG based analyses, don't forget to check the child
statements of an asm goto, such as the expressions used for
inputs+outputs.

Fixes: llvm/llvm-project#51024
Fixes: ClangBuiltLinux/linux#1439

Reviewed By: void, jyknight, jyu2, efriedma

Differential Revision: https://reviews.llvm.org/D116059

(cherry picked from commit 3a604fd)
mem-frob pushed a commit to draperlaboratory/hope-llvm-project that referenced this issue Oct 7, 2022
When performing CFG based analyses, don't forget to check the child
statements of an asm goto, such as the expressions used for
inputs+outputs.

Fixes: llvm/llvm-project#51024
Fixes: ClangBuiltLinux/linux#1439

Reviewed By: void, jyknight, jyu2, efriedma

Differential Revision: https://reviews.llvm.org/D116059
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c
Projects
None yet
Development

No branches or pull requests

3 participants