public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/103176] New: -foptimize-strlen causes stringop-overflow warning
@ 2021-11-10 18:40 josiah_vanderzee at mediacombb dot net
  2021-11-10 18:43 ` [Bug tree-optimization/103176] " josiah_vanderzee at mediacombb dot net
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: josiah_vanderzee at mediacombb dot net @ 2021-11-10 18:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103176

            Bug ID: 103176
           Summary: -foptimize-strlen causes stringop-overflow warning
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: josiah_vanderzee at mediacombb dot net
  Target Milestone: ---

The following warning appears while compiling
https://github.com/minetest/irrlicht with at least -O2. Compiling with
-fno-optimize-strlen makes the warning disappear. Diffing a binary compiled
with the optimization and one compiled without show that there is no difference
in the generated code.The relevant functions are inlined (and I verified this
by hand) so all of it is present in the binary. The warning follows.

I have considered the view that the warning is desirable; the code is very
dangerous; and I am not claiming that the warning is incorrect. The problem
here is that for some reason the warning only occurs when strlen optimizations
are enabled. This doesn't seem logical to me.

NOTE: The binaries I diffed were generated by compiling the flattenFilepath()
function as a unit test.

[49/99] ccache /usr/bin/c++ -DIRRLICHT_EXPORTS -D_IRR_STATIC_LIB_ -I../include
-I../source/Irrlicht -O3 -fPIC -Wall -pipe -fno-exceptions -fno-rtti
-std=gnu++11 -MD -MT source/Irrlicht/CMakeFiles/IRRIOOBJ.dir/CFileSystem.cpp.o
-MF source/Irrlicht/CMakeFiles/IRRIOOBJ.dir/CFileSystem.cpp.o.d -o
source/Irrlicht/CMakeFiles/IRRIOOBJ.dir/CFileSystem.cpp.o -c
../source/Irrlicht/CFileSystem.cpp
In file included from ../include/coreutil.h:8,
                 from ../include/IReadFile.h:9,
                 from ../include/IFileArchive.h:8,
                 from ../include/IFileSystem.h:9,
                 from ../source/Irrlicht/CFileSystem.h:8,
                 from ../source/Irrlicht/CFileSystem.cpp:7:
In member function ‘irr::core::string<T> irr::core::string<T,
TAlloc>::subString(irr::u32, irr::s32, bool) const [with T = char; TAlloc =
irr::core::irrAllocator<char>]’,
    inlined from ‘virtual irr::io::path&
irr::io::CFileSystem::flattenFilename(irr::io::path&, const path&) const’ at
../source/Irrlicht/CFileSystem.cpp:679:58:
../include/irrString.h:937:19: warning: writing 1 byte into a region of size 0
[-Wstringop-overflow=]
  937 |   o.array[length] = 0;
      |   ~~~~~~~~~~~~~~~~^~~
In file included from ../include/irrString.h:9,
                 from ../include/coreutil.h:8,
                 from ../include/IReadFile.h:9,
                 from ../include/IFileArchive.h:8,
                 from ../include/IFileSystem.h:9,
                 from ../source/Irrlicht/CFileSystem.h:8,
                 from ../source/Irrlicht/CFileSystem.cpp:7:
../include/irrAllocator.h: In member function ‘virtual irr::io::path&
irr::io::CFileSystem::flattenFilename(irr::io::path&, const path&) const’:
../include/irrAllocator.h:60:22: note: at offset [1, -1] to an object with size
1 allocated by ‘operator new’ here
   60 |   return operator new(cnt);
      |          ~~~~~~~~~~~~^~~~~
In file included from ../include/coreutil.h:8,
                 from ../include/IReadFile.h:9,
                 from ../include/IFileArchive.h:8,
                 from ../include/IFileSystem.h:9,
                 from ../source/Irrlicht/CFileSystem.h:8,
                 from ../source/Irrlicht/CFileSystem.cpp:7:
In member function ‘irr::core::string<T> irr::core::string<T,
TAlloc>::subString(irr::u32, irr::s32, bool) const [with T = char; TAlloc =
irr::core::irrAllocator<char>]’,
    inlined from ‘virtual irr::io::path
irr::io::CFileSystem::getFileBasename(const path&, bool) const’ at
../source/Irrlicht/CFileSystem.cpp:655:73:
../include/irrString.h:937:19: warning: writing 1 byte into a region of size 0
[-Wstringop-overflow=]
  937 |   o.array[length] = 0;
      |   ~~~~~~~~~~~~~~~~^~~
In file included from ../include/irrString.h:9,
                 from ../include/coreutil.h:8,
                 from ../include/IReadFile.h:9,
                 from ../include/IFileArchive.h:8,
                 from ../include/IFileSystem.h:9,
                 from ../source/Irrlicht/CFileSystem.h:8,
                 from ../source/Irrlicht/CFileSystem.cpp:7:
../include/irrAllocator.h: In member function ‘virtual irr::io::path
irr::io::CFileSystem::getFileBasename(const path&, bool) const’:
../include/irrAllocator.h:60:22: note: at offset [1, -1] to an object with size
1 allocated by ‘operator new’ here
   60 |   return operator new(cnt);
      |          ~~~~~~~~~~~~^~~~~
In file included from ../include/coreutil.h:8,
                 from ../include/IReadFile.h:9,
                 from ../include/IFileArchive.h:8,
                 from ../include/IFileSystem.h:9,
                 from ../source/Irrlicht/CFileSystem.h:8,
                 from ../source/Irrlicht/CFileSystem.cpp:7:
In member function ‘irr::core::string<T> irr::core::string<T,
TAlloc>::subString(irr::u32, irr::s32, bool) const [with T = char; TAlloc =
irr::core::irrAllocator<char>]’,
    inlined from ‘virtual irr::io::path
irr::io::CFileSystem::getRelativeFilename(const path&, const path&) const’ at
../include/coreutil.h:158:70:
../include/irrString.h:937:19: warning: writing 1 byte into a region of size 0
[-Wstringop-overflow=]
  937 |   o.array[length] = 0;
      |   ~~~~~~~~~~~~~~~~^~~
In file included from ../include/irrString.h:9,
                 from ../include/coreutil.h:8,
                 from ../include/IReadFile.h:9,
                 from ../include/IFileArchive.h:8,
                 from ../include/IFileSystem.h:9,
                 from ../source/Irrlicht/CFileSystem.h:8,
                 from ../source/Irrlicht/CFileSystem.cpp:7:
../include/irrAllocator.h: In member function ‘virtual irr::io::path
irr::io::CFileSystem::getRelativeFilename(const path&, const path&) const’:
../include/irrAllocator.h:60:22: note: at offset [1, -1] to an object with size
1 allocated by ‘operator new’ here
   60 |   return operator new(cnt);
      |          ~~~~~~~~~~~~^~~~~```

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-11-15 21:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-10 18:40 [Bug tree-optimization/103176] New: -foptimize-strlen causes stringop-overflow warning josiah_vanderzee at mediacombb dot net
2021-11-10 18:43 ` [Bug tree-optimization/103176] " josiah_vanderzee at mediacombb dot net
2021-11-10 18:58 ` msebor at gcc dot gnu.org
2021-11-11 14:04 ` josiah_vanderzee at mediacombb dot net
2021-11-12 23:39 ` msebor at gcc dot gnu.org
2021-11-13  9:13 ` egallager at gcc dot gnu.org
2021-11-13 14:36 ` josiah_vanderzee at mediacombb dot net
2021-11-15 21:19 ` msebor at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).