Issue |
77085
|
Summary |
Initializing union containing struct with flexible array member asserts
|
Labels |
clang:codegen,
crash-on-valid
|
Assignees |
|
Reporter |
nikic
|
```c
struct _NMPObject {
int ifindex;
char network_ptr[];
};
union {
int x;
struct _NMPObject k;
} foo = {};
```
Appears to have regressed in clang 15: https://cpp.godbolt.org/z/ePnc1PKdG
```
clang: /home/npopov/repos/llvm-project/clang/include/clang/AST/Expr.h:4905: const Expr *clang::InitListExpr::getInit(unsigned int) const: Assertion `Init < getNumInits() && "Initializer access out of range!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /home/npopov/repos/llvm-project/build/bin/clang repro.c -c
1. <eof> parser at end of file
2. repro.c:6:1: LLVM IR generation of declaration 'union (unnamed at repro.c:6:1)'
3. repro.c:9:3: Generating code for declaration 'foo'
#0 0x0000000006fe2c98 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/npopov/repos/llvm-project/build/bin/clang+0x6fe2c98)
#1 0x0000000006fe083e llvm::sys::RunSignalHandlers() (/home/npopov/repos/llvm-project/build/bin/clang+0x6fe083e)
#2 0x0000000006f4a066 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007f1fe2a5fbb0 __restore_rt (/lib64/libc.so.6+0x3dbb0)
#4 0x00007f1fe2ab0884 __pthread_kill_implementation (/lib64/libc.so.6+0x8e884)
#5 0x00007f1fe2a5fafe gsignal (/lib64/libc.so.6+0x3dafe)
#6 0x00007f1fe2a4887f abort (/lib64/libc.so.6+0x2687f)
#7 0x00007f1fe2a4879b _nl_load_domain.cold (/lib64/libc.so.6+0x2679b)
#8 0x00007f1fe2a58187 (/lib64/libc.so.6+0x36187)
#9 0x000000000a3d331e clang::VarDecl::getFlexibleArrayInitChars(clang::ASTContext const&) const (/home/npopov/repos/llvm-project/build/bin/clang+0xa3d331e)
#10 0x00000000071f584e clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition(clang::VarDecl const*, bool) (/home/npopov/repos/llvm-project/build/bin/clang+0x71f584e)
#11 0x00000000071ec526 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/home/npopov/repos/llvm-project/build/bin/clang+0x71ec526)
#12 0x00000000071f1002 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/home/npopov/repos/llvm-project/build/bin/clang+0x71f1002)
#13 0x00000000071eb1b9 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (/home/npopov/repos/llvm-project/build/bin/clang+0x71eb1b9)
```
(I'm marking this as "crash-on-valid" as it should at least compile with GNU extensions -- I'm not sure whether this is conformant with standard C. It occurs in the wild in NetworkManager.)
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs