Antiro42
Antiro42

Reputation: 187

how to debug a clang C++ compiler bug? (clang frontend command failed with exit code 139)

I'm repeatedly running into clang 12.0.1 compiler bugs when trying to integrate a rather complex library using c++20 features in an existing code base. The library itself has thorough unit tests which compile correctly and I'm having problems recreating the bug in any reasonably small example. It seems that it only triggers when a lot of different elements come together. As the library is replacing one the core building blocks in the codebase it is hard to gradually integrate it and see when the error starts to happen.

Note that the integrated version of the code does compile correctly in gcc 11.2 so it seems to be valid c++.

For various (legal) reasons I am not able to just upload the preprocessed code and logs in a bug report so I would like to to 1) find a workaround so I can continue my work and preferably also 2) understand the bug so I can recreate it in smaller example which I can submit to the clang developers.

Are there any ways to narrow down the piece of code that is triggering this bug? or otherwise getting more information from clang? The preprocessed sources which are suggested to put bug reports are huge.

For context: I'm running into the type where you get a huge stacktrace from clang's internals (which I have a hard time interpreting as I'm not a clang developer) followed by the "Clang frontend command failed" message as shown in the screenshot below: clang frontend bug

Upvotes: 0

Views: 1656

Answers (1)

David Grayson
David Grayson

Reputation: 87486

I suggest getting the preprocessed source code that triggers the error (i.e. a single C++ file without #include or any other preprocessor statement), along with the corresponding command line for clang that attempts to compile the source code. Then you can simplify both the source code and the command line one step at a time, while still making sure the same error gets triggered, until it is something very small that does not contain any resemblance to the original legally-protected source code. This simplified code and command line would then be suitable for a bug report to the Clang developers.

There is a tool called C-Reduce that might help you speed up this process, but I have not personally used it and I am not sure if your use of advanced C++ features might cause problems with it.

If you are simplifying the file manually, I recommend starting at the bottom of it, where you are more likely to find lots of function and variable definitions that are not used anywhere else in the file. There is probably just one function in the file triggering the bug, so you can remove any unused functions that do not trigger it. When you find the function or variable definition that triggers the bug, you can simplify it as much as possible, and then remove any definitions that are not used by it.

Upvotes: 3

Related Questions