From bd6c430dcb52f3e4f86abc5f572126355fa39936 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Wed, 23 Oct 2024 09:21:27 +0800 Subject: [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. --- clang/lib/CodeGen/CodeGenModule.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') 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)); -- cgit v1.1