[llvm-bugs] [Bug 49916] New: Zero-sized alloca causes assertion failure in coroutine lowering
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat Apr 10 15:19:41 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=49916
Bug ID: 49916
Summary: Zero-sized alloca causes assertion failure in
coroutine lowering
Product: new-bugs
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: aykevanlaethem at gmail.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
rjmccall at apple.com
See: https://llvm.godbolt.org/z/e9eGvrjd8
The code below crashes when running `opt -O2 --enable-coroutines`. This looks
like a bug in the coroutine passes: I would expect zero-sized alloca
instructions to work fine (and take up no space in the coroutine frame) but
instead this code crashes with the following error:
opt:
/home/ayke/src/github.com/tinygo-org/tinygo/llvm-project/llvm/include/llvm/Support/OptimizedStructLayout.h:52:
llvm::OptimizedStructLayoutField::OptimizedStructLayoutField(const void *,
uint64_t, llvm::Align, uint64_t): Assertion `Size > 0 && "adding an empty field
to the layout"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash
backtrace.
Stack dump:
0. Program arguments: llvm-build/bin/opt -enable-coroutines -O2 -o
bugpoint.ll bugpoint-reduced-function.ll
1. Running pass 'CallGraph Pass Manager' on module
'bugpoint-reduced-function.ll'.
2. While splitting coroutine @main.main
#0 0x0000000003151c84 PrintStackTraceSignalHandler(void*)
(llvm-build/bin/opt+0x3151c84)
#1 0x000000000314f85e llvm::sys::RunSignalHandlers()
(llvm-build/bin/opt+0x314f85e)
#2 0x0000000003151fa5 SignalHandler(int) (llvm-build/bin/opt+0x3151fa5)
#3 0x00007f6db4c55730 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x12730)
#4 0x00007f6db47877bb raise (/lib/x86_64-linux-gnu/libc.so.6+0x377bb)
#5 0x00007f6db4772535 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22535)
#6 0x00007f6db477240f (/lib/x86_64-linux-gnu/libc.so.6+0x2240f)
#7 0x00007f6db4780102 (/lib/x86_64-linux-gnu/libc.so.6+0x30102)
#8 0x0000000002a67c42 llvm::coro::buildCoroutineFrame(llvm::Function&,
llvm::coro::Shape&) (llvm-build/bin/opt+0x2a67c42)
#9 0x0000000002a57649 splitCoroutine(llvm::Function&,
llvm::SmallVectorImpl<llvm::Function*>&) (llvm-build/bin/opt+0x2a57649)
#10 0x0000000002a5f332 (anonymous
namespace)::CoroSplitLegacy::runOnSCC(llvm::CallGraphSCC&)
(llvm-build/bin/opt+0x2a5f332)
#11 0x00000000021a7ed8 (anonymous
namespace)::CGPassManager::runOnModule(llvm::Module&)
(llvm-build/bin/opt+0x21a7ed8)
#12 0x00000000029c5964 llvm::legacy::PassManagerImpl::run(llvm::Module&)
(llvm-build/bin/opt+0x29c5964)
#13 0x00000000019390dd main (llvm-build/bin/opt+0x19390dd)
#14 0x00007f6db477409b __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x2409b)
#15 0x000000000192445a _start (llvm-build/bin/opt+0x192445a)
The code which causes this crash is below (and in the Godbolt link above):
---
target datalayout =
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64--linux"
declare i8* @malloc(i64)
declare void @abort()
declare void @free(i8*)
declare void @usePointer(i8*)
declare token @llvm.coro.id(i32, i8* readnone, i8* nocapture readonly, i8*)
declare i64 @llvm.coro.size.i64()
declare i8* @llvm.coro.begin(token, i8* writeonly)
declare i8 @llvm.coro.suspend(token, i1)
declare i1 @llvm.coro.end(i8*, i1)
declare i8* @llvm.coro.free(token, i8* nocapture readonly)
declare token @llvm.coro.save(i8*)
define void @main.main() {
entry:
%stackalloc.alloca = alloca [0 x i8]
%stackalloc = bitcast [0 x i8]* %stackalloc.alloca to i8*
%coro.id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
%coro.size = call i64 @llvm.coro.size.i64()
%coro.alloc = call i8* @malloc(i64 %coro.size)
%coro.state = call i8* @llvm.coro.begin(token %coro.id, i8* %coro.alloc)
%coro.save = call token @llvm.coro.save(i8* %coro.state)
%call.suspend = call i8 @llvm.coro.suspend(token %coro.save, i1 false)
switch i8 %call.suspend, label %suspend [
i8 0, label %wakeup
i8 1, label %cleanup
]
wakeup: ; preds = %entry
call void @usePointer(i8* %stackalloc)
br label %cleanup
suspend: ; preds = %cleanup, %entry
%unused = call i1 @llvm.coro.end(i8* %coro.state, i1 false)
ret void
cleanup: ; preds = %wakeup, %entry
%coro.memFree = call i8* @llvm.coro.free(token %coro.id, i8* %coro.state)
call void @free(i8* %coro.memFree)
br label %suspend
}
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210410/d8ab0840/attachment.html>
More information about the llvm-bugs
mailing list