Fix #284: Resolve forward-declared struct types in member expressions - #3780
nurmukhametov wants to merge 1 commit into
Conversation
…ions When a struct is forward-declared, used as a pointer member in another struct, and then fully defined, member access through the pointer incorrectly errored with "declared but not defined struct type". This happened because the PointerType cached UndefinedStructType as its base type and never re-resolved it after the full definition. Add lResolveUndefinedStructType() helper that looks up UndefinedStructType in the symbol table to find the fully defined StructType, preserving variability and constness. Apply this resolution at three points in MemberExpr creation and struct type resolution. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 98397c5f6e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const StructType *resolved = lResolveUndefinedStructType(ust); | ||
| if (resolved != nullptr) { | ||
| exprType = resolved; | ||
| } |
There was a problem hiding this comment.
Preserve pointer misuse check after type resolution
After resolving an UndefinedStructType pointer base to exprType, the code leaves pointerType unchanged, so the subsequent .-on-pointer guard still inspects the stale unresolved base and can be skipped. This allows invalid p.member access on forward-declared struct pointers (where p is a pointer) to proceed as a StructMemberExpr instead of emitting the expected use "->" diagnostic, and it can later trip assertions when getStructType() cannot derive a struct from the pointer lvalue path.
Useful? React with 👍 / 👎.
Description
When a struct is forward-declared, used as a pointer member in another struct, and then fully defined, member access through the pointer incorrectly errored with "declared but not defined struct type". This happened because the PointerType cached UndefinedStructType as its base type and never re-resolved it after the full definition.
Add lResolveUndefinedStructType() helper that looks up UndefinedStructType in the symbol table to find the fully defined StructType, preserving variability and constness. Apply this resolution at three points in MemberExpr creation and struct type resolution.
Related Issue
Checklist
clang-format(e.g.,clang-format -i src/ispc.cpp)