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

Direct binding gets incorrectly overwritten #62822

Open
isuckatcs opened this issue May 20, 2023 · 1 comment
Open

Direct binding gets incorrectly overwritten #62822

isuckatcs opened this issue May 20, 2023 · 1 comment
Labels
clang:static analyzer false-positive Warning fires when it should not

Comments

@isuckatcs
Copy link
Member

isuckatcs commented May 20, 2023

int main() {
  int x = 1024;
  *((char *)&x) = 0;

  if (!x) {
    clang_analyzer_warnIfReached();
  }

  return 0;
}
warning: REACHABLE [debug.ExprInspection]
    clang_analyzer_warnIfReached();
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The statement *((char *)&x) = 0 assigns 0 to the last byte of x (on a little endian system), but the analyzer incorrectly models it as overwriting the value of x with 0. In reality the value of x remains 1024.

See the example on Godbolt.

@isuckatcs isuckatcs added clang:static analyzer false-positive Warning fires when it should not labels May 20, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented May 20, 2023

@llvm/issue-subscribers-clang-static-analyzer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:static analyzer false-positive Warning fires when it should not
Projects
None yet
Development

No branches or pull requests

2 participants