Skip to content

Bogus warning: 'memset' will always overflow; destination buffer has size 1, but size argument is 2 [-Wfortify-source] #124513

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

Closed
stbergmann opened this issue Jan 27, 2025 · 3 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@stbergmann
Copy link
Collaborator

On recent LLVM trunk (towards LLVM 20), bisecting shows that 0a9c08c "[Clang] Implement P2280R4 Using unknown pointers and references in constant expressions (#95474)" started to cause

$ cat test.cc
#include <cstring>
struct S { char m1, m2; };
void f(S & x) { std::memset(&x, 0, sizeof (S)); }
$ clang++ -std=c++23 -fsyntax-only test.cc
test.cc:3:17: warning: 'memset' will always overflow; destination buffer has size 1, but size argument is 2 [-Wfortify-source]
    3 | void f(S & x) { std::memset(&x, 0, sizeof (S)); }
      |                 ^
1 warning generated.
@stbergmann
Copy link
Collaborator Author

ah, this has apparently already been fixed with c9637af "[Clang] Fix createConstexprUnknownAPValues to use zero offset when ceating APValue (#124478)"

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Jan 27, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 27, 2025

@llvm/issue-subscribers-clang-frontend

Author: Stephan Bergmann (stbergmann)

On recent LLVM trunk (towards LLVM 20), bisecting shows that <https://github.com/llvm/llvm-project/commit/0a9c08c59ba61e727e9dee6d71883d9106963442> "[Clang] Implement P2280R4 Using unknown pointers and references in constant expressions (https://github.com//pull/95474)" started to cause ``` $ cat test.cc #include <cstring> struct S { char m1, m2; }; void f(S & x) { std::memset(&x, 0, sizeof (S)); } ``` ``` $ clang++ -std=c++23 -fsyntax-only test.cc test.cc:3:17: warning: 'memset' will always overflow; destination buffer has size 1, but size argument is 2 [-Wfortify-source] 3 | void f(S & x) { std::memset(&x, 0, sizeof (S)); } | ^ 1 warning generated. ```

@shafik
Copy link
Collaborator

shafik commented Jan 27, 2025

Thank you for the bug report, I was pondering filing one just for tracking purposes :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

4 participants