Skip to content

fix: do correct indexing of padding fields - #1387

Merged
nunoplopes merged 2 commits into
AliveToolkit:masterfrom
regehr:regehr/padding-fix
Nov 14, 2026
Merged

nunoplopes merged 2 commits into
AliveToolkit:masterfrom
regehr:regehr/padding-fix

Conversation

@regehr

@regehr regehr commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

there's nothing wrong with the 2 new test cases here, but without this PR, running alive-tv on them gives: ERROR: program doesn't type check!

@regehr

regehr commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

I think this is completely independent of #1386

@regehr

regehr commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

ah, I ran into the typecheck error first so that's what I reported, but this bug like the previous PR is an unsoundness bug. adding a test case about that now (which covers arrays, which I should have added tests about in the first place).

Comment thread ir/type.cpp
return i;
++seen;
}
UNREACHABLE();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think this is UB for an out-of-bounds idx. Also I think the logic could be simplified. Maybe something like

unsigned AggregateType::paddedIndex(unsigned idx) const {
  assert(idx < elements - numPaddingsConst());
  for (unsigned i = 0; ; ++i) {
    if (!is_padding[i] && idx-- == 0)
      return i;
  }
}

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.

in alive2 UNREACHABLE() becomes __builtin_unreachable() which turns into a trap, so the effect would be the same, assuming your assert and my UNREACHABLE() are equisatisfiable

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

From clang docs:

The __builtin_unreachable() builtin has completely undefined behavior.

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.

yes of course. but it turns into a trap in practice.

@nunoplopes
nunoplopes merged commit 69e214a into AliveToolkit:master Nov 14, 2026
16 checks passed
@regehr
regehr deleted the regehr/padding-fix branch November 15, 2026 04:03
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.

3 participants