Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Compiler crash #368

Open
Ingenu opened this Issue Sep 4, 2012 · 21 comments

Comments

Projects
None yet
2 participants

Ingenu commented Sep 4, 2012

Some code makes the compiler crash, I tried to build a minimal exemple.

Compiling either of those will crash the compiler.
https://dl.dropbox.com/u/50273045/bug%20crash.rar
https://dl.dropbox.com/u/50273045/bug%20crash2.rar

@ghost

ghost commented Sep 5, 2012

This looks like it could be LLVM bug #12743 which is marked as fixed in r154157. Maybe this fix was too late to go into 3.1?

Owner

jckarter commented Oct 10, 2012

@Ingenu Sorry for taking so long to get to this. I tried both of these on Mac, and they work for me. Is this on Windows? 32- or 64-bit?

Ingenu commented Oct 10, 2012

Win7 x64 Home using VS2010Express + Windows SDK 64bits and Clay64 from the
website.

2012/10/10 Joe Groff notifications@github.com

@Ingenu https://github.com/Ingenu Sorry for taking so long to get to
this. I tried both of these on Mac, and they work for me. Is this on
Windows? 32- or 64-bit?


Reply to this email directly or view it on GitHubhttps://github.com/jckarter/clay/issues/368#issuecomment-9288022.

Owner

jckarter commented Oct 10, 2012

Hmm, it doesn't crash under a debug build—annoying.

Owner

jckarter commented Oct 10, 2012

The compiled program crashes after printing "allocate size=48"—is that expected?

@ghost

ghost commented Oct 10, 2012

I get an optimizer crash during compilation with debug build:

Program received signal SIGSEGV, Segmentation fault.
0x00000000011dbd78 in llvm::IntegerType::get(llvm::LLVMContext&, unsigned int) ()
(gdb) bt
#0  0x00000000011dbd78 in llvm::IntegerType::get(llvm::LLVMContext&, unsigned int) ()
#1  0x000000000113f2a5 in llvm::ConstantInt::get(llvm::LLVMContext&, llvm::APInt const&) ()
#2  0x000000000113f465 in llvm::ConstantInt::get(llvm::IntegerType*, unsigned long, bool) ()
#3  0x00000000011447ff in llvm::ConstantInt::get(llvm::Type*, unsigned long, bool) ()
#4  0x000000000113cfba in llvm::ConstantFoldCompareInstruction(unsigned short, llvm::Constant*, llvm::Constant*) ()
#5  0x000000000114096c in llvm::ConstantExpr::getICmp(unsigned short, llvm::Constant*, llvm::Constant*) ()
#6  0x000000000085c24b in (anonymous namespace)::Evaluator::EvaluateBlock(llvm::ilist_iterator<llvm::Instruction>, llvm::BasicBlock*&) ()
#7  0x000000000085a92b in (anonymous namespace)::Evaluator::EvaluateFunction(llvm::Function*, llvm::Constant*&, llvm::SmallVectorImpl<llvm::Constant*> const&) ()
#8  0x000000000085d273 in (anonymous namespace)::Evaluator::EvaluateBlock(llvm::ilist_iterator<llvm::Instruction>, llvm::BasicBlock*&) ()
#9  0x000000000085a92b in (anonymous namespace)::Evaluator::EvaluateFunction(llvm::Function*, llvm::Constant*&, llvm::SmallVectorImpl<llvm::Constant*> const&) ()
#10 0x000000000085d273 in (anonymous namespace)::Evaluator::EvaluateBlock(llvm::ilist_iterator<llvm::Instruction>, llvm::BasicBlock*&) ()
#11 0x000000000085a92b in (anonymous namespace)::Evaluator::EvaluateFunction(llvm::Function*, llvm::Constant*&, llvm::SmallVectorImpl<llvm::Constant*> const&) ()
---Type <return> to continue, or q <return> to quit---
#12 0x000000000085d4f5 in EvaluateStaticConstructor(llvm::Function*, llvm::TargetData const*, llvm::TargetLibraryInfo const*)
    ()
#13 0x0000000000861e93 in (anonymous namespace)::GlobalOpt::runOnModule(llvm::Module&) ()
#14 0x00000000011d5994 in llvm::MPPassManager::runOnModule(llvm::Module&) ()
#15 0x00000000011d5a5b in llvm::PassManagerImpl::run(llvm::Module&) ()
#16 0x0000000000638954 in clay::optimizeLLVM (module=0x18b1510, optLevel=2, internalize=true)
    at /home/jeremy/dev/clay/clay/compiler/clay.cpp:239
