LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 1314 - Inline asm crash
Summary: Inline asm crash
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Common Code Generator Code (show other bugs)
Version: trunk
Hardware: PC Linux
: P normal
Assignee: Chris Lattner
URL:
Keywords: compile-fail
Depends on:
Blocks: 862
  Show dependency tree
 
Reported: 2007-04-06 19:05 PDT by Ryan M. Lefever
Modified: 2010-02-22 12:54 PST (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments
Original bytecode file that caused assertion failure with llc (225.31 KB, application/octet-stream)
2007-04-06 19:08 PDT, Ryan M. Lefever
Details
Bytecode produced by bugpoint (54.56 KB, application/octet-stream)
2007-04-06 19:09 PDT, Ryan M. Lefever
Details
Stdout and stderr from running bugpoint (908.00 KB, text/plain)
2007-04-06 19:10 PDT, Ryan M. Lefever
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ryan M. Lefever 2007-04-06 19:05:51 PDT
I am getting an assertion failure when I run "llc -f -o /dev/null code.bc"
code.bc has been formed by linking other bytecode files that were all generated
by llvm-gcc and transformed using opt.  All uses of opt passed the -verify option.

I ran llc in gdb and it stops with:

llc:
/home/data2/lefever/work/llvm-cvs-070306/include/llvm/Support/Casting.h:199:
typename llvm::cast_retty<To, From>::ret_type llvm::cast(const Y&) [with X =
llvm::ConstantSDNode, Y = llvm::SDOperand]: Assertion `isa<X>(Val) &&
"cast<Ty>() argument of incompatible type!"' failed.

The stack trace at that point is:

(gdb) bt
#0  0x0000003de682e37d in raise () from /lib64/tls/libc.so.6
#1  0x0000003de682faae in abort () from /lib64/tls/libc.so.6
#2  0x0000003de6827c31 in __assert_fail () from /lib64/tls/libc.so.6
#3  0x000000000082829c in llvm::cast<llvm::ConstantSDNode, llvm::SDOperand>
(Val=@0x166eb20) at
/home/data2/lefever/work/llvm-cvs-070306/include/llvm/Support/Casting.h:199
#4  0x0000000000a6b18d in llvm::ScheduleDAG::EmitNode (this=0x1660180,
Node=0x1672330, VRBaseMap=@0x7fbfffe5e0) at ScheduleDAG.cpp:543
#5  0x0000000000a6b67b in llvm::ScheduleDAG::EmitSchedule (this=0x1660180) at
ScheduleDAG.cpp:616
#6  0x00000000009e4e16 in (anonymous namespace)::ScheduleDAGRRList::Schedule
(this=0x1660180) at ScheduleDAGRRList.cpp:114
#7  0x0000000000a6b7e9 in llvm::ScheduleDAG::Run (this=0x1660180) at
ScheduleDAG.cpp:644
#8  0x0000000000a18c1c in llvm::SelectionDAGISel::ScheduleAndEmitDAG
(this=0x1011d20, DAG=@0x7fbfffec70) at SelectionDAGISel.cpp:4528
#9  0x00000000008d6052 in (anonymous
namespace)::X86DAGToDAGISel::InstructionSelectBasicBlock (this=0x1011d20,
DAG=@0x7fbfffec70) at X86ISelDAGToDAG.cpp:476
#10 0x0000000000a1823d in llvm::SelectionDAGISel::CodeGenAndEmitDAG
(this=0x1011d20, DAG=@0x7fbfffec70) at SelectionDAGISel.cpp:4387
#11 0x0000000000a18317 in llvm::SelectionDAGISel::SelectBasicBlock
(this=0x1011d20, LLVMBB=0x12780c0, MF=@0x15ee620, FuncInfo=@0x7fbfffee50) at
SelectionDAGISel.cpp:4405
#12 0x0000000000a16958 in llvm::SelectionDAGISel::runOnFunction (this=0x1011d20,
Fn=@0x1058130) at SelectionDAGISel.cpp:4090
#13 0x000000000098b6a9 in (anonymous namespace)::X86DAGToDAGISel::runOnFunction
(this=0x1011d20, Fn=@0x1058130) at X86ISelDAGToDAG.cpp:122
#14 0x0000000000bd90b2 in llvm::FPPassManager::runOnFunction (this=0x1013020,
F=@0x1058130) at PassManager.cpp:1047
#15 0x0000000000bd8e7c in llvm::FunctionPassManagerImpl::run (this=0x119be60,
F=@0x1058130) at PassManager.cpp:1006
#16 0x0000000000bd8d76 in llvm::FunctionPassManager::run (this=0x7fbffff1d0,
F=@0x1058130) at PassManager.cpp:951
#17 0x00000000007bd037 in main (argc=5, argv=0x7fbffff338) at llc.cpp:290
Comment 1 Ryan M. Lefever 2007-04-06 19:08:47 PDT
Created attachment 763 [details]
Original bytecode file that caused assertion failure with llc
Comment 2 Ryan M. Lefever 2007-04-06 19:09:41 PDT
Created attachment 764 [details]
Bytecode produced by bugpoint
Comment 3 Ryan M. Lefever 2007-04-06 19:10:32 PDT
Created attachment 765 [details]
Stdout and stderr from running bugpoint
Comment 4 Ryan M. Lefever 2007-04-06 19:12:26 PDT
I ran bugpoint on the original bytecode file that caused llc to fail with an
assertion.  I have attached the original bytecode file causing the assertion,
the bytecode file produced by bugpoint, and a text file with the output from
bugpoint.
Comment 5 Reid Spencer 2007-04-06 19:16:35 PDT
Thank you for the complete bug report, Ryan.

On the Head, the problem is actually offset a few lines at ScheduleDAG.cpp:557


      // Add all of the operand registers to the instruction.
      for (unsigned i = 2; i != NumOps;) {
        unsigned Flags = cast<ConstantSDNode>(Node->getOperand(i))->getValue();
        unsigned NumVals = Flags >> 3;

The cast to ConstantSDNode is not correct in this case as the node's operand is
actually an SDOperand. I'm not sure what this should be (other than SDOperand),
but its probably obvious to Chris or Evan.

Can you try cast<SDOperand>(...) instead ?
Comment 6 Reid Spencer 2007-04-06 19:18:26 PDT
P.S. The bugpoint run was inconclusive (it failed).
Comment 7 Reid Spencer 2007-04-06 19:41:40 PDT
Ryan,

Actually, don't bother. It doesn't compile. I'm not sure what the right solution
here is.

Reid.
Comment 8 Chris Lattner 2007-04-08 17:10:42 PDT
reduced testcase: 

target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-
v64:64:64-v128:128:128-a0:0:64"
target triple = "x86_64-unknown-linux-gnu"
        %struct.CycleCount = type { i64, i64 }
        %struct.bc_struct = type { i32, i32, i32, i32, %struct.bc_struct*, i8*, i8* }
@_programStartTime = external global %struct.CycleCount         ; <%struct.CycleCount*> [#uses=1]

define fastcc i32 @bc_divide(%struct.bc_struct* %n1, %struct.bc_struct* %n2, %struct.bc_struct** %quot, 
i32 %scale) {
entry:
        br i1 false, label %cond_next60, label %UnifiedReturnBlock86

cond_next60:            ; preds = %entry
        br i1 false, label %cond_next155, label %cond_next81.preheader

cond_next81.preheader:          ; preds = %cond_next60
        ret i32 0

cond_next155:           ; preds = %cond_next60
        %tmp7.i46 = tail call i64 asm sideeffect ".byte 0x0f,0x31", "={dx},=={ax},~{dirflag},~{fpsr},~
{flags}"( i64* getelementptr (%struct.CycleCount* @_programStartTime, i32 0, i32 1) )            ; <i64> 
[#uses=0]
        %tmp221 = sdiv i32 10, 0                ; <i32> [#uses=1]
        tail call fastcc void @_one_mult( i8* null, i32 0, i32 %tmp221, i8* null )
        ret i32 0

UnifiedReturnBlock86:           ; preds = %entry
        ret i32 -1
}

declare fastcc void @_one_mult(i8*, i32, i32, i8*)
Comment 9 Chris Lattner 2007-04-08 17:24:09 PDT
Fixed, testcase here: CodeGen/X86/2007-04-08-InlineAsmCrash.ll

Patch here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070402/047028.html

Thanks!

-Chris