# Compilation issue with Crystal 1.6.x

**URL:** <https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038>\
**Category:** Help & Support\
**Created:** [October 28, 2022, 5:13am UTC](https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038 "2022-10-28T05:13:06Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![stakach](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/stakach/32/58_2.png) [@stakach](https://forum.crystal-lang.org/u/stakach)\
**Post date:** [October 28, 2022, 5:13am UTC](https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038/1 "2022-10-28T05:13:06Z")

</div>

So I have a challenging one, not sure how to solve it either.  
Basically seeing a segfault when compiling

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/crystal_lang/original/2X/f/fa2d5e7025f59972d465015420e8b1b827fc2a66.jpeg)

This is the repo:

> **[GitHub - PlaceOS/core: PlaceOS primary coordination service.](https://github.com/placeos/core)**
>
> PlaceOS primary coordination service. Contribute to PlaceOS/core development by creating an account on GitHub.

It does compile on Crystal 1.5.x currently  
Any pointers on what I can do would be much appreciated - I’m pulling out some of the less critical shards used for instrumentation etc to see if that has any effect currently

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [October 28, 2022, 8:29am UTC](https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038/2 "2022-10-28T08:29:53Z")

</div>

So the failure happens with 1.6.1?

I’d recommend to build the compiler locally and then run with that. It should show more debug info. A meaningful stack trace could help localize the error.

---

<div class="post-metadata">

**Author:** ![stakach](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/stakach/32/58_2.png) [@stakach](https://forum.crystal-lang.org/u/stakach)\
**Post date:** [October 28, 2022, 9:14am UTC](https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038/3 "2022-10-28T09:14:37Z")

</div>

Yeah 1.6.1. Thanks for the pointer 🙂

---

<div class="post-metadata">

**Author:** ![stakach](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/stakach/32/58_2.png) [@stakach](https://forum.crystal-lang.org/u/stakach)\
**Post date:** [October 28, 2022, 9:37am UTC](https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038/4 "2022-10-28T09:37:27Z")

</div>

By chance I had 1.6.0-dev compiled already when I was looking into static compilation issues  
here is the backtrace for that: [compiler error · GitHub](https://gist.github.com/stakach/4403d8c6f2b8ee99b79418baf6f45129)

Just waiting for 1.6.1 to finish compiling

---

<div class="post-metadata">

**Author:** ![stakach](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/stakach/32/58_2.png) [@stakach](https://forum.crystal-lang.org/u/stakach)\
**Post date:** [October 28, 2022, 9:40am UTC](https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038/5 "2022-10-28T09:40:38Z")

</div>

1.7.0-dev backtrace

> <https://gist.github.com/stakach/480273e2daab71a1b14c4e6f12c357cb>

---

<div class="post-metadata">

**Author:** ![HertzDevil](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/hertzdevil/32/1023_2.png) [@HertzDevil](https://forum.crystal-lang.org/u/HertzDevil)\
**Post date:** [October 28, 2022, 11:18am UTC](https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038/6 "2022-10-28T11:18:13Z")

</div>

This is very likely the result of [LLVM phasing out typed pointers](https://github.com/crystal-lang/crystal/issues/12484). Did you use LLVM 15 or 16?

---

<div class="post-metadata">

**Author:** ![stakach](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/stakach/32/58_2.png) [@stakach](https://forum.crystal-lang.org/u/stakach)\
**Post date:** [October 28, 2022, 11:21am UTC](https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038/7 "2022-10-28T11:21:10Z")

</div>

using LLVM 11

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/crystal_lang/original/2X/1/199b1657a2c9ff8fbfa09d40cb688c2fae996903.jpeg)

---

<div class="post-metadata">

**Author:** ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)\
**Post date:** [October 28, 2022, 11:33am UTC](https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038/8 "2022-10-28T11:33:16Z")

</div>

Wow… could you try using a more recent LLVM version? Old LLVM versions were full of bugs. The Crystal team even reported a few of them. This is likely an LLVM bug.

What LLVM version do you have for Crystal 1.5.x?

---

<div class="post-metadata">

**Author:** ![stakach](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/stakach/32/58_2.png) [@stakach](https://forum.crystal-lang.org/u/stakach)\
**Post date:** [October 28, 2022, 12:03pm UTC](https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038/9 "2022-10-28T12:03:36Z")

</div>

That’s the latest version available for Debian stable when I run `apt install llvm`

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/crystal_lang/original/2X/d/d5081dbcf4ff45fcd3c3f9eda49e428a7b9dc103.jpeg)

I do have the same issue in docker containers such as the official crystal lang alpine containers.  
Simple to replicate:

```auto
git clone https://github.com/placeos/core
shards install
crystal build ./src/core-app.cr

```

The release version of crystal uses the LLVM it comes packaged with

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/crystal_lang/original/2X/3/38beb7900a605fd6b34d04593429b13816ded858.jpeg)

---

<div class="post-metadata">

**Author:** ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)\
**Post date:** [October 28, 2022, 12:22pm UTC](https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038/10 "2022-10-28T12:22:40Z")

</div>

Some alternatives to figure out the problem:

1. Try to use an LLVM compiled with assertions. Then instead of a segfault we’ll know what went wrong inside LLVM.
2. Put `puts` in the methods that are near the end of the backtrace, and report back here with what’s printed, to see if we are clearly doing something wrong.

With point 2, I mean… this is the backtrace:

```auto
Crystal::CodeGenVisitor#aggregate_index<LLVM::Value, Int32>:LLVM::Value
Crystal::CodeGenVisitor#union_type_id<LLVM::Value>:LLVM::Value
Crystal::CodeGenVisitor#union_type_and_value_pointer<LLVM::Value, Crystal::MixedUnionType>:Tuple(LLVM::Value, LLVM::Value) 
Crystal::CodeGenVisitor#type_id_impl<LLVM::Value, Crystal::MixedUnionType>:LLVM::Value
Crystal::CodeGenVisitor#type_id<LLVM::Value, Crystal::Type+>:LLVM::Value
Crystal::CodeGenVisitor#codegen_dispatch<Crystal::Call, Crystal::ZeroOneOrMany(Crystal::Def+)>:Bool
Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool

```

So I would put `puts` in `CodeGenVisitor#visit(node : Call)` and output `node`, and also do the same for `type_id`, to see what type is causing the issue.

---

<div class="post-metadata">

**Author:** ![zw963](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/zw963/32/1623_2.png) [@zw963](https://forum.crystal-lang.org/u/zw963)\
**Post date:** [October 28, 2022, 2:36pm UTC](https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038/11 "2022-10-28T14:36:15Z")

</div>

Get same backtrace when compile with 1.6.1 self-compiled compiler.

```auto
Crystal 1.6.1 [fc61bd678] (2022-10-21)

LLVM: 14.0.6
Default target: x86_64-pc-linux-gnu

```

[http://dpaste.com/HMPT79QFX](http://dpaste.com/HMPT79QFX)

---

<div class="post-metadata">

**Author:** ![zw963](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/zw963/32/1623_2.png) [@zw963](https://forum.crystal-lang.org/u/zw963)\
**Post date:** [October 28, 2022, 3:00pm UTC](https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038/12 "2022-10-28T15:00:35Z")

</div>

Hi, i check all visit in `src/compiler/crystal/codegen/codegen.cr` no `CodeGenVisitor#visit(node : Call)`.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/crystal_lang/original/2X/9/9e92c4eb764ddbdfe4e74b7f175ab0f9689184ff.png)

---

<div class="post-metadata">

**Author:** ![stakach](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/stakach/32/58_2.png) [@stakach](https://forum.crystal-lang.org/u/stakach)\
**Post date:** [October 28, 2022, 3:16pm UTC](https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038/13 "2022-10-28T15:16:03Z")

</div>

Most of the last couple of hours was just compiling LLVM

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/crystal_lang/original/2X/2/2fafe1c104c4787829ad8476b32f41b096427e96.png)

Now it outputs this when I try to compile any crystal code…

```auto
crystal: /llvm-project/llvm/include/llvm/IR/Type.h:389: llvm::Type* llvm::Type::getNonOpaquePointerElementType() const: Assertion `NumContainedTys && "Attempting to get element type of opaque pointer"' failed.
Aborted

```

That’s after building LLVM with:

```auto
cmake -DCMAKE_BUILD_TYPE:STRING=Debug ./llvm
make install

```

---

<div class="post-metadata">

**Author:** ![HertzDevil](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/hertzdevil/32/1023_2.png) [@HertzDevil](https://forum.crystal-lang.org/u/HertzDevil)\
**Post date:** [October 28, 2022, 3:28pm UTC](https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038/14 "2022-10-28T15:28:17Z")

</div>

That error is [expected for LLVM 15](https://releases.llvm.org/15.0.0/docs/OpaquePointers.html#frontends); Crystal doesn’t support that version yet, nor does it use the `LLVMContextSetOpaquePointers` opt-out.

Older LLVM versions shouldn’t be using opaque pointers, though.

---

<div class="post-metadata">

**Author:** ![stakach](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/stakach/32/58_2.png) [@stakach](https://forum.crystal-lang.org/u/stakach)\
**Post date:** [October 28, 2022, 3:29pm UTC](https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038/15 "2022-10-28T15:29:23Z")

</div>

Dang, looks like I’m building LLVM 14 😂

---

<div class="post-metadata">

**Author:** ![zw963](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/zw963/32/1623_2.png) [@zw963](https://forum.crystal-lang.org/u/zw963)\
**Post date:** [October 28, 2022, 3:48pm UTC](https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038/16 "2022-10-28T15:48:41Z")

</div>

I can reproduce the above backtrace use compiler 1.6.1 (built with llvm 14.0.6) and built compiler and app use same env (llvm version)

---

<div class="post-metadata">

**Author:** ![stakach](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/stakach/32/58_2.png) [@stakach](https://forum.crystal-lang.org/u/stakach)\
**Post date:** [October 29, 2022, 12:27am UTC](https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038/17 "2022-10-29T00:27:58Z")

</div>

Now that I have LLVM 14 compiled with Debug enabled, in terms of point 1 @asterite  
I’m seeing this when I try to compile:

```auto
crystal: /llvm-project/llvm/lib/IR/Instructions.cpp:3154: 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.
Aborted

```

part 2

```auto
visit => Emitter.new(@source, severity, exception)
visit => ::String.interpolation("missing edge manager for ", edge_id)
visit => backend.dispatch(dsl.emit(result.to_s))
visit => dsl.emit(result.to_s)
visit => result.to_s
visit => callbacks.try(&.each do |callback|
  manager.debug(module_id, &callback) do |__arg0|
    callback.call(__arg0)
  end
end)
type_id => val: %499 = load %"Array(Proc(String, Nil))"*, %"Array(Proc(String, Nil))"** %callbacks, align 8, !dbg !36, type: (Array(Proc(String, Nil)) | Nil)
visit => %self.try(&.each do |callback|
  manager.debug(module_id, &callback) do |__arg0|
    callback.call(__arg0)
  end
end)
visit => %self.try(&.each do |callback|
  manager.debug(module_id, &callback) do |__arg0|
    callback.call(__arg0)
  end
end)
visit => __arg5.each do |callback|
  manager.debug(module_id, &callback) do |__arg0|
    callback.call(__arg0)
  end
end
visit => each_index do |i|
  yield unsafe_fetch(i)
end
visit => i < size
visit => size
visit => unsafe_fetch(i)
visit => manager.debug(module_id, &callback) do |__arg0|
  callback.call(__arg0)
end
crystal: /home/steve/projects/client-projects/llvm-project/llvm/lib/IR/Instructions.cpp:3154: 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.
Aborted

```

---

<div class="post-metadata">

**Author:** ![caspiano](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/caspiano/32/527_2.png) [@caspiano](https://forum.crystal-lang.org/u/caspiano)\
**Post date:** [November 1, 2022, 1:01pm UTC](https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038/18 "2022-11-01T13:01:24Z")

</div>

~~Looks like this is the culprit from a bisection~~

> <https://github.com/crystal-lang/crystal/commit/f0214245cd2d96b9dc3d92edd95e9d67ed5e2bd5>
>
> \* Extract type\_from\_dependencies
> 
> \* No need for bind's yield to return anythin…g

---

<div class="post-metadata">

**Author:** ![stakach](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/stakach/32/58_2.png) [@stakach](https://forum.crystal-lang.org/u/stakach)\
**Post date:** [November 1, 2022, 1:07pm UTC](https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038/19 "2022-11-01T13:07:49Z")

</div>

although that made it into crystal 1.5.1 and there are no issues with that version

I noticed that most of our services don’t pass specs when running on crystal 1.6.1  
I’m seeing issues like:

```auto
Invalid memory access (signal 11) at address 0x7ffdbf0650b0
[0x55d680829ca6] print_backtrace at /usr/share/crystal/src/exception/call_stack/libunwind.cr:100:5
[0x55d68068c5e6] -> at /usr/share/crystal/src/signal.cr:151:5
[0x7f6062743c9f] ?? +140051945372831 in /lib/ld-musl-x86_64.so.1

```

That occurs running specs using the official crystal lang 1.6.1 image and the 84codes image.  
reverting back to crystal 1.5.1 and everything passes (example above is from our rest-api service)

Although I am probably conflating two separate problems

---

<div class="post-metadata">

**Author:** ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)\
**Post date:** [November 1, 2022, 2:27pm UTC](https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038/20 "2022-11-01T14:27:08Z")

</div>

We could revert that commit and see if that fixes the issue. In the end I did that commit in preparation of something else that I never got to do. So reverting it would be harmless.

[Next page](https://forum.crystal-lang.org/t/compilation-issue-with-crystal-1-6-x/5038.md?page=2)