#17 0x000000000063cf19 in clay::main2 (argc=3, argv=0x7fffffffe558, envp=0x7fffffffe578)
    at /home/jeremy/dev/clay/clay/compiler/clay.cpp:1058
#18 0x00000000007691cb in clay::parachute (mainfn=0x639d98 <clay::main2(int, char**, char const* const*)>, argc=3,
    argv=0x7fffffffe558, envp=0x7fffffffe578) at /home/jeremy/dev/clay/clay/compiler/parachute.cpp:85
#19 0x000000000063d75e in main (argc=3, argv=0x7fffffffe558, envp=0x7fffffffe578)
    at /home/jeremy/dev/clay/clay/compiler/clay.cpp:1137

Using -O0 gives:

Program received signal SIGSEGV, Segmentation fault.
0x00000000011e57ba in llvm::EVT::getExtendedVectorElementType() const ()
(gdb) bt
#0  0x00000000011e57ba in llvm::EVT::getExtendedVectorElementType() const ()
#1  0x00007fff00000000 in ?? ()
#2  0x00007fffffffb820 in ?? ()
#3  0x00007fffffffb820 in ?? ()
#4  0x00007fffffffb820 in ?? ()
#5  0x00007fffffffb840 in ?? ()
#6  0x0000000000000002 in ?? ()
#7  0x0000000000000004 in ?? ()
#8  0x0000000000000000 in ?? ()
(gdb)
@ghost

ghost commented Oct 10, 2012

Thats using the latest (0.2-WIP) on linux x86_64.

Owner

jckarter commented Oct 10, 2012

Well that's worrisome. I assumed the code was written against 0.1, and I get a syntax error trying to build with 0.2.

@ghost

ghost commented Oct 10, 2012

Of course i updated the example to be 0.2 compatible.

From: "Joe Groff" notifications@github.com
To: "jckarter/clay" clay@noreply.github.com
CC: "agemogolk" agemogolk@gmail.com
Sent: 10 October 2012 20:54
Subject: Re: [clay] Compiler crash (#368)

Well that's worrisome. I assumed the code was written against 0.1, and I
get a syntax error trying to build with 0.2.


Reply to this email directly or view it on
GitHubhttps://github.com/jckarter/clay/issues/368#issuecomment-9317106.

Owner

jckarter commented Oct 10, 2012

OK. Does your LLVM has assertions enabled?

@ghost

ghost commented Oct 10, 2012

Ah, no it doesn't, working on a different system now.

From: "Joe Groff" notifications@github.com
To: "jckarter/clay" clay@noreply.github.com
CC: "agemogolk" agemogolk@gmail.com
Sent: 10 October 2012 21:00
Subject: Re: [clay] Compiler crash (#368)

OK. Does your LLVM has assertions enabled?


Reply to this email directly or view it on
GitHubhttps://github.com/jckarter/clay/issues/368#issuecomment-9317352.

Owner

jckarter commented Oct 10, 2012

With a Win64 Release+Asserts build I get the assertion failure:

C:\Users\Joe\Documents\Code\source>..\clay\build64asserts\compiler\src\clay.exe -I..\clay\lib-clay bug.clay
Assertion failed: castIsValid(op, S, Ty) && "Invalid cast!", file C:\Users\Joe\Documents\Code\llvm-3.1.src\lib\VMCore\Instructions.cpp, line 2273
@ghost

ghost commented Oct 10, 2012

Llvm rebuilt with assertions.
Test case compile fails with:

While deleting: i32 (i32)* %ctlz.i32.old
Use still stuck around after Def is destroyed:void ()* bitcast (i32 (i32)* @ctlz.i32.old to void ()*)
clay: Value.cpp:75: virtual llvm::Value::~Value(): Assertion `use_empty() && "Uses remain when a value is destroyed!"' failed.
Owner

jckarter commented Oct 10, 2012

I see that in b.clay the intrinsics are bound as externals without the needed llvm linkage. Does it work if you change them to:

private external (llvm, "llvm.ctlz.i32") x86_bsr(a: Int32) : Int32;
private external (llvm, "llvm.cttz.i32") x86_bsf(a: Int32) : Int32;
@ghost

ghost commented Oct 10, 2012

Same result with llvm linkage attributes included.

From: "Joe Groff" notifications@github.com
To: "jckarter/clay" clay@noreply.github.com
CC: "agemogolk" agemogolk@gmail.com
Sent: 10 October 2012 22:19
Subject: Re: [clay] Compiler crash (#368)

I see that in b.clay the intrinsics are bound as externals without the
needed llvm linkage. Does it work if you change them to:

private external (llvm, "llvm.ctlz.i32") x86_bsr(a: Int32) : Int32;
private external (llvm, "llvm.cttz.i32") x86_bsf(a: Int32) : Int32;


Reply to this email directly or view it on
GitHubhttps://github.com/jckarter/clay/issues/368#issuecomment-9319984.

Owner

jckarter commented Oct 10, 2012

It looks like the interface for those intrinsics has changed:

http://llvm.org/docs/LangRef.html#int_ctlz

They require a static i1 (Bool) as their second argument. However, the external interface is currently unable to provide static arguments to intrinsics directly, so you'll need to interface with ctlz and cttz using __llvm__ procedures.

@ghost

ghost commented Oct 10, 2012

With Clay 0.1 the first bug case compiles and runs fine for me. The bits example fails with:

clay: Instructions.cpp:2273: static llvm::CastInst* llvm::CastInst::Create(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, const llvm::Twine&, llvm::Instruction*): Assertion `castIsValid(op, S, Ty) && "Invalid cast!"' failed.

Owner

jckarter commented Oct 10, 2012

That looks like the same assertion failure I was seeing on Windows. Is the backtrace or context useful at all?

@ghost

ghost commented Oct 10, 2012

#0  0x00007ffff6a26fa5 in raise () from /usr/lib/libc.so.6
#1  0x00007ffff6a28428 in abort () from /usr/lib/libc.so.6
#2  0x00007ffff6a20002 in __assert_fail_base () from /usr/lib/libc.so.6
#3  0x00007ffff6a200b2 in __assert_fail () from /usr/lib/libc.so.6
#4  0x0000000001109630 in llvm::CastInst::Create(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&, llvm::Instruction*) ()
#5  0x00000000005eea0b in CreateCast (Name=..., DestTy=0x464d860, V=0x5639af0, Op=llvm::Instruction::BitCast, this=0x63f9260)
    at /usr/include/llvm/Support/IRBuilder.h:1019
#6  llvm::IRBuilder<true, llvm::ConstantFolder, llvm::IRBuilderDefaultInserter<true> >::CreateCast (this=0x63f9260,
    Op=llvm::Instruction::BitCast, V=0x5639af0, DestTy=0x464d860, Name=...) at /usr/include/llvm/Support/IRBuilder.h:1013
#7  0x00000000005bf711 in CreateBitCast (Name=..., DestTy=<optimized out>, V=0x5639af0, this=<optimized out>)
    at /usr/include/llvm/Support/IRBuilder.h:987
#8  clay::codegenCallCCode (t=..., llCallable=0x5639af0, args=..., ctx=..., out=...)
    at /home/jeremy/dev/clay/clay/compiler/src/codegen.cpp:2464
#9  0x00000000005d1053 in clay::codegenCallExpr (callable=..., args=..., env=..., ctx=..., out=...)
    at /home/jeremy/dev/clay/clay/compiler/src/codegen.cpp:2071
#10 0x00000000005d2da8 in clay::codegenExpr (expr=..., env=..., ctx=..., out=...)
    at /home/jeremy/dev/clay/clay/compiler/src/codegen.cpp:1054
@ghost

ghost commented Oct 10, 2012

When trying to compile with -O0 -S -emit-llvm it segfaults with:

signal 11!

compilation context:
    UInt32(Int32)
  ./ingenu/bits.clay(19,32):
    bsf(UInt32)
  ./ingenu/m.clay(283,18):
    getAvailableNode(TwoLevelSegregatedFit, UInt32)
  ./ingenu/m.clay(116,28):
    allocate(TwoLevelSegregatedFit, UInt32)
  ./ingenu/m.clay(416,26):
    push(Vector[Pointer[UInt8]], Pointer[UInt8])
  ./ingenu/m.clay(416,8):
    m_UNITTEST()
  bug.clay(10,11):
    main(Int32, Pointer[Pointer[Int8]])
  /opt/clay/bin/../lib/lib-clay/system/system.clay(54,33):
    getExitCode()
  /opt/clay/bin/../lib/lib-clay/system/system.clay(54,26):
    callMain(Static[main])
    external main
Owner

jckarter commented Oct 10, 2012

Clay's signal handler should kick in and give you the Clay context for the LLVM assertion failure—I wonder why it doesn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment