illegal hardware instruction on macos 10.15.3
Closed this issue · 11 comments
When I finished compiling the compiler,and wanted to run it,it gave me a SIGILL like this:
Hello World!
zsh: illegal hardware instruction ./pinecone examples/hello_world.pn
Why does it happen?
I don't have any sort of Mac box available and I'm not maintaining this anymore, so I can't help too much. If you run it in GDB you should be able to see where it crashes, and that might help you debug the problem. Make a debug build by replacing -O2
with -g
in the Makefile and rebuilding. Then run gdb --ex r --args ./pinecone examples/hello_world.pn
to run it in GDB. If it still hits the error, type bt
to get a stack trace (top most function is the one it crashed in). Hope that helps.
I replace -O2
with -O1
and -g
but it still occurred. It seems gdb cannot run on my computer , so I use lldb to debug it.
It outputs these:
Hello World!
Process 35703 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
frame #0: 0x000000010001a8b8 pinecone`AstNodeBase::~AstNodeBase(this=0x0000000100f00500) at AstNode.h:18:7
15
16 AstNode astNodeFromTokens(const vector<Token>& tokens, int left, int right);
17
-> 18 class AstNodeBase
19 {
20 public:
21
Target 0: (pinecone) stopped.
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
* frame #0: 0x000000010001a8b8 pinecone`AstNodeBase::~AstNodeBase(this=0x0000000100f00500) at AstNode.h:18:7
frame #1: 0x000000010019aaab pinecone`std::__1::default_delete<AstNodeBase>::operator(this=0x00007ffeefbff4e8, __ptr=0x0000000100f00500)(AstNodeBase*) const at memory:2338:5
frame #2: 0x000000010019aa2f pinecone`std::__1::unique_ptr<AstNodeBase, std::__1::default_delete<AstNodeBase> >::reset(this=0x00007ffeefbff4e8, __p=0x0000000000000000) at memory:2651:7
frame #3: 0x000000010019a9c9 pinecone`std::__1::unique_ptr<AstNodeBase, std::__1::default_delete<AstNodeBase> >::~unique_ptr(this=0x00007ffeefbff4e8) at memory:2605:19
frame #4: 0x000000010019a3d5 pinecone`std::__1::unique_ptr<AstNodeBase, std::__1::default_delete<AstNodeBase> >::~unique_ptr(this=0x00007ffeefbff4e8) at memory:2605:17
frame #5: 0x000000010019a2eb pinecone`PineconeProgram::~PineconeProgram(this=0x00007ffeefbff4c0) at PineconeProgram.h:36:32
frame #6: 0x0000000100199fd5 pinecone`PineconeProgram::~PineconeProgram(this=0x00007ffeefbff4c0) at PineconeProgram.h:36:21
frame #7: 0x000000010019972a pinecone`main(argc=2, argv=0x00007ffeefbff608) at main.cpp:167:1
frame #8: 0x00007fff648727fd libdyld.dylib`start + 1
frame #9: 0x00007fff648727fd libdyld.dylib`start + 1
Sorry for the bad typography...
Seems the problem is in h/AstNode.h and h/PineconeProgram.h. How can I fix it?
Tip: much easier to read once you wrap the output in triple back-tics (```)
Perhaps try replacing g++
with clang
in the Makefile (and install Clang if needed)?
I have no idea what the problem is. All I can think of is a double-free, but since it looks like I consistently used smart pointers, I'm not sure where that could have happened. Feel free to report back if you figure it out.
Perhaps try replacing
g++
withclang
in the Makefile (and install Clang if needed)?
Actually I'm just using clang++... Maybe I should replace it with g++...
P.S. I use Homebrew to install g++ , so it names g++-9
on my computer...
Tip: much easier to read once you wrap the output in triple back-tics (```)
It seems great!
Thanks very much for your tips! I'll try them.
I replace g++
with g++-9
and it works properly!
Perhaps I need to report an issue to the LLVM project. :)
P.S.There are lots of warnings when I compile it with clang++ but there is not even A warning when I compile it with g++......
Almost certainly Pinecone doing something undefined and not a Clang/LLVM bug (since it's undefined behavior, GCC is free to make it work and Clang is free to crash). If this was a project I still cared about or Mac was a platform I was more interested in I would dig in to see what was going on. As it is I can't be bothered. Glad you got it working
Oh! compiling with Clang on Linux completely fails, and I see all the warnings you're talking about. I'm now almost positive the crash is caused by the good ol' non-virtual destructor problem. Sticking
virtual ~AstNodeBase() {}
in the AstNodeBase
class will probably fix it (there may also be similar errors with similar solutions). I'm not going to push to this repo because I don't want to look like I'm working on it, but if someone sends in a PR I would merge it.