Skip to content

Conversation

apach301
Copy link
Contributor

@apach301 apach301 commented Sep 8, 2025

Fixes #157448

@llvmbot llvmbot added the llvm:ir label Sep 8, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 8, 2025

@llvm/pr-subscribers-debuginfo

@llvm/pr-subscribers-llvm-ir

Author: Daniel Kuts (apach301)

Changes

Fixes #157448


Full diff: https://github.com/llvm/llvm-project/pull/157458.diff

1 Files Affected:

  • (modified) llvm/lib/IR/Verifier.cpp (+1-1)
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index f38871f09f35f..57ea5b53647aa 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -3188,7 +3188,7 @@ void Verifier::visitFunction(const Function &F) {
     if (SP && ((Scope != SP) && !Seen.insert(SP).second))
       return;
 
-    CheckDI(SP->describes(&F),
+    CheckDI(SP && SP->describes(&F),
             "!dbg attachment points at wrong subprogram for function", N, &F,
             &I, DL, Scope, SP);
   };

Copy link
Contributor

@artagnon artagnon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kindly add a test, showing that this bug can actually be hit.

@apach301
Copy link
Contributor Author

apach301 commented Sep 9, 2025

Kindly add a test, showing that this bug can actually be hit.

It was a static analyzer report, so I don't know how to run this code and have any input data. But the problem in this code is that 'SP' could be NULL - in previous if-statement it is checked on NULL. So it also shoulf be checked in current function

Copy link
Contributor

@artagnon artagnon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think DISubprogram::getSubprogram can return null:

DISubprogram *DILocalScope::getSubprogram() const {
  if (auto *Block = dyn_cast<DILexicalBlockBase>(this))
    return Block->getScope()->getSubprogram();
  return const_cast<DISubprogram *>(cast<DISubprogram>(this));
}

So, the check SP && preceding your patch should probably be stripped, as it is dead?

@apach301
Copy link
Contributor Author

apach301 commented Sep 9, 2025

So, the check SP && preceding your patch should probably be stripped, as it is dead?

If it cant return nullptr after cast, then yes, I could remove both checks

Copy link
Contributor

@artagnon artagnon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the PR title/description. Suffix the title with "(NFC)" to make it clear that the change is non-functional.

@artagnon artagnon requested a review from nikic September 9, 2025 20:20
@apach301 apach301 changed the title [llvm] Fix potential null dereference in IR/Verifier [llvm] Remove redunant nullptr check in IR/Verifier (NFC) Sep 9, 2025
@nikic nikic added the debuginfo label Sep 9, 2025
@artagnon artagnon changed the title [llvm] Remove redunant nullptr check in IR/Verifier (NFC) [Verifier] Remove redundant null-check (NFC) Sep 9, 2025
Copy link
Contributor

@artagnon artagnon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@hstk30-hw hstk30-hw merged commit ebf7858 into llvm:main Sep 10, 2025
10 checks passed
@apach301 apach301 deleted the llvm-verifier-null-derefernce branch September 15, 2025 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possible NULL dereference in llvm/IR
5 participants