Skip to content
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

[NFC][CLANG] Fix null pointer dereferences #86760

Merged
merged 1 commit into from
Mar 27, 2024

Conversation

smanna12
Copy link
Contributor

This patch replaces getAs<> with castAs<> to resolve potential static analyzer bugs for

  1. Dereferencing Proto1->param_type_begin(), which is known to be nullptr
  2. Dereferencing Proto2->param_type_begin(), which is known to be nullptr
  3. Dereferencing a pointer issue with nullptr Proto1 when calling param_type_end()
  4. Dereferencing a pointer issue with nullptr Proto2 when calling param_type_end()

in clang::Sema::getMoreSpecializedTemplate().

This patch replaces getAs<> with castAs<> to resolve potential static
analyzer bugs for

1. Dereferencing Proto1->param_type_begin(), which is known to be nullptr
2. Dereferencing Proto2->param_type_begin(), which is known to be nullptr
3. Dereferencing a pointer issue with nullptr Proto1 when calling param_type_end()
4. Dereferencing a pointer issue with nullptr Proto2 when calling param_type_end()

in clang::Sema::getMoreSpecializedTemplate().
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Mar 27, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 27, 2024

@llvm/pr-subscribers-clang

Author: None (smanna12)

Changes

This patch replaces getAs<> with castAs<> to resolve potential static analyzer bugs for

  1. Dereferencing Proto1->param_type_begin(), which is known to be nullptr
  2. Dereferencing Proto2->param_type_begin(), which is known to be nullptr
  3. Dereferencing a pointer issue with nullptr Proto1 when calling param_type_end()
  4. Dereferencing a pointer issue with nullptr Proto2 when calling param_type_end()

in clang::Sema::getMoreSpecializedTemplate().


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

1 Files Affected:

  • (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+2-2)
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 97f8445bf819c8..9a55881f644254 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5514,9 +5514,9 @@ FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
   QualType Obj2Ty;
   if (TPOC == TPOC_Call) {
     const FunctionProtoType *Proto1 =
-        FD1->getType()->getAs<FunctionProtoType>();
+        FD1->getType()->castAs<FunctionProtoType>();
     const FunctionProtoType *Proto2 =
-        FD2->getType()->getAs<FunctionProtoType>();
+        FD2->getType()->castAs<FunctionProtoType>();
 
     //   - In the context of a function call, the function parameter types are
     //     used.

@HoBoIs
Copy link
Contributor

HoBoIs commented Mar 27, 2024

Looks good to me.

Copy link
Contributor

@tahonermann tahonermann left a comment

Choose a reason for hiding this comment

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

Looks good, thanks @smanna12!

@smanna12
Copy link
Contributor Author

Thanks @tahonermann and @HoBoIs for reviews!

@smanna12 smanna12 merged commit 8a75faf into llvm:main Mar 27, 2024
7 checks passed
@smanna12 smanna12 deleted the FixNUllPointerBugs branch March 27, 2024 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants