-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Clang] Assert non-null enum definition in CGDebugInfo::CreateTypeDefinition(const EnumType*) #105556
Conversation
@llvm/pr-subscribers-clang-codegen @llvm/pr-subscribers-debuginfo Author: None (smanna12) ChangesThis commit adds an assertion to the CreateTypeDefinition function in CGDebugInfo.cpp to verify that an enumeration definition (ED) is available before iterating over its enumerators. This prevents potential null pointer dereferences and ensures that the function operates on a valid enumeration definition. Full diff: https://github.com/llvm/llvm-project/pull/105556.diff 1 Files Affected:
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 7ad3088f0ab756..dc83d596e3cb06 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3561,6 +3561,7 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const EnumType *Ty) {
SmallVector<llvm::Metadata *, 16> Enumerators;
ED = ED->getDefinition();
+ assert(ED && "An enumeration definition is required");
for (const auto *Enum : ED->enumerators()) {
Enumerators.push_back(
DBuilder.createEnumerator(Enum->getName(), Enum->getInitVal()));
|
@llvm/pr-subscribers-clang Author: None (smanna12) ChangesThis commit adds an assertion to the CreateTypeDefinition function in CGDebugInfo.cpp to verify that an enumeration definition (ED) is available before iterating over its enumerators. This prevents potential null pointer dereferences and ensures that the function operates on a valid enumeration definition. Full diff: https://github.com/llvm/llvm-project/pull/105556.diff 1 Files Affected:
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 7ad3088f0ab756..dc83d596e3cb06 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3561,6 +3561,7 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const EnumType *Ty) {
SmallVector<llvm::Metadata *, 16> Enumerators;
ED = ED->getDefinition();
+ assert(ED && "An enumeration definition is required");
for (const auto *Enum : ED->enumerators()) {
Enumerators.push_back(
DBuilder.createEnumerator(Enum->getName(), Enum->getInitVal()));
|
The patch title and description claims more than it actually does. The assertion does not "fix" or prevent a null dereference, it's simply documenting a requirement. Please update the title and description. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @tahonermann and @pogo59 for reviews. I have updated title and commit messages. |
What static analysis tool flagged this? Any idea why this particular null dereference, when LLVM/Clang have loads of assumed-non-null pointers that are dereferenced in a great many places? |
…inition(const EnumType*) (llvm#105556) This commit adds an assert to check for a non-null enum definition in CGDebugInfo::CreateTypeDefinition(const EnumType*), ensuring precondition validity. Previous discussion on llvm#97105
This commit adds an assert to check for a non-null enum definition in CGDebugInfo::CreateTypeDefinition(const EnumType*), ensuring precondition validity.
Previous discussion on #97105