Author: smanna12
Date: 2024-07-01T13:03:03-05:00
New Revision: 1c0e7221ce35e4b709951c06c67aeb1ed3205f27

URL: 
https://github.com/llvm/llvm-project/commit/1c0e7221ce35e4b709951c06c67aeb1ed3205f27
DIFF: 
https://github.com/llvm/llvm-project/commit/1c0e7221ce35e4b709951c06c67aeb1ed3205f27.diff

LOG: [Clang] Prevent null pointer dereference in DiagnoseDeclAvailability() 
(#97095)

This patch adds an assertion in the DiagnoseDeclAvailabilit() function
to ensure that the expected availability attribute is not null before
they are passed to hasMatchingEnvironmentOrNone() to prevent potential
null pointer dereferences and improve the robustness of the availability
diagnostics process.

Added: 
    

Modified: 
    clang/lib/Sema/SemaAvailability.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaAvailability.cpp 
b/clang/lib/Sema/SemaAvailability.cpp
index fed1c68d4d33a..df83bbfb7aac8 100644
--- a/clang/lib/Sema/SemaAvailability.cpp
+++ b/clang/lib/Sema/SemaAvailability.cpp
@@ -842,6 +842,7 @@ void 
DiagnoseUnguardedAvailability::DiagnoseDeclAvailability(
 
     const AvailabilityAttr *AA =
       getAttrForPlatform(SemaRef.getASTContext(), OffendingDecl);
+    assert(AA != nullptr && "expecting valid availability attribute");
     bool EnvironmentMatchesOrNone =
         hasMatchingEnvironmentOrNone(SemaRef.getASTContext(), AA);
     VersionTuple Introduced = AA->getIntroduced();


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to