From bbab17c6c987d7a6612855c02a4e8988dac0dc17 Mon Sep 17 00:00:00 2001 From: Yonghong Song Date: Sat, 6 Nov 2021 17:46:40 -0700 Subject: [PATCH] [Clang][Attr] fix a btf_type_attr CGDebugInfo codegen bug Nathan Chancellor reported a crash due to commit 3466e00716e1 (Reland "[Attr] support btf_type_tag attribute"). The following test can reproduce the crash: $ cat efi.i typedef unsigned long efi_query_variable_info_t(int); typedef struct { struct { efi_query_variable_info_t __attribute__((regparm(0))) * query_variable_info; }; } efi_runtime_services_t; efi_runtime_services_t efi_0; $ clang -m32 -O2 -g -c -o /dev/null efi.i The reason is that FunctionTypeLoc.getParam(Idx) may return a nullptr which should be checked before dereferencing the result pointer. This patch fixed this issue. --- clang/lib/CodeGen/CGDebugInfo.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 2b95325..1ce56f9 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -1446,9 +1446,10 @@ llvm::DIType *CGDebugInfo::CreateType(const FunctionType *Ty, for (const QualType &ParamType : FPT->param_types()) { TypeLoc ParamTL; if (Idx < FTL_NumParams) { - ParmVarDecl *Param = FTL.getParam(Idx); - if (const TypeSourceInfo *TSI = Param->getTypeSourceInfo()) - ParamTL = TSI->getTypeLoc(); + if (ParmVarDecl *Param = FTL.getParam(Idx)) { + if (const TypeSourceInfo *TSI = Param->getTypeSourceInfo()) + ParamTL = TSI->getTypeLoc(); + } } EltTys.push_back(getOrCreateType(ParamType, Unit, ParamTL)); Idx++; -- 2.7.4