public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/66868] New: [5/6 Regression] wrong code generated with -O3 (dead code removal?)
@ 2015-07-14 12:06 doko at gcc dot gnu.org
  2015-07-14 12:25 ` [Bug tree-optimization/66868] " trippels at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: doko at gcc dot gnu.org @ 2015-07-14 12:06 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 66868
           Summary: [5/6 Regression] wrong code generated with -O3 (dead
                    code removal?)
           Product: gcc
           Version: 5.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: doko at gcc dot gnu.org
  Target Milestone: ---

Created attachment 35975
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35975&action=edit
preprocessed source

[forwarded from https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1473674]

seen in the apt package manager, when built with -O3. Works with -O2 or -O3
-fno-inline-functions -finline-small-functions, on at least x86_64 and
powerpc64le. The test CDROMTest.FindPackages from the apt testsuite then fails.

built with g++ -c -g -O3 -fPIE -fstack-protector-strong -fPIC 

upstream writes:

There is a Cdrom wrapper:
"""
class Cdrom : public pkgCdrom {
   public:
      bool FindPackages(std::string const &CD,
     std::vector<std::string> &List,
     std::vector<std::string> &SList,
     std::vector<std::string> &SigList,
     std::vector<std::string> &TransList,
     std::string &InfoDir) {
  std::string const startdir = SafeGetCWD();
  EXPECT_FALSE(startdir.empty());
  bool const result = pkgCdrom::FindPackages(CD, List, SList, SigList,
TransList, InfoDir, NULL, 0);
...
}
"""

and a unittest that calls it:
"""
TEST(CDROMTest,FindPackages)
{
   Cdrom cd;
  std::string InfoDir;
  EXPECT_TRUE(cd.FindPackages(path, Packages, Sources, Signatur, Translation,
InfoDir));
...
  EXPECT_EQ(path + "/.disk/", InfoDir);
}
"""
The actual code for this is apt-pkg/cdrom.cc:
"""
bool pkgCdrom::FindPackages(string CD,
       vector<string> &List,
       vector<string> &SList,
       vector<string> &SigList,
       vector<string> &TransList,
       string &InfoDir, pkgCdromStatus *log,
       unsigned int Depth)
{
...
   if (DirectoryExists(".disk") == true)
   {
      if (InfoDir.empty() == true)
  InfoDir = CD + ".disk/";
   }
...
"""

So I suspect that the optimizer gets confused that InfoDir is a reference or it
gets confused because InfoDir is not used in FindPackages anymore and it
assumes its dead code.

I tried to create a simplified testcase but failed so far. Whats interessting
is that if I add a std::cerr << "debug" line into cdrom.cc lines (or even a "CD
= CD"):
"""
   if (DirectoryExists(".disk") == true)
   {
      if (InfoDir.empty() == true) {
std::cerr << "debug" << std::endl;
  InfoDir = CD + ".disk/";
}
   }
"""
it works (which indicates dead-code elimination to me).


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

end of thread, other threads:[~2015-07-27 17:05 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-14 12:06 [Bug tree-optimization/66868] New: [5/6 Regression] wrong code generated with -O3 (dead code removal?) doko at gcc dot gnu.org
2015-07-14 12:25 ` [Bug tree-optimization/66868] " trippels at gcc dot gnu.org
2015-07-14 12:53 ` rguenth at gcc dot gnu.org
2015-07-14 13:02 ` doko at gcc dot gnu.org
2015-07-16  9:15 ` rguenth at gcc dot gnu.org
2015-07-21 22:10 ` wschmidt at gcc dot gnu.org
2015-07-22 13:54 ` wschmidt at gcc dot gnu.org
2015-07-22 13:55 ` wschmidt at gcc dot gnu.org
2015-07-22 14:07 ` wschmidt at gcc dot gnu.org
2015-07-22 14:28 ` wschmidt at gcc dot gnu.org
2015-07-24 19:58 ` doko at gcc dot gnu.org
2015-07-27 17:05 ` doko 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).