Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on spaceship operator #1891

Open
duckdoom5 opened this issue Jan 21, 2025 · 14 comments
Open

Crash on spaceship operator #1891

duckdoom5 opened this issue Jan 21, 2025 · 14 comments

Comments

@duckdoom5
Copy link
Contributor

I just installed this nuget package so I'm not very familiar with this tool yet. It seems the converter for the spaceship operator is not implemented. I get the following debug crash if I try to parse a file that has the spaceship operator.

Image

If I was more familiar I'd try to fix it myself, but I don't feel comfortable enough to do so yet. In the meantime, is there a way to pre-process this file to convert this operator implementation into the equivalent <, <=, ==, >=, > operator pairs?

@tritao
Copy link
Collaborator

tritao commented Jan 21, 2025

You could try compiling from source and adding spaceship operator starting here: https://github.com/mono/CppSharp/blob/main/src/Parser/ASTConverter.cs#L1367

Otherwise probably easier to just rewrite the input C++ code, as annoying as it is.

@duckdoom5
Copy link
Contributor Author

Sure, I'll give it a go. Thanks for the quick reply :)

@duckdoom5
Copy link
Contributor Author

duckdoom5 commented Jan 21, 2025

You could try compiling from source and adding spaceship operator starting here: https://github.com/mono/CppSharp/blob/main/src/Parser/ASTConverter.cs#L1367

Otherwise probably easier to just rewrite the input C++ code, as annoying as it is.

So I managed to get it to build in c++20 debug mode (with some edits that I'll make a PR for soon) so I can see if my changes actually work, but I'm running into the following error:

10>------ Rebuild All started: Project: Encodings.Gen, Configuration: Debug x64 ------
10>Encodings.Gen -> CppSharp\bin\Debug\Encodings.Gen.dll
10>
10>Generating bindings for Encodings (CSharp)
10>Assert at CppSharp\src\CppParser\Parser.cpp:963 in GetCXXRecordDeclFromBaseType failed. Could not get base CXX record from type. Unhandled type: Filename C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include\xmemory:1486

I'll continue investigating tomorrow, but if you have any idea what might cause this missing record or if you see something I did incorrectly let me know

@tritao
Copy link
Collaborator

tritao commented Jan 21, 2025

That seems to be some new kind of C++ type we cannot handle yet:

assertml(0, "Could not get base CXX record from type. Unhandled type: ", context.getSourceManager(), base.getBeginLoc());

Can you share the lines around C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include\xmemory:1486?

You can also try calling dump() on the Clang type, see: https://clang.llvm.org/doxygen/classclang_1_1Type.html#a90c89709fd5e5e1d96455aec8b0c3916

@duckdoom5
Copy link
Contributor Author

This is the code at the specified line:

Image

@tritao
Copy link
Collaborator

tritao commented Jan 21, 2025

Some kind of templated type, can you dump the type? Think that should tell us what we need to know.

@duckdoom5
Copy link
Contributor Author

duckdoom5 commented Jan 21, 2025

The dump output is:

 1>TemplateTypeParmType 0x24e820a7b70 '_Ty1' dependent depth 0 index 0
 1>`-TemplateTypeParm 0x24e820a7b20 '_Ty1'

@tritao
Copy link
Collaborator

tritao commented Jan 21, 2025

What's the call stack when the assert hits?

@tritao
Copy link
Collaborator

tritao commented Jan 21, 2025

And you can try something like:

    else if (auto TPT = Ty->getAs<clang::TemplateTypeParmType>())
        return nullptr;

@duckdoom5
Copy link
Contributor Author

duckdoom5 commented Jan 21, 2025

Not sure how to debug the c++ bit atm.

It came up as a part of building another project:

1>------ Build started: Project: Common.Gen, Configuration: Debug x64 ------
1>Skipping analyzers to speed up the build. You can execute 'Build' or 'Rebuild' command to run analyzers.
1>Common.Gen -> C:\SSD_WorkProjects\CppSharp\bin\Debug\Common.Gen.dll
1>
1>Generating bindings for Common (CLI)
1>TemplateTypeParmType 0x24e820a7b70 '_Ty1' dependent depth 0 index 0
1>`-TemplateTypeParm 0x24e820a7b20 '_Ty1'
1>Assert at C:\SSD_WorkProjects\CppSharp\src\CppParser\Parser.cpp:964 in GetCXXRecordDeclFromBaseTypefailed. Could not get base CXX record from type. Unhandled type:  Filename C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include\xmemory:1486

Edit: return nullptr seems to work so far

@duckdoom5
Copy link
Contributor Author

Ah, now a new error appeared.

10>Assert at `CppSharp\src\CppParser\Parser.cpp:2768`` in CppSharp::CppParser::Parser::WalkType` failed. Dependent template only accepted! Filename `C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include\xstring:532`
10>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(5933,5): error MSB3073: The command ""C:\Program Files\dotnet\dotnet.exe" "C:\SSD_WorkProjects\CppSharp\bin\Debug\Common.Gen.dll"" exited with code 3.

Which is around this source:

Image

Anyway, thanks for the help so far. I'm gonna take the rest of the night off though, I'll be back tomorrow to continue trying to get this working :p

@duckdoom5
Copy link
Contributor Author

duckdoom5 commented Jan 22, 2025

You could try compiling from source and adding spaceship operator starting here: https://github.com/mono/CppSharp/blob/main/src/Parser/ASTConverter.cs#L1367
Otherwise probably easier to just rewrite the input C++ code, as annoying as it is.

So I managed to get it to build in c++20 debug mode (with some edits that I'll make a PR for soon) so I can see if my changes actually work, but I'm running into the following error:

10>------ Rebuild All started: Project: Encodings.Gen, Configuration: Debug x64 ------ 10>Encodings.Gen -> CppSharp\bin\Debug\Encodings.Gen.dll 10> 10>Generating bindings for Encodings (CSharp) 10>Assert at CppSharp\src\CppParser\Parser.cpp:963 in GetCXXRecordDeclFromBaseType failed. Could not get base CXX record from type. Unhandled type: Filename C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include\xmemory:1486

I'll continue investigating tomorrow, but if you have any idea what might cause this missing record or if you see something I did incorrectly let me know

Okay, made a PR for those compiler error fixes #1892

@duckdoom5
Copy link
Contributor Author

@tritao
Okay, made some progress again. I'm now able to debug the c++ code, so that makes it a lot easier to see what's going on.

Got a quick question for you though. Does the shipped version of llvm already support c++20 ?
I'm getting syntax errors, so I was wondering if the version needs to be updated of if I need to change some other setting somewhere.

(Though I think I might know already. I guess I need to change the C# hardcoded config in the test projects somewhere)

@tritao
Copy link
Collaborator

tritao commented Jan 22, 2025

@tritao Okay, made some progress again. I'm now able to debug the c++ code, so that makes it a lot easier to see what's going on.

Got a quick question for you though. Does the shipped version of llvm already support c++20 ? I'm getting syntax errors, so I was wondering if the version needs to be updated of if I need to change some other setting somewhere.

(Though I think I might know already. I guess I need to change the C# hardcoded config in the test projects somewhere)

Nice.

It should support C++20, you probably need to enable it in the parser options around here:
https://github.com/mono/CppSharp/blob/main/src/Generator.Tests/GeneratorTest.cs#L23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants