From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id ED9E4385803B; Sat, 2 Jan 2021 11:11:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED9E4385803B From: "slyfox at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/98499] New: [11 Regression] Possibly bad std::string initialization in constructors Date: Sat, 02 Jan 2021 11:11:09 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: slyfox 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 Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Jan 2021 11:11:10 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98499 Bug ID: 98499 Summary: [11 Regression] Possibly bad std::string initialization in constructors Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: slyfox at gcc dot gnu.org Target Milestone: --- Initially bug is observed on a usage crash of libsass-3.6.4. Code snippet around the crash: https://github.com/sass/libsass/blob/3.6.4/src/context.cpp#L621 I think I extracted a small example that illustrates the problem: ```c++ // cat main.cc #include __attribute__((noinline)) static std::string dir_name() { return "c"; } __attribute__((noinline)) static std::string make_canonical_path (std::string path) { return path; } class Importer { public: std::string imp_path; std::string ctx_path; std::string base_path; public: __attribute__((noinline)) Importer(std::string imp_path, std::string ctx_path) : imp_path(make_canonical_path(imp_path)) , ctx_path(make_canonical_path(ctx_path)) , base_path(dir_name()) {} }; struct Include { Include(const Importer& imp){} }; int main() { const Include & inc =3D {{"a", "b"}}; } ``` g++-11 generates crashing binaries, g++-10 does not: ``` $ g++-11.0.0 -O2 -std=3Dc++11 main.cc -o a-11; ./a-11; echo $? free(): invalid pointer Aborted (core dumped) 134 $ g++-10.2.0 -O2 -std=3Dc++11 main.cc -o a-10; ./a-10; echo $? 0 ``` I was not able to easily get rid of std::string as it uses something from libstdc++.so. Thus I'm not sure where the bug is. My suspictions are: 1. invalid c++ 2. std::string implementation bug 3. g++'s code generation problem around lifetimes of temporary values I suspect `[3.]`. ``` $ g++-11.0.0 -v Using built-in specs. COLLECT_GCC=3D/usr/bin/g++-11.0.0 COLLECT_LTO_WRAPPER=3D/usr/libexec/gcc/x86_64-pc-linux-gnu/11.0.0/lto-wrapp= er Target: x86_64-pc-linux-gnu Configured with: /var/tmp/portage/sys-devel/gcc-11.0.0_pre9999/work/gcc-11.0.0_pre9999/confi= gure --host=3Dx86_64-pc-linux-gnu --build=3Dx86_64-pc-linux-gnu --prefix=3D/usr --bindir=3D/usr/x86_64-pc-linux-gnu/gcc-bin/11.0.0 --includedir=3D/usr/lib/gcc/x86_64-pc-linux-gnu/11.0.0/include --datadir=3D/usr/share/gcc-data/x86_64-pc-linux-gnu/11.0.0 --mandir=3D/usr/share/gcc-data/x86_64-pc-linux-gnu/11.0.0/man --infodir=3D/usr/share/gcc-data/x86_64-pc-linux-gnu/11.0.0/info --with-gxx-include-dir=3D/usr/lib/gcc/x86_64-pc-linux-gnu/11.0.0/include/g+= +-v11 --with-python-dir=3D/share/gcc-data/x86_64-pc-linux-gnu/11.0.0/python --enable-languages=3Dc,c++,go,jit,fortran --enable-obsolete --enable-secure= plt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --enable-checking=3Drelease --with-bugurl=3Dhttps://bugs.gentoo.org/ --with-pkgversion=3D'Gentoo 11.0.0_pre9999 p5, commit 12ae2bc70846a2be8255eaa41322cd1a5a7b7350' --disable-esp --enable-libstdcxx-= time --enable-host-shared --enable-shared --enable-threads=3Dposix --enable-__cxa_atexit --enable-clocale=3Dgnu --enable-multilib --with-multilib-list=3Dm32,m64 --disable-fixed-point --enable-targets=3Dall --enable-libgomp --disable-libssp --disable-libada --disable-systemtap --enable-valgrind-annotations --enable-vtable-verify --with-zstd --enable-l= to --with-isl --disable-isl-version-check --enable-default-pie --enable-default-ssp Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.0.0 20201228 (experimental) (Gentoo 11.0.0_pre9999 p5, commit 12ae2bc70846a2be8255eaa41322cd1a5a7b7350) ```=