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

[stable] Fix issue 20700 - Forward references leads to extern(C++, class|struct) being ignored #10988

Merged
merged 1 commit into from Apr 3, 2020

Conversation

Geod24
Copy link
Member

@Geod24 Geod24 commented Mar 31, 2020

On the long run, it looks like we should just move the setScope to AttribDeclaration,
but this is a simple bugfix to target stable.

Note: This is a WIP for the moment as I can't test on Windows. However, I'd like to be sure the test fails before I make it pass.

@Geod24 Geod24 added Bug Fix WIP Work In Progress - not ready for review or pulling labels Mar 31, 2020
@Geod24 Geod24 requested a review from ibuclaw as a code owner March 31, 2020 03:39
@dlang-bot
Copy link
Contributor

dlang-bot commented Mar 31, 2020

Thanks for your pull request, @Geod24!

Bugzilla references

Auto-close Bugzilla Severity Description
20700 major Forward references leads to `extern(C++, class

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "stable + dmd#10988"

@Geod24 Geod24 changed the base branch from master to stable March 31, 2020 03:45
@Geod24 Geod24 force-pushed the fix-20700 branch 3 times, most recently from d96ee5e to e05468b Compare March 31, 2020 04:59
@Geod24 Geod24 removed the WIP Work In Progress - not ready for review or pulling label Mar 31, 2020
@Geod24 Geod24 force-pushed the fix-20700 branch 2 times, most recently from af6b48e to c533ad1 Compare April 2, 2020 11:08
src/dmd/mtype.h Outdated Show resolved Hide resolved
@Geod24 Geod24 added the WIP Work In Progress - not ready for review or pulling label Apr 2, 2020
@Geod24
Copy link
Member Author

Geod24 commented Apr 2, 2020

Found out the issue is harder than expected so back tip WIP

@Geod24 Geod24 force-pushed the fix-20700 branch 5 times, most recently from 23ad49c to 350ee80 Compare April 3, 2020 01:27
@Geod24 Geod24 removed the WIP Work In Progress - not ready for review or pulling label Apr 3, 2020
src/dmd/cppmanglewin.d Outdated Show resolved Hide resolved
buf.writeByte('T');
else
buf.writeByte(type.cppmangle == CPPMANGLE.asClass ? 'V' : 'U');
mangleIdent(type.sym);
buf.writeByte(agg.cppmangle == CPPMANGLE.asClass ? 'V' : 'U');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.cppmangle is a field in AggregateDeclaration, but the only use of agg is to get that field. Shouldn't agg be an AggregateDeclaration, not a StructDeclaration ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be, but since we are in visit(TypeStruct), we know that it's a StructDeclaration already, and I thought it'd be less confusing.

src/dmd/cppmanglewin.d Outdated Show resolved Hide resolved
@Geod24 Geod24 force-pushed the fix-20700 branch 2 times, most recently from bc3fdfe to 4f4b97c Compare April 3, 2020 04:51
@@ -82,6 +82,10 @@ extern (C++) abstract class AggregateDeclaration : ScopeDsymbol

/// specifies whether this is a D, C++, Objective-C or anonymous struct/class/interface
ClassKind classKind;
/// Specify whether to mangle the aggregate as a `class` or a `struct`
/// This information is used by the MSVC mangler
/// Only valid for class and struct. TODO: Merge with ClassKind ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It looks like it should be merged with classKind.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not doing it here just because this targets stable

…gnored

`Type`-derived AST nodes do not support the same kind of semantic analysis that
`Dsymbol`-derived one do. The issue was that in some codes, semantic analysis on
the type was performed before it was performed on the declaration,
and chasing those cases turned out to be endless, hence the minor refactoring.
extern(C++, class) struct TStruct20700_1 (T1, T2 = DefaultStruct20700_1) {}
extern(C++, class) struct DefaultStruct20700_1 {}
extern(C++, struct) class DefaultClass20700_1 {}
static assert(test20700_3.mangleof == `?test20700_3@@YAXV?$TStruct20700_1@PEAUDefaultClass20700_1@@VDefaultStruct20700_1@@@@@Z`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is demangled by UnDecorateSymbolName to
void __cdecl test20700_3(class TStruct20700_1<struct DefaultClass20700_1 * __ptr64,class DefaultStruct20700_1>)
so it seems class and struct are swapped.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry for the noise, I somehow missed that you explicitly changed the mangling.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DefaultStruct is a D struct but mangled as a class. DefaultClass is a D class but mangled as a struct (well, a pointer to struct). Same for TStruct..., it's a D struct, but mangled as class.

@Geod24
Copy link
Member Author

Geod24 commented Apr 3, 2020

Ready to go (@thewilsonator )

@dlang-bot dlang-bot merged commit 4a39506 into dlang:stable Apr 3, 2020
@Geod24 Geod24 deleted the fix-20700 branch April 3, 2020 07:10
kinke added a commit to kinke/dmd that referenced this pull request Apr 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants