diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -4198,16 +4198,23 @@ } void CodeGenModule::EmitExternalVarDeclaration(const VarDecl *D) { - if (CGDebugInfo *DI = getModuleDebugInfo()) - if (getCodeGenOpts().hasReducedDebugInfo()) { - QualType ASTTy = D->getType(); - llvm::Type *Ty = getTypes().ConvertTypeForMem(D->getType()); - llvm::PointerType *PTy = - llvm::PointerType::get(Ty, getContext().getTargetAddressSpace(ASTTy)); - llvm::Constant *GV = GetOrCreateLLVMGlobal(D->getName(), PTy, D); - DI->EmitExternalVariable( - cast(GV->stripPointerCasts()), D); - } + if (CGDebugInfo *DI = getModuleDebugInfo()) { + if (!getCodeGenOpts().hasReducedDebugInfo()) + return; + + // The DIGlobalVariable must have a type, skip the generation + // if the underlying type is void without any qualifiers. + QualType ASTTy = D->getType(); + if (!ASTTy.hasQualifiers() && ASTTy.getTypePtr()->isVoidType()) + return; + + llvm::Type *Ty = getTypes().ConvertTypeForMem(D->getType()); + llvm::PointerType *PTy = + llvm::PointerType::get(Ty, getContext().getTargetAddressSpace(ASTTy)); + llvm::Constant *GV = GetOrCreateLLVMGlobal(D->getName(), PTy, D); + DI->EmitExternalVariable( + cast(GV->stripPointerCasts()), D); + } } static bool isVarDeclStrongDefinition(const ASTContext &Context,