Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad align argument on store instr for struct parameter #3692

Closed
tjhann opened this issue Apr 3, 2021 · 1 comment · Fixed by #3698
Closed

Bad align argument on store instr for struct parameter #3692

tjhann opened this issue Apr 3, 2021 · 1 comment · Fixed by #3698

Comments

@tjhann
Copy link

tjhann commented Apr 3, 2021

LDC emits IR where a store with alignment of 8 writes to an alloca with alignment of 4. Overestimating the alignment causes undefined behaviour [0]. I tried with LDC 1.25.1 and LDC 1.24.0 on Ubuntu 20.04.2 LTS / x86-64 (Xubuntu, actually).
[0] https://llvm.org/docs/LangRef.html#id212

For this:

struct Box {
    int a;
    int b;
    int c;
}

void takebox(Box box) { }

void main()
{
    Box box;
    takebox(box);
}

I'm getting this code:

define void @_D3bug7takeboxFSQo3BoxZv({ i64, i32 } %box_arg) #0 {
  %.BaseBitcastABIRewrite_param_storage = alloca { i64, i32 }, align 4 ; [#uses = 2, size/byte = 16]
  store { i64, i32 } %box_arg, { i64, i32 }* %.BaseBitcastABIRewrite_param_storage, align 8 ; <-- BAD ALIGNMENT!
  %box = bitcast { i64, i32 }* %.BaseBitcastABIRewrite_param_storage to %bug.Box* ; [#uses = 0]
  ret void
}
kinke added a commit to kinke/ldc that referenced this issue Apr 11, 2021
As the alignment of the final LL type may be greater than the
rewritten value's. Fixes ldc-developers#3692.
kinke added a commit to kinke/ldc that referenced this issue Apr 11, 2021
As the alignment of the final LL type may be greater than the
rewritten value's. Fixes ldc-developers#3692.
kinke added a commit that referenced this issue Apr 17, 2021
As the alignment of the final LL type may be greater than the
rewritten value's. Fixes #3692.
@kinke
Copy link
Member

kinke commented Apr 17, 2021

Thx for reporting.

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 a pull request may close this issue.

2 participants