[clang] 7b2fe84 - Don't run the lifetime analysis for pointer assignment if the warning is

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 1 07:31:27 PDT 2024


Author: Haojian Wu
Date: 2024-09-01T16:19:18+02:00
New Revision: 7b2fe84ff57b49f6275bc12d47f87a1887919d9e

URL: https://github.com/llvm/llvm-project/commit/7b2fe84ff57b49f6275bc12d47f87a1887919d9e
DIFF: https://github.com/llvm/llvm-project/commit/7b2fe84ff57b49f6275bc12d47f87a1887919d9e.diff

LOG: Don't run the lifetime analysis for pointer assignment if the warning is
disabled.

Added: 
    

Modified: 
    clang/lib/Sema/CheckExprLifetime.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/CheckExprLifetime.cpp b/clang/lib/Sema/CheckExprLifetime.cpp
index c1362559536962..f28789dba34e10 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -1297,7 +1297,10 @@ void checkExprLifetime(Sema &SemaRef, const AssignedEntity &Entity,
                        Expr *Init) {
   bool EnableLifetimeWarnings = !SemaRef.getDiagnostics().isIgnored(
       diag::warn_dangling_lifetime_pointer, SourceLocation());
-  bool RunAnalysis = Entity.LHS->getType()->isPointerType() ||
+  bool EnableDanglingPointerAssignment = !SemaRef.getDiagnostics().isIgnored(
+      diag::warn_dangling_pointer_assignment, SourceLocation());
+  bool RunAnalysis = (EnableDanglingPointerAssignment &&
+                      Entity.LHS->getType()->isPointerType()) ||
                      (EnableLifetimeWarnings &&
                       isRecordWithAttr<PointerAttr>(Entity.LHS->getType()));
 


        


More information about the cfe-commits mailing list