-
-
Notifications
You must be signed in to change notification settings - Fork 613
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
Lower _d_arraycast to object.__ArrayCast #8531
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -421,6 +421,8 @@ immutable Msgtable[] msgtable = | |
{ "FALSE" }, | ||
{ "unsigned" }, | ||
{ "wchar_t" }, | ||
|
||
{ "__ArrayCast"} | ||
]; | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* REQUIRED_ARGS: -betterC | ||
PERMUTE_ARGS: | ||
*/ | ||
|
||
// test call to `object.__ArrayCast` | ||
|
||
import core.stdc.stdlib; | ||
import core.stdc.stdio; | ||
import core.stdc.string; | ||
|
||
extern(C) void __assert(const char *msg, const char *file, int line) | ||
{ | ||
if (strcmp(msg, "array cast misalignment") != 0) | ||
{ | ||
fprintf(stderr, "Assertion failure message is not correct\n"); | ||
exit(1); | ||
} | ||
} | ||
|
||
extern(C) void main() | ||
{ | ||
byte[] b; | ||
long[] l; | ||
|
||
// We can't actually create dynamic arrays in idiomatic D when | ||
// compiling with -betterC, so we do it manually. | ||
auto b_length = cast(size_t*)&b; | ||
auto b_ptr = cast(void*)(b_length + 1); | ||
*b_length = int.sizeof * 3; | ||
b_ptr = malloc(*b_length); | ||
|
||
// size mismatch, should result in an assertion failure | ||
l = cast(long[])b; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
How can I fully qualify this to
object.__ArrayCast
?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.
Look at how the comparison lowering is done to
__cmp
.dmd/src/dmd/expressionsem.d
Lines 9794 to 9798 in 03e7693
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.
But I need an
Identifer
, not anExpression
, for theTemplateInstance
, later. How do I create a fully-qualifiedIdentifier
?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 don't think that is possible. To get the fully qualified name inside the compiler one needs to walk up the parent chain and build up the name that way. In your case, I think you need to use the overload of the
TemplateInstance
constructor that takes aTemplateDeclaration
. Perhaps you can store theTemplateDeclaration
when it's analyzed in the same way as theObject
class declaration (and others) is stored:dmd/src/dmd/dclass.d
Lines 367 to 372 in 03e7693