This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Disable GCC's -Wstringop-truncation warning. NFC.
ClosedPublic

Authored by mstorsjo on Apr 6 2022, 1:47 PM.

Details

Summary

This warning gives false positives about lldb's correct use of
strncpy to fill fixed length fields that don't need null termination,
in lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp, like this:

In file included from /usr/include/string.h:495,
                 from /usr/include/c++/9/cstring:42,
                 from ../include/llvm/ADT/StringRef.h:19,
                 from ../tools/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp:10:
In function ‘char* strncpy(char*, const char*, size_t)’,
    inlined from ‘lldb::offset_t CreateAllImageInfosPayload(const ProcessSP&, lldb::offset_t, lldb_private::StreamString&, lldb::SaveCoreStyle)’ at ../tools/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp:6341:16:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:34: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ specified bound 16 equals destination size [-Wstringop-truncation]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
      |          ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~

The warning could be squelched locally with

#pragma GCC diagnostic ignored "-Wstringop-truncation"

too, but Clang also interprets those GCC pragmas, and produces
a -Wunknown-warning-option warning instead. That could be remedied
by wrapping the pragma in an "#ifndef clang" - but that makes
things even more messy. Instead, just silence this warning entirely.

Diff Detail

Event Timeline

mstorsjo created this revision.Apr 6 2022, 1:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 6 2022, 1:47 PM
mstorsjo requested review of this revision.Apr 6 2022, 1:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 6 2022, 1:48 PM
JDevlieghere accepted this revision.Apr 6 2022, 2:24 PM

I saw this warning on the bots and was confused because I too came to the conclusion that we were using strncpy correctly. LGTM.

This revision is now accepted and ready to land.Apr 6 2022, 2:24 PM
This revision was landed with ongoing or failed builds.Apr 7 2022, 2:10 AM
This revision was automatically updated to reflect the committed changes.