================
@@ -3248,6 +3248,61 @@ Loss of sign/precision in implicit conversions.
short X = A; // warn (loss of precision)
}
+.. _alpha-core-DanglingPtrDeref:
+
+alpha.core.DanglingPtrDeref (C, C++)
+""""""""""""""""""""""""""""""""""""
+Check for dereferences of pointers that refer to an object whose
+lifetime has already ended. Such a pointer is dangling. The checker
+reports it when it is dereferenced and when it is passed to a function.
+
+Each object is reported at most once on an execution path. If the same dangling
+pointer is used several times then only the first use is reported.
+
+.. code-block:: cpp
+
+ void test_deref() {
+ int *ptr = 0;
+ {
+ int num = 5;
+ ptr = #
+ } // note: 'num' is destroyed here
+ *ptr = 6; // warn: use of 'num' after its lifetime ended
+ }
+
+ void test_in_scope() {
+ int num = 5;
+ int *ptr = #
+ {
+ *ptr = 6; // no warning, 'num' is still in scope
+ }
+ }
+
+The checker requires end-of-lifetime information from the CFG. It is enabled
+with the ``-analyzer-config cfg-lifetime=true`` option.
----------------
steakhal wrote:
I think "needs" doens't address the problem. We should just say plainly what
will happen when you enable the checker and have this or don't have this. Of
course we should also mention how to enable it but that's a different problem.
https://github.com/llvm/llvm-project/pull/216688
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits