[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:04:15 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
@llvm/pr-subscribers-clang-codegen
Author: None (smanna12)
<details>
<summary>Changes</summary>
This patch prevents dereferencing a null enum definition by returning `nullptr` if `getDefinition()` fails in `CreateTypeDefinition()`.
---
Full diff: https://github.com/llvm/llvm-project/pull/97105.diff
1 Files Affected:
- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+4)
``````````diff
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()));
``````````
</details>
https://github.com/llvm/llvm-project/pull/97105
More information about the cfe-commits
mailing list