[clang] [Clang] Fix null pointer dereference in enum debug info generation (PR #97105)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 23 15:14:13 PDT 2024
https://github.com/smanna12 updated https://github.com/llvm/llvm-project/pull/97105
>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 1/2] [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()));
>From 0cf295bc69a90b4f1239284a03a1a2ae89cadaee Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.manna at intel.com>
Date: Tue, 23 Jul 2024 15:13:32 -0700
Subject: [PATCH 2/2] Address review comments- add test
---
clang/test/CodeGen/debug-info-enum.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/clang/test/CodeGen/debug-info-enum.cpp b/clang/test/CodeGen/debug-info-enum.cpp
index 4d83fdc32903c..48565920437d1 100644
--- a/clang/test/CodeGen/debug-info-enum.cpp
+++ b/clang/test/CodeGen/debug-info-enum.cpp
@@ -98,3 +98,6 @@ enum E8 { A8 = -128, B8 = 127 } x8;
// CHECK-NOT: DIFlagEnumClass
// CHECK: !DIEnumerator(name: "A8", value: -128)
+// Forward declaration of an enum class.
+enum class Color : int;
+// CHECK-NOT: !DICompositeType(tag: DW_TAG_enumeration_type, name: "Color"
More information about the cfe-commits
mailing list