From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 194AF3858431; Thu, 11 May 2023 19:39:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 194AF3858431 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683833997; bh=Q4OlthPKb4rA6alsgN1c2XZFZO4Ph+B4JgWCW9zaO1o=; h=From:To:Subject:Date:In-Reply-To:References:From; b=s1V320SmvUoU888elH0V0Ca3QQR6q4rvvYtBSGj0ZCjEuWIrWXS9ttPHIUZ6noIab usuhOqk7hVkkYGBDGf4K6ZyjNgIGhKOB9wOoSepxuXboJcBLD6Vdmc66aPZEkbKw8J LvCWxL15af6vXcnWu19T0Fs069dqDH8NxNHsfndc= From: "amonakov at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106943] GCC building clang/llvm with LTO flags causes ICE in clang Date: Thu, 11 May 2023 19:39:56 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: needs-reduction, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: amonakov at gcc dot gnu.org X-Bugzilla-Status: WAITING 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: Message-ID: In-Reply-To: References: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106943 --- Comment #7 from Alexander Monakov --- This problem seems to go way back. I'm told even gcc-9 broke LLVM like that. For my investigation, I took latest gcc-11 snapshot and llvm-13.0.1. My conclusion that it is a lifetime-dse violation in LLVM (they already pass -fno-strict-aliasing, but apparently lifetime-dse issue is latent without L= TO). As evidence, I submit the following: It breaks with -flto -flto-partition=3D1to1 with the following backtrace: #4 0x00007ffff4557216 in __assert_fail () from /lib64/libc.so.6 #5 0x00007ffff6d233a9 in llvm::User::allocHungoffUses () at /tmp/llvm-project-llvmorg-13.0.1/llvm/lib/IR/User.cpp:45 #6 0x00007ffff676945f in llvm::PHINode::allocHungoffUses () at /tmp/llvm-project-llvmorg-13.0.1/llvm/include/llvm/IR/Instructions.h:2633 #7 llvm::PHINode::PHINode () at /tmp/llvm-project-llvmorg-13.0.1/llvm/include/llvm/IR/Instructions.h:2611 #8 llvm::PHINode::Create () at /tmp/llvm-project-llvmorg-13.0.1/llvm/include/llvm/IR/Instructions.h:2642 #9 0x00007ffff5c633f4 in llvm::InstCombinerImpl::foldPHIArgLoadIntoPHI () = at /tmp/llvm-project-llvmorg-13.0.1/llvm/lib/Transforms/InstCombine/InstCombin= ePHI.cpp:691 #10 llvm::InstCombinerImpl::foldPHIArgOpIntoPHI () at /tmp/llvm-project-llvmorg-13.0.1/llvm/lib/Transforms/InstCombine/InstCombin= ePHI.cpp:835 #11 0x00007ffff5c64656 in llvm::InstCombinerImpl::visitPHINode () at /tmp/llvm-project-llvmorg-13.0.1/llvm/lib/Transforms/InstCombine/InstCombin= ePHI.cpp:1316 #12 0x00007ffff5c0c1b7 in llvm::InstCombinerImpl::run () at /tmp/llvm-project-llvmorg-13.0.1/llvm/lib/Transforms/InstCombine/Instructio= nCombining.cpp:3902 #13 combineInstructionsOverFunction () at /tmp/llvm-project-llvmorg-13.0.1/llvm/lib/Transforms/InstCombine/Instructio= nCombining.cpp:4192 #14 0x00007ffff522efa4 in llvm::InstCombinePass::run () at /tmp/llvm-project-llvmorg-13.0.1/llvm/lib/Transforms/InstCombine/Instructio= nCombining.cpp:4223 #15 0x00007ffff66463de in llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) () at /tmp/llvm-project-llvmorg-13.0.1/llvm/include/llvm/IR/PassManagerInternal.h= :85 #16 0x00007ffff51250da in llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) () at /tmp/llvm-project-llvmorg-13.0.1/llvm/include/llvm/IR/PassManager.h:509 #17 0x00007ffff65ffb6e in llvm::detail::PassModel>, llvm::PreservedAnalyses, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) () at /tmp/llvm-project-llvmorg-13.0.1/llvm/include/llvm/IR/PassManagerInternal.h= :85 #18 0x00007ffff5158512 in llvm::ModuleToFunctionPassAdaptor::run () at /tmp/llvm-project-llvmorg-13.0.1/llvm/lib/IR/PassManager.cpp:117 #19 0x00007ffff664513e in llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) () at /tmp/llvm-project-llvmorg-13.0.1/llvm/include/llvm/IR/PassManagerInternal.h= :85 #20 0x00007ffff51243f9 in llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) () at /tmp/llvm-project-llvmorg-13.0.1/llvm/include/llvm/IR/PassManager.h:509 #21 0x00000000007816d5 in EmitAssemblyWithNewPassManager () at /tmp/llvm-project-llvmorg-13.0.1/clang/lib/CodeGen/BackendUtil.cpp:1494 #22 0x00000000007842b8 in clang::EmitBackendOutput () at /tmp/llvm-project-llvmorg-13.0.1/clang/lib/CodeGen/BackendUtil.cpp:1660 #23 0x0000000000d1a7d2 in clang::BackendConsumer::HandleTranslationUnit () = at /tmp/llvm-project-llvmorg-13.0.1/clang/lib/CodeGen/CodeGenAction.cpp:334 #24 0x0000000001e3e499 in clang::ParseAST () at /tmp/llvm-project-llvmorg-13.0.1/clang/lib/Parse/ParseAST.cpp:171 #25 0x0000000000bdd349 in clang::FrontendAction::Execute () at /tmp/llvm-project-llvmorg-13.0.1/clang/lib/Frontend/FrontendAction.cpp:951 #26 0x0000000000b91358 in clang::CompilerInstance::ExecuteAction () at /tmp/llvm-project-llvmorg-13.0.1/clang/lib/Frontend/CompilerInstance.cpp:974 #27 0x0000000002003b6b in clang::ExecuteCompilerInvocation () at /tmp/llvm-project-llvmorg-13.0.1/clang/lib/FrontendTool/ExecuteCompilerInvo= cation.cpp:278 #28 0x00000000019bb7ca in cc1_main () at /tmp/llvm-project-llvmorg-13.0.1/clang/tools/driver/cc1_main.cpp:246 #29 0x000000000073290d in ExecuteCC1Tool () at /tmp/llvm-project-llvmorg-13.0.1/clang/tools/driver/driver.cpp:338 #30 0x0000000000697eb0 in main () at /tmp/llvm-project-llvmorg-13.0.1/clang/tools/driver/driver.cpp:409 With the input to clang being just int f(int *p, int c) { return c ? p[0] : c+p[1]; } In frame 5 in the backtrace, User.cpp has this highly suspicious snippet: void *User::operator new(size_t Size) { // Allocate space for a single Use* void *Storage =3D ::operator new(Size + sizeof(Use *)); Use **HungOffOperandList =3D static_cast(Storage); User *Obj =3D reinterpret_cast(HungOffOperandList + 1); Obj->NumUserOperands =3D 0; Obj->HasHungOffUses =3D true; Obj->HasDescriptor =3D false; *HungOffOperandList =3D nullptr; return Obj; } and finally adding -flifetime-dse=3D1 cures the problem. As for ranger ICE in gcc-12... sigh. How shall we proceed here?=