From 3cff6593e6ab1e1d52df2960e723943542465eed Mon Sep 17 00:00:00 2001 From: Pogobanane Date: Fri, 31 May 2024 22:00:20 +0000 Subject: [PATCH] fix name for unnamed undeclared types type->getAsTagDecl() may return null, e.g. in the following example: struct Foo { struct { uint64_t len; uint64_t flags; } __attribute__((packed)) bars[BARS]; ... }; --- src/common/clang_utils.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/common/clang_utils.cc b/src/common/clang_utils.cc index f2fce146..38881b9e 100644 --- a/src/common/clang_utils.cc +++ b/src/common/clang_utils.cc @@ -150,7 +150,13 @@ std::string to_string(const clang::QualType &type, const clang::ASTContext &ctx, result = "(anonymous)"; else if (util::contains(result, "unnamed struct") || util::contains(result, "unnamed union")) { - result = common::get_tag_name(*type->getAsTagDecl()); + auto declarationTag = type->getAsTagDecl(); + if (declarationTag == NULL) { + result = "(unnamed undeclared)"; + } + else { + result = common::get_tag_name(*declarationTag); + } } else if (util::contains(result, "anonymous struct") || util::contains(result, "anonymous union")) {