public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "amonakov at gcc dot gnu.org" <gcc-bugzilla@gcc.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	[thread overview]
Message-ID: <bug-106943-4-svtAFbD98x@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-106943-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #7 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
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 LTO).

As evidence, I submit the following:

It breaks with -flto -flto-partition=1to1 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/InstCombinePHI.cpp:691
#10 llvm::InstCombinerImpl::foldPHIArgOpIntoPHI () at
/tmp/llvm-project-llvmorg-13.0.1/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp:835
#11 0x00007ffff5c64656 in llvm::InstCombinerImpl::visitPHINode () at
/tmp/llvm-project-llvmorg-13.0.1/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp:1316
#12 0x00007ffff5c0c1b7 in llvm::InstCombinerImpl::run () at
/tmp/llvm-project-llvmorg-13.0.1/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:3902
#13 combineInstructionsOverFunction () at
/tmp/llvm-project-llvmorg-13.0.1/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:4192
#14 0x00007ffff522efa4 in llvm::InstCombinePass::run () at
/tmp/llvm-project-llvmorg-13.0.1/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:4223
#15 0x00007ffff66463de in llvm::detail::PassModel<llvm::Function,
llvm::InstCombinePass, llvm::PreservedAnalyses,
llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&,
llvm::AnalysisManager<llvm::Function>&) ()
    at
/tmp/llvm-project-llvmorg-13.0.1/llvm/include/llvm/IR/PassManagerInternal.h:85
#16 0x00007ffff51250da in llvm::PassManager<llvm::Function,
llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&,
llvm::AnalysisManager<llvm::Function>&) () at
/tmp/llvm-project-llvmorg-13.0.1/llvm/include/llvm/IR/PassManager.h:509
#17 0x00007ffff65ffb6e in llvm::detail::PassModel<llvm::Function,
llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>,
llvm::PreservedAnalyses,
llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&,
llvm::AnalysisManager<llvm::Function>&) () 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<llvm::Module,
llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses,
llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&,
llvm::AnalysisManager<llvm::Module>&) ()
    at
/tmp/llvm-project-llvmorg-13.0.1/llvm/include/llvm/IR/PassManagerInternal.h:85
#20 0x00007ffff51243f9 in llvm::PassManager<llvm::Module,
llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&,
llvm::AnalysisManager<llvm::Module>&) () 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/ExecuteCompilerInvocation.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 = ::operator new(Size + sizeof(Use *));
  Use **HungOffOperandList = static_cast<Use **>(Storage);
  User *Obj = reinterpret_cast<User *>(HungOffOperandList + 1);
  Obj->NumUserOperands = 0;
  Obj->HasHungOffUses = true;
  Obj->HasDescriptor = false;
  *HungOffOperandList = nullptr;
  return Obj;
}

and finally adding -flifetime-dse=1 cures the problem.

As for ranger ICE in gcc-12... sigh.

How shall we proceed here?

  parent reply	other threads:[~2023-05-11 19:39 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-14 17:39 [Bug c++/106943] New: " immoloism at googlemail dot com
2022-09-14 17:39 ` [Bug c++/106943] " immoloism at googlemail dot com
2022-09-14 17:50 ` pinskia at gcc dot gnu.org
2022-09-14 19:49 ` immoloism at googlemail dot com
2022-09-15  7:17 ` rguenth at gcc dot gnu.org
2022-09-19 14:12 ` immoloism at googlemail dot com
2023-05-11 12:49 ` amonakov at gcc dot gnu.org
2023-05-11 19:39 ` amonakov at gcc dot gnu.org [this message]
2023-05-11 20:29 ` amonakov at gcc dot gnu.org
2023-05-12 13:14 ` xry111 at gcc dot gnu.org
2023-05-12 13:27 ` amonakov at gcc dot gnu.org
2023-05-12 13:32 ` xry111 at gcc dot gnu.org
2023-05-12 14:00 ` amonakov at gcc dot gnu.org
2023-05-12 14:09 ` hubicka at gcc dot gnu.org
2023-05-12 14:23 ` amonakov at gcc dot gnu.org
2023-05-12 14:29   ` Jan Hubicka
2023-05-12 14:29 ` hubicka at ucw dot cz
2023-05-12 14:41 ` xry111 at gcc dot gnu.org
2023-05-12 14:57 ` amonakov at gcc dot gnu.org
2023-05-12 15:16 ` xry111 at gcc dot gnu.org
2023-05-12 15:29 ` hubicka at ucw dot cz
2023-05-12 15:45 ` xry111 at gcc dot gnu.org
2023-05-12 15:48 ` amonakov at gcc dot gnu.org
2023-05-12 15:55 ` amonakov at gcc dot gnu.org
2023-05-12 16:56 ` pinskia at gcc dot gnu.org
2023-05-12 19:10 ` amonakov at gcc dot gnu.org
2023-05-12 19:19 ` pinskia at gcc dot gnu.org
2023-05-12 19:27 ` amonakov at gcc dot gnu.org
2023-05-12 19:30 ` pinskia at gcc dot gnu.org
2023-05-13  3:18 ` xry111 at gcc dot gnu.org
2023-05-13  3:19 ` xry111 at gcc dot gnu.org
2023-05-13  5:29 ` xry111 at gcc dot gnu.org
2023-05-13  6:30 ` amonakov at gcc dot gnu.org
2023-05-13  7:58 ` amonakov at gcc dot gnu.org
2023-05-13 20:06 ` xry111 at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-106943-4-svtAFbD98x@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).