diff options
author | Congcong Cai <congcongcai0907@163.com> | 2024-10-23 09:21:27 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-23 09:21:27 +0800 |
commit | bd6c430dcb52f3e4f86abc5f572126355fa39936 (patch) | |
tree | 6041e76465f091e59f07285e8b9cc302330e18e1 /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 0fbf91ab8e395717ed886c6827ca572c5baaa7a0 (diff) | |
download | llvm-bd6c430dcb52f3e4f86abc5f572126355fa39936.zip llvm-bd6c430dcb52f3e4f86abc5f572126355fa39936.tar.gz llvm-bd6c430dcb52f3e4f86abc5f572126355fa39936.tar.bz2 |
[clang codegen] avoid to crash when emit init func for global variable with flexible array init (#113336)
Fixes: #113187
Avoid to create init function since clang does not support global
variable with flexible array init.
It will cause assertion failure later.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 24655b8..2bcca5e 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -5529,12 +5529,14 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D, T = D->getType(); if (getLangOpts().CPlusPlus) { - if (InitDecl->hasFlexibleArrayInit(getContext())) - ErrorUnsupported(D, "flexible array initializer"); Init = EmitNullConstant(T); - if (!IsDefinitionAvailableExternally) NeedsGlobalCtor = true; + if (InitDecl->hasFlexibleArrayInit(getContext())) { + ErrorUnsupported(D, "flexible array initializer"); + // We cannot create ctor for flexible array initializer + NeedsGlobalCtor = false; + } } else { ErrorUnsupported(D, "static initializer"); Init = llvm::UndefValue::get(getTypes().ConvertType(T)); |