Skip to content

compiler: avoid zero-sized alloca in channel operations #2100

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

Merged
merged 1 commit into from
Sep 9, 2021

Conversation

aykevl
Copy link
Member

@aykevl aykevl commented Sep 8, 2021

This works around a bug in LLVM (https://bugs.llvm.org/show_bug.cgi?id=49916) but seems like a good change in general.

Fixes #2041.

@dgryski
Copy link
Member

dgryski commented Sep 8, 2021

Are there any other places that zero-byte structs will be affected with a similar problem?

@deadprogram
Copy link
Member

This works around a bug in LLVM
(https://bugs.llvm.org/show_bug.cgi?id=49916) but seems like a good
change in general.
@aykevl aykevl force-pushed the fix-zero-channel-alloca branch from 48fc9cc to 9e6ed9a Compare September 8, 2021 19:48
@aykevl
Copy link
Member Author

aykevl commented Sep 8, 2021

@aykevl not sure if you noticed that all of the CI builds are failing

Oops, yeah I just read the message from CircleCI. It should e fixed now.

@aykevl
Copy link
Member Author

aykevl commented Sep 8, 2021

Are there any other places that zero-byte structs will be affected with a similar problem?

Yes. Some places have a zero sized alloca. This might be the last one remaining:

tinygo/compiler/compiler.go

Lines 1533 to 1537 in 485a928

buf := llvmutil.CreateEntryBlockAlloca(b.Builder, typ, expr.Comment)
if b.targetData.TypeAllocSize(typ) != 0 {
b.CreateStore(llvm.ConstNull(typ), buf) // zero-initialize var
}
return buf, nil

If you want to catch them, you can build LLVM using ASSERTS=1 on the make command line (something like make llvm-build ASSERTS=1) and then build TinyGo using it.
I'm not sure I'm going to bother fixing this, unless it results in actual bugs: it will be fixed when we upgrade to LLVM 12 anyway. So I'd rather focus now on getting LLVM 12 to work properly (and after that, LLVM 13).

@deadprogram
Copy link
Member

🚫 0️⃣

Thanks @aykevl now merging.

@deadprogram deadprogram merged commit 6315db2 into dev Sep 9, 2021
@deadprogram deadprogram deleted the fix-zero-channel-alloca branch September 9, 2021 09:24
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