Sitelet https://github.com/ispc/ispc/pull/3780
Skip to content

Fix #284: Resolve forward-declared struct types in member expressions - #3780

Open
nurmukhametov wants to merge 1 commit into
ispc:mainfrom
nurmukhametov:fix-284
Open

nurmukhametov wants to merge 1 commit into
ispc:mainfrom
nurmukhametov:fix-284

Conversation

@nurmukhametov

Copy link
Copy Markdown
Collaborator

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

  • Code has been formatted with clang-format (e.g., clang-format -i src/ispc.cpp)
  • Git history has been squashed to meaningful commits (one commit per logical change)
  • Compiler changes are covered by lit tests

…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>
@dbabokin

dbabokin commented Apr 6, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread src/expr.cpp
Comment on lines +5959 to +5962
const StructType *resolved = lResolveUndefinedStructType(ust);
if (resolved != nullptr) {
exprType = resolved;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

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.

incorrect error with forward declaration of struct member

2 participants