[clang] [Clang] Fix null pointer dereference in enum debug info generation (PR #97105)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 28 13:03:46 PDT 2024
https://github.com/smanna12 created https://github.com/llvm/llvm-project/pull/97105
This patch prevents dereferencing a null enum definition by returning `nullptr` if `getDefinition()` fails in `CreateTypeDefinition()`.
>From 5a4f0207afa9a473ba8ebf1e24a75730cd13a553 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.manna at intel.com>
Date: Fri, 28 Jun 2024 12:58:45 -0700
Subject: [PATCH] [Clang] Fix null pointer dereference in enum debug info
generation
This patch prevents dereferencing a null enum definition by returning
`nullptr` if `getDefinition()` fails in `CreateTypeDefinition()`.
---
clang/lib/CodeGen/CGDebugInfo.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 3d8a715b692de..c236e2657fe98 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3518,6 +3518,10 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const EnumType *Ty) {
SmallVector<llvm::Metadata *, 16> Enumerators;
ED = ED->getDefinition();
+
+ if (!ED)
+ return nullptr;
+
for (const auto *Enum : ED->enumerators()) {
Enumerators.push_back(
DBuilder.createEnumerator(Enum->getName(), Enum->getInitVal()));
More information about the cfe-commits
mailing list