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

__builtin_unreachable(); should be recognized #519

Closed
krader1961 opened this issue Sep 12, 2018 · 3 comments
Closed

__builtin_unreachable(); should be recognized #519

krader1961 opened this issue Sep 12, 2018 · 3 comments

Comments

@krader1961
Copy link

Issue Summary

Use of __builtin_unreachable(); where a break; would otherwise be used should suppress a missing break in switch statement warning.

Environment

  • Operation system name and version: macOS 10.12
  • OCLint version: 0.13
  • How OCLint is installed: homebrew install

Reproduction Steps

This came to my attention because the korn shell project has had to inset quite a few __builtin_unreachable(); statements to silence static analysis warnings. This is a consequence of its errormsg() interface not returning, executing a longjmp() instead, when certain arguments are used.

Sample code

case '?': {
    errormsg(SH_DICT, ERROR_usage(2), "%s", opt_info.arg);
    __builtin_unreachable();
}

Expected Behavior

Using __builtin_unreachable();, or function call with an equivalent annotation, as the last statement in a case: block should inhibit the warning about a missing break statement.

Actual Behavior

Warnings such as src/cmd/ksh93/bltins/cd_pwd.c:328:9: missing break in switch statement [convention|P2].

Even Better

Feel free to clone https://github.com/att/ast/, configure the build with meson -C build, then run oclint over all the code via bin/lint all. It's a gold mine of bad practices 😄

@krader1961
Copy link
Author

Also, goto a_label; as the last statement in a case block should be treated as equivalent to break;. Personally I would never write code like that but there are quite a few instances in the ksh source where they use it as an early exit. It's usually this pattern:

int a_fun() {
    for(...) {
        switch (n) {
            case 1:
                  goto done;
             case 2:
                   // stuff
                   break;
          }
    }
done:
    // stuff
    return n;
}

@ryuichi-assistant
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by adding a comment.

@krader1961
Copy link
Author

The ksh project I was contributing to was killed a year ago and I'm currently working with the Go language so this is no longer an issue for me. Hopefully this has either already been resolved or this issue will serve as a starting point for someone else who would benefit from the feature.

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