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

Add 'inside' statements to -Wlogical-not-parentheses #1183

Open
jcurtiss8086 opened this issue Dec 2, 2024 · 2 comments
Open

Add 'inside' statements to -Wlogical-not-parentheses #1183

jcurtiss8086 opened this issue Dec 2, 2024 · 2 comments

Comments

@jcurtiss8086
Copy link

jcurtiss8086 commented Dec 2, 2024

Can the -Wlogical-not-parentheses warning be enhanced to also cover 'inside' statements? Since SV does not have a 'not_inside' type operator, it is really common to have to add a !() around the inside call and there isn't a warning here when developers forget the parentheses.

inside_paren.sv:4:13: warning: logical not is only applied to the left hand side of this comparison [-Wlogical-not-parentheses]
        if (!a == 3) begin
            ^  ~~
inside_paren.sv:4:14: note: add parentheses after the '!' to evaluate the comparison first
        if (!a == 3) begin
             ^~~~~~
inside_paren.sv:4:13: note: add parentheses around left hand side expression to silence this warning
        if (!a == 3) begin
            ^~
class C;
    function f();
        bit [7:0] a;
        if (!a == 3) begin
        end
        if (!a inside {0, 3, 9}) begin
        end
    endfunction
endclass
@jcurtiss8086
Copy link
Author

jcurtiss8086 commented Dec 4, 2024

Looks like there is some partial overlap with Wcase-outside-range which catches the issue due to the size-mismatch. But that warning would not flag if the inside-vector only had the values 0 and 1.

Also, I'm not 100% certain if it was intended for case-outside-range to apply to inside-statements as well, although it is useful and is finding real bugs.

inside_paren.sv:6:27: warning: 'inside' item with 2 bits can never match the 1 bit case expression [-Wcase-outside-range]
        if (!a inside {0, 3, 9}) begin
                          ^
inside_paren.sv:6:30: warning: 'inside' item with 4 bits can never match the 1 bit case expression [-Wcase-outside-range]
        if (!a inside {0, 3, 9}) begin
                             ^

@MikePopoloski
Copy link
Owner

Yeah, it should be straightforward to add this and seems useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants