Skip to content

Commit

Permalink
[Clang][Attr] fix a btf_type_attr CGDebugInfo codegen bug
Browse files Browse the repository at this point in the history
Nathan Chancellor reported a crash due to commit
3466e00 (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.
  • Loading branch information
yonghong-song committed Nov 7, 2021
1 parent d9e2c8f commit bbab17c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Expand Up @@ -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++;
Expand Down

0 comments on commit bbab17c

Please sign in to comment.