From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 64438 invoked by alias); 14 Jul 2015 12:06:01 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 64390 invoked by uid 48); 14 Jul 2015 12:05:55 -0000 From: "doko at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/66868] New: [5/6 Regression] wrong code generated with -O3 (dead code removal?) Date: Tue, 14 Jul 2015 12:06:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 5.1.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: doko at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-07/txt/msg01119.txt.bz2 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 &List, std::vector &SList, std::vector &SigList, std::vector &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 &List, vector &SList, vector &SigList, vector &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).