terralang / terra

Terra is a low-level system programming language that is embedded in and meta-programmed by the Lua programming language.
terralang.org
Other
2.71k stars 197 forks source link

hello.t and a few other tests broken on llvm15 #646

Open 7v0lk0v opened 10 months ago

7v0lk0v commented 10 months ago
bash-5.2$ ~/net/terra/bin/terra hello.t
terra: /llvm/include/llvm/Support/ErrorOr.h:237: llvm::ErrorOr<T>::storage_type* llvm::ErrorOr<T>::getStorage() [with T = std::__cxx11::basic_string<char>; llvm::ErrorOr<T>::storage_type = std::__cxx11::basic_string<char>]: Assertion `!HasError && "Cannot get value when an error exists!"' failed.
Aborted

This is using the pre-built downloaded binary and tests.

I had a total of 12 (including this one) seemingly simple tests fail but strangely the rest passed.

Another odd thing I found is different behaviour between running using terra and the simple.cpp example (which I was able to compile and run but it dies with the same error as above, as well as the next example):

Running the following shows the different behaviour:

local c = terralib.includec("stdio.h")

terra hello()
    c.printf("hello, world\n")
end

print'a'
hello()
print'b'
bash-5.2$ ./simple hello.t
a
bash-5.2$ echo $?
1

bash-5.2$ ~/net/terra/bin/terra hello.t
a
hello, world
b
bash-5.2$ echo $?
0

System:

bash-5.2$ clang++ --version
clang version 15.0.7
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

bash-5.2$ uname -a
Linux 6.4.16-0-generic #1 SMP PREEMPT_DYNAMIC Wed Sep 13 22:59:43 UTC 2023 x86_64 GNU/Linux

Not sure what other info I can provide, but happy to help.

elliottslaughter commented 10 months ago

To be clear, is this using a Terra pre-built binary, or an LLVM pre-built binary? Can you link the specific binary you used?

What distro and version is this?

7v0lk0v commented 10 months ago

Sorry for muddling things a bit. Yes, this is using the pre-built binary: terra-Linux-x86_64-094c5ad

And I should've mentioned this, I'm running via a voidlinux chroot: void-x86_64-ROOTFS-20230628 not the musl version, just regular glibc (I'm running on a musl system, hence the chroot).

elliottslaughter commented 10 months ago

The official Terra binaries are compiled on Ubuntu 18.04. Cross-distro usage is always a bit screwy. Sometimes it works (e.g., I've tested Ubuntu -> RHEL), but it's not hard to see it blowing up on you.

If you have working LLVM/Clang binaries you may be able to build Terra yourself. On Ubuntu, you'd need something like:

sudo apt-get install llvm-15-dev libclang-15-dev clang-15 libmlir-15-dev libedit-dev libncurses5-dev zlib1g-dev libpfm4-dev

The exact set of dependencies depends on how LLVM is packaged. LLVM can be built without any external dependencies, but the Debian/Ubuntu packagers choose to include some (as noted above).

You may need to fiddle with CMAKE_PREFIX_PATH to tell it where LLVM is installed.

Alternatively, if the packaged LLVM doesn't work for you, there's a build recipe here that is guarranteed to work with Terra, but will take a while to build (depending on how beefy your machine is):

https://github.com/terralang/terra/tree/master#instructions-for-building-llvm-from-source

Good luck!

7v0lk0v commented 10 months ago

Fair enough, might try an ubuntu chroot first then. Thanks.