-
-
Notifications
You must be signed in to change notification settings - Fork 609
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
Fix issue 19949 - C++ Mangling: add support for abi-tags from the Itanium ABI #9995
Conversation
a661c7d to
ea0d336
Compare
src/dmd/dsymbolsem.d
Outdated
| attribSemantic(uad); | ||
| if (uad.atts) | ||
| { | ||
| // detect the special attribute @__gnu_abi_tag(...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a magic name. I would prefer to implement this as a true UDA which can use the fully qualified name to resolve any conflicts. This would avoid the need for the ugly double underscore prefix. You can have a look at how the @selector attribute is implemented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take a look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is a better approach. I switched to it. I didn't make it part of druntime yet though.
I also ended up making an exception for namespaces from the UDA inheritance rules to stop members from inheriting this special UDA from namespaces, this is how it behaves in C++.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the core.attribute addition dlang/druntime#2639. Once it gets in I'll activate the module checks.
src/dmd/cppmangle.d
Outdated
| @@ -150,18 +150,21 @@ private final class CppMangleVisitor : Visitor | |||
| Objects components; // array of components available for substitution | |||
| OutBuffer* buf; // append the mangling to buf[] | |||
| Loc loc; // location for use in error messages | |||
| Strings* abiTags; // record of the processed abi-tags | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use D arrays?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DMD arrays mange their own memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SSoulaimane DMD is a mechanical translation from a C++ code base so it contains a lot of code that is not considered idiomatic D. Please prefer modern idiomatic D types and patterns (unless explicitly asked not to) for any new code so we can gradually transition DMD away from the cruft of the past.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use Ddoc comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The array is being filled by the visitor, I'm not sure that using D arrays is an improvement here because they rely on the GC. As I understand DMD is moving away from the GC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand DMD is moving away from the GC.
No, not that I've heard of. Also, D arrays can be allocated using other means than the GC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, not that I've heard of.
I thought using mem.xmalloc and mem.xfree was supposed to make DMD more responsible about memory.
Also, D arrays can be allocated using other means than the GC.
How do you append to it.
The array fed to the visitor is stack allocated hence automatically freed.
|
Why is this targeting stable rather than master? |
|
This is a very large PR. Please factor out isPosix into a separate one. |
It just happened that way because it was based on #9946. I'll change that before it's merged. |
Rebased |
2b44e5a to
70037d0
Compare
| } | ||
| if (e.op == TOK.type) | ||
| { | ||
| e.error("`@%s` at least one argument expected", Id.udaGNUAbiTag.toChars()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this be handled automatically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that is the case where the UDA is a type i.e. @type instead of @type().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I would expect the compiler to complain if the UDA is a function expecting one argument. But that seems to not be the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's useful to have.
4e4d22f to
a2af683
Compare
|
Because of the use of ancient C++ compilers in some the CIs, I will remove the runnable tests and stick to manual checks of the mangling with compilable tests instead. It has been demonstrated that it works at least. |
|
Thanks for your pull request and interest in making D better, @SSoulaimane! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + dmd#9995" |
| */ | ||
| this(OutBuffer* buf, Loc loc) | ||
| this(OutBuffer* buf, Loc loc, Strings* abiTags = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know Walter doesn’t like default values for parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's something with being less readable, but you'll have to ask him.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, pick your poison. Either this or an overload. Everything has a purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer a default value, but it’s not my decision.
It’s also possible to explicitly pass in the default value.
|
Any chance to get a runnable test with this ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And also, extern(C++, "namespace") is preferred (and code path are quite different).
You can either tests both or test only the string version (I'll have a deprecation PR for the non-string version up soon).
1e58f7c. I deleted them because semaphore and OSX on the auto-tester have ancient c++ compilers. |
Could easily disable it on OSX. Semaphore you'll need to read the environment variable I suppose. |
To do what? |
|
Disable it |
d9d43f7 to
cca05a0
Compare
39bb395 to
f3703cb
Compare
Uses a bash test to get version information about the host C++ compiler.
|
The replacement PR has been merged. Thanks for getting us started on this, your work was a great help. |
Implements "abi-tags" from the Itanium ABI specification.
https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangle.abi-tag.
By introducing a special compile time attribute
@__gnu_abi_tag().This is crucial in order to interface
std::stringandstd::liston linux.See: issue 14956 (comment 13).