[PATCH] D151529: [NFC][CLANG] Fix nullptr dereference issue in DeduceTemplateArgumentsByTypeMatch()

Soumi Manna via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 25 19:48:24 PDT 2023


Manna created this revision.
Manna added a reviewer: erichkeane.
Herald added a project: All.
Manna requested review of this revision.
Herald added a project: clang.

DeduceTemplateArgumentsByTypeMatch() returns null value which is dereferenced without checking since  
getAsIncompleteArrayType() returns nullptr and we are dereferencing null pointer value for S.Context->getAsIncompleteArrayType(P) when calling getElementType().

This patch adds an assert.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151529

Files:
  clang/lib/Sema/SemaTemplateDeduction.cpp


Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===================================================================
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -1703,10 +1703,12 @@
       if (!IAA)
         return Sema::TDK_NonDeducedMismatch;
 
+      const auto *IAP = S.Context.getAsIncompleteArrayType(P);
+      assert(IAP && "Template arguments not of incomplete array type!");
+
       return DeduceTemplateArgumentsByTypeMatch(
-          S, TemplateParams,
-          S.Context.getAsIncompleteArrayType(P)->getElementType(),
-          IAA->getElementType(), Info, Deduced, TDF & TDF_IgnoreQualifiers);
+          S, TemplateParams, IAP->getElementType(), IAA->getElementType(), Info,
+          Deduced, TDF & TDF_IgnoreQualifiers);
     }
 
     //     T [integer-constant]


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151529.525915.patch
Type: text/x-patch
Size: 834 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230526/2b564a44/attachment.bin>


More information about the cfe-commits mailing list