Created attachment 19307 [details] Reduced test case for producing assertion on AArch64 In https://bugs.freebsd.org/223048, Jan Beich reports an assertion failure in clang while compiling a recent version of Firefox for AArch64. A reduced test case is attached. Compile this with: clang -cc1 -triple aarch64 -S -O2 -std=c++11 assertion-r308025-aarch64.cpp Gdb backtrace, with some additional information: (gdb) run Starting program: /home/dim/obj/llvm-trunk-r308025-dbg/bin/clang -cc1 -triple aarch64 -S -O2 -std=c++11 testcase.cpp Assertion failed: (isReg() && "This is not a register operand!"), function getReg, file /home/dim/src/llvm-trunk/include/llvm/CodeGen/MachineOperand.h, line 278. Program received signal SIGABRT, Aborted. 0x00000008077d851a in thr_kill () from /lib/libc.so.7 (gdb) bt #0 0x00000008077d851a in thr_kill () from /lib/libc.so.7 #1 0x00000008077d84e4 in raise () from /lib/libc.so.7 #2 0x00000008077d8459 in abort () from /lib/libc.so.7 #3 0x00000008078544b1 in __assert () from /lib/libc.so.7 #4 0x00000000008f34ea in llvm::MachineOperand::getReg (this=0x808793d18) at /home/dim/src/llvm-trunk/include/llvm/CodeGen/MachineOperand.h:278 #5 0x0000000000a1ef65 in llvm::AArch64InstrInfo::analyzeCompare (this=0x8088ae0e0, MI=..., SrcReg=@0x7fffffff5fc4: 8, SrcReg2=@0x7fffffff5fc0: 142163032, CmpMask=@0x7fffffff5fbc: 9, CmpValue=@0x7fffffff5fb8: 0) at /home/dim/src/llvm-trunk/lib/Target/AArch64/AArch64InstrInfo.cpp:971 #6 0x00000000011c5742 in (anonymous namespace)::PeepholeOptimizer::optimizeCmpInstr (this=0x80870b480, MI=0x808793c58, MBB=0x808786428) at /home/dim/src/llvm-trunk/lib/CodeGen/PeepholeOptimizer.cpp:629 #7 0x00000000011c4693 in (anonymous namespace)::PeepholeOptimizer::runOnMachineFunction (this=0x80870b480, MF=...) at /home/dim/src/llvm-trunk/lib/CodeGen/PeepholeOptimizer.cpp:1754 #8 0x000000000111e541 in llvm::MachineFunctionPass::runOnFunction (this=0x80870b480, F=...) at /home/dim/src/llvm-trunk/lib/CodeGen/MachineFunctionPass.cpp:62 #9 0x000000000171504f in llvm::FPPassManager::runOnFunction (this=0x8064aa9c0, F=...) at /home/dim/src/llvm-trunk/lib/IR/LegacyPassManager.cpp:1514 #10 0x0000000001715365 in llvm::FPPassManager::runOnModule (this=0x8064aa9c0, M=...) at /home/dim/src/llvm-trunk/lib/IR/LegacyPassManager.cpp:1535 #11 0x0000000001716068 in (anonymous namespace)::MPPassManager::runOnModule (this=0x8087a0c00, M=...) at /home/dim/src/llvm-trunk/lib/IR/LegacyPassManager.cpp:1591 #12 0x0000000001715626 in llvm::legacy::PassManagerImpl::run (this=0x80884c500, M=...) at /home/dim/src/llvm-trunk/lib/IR/LegacyPassManager.cpp:1694 #13 0x0000000001716c51 in llvm::legacy::PassManager::run (this=0x7fffffff71c0, M=...) at /home/dim/src/llvm-trunk/lib/IR/LegacyPassManager.cpp:1725 #14 0x00000000022ce261 in (anonymous namespace)::EmitAssemblyHelper::EmitAssembly (this=0x7fffffff7cb8, Action=clang::Backend_EmitAssembly, OS=...) at /home/dim/src/llvm-trunk/tools/clang/lib/CodeGen/BackendUtil.cpp:790 #15 0x00000000022c8c11 in clang::EmitBackendOutput (Diags=..., HeaderOpts=..., CGOpts=..., TOpts=..., LOpts=..., TDesc=..., M=0x80870d600, Action=clang::Backend_EmitAssembly, OS=...) at /home/dim/src/llvm-trunk/tools/clang/lib/CodeGen/BackendUtil.cpp:1134 #16 0x000000000326a371 in clang::BackendConsumer::HandleTranslationUnit (this=0x80651c300, C=...) at /home/dim/src/llvm-trunk/tools/clang/lib/CodeGen/CodeGenAction.cpp:261 #17 0x00000000039a66c7 in clang::ParseAST (S=..., PrintStats=false, SkipFunctionBodies=false) at /home/dim/src/llvm-trunk/tools/clang/lib/Parse/ParseAST.cpp:159 #18 0x0000000002b90495 in clang::ASTFrontendAction::ExecuteAction (this=0x80649a180) at /home/dim/src/llvm-trunk/tools/clang/lib/Frontend/FrontendAction.cpp:1003 #19 0x00000000032651ae in clang::CodeGenAction::ExecuteAction (this=0x80649a180) at /home/dim/src/llvm-trunk/tools/clang/lib/CodeGen/CodeGenAction.cpp:992 #20 0x0000000002b8fa00 in clang::FrontendAction::Execute (this=0x80649a180) at /home/dim/src/llvm-trunk/tools/clang/lib/Frontend/FrontendAction.cpp:902 #21 0x0000000002adc5c1 in clang::CompilerInstance::ExecuteAction (this=0x80651c000, Act=...) at /home/dim/src/llvm-trunk/tools/clang/lib/Frontend/CompilerInstance.cpp:980 #22 0x0000000002d5317c in clang::ExecuteCompilerInvocation (Clang=0x80651c000) at /home/dim/src/llvm-trunk/tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:250 #23 0x00000000008d2fa0 in cc1_main (Argv=..., Argv0=0x7fffffffe900 "/home/dim/obj/llvm-trunk-r308025-dbg/bin/clang", MainAddr=0x8bd830 <GetExecutablePath(char const*, bool)>) at /home/dim/src/llvm-trunk/tools/clang/tools/driver/cc1_main.cpp:221 #24 0x00000000008c15c9 in ExecuteCC1Tool (argv=..., Tool=...) at /home/dim/src/llvm-trunk/tools/clang/tools/driver/driver.cpp:306 #25 0x00000000008bf143 in main (argc_=8, argv_=0x7fffffffe680) at /home/dim/src/llvm-trunk/tools/clang/tools/driver/driver.cpp:387 (gdb) frame 4 #4 0x00000000008f34ea in llvm::MachineOperand::getReg (this=0x808793d18) at /home/dim/src/llvm-trunk/include/llvm/CodeGen/MachineOperand.h:278 278 assert(isReg() && "This is not a register operand!"); (gdb) list 273 // Accessors for Register Operands 274 //===--------------------------------------------------------------------===// 275 276 /// getReg - Returns the register number. 277 unsigned getReg() const { 278 assert(isReg() && "This is not a register operand!"); 279 return SmallContents.RegNo; 280 } 281 282 unsigned getSubReg() const { (gdb) print SmallContents $1 = {RegNo = 8, OffsetLo = 8} (gdb) up #5 0x0000000000a1ef65 in llvm::AArch64InstrInfo::analyzeCompare (this=0x8088ae0e0, MI=..., SrcReg=@0x7fffffff5fc4: 8, SrcReg2=@0x7fffffff5fc0: 142163032, CmpMask=@0x7fffffff5fbc: 9, CmpValue=@0x7fffffff5fb8: 0) at /home/dim/src/llvm-trunk/lib/Target/AArch64/AArch64InstrInfo.cpp:971 971 SrcReg = MI.getOperand(1).getReg(); (gdb) print MI $2 = (const llvm::MachineInstr &) @0x808793c58: {<llvm::ilist_node_with_parent<llvm::MachineInstr, llvm::MachineBasicBlock, llvm::ilist_sentinel_tracking<true> >> = {<llvm::ilist_node<llvm::MachineInstr, llvm::ilist_sentinel_tracking<true> >> = {<llvm::ilist_node_impl<llvm::ilist_detail::node_options<llvm::MachineInstr, true, true, void> >> = {<llvm::ilist_node_base<true>> = {PrevAndSentinel = {Value = 34501898840}, Next = 0x808793438}, <No data fields>}, <No data fields>}, <No data fields>}, MCID = 0x632b030 <llvm::AArch64Insts+8448>, Parent = 0x808786428, Operands = 0x808793cf8, NumOperands = 5, CapOperands = {Index = 3 '\003'}, Flags = 0 '\000', AsmPrinterFlags = 0 '\000', NumMemRefs = 0 '\000', MemRefs = 0x0, debugLoc = {Loc = {Ref = {MD = 0x0}}}} (gdb) print MI.Operands[0] $5 = {OpKind = llvm::MachineOperand::MachineOperandType::MO_Register, SubReg_TargetFlags = 0, TiedTo = 0 '\000', IsDef = true, IsImp = false, IsKill = false, IsDead = false, IsUndef = false, IsInternalRead = false, IsEarlyClobber = false, IsDebug = false, SmallContents = {RegNo = 2147483649, OffsetLo = 2147483649}, ParentMI = 0x808793c58, Contents = {MBB = 0x808793798, CFP = 0x808793798, CI = 0x808793798, ImmVal = 34501900184, RegMask = 0x808793798, MD = 0x808793798, Sym = 0x808793798, CFIIndex = 142161816, IntrinsicID = 142161816, Pred = 142161816, Reg = {Prev = 0x808793798, Next = 0x808793478}, OffsetedInfo = {Val = {Index = 142161816, SymbolName = 0x808793798 "", GV = 0x808793798, BA = 0x808793798}, OffsetHi = 142161016}}} (gdb) print MI.Operands[1] $6 = {OpKind = llvm::MachineOperand::MachineOperandType::MO_FrameIndex, SubReg_TargetFlags = 0, TiedTo = 8 '\b', IsDef = false, IsImp = false, IsKill = false, IsDead = true, IsUndef = false, IsInternalRead = false, IsEarlyClobber = false, IsDebug = false, SmallContents = {RegNo = 8, OffsetLo = 8}, ParentMI = 0x808793c58, Contents = {MBB = 0x7fff00000001, CFP = 0x7fff00000001, CI = 0x7fff00000001, ImmVal = 140733193388033, RegMask = 0x7fff00000001, MD = 0x7fff00000001, Sym = 0x7fff00000001, CFIIndex = 1, IntrinsicID = llvm::Intrinsic::ID::addressofreturnaddress, Pred = 1, Reg = {Prev = 0x7fff00000001, Next = 0x3073cab <llvm::dyn_cast<llvm::FrameIndexSDNode, llvm::SDValue>(llvm::SDValue&)+43>}, OffsetedInfo = {Val = {Index = 1, SymbolName = 0x7fff00000001 <error: Cannot access memory at address 0x7fff00000001>, GV = 0x7fff00000001, BA = 0x7fff00000001}, OffsetHi = 50805931}}} E.g. it seems that MI.Operands[1] is a FrameIndex, not a Register.
As mentioned in the title, this assertion did not fire before https://reviews.llvm.org/rL308025. However, r308025 might only expose some other deeper lying issue?
Spamming a few more people who were reviewers/subscribed to https://reviews.llvm.org/D33345, to hopefully get some attention on this bug. :)
Did you try this with something newer than r316035 which fixes an issue like this?
Thanks Matthias, I can confirm that r316035 fixes this assertion. I'll create a PR to have this merged into 5.0.1.