Skip to content

Fix GEP-from-GEP merge across struct boundary - #1699

Open
carbotaniuman wants to merge 2 commits into
google:mainfrom
carbotaniuman:fix-gep-from-gep-struct-array
Open

carbotaniuman wants to merge 2 commits into
google:mainfrom
carbotaniuman:fix-gep-from-gep-struct-array

Conversation

@carbotaniuman

Copy link
Copy Markdown

runOnGEPFromGEP folds a constant GEP into a preceding GEP, but this merged GEP may be outside the bounds of the struct, leading to issues.

This is reachable from OpenCL C.

typedef struct { ushort x, y; } P;
kernel void k(global P *out, ushort y, uint i) {
P pts[2];
pts[0].y = y;
out[0] = pts[i];
}

@google-cla

google-cla Bot commented Oct 23, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@carbotaniuman
carbotaniuman force-pushed the fix-gep-from-gep-struct-array branch from d247304 to dfc04d9 Compare October 23, 2026 03:12
runOnGEPFromGEP folds a constant GEP into a preceding GEP, but this
merged GEP may be outside the bounds of the struct, leading to issues.

This is reachable from OpenCL C.

  typedef struct { ushort x, y; } P;
  kernel void k(global P *out, ushort y, uint i) {
    P pts[2];
    pts[0].y = y;
    out[0] = pts[i];
  }
@carbotaniuman
carbotaniuman force-pushed the fix-gep-from-gep-struct-array branch from dfc04d9 to 43690b3 Compare October 23, 2026 04:58

@rjodinchr rjodinchr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for catching and fixing this issue! The fix and tests look good overall; I just left two suggestions to reuse existing helpers.

Comment thread lib/SimplifyPointerBitcastPass.cpp
Comment thread lib/SimplifyPointerBitcastPass.cpp
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