Skip to content

Fix #5114 - Avoid same-symbol qualifier-difference case falling into DtoCastClass#5117

Open
gulugulubing wants to merge 3 commits intoldc-developers:masterfrom
gulugulubing:issue5114
Open

Fix #5114 - Avoid same-symbol qualifier-difference case falling into DtoCastClass#5117
gulugulubing wants to merge 3 commits intoldc-developers:masterfrom
gulugulubing:issue5114

Conversation

@gulugulubing
Copy link
Copy Markdown
Contributor

@gulugulubing gulugulubing commented Apr 20, 2026

It is related to #5114. The root cause is the const(I) -> I contract-context conversion always called DtoCastClass, then due to I.isBaseOf(I, ...) return false, the program accidently fall into the DtoDynamicCastInterface which is ObjC-only and ends in unreachable for non-ObjC.

So I added an early guard for same-symbol qualifier-difference case there.

The patch is only in tocall.cpp, while objcgen.cpp and classes.cpp are modified just because of removing trailing blank.

Copy link
Copy Markdown
Contributor

@thewilsonator thewilsonator left a comment

Choose a reason for hiding this comment

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

please remove the whitespace changes

Comment thread gen/tocall.cpp Outdated
@gulugulubing
Copy link
Copy Markdown
Contributor Author

please remove the whitespace changes

OK, is it accpetable:
For files with actual content changes, I kept the trailing whitespace cleanup (since we're already modifying these files)
For files with only whitespace changes, I reverted them completely to avoid unnecessary diffs.

Comment thread gen/tocall.cpp
thisptrLval = DtoAllocaDump(DtoCastClass(loc, dthis, iface->type));
auto thisVal = DtoLoad(DtoType(thistype), thisptrLval);
DImValue dthis(thistype, thisVal);
thisptrLval = DtoAllocaDump(DtoCastClass(loc, &dthis, iface->type));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks like no change was made here, except for the dangerous-looking change from heap allocated dthis to stack allocated. Possibly use-after-scope. Revert this change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Does the original heap allocated dthis cause potential leak-like lifetime?

Comment thread tests/codegen/gh5114.d
// True dynamic interface casts (different interface symbols) are still valid
// and are covered below.
//
// RUN: %ldc -c %s
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nitpick: line 11 already tests compilation, so you can remove line 10

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

Successfully merging this pull request may close these issues.

4 participants