================
@@ -0,0 +1,208 @@
+FAQ and How to Deal with Common False Positives
+===============================================
+
+.. contents::
+   :local:
+
+Custom Assertions
+-----------------
+
+Q: How do I tell the analyzer that I do not want the bug being reported here 
since my custom error handler will safely end the execution before the bug is 
reached?
+
+You can tell the analyzer that this path is unreachable by teaching it about 
your `custom assertion handlers <annotations.html#custom_assertions>`_. For 
example, you can modify the code segment as following:
+
+.. code-block:: c
+
+   void customAssert() __attribute__((analyzer_noreturn));
+   int foo(int *b) {
+     if (!b)
+       customAssert();
+     return *b;
+   }
+
+Null Pointer Dereference
+------------------------
+
+Q: The analyzer reports a null dereference, but I know that the pointer is 
never null. How can I tell the analyzer that a pointer can never be null?
+
+The reason the analyzer often thinks that a pointer can be null is because the 
preceding code checked compared it against null. If you are absolutely sure 
that it cannot be null, remove the preceding check and, preferably, add an 
assertion as well. For example:
+
+.. code-block:: c
+
+   void usePointer(int *b);
+   int foo(int *b) {
+     usePointer(b);
+     return *b;
+   }
+
+Dead Store
+----------
+
+Q: How do I tell the static analyzer that I don't care about a specific dead 
store?
+
+When the analyzer sees that a value stored into a variable is never used, it's 
going to produce a message similar to this one:
+
+.. code-block:: none
+
+   Value stored to 'x' is never read
+
+You can use the ``(void)x;`` idiom to acknowledge that there is a dead store 
in your code but you do not want it to be reported in the future.
+
+Unused Instance Variable
+------------------------
+
+Q: How do I tell the static analyzer that I don't care about a specific unused 
instance variable in Objective-C?
+
+When the analyzer sees that a value stored into a variable is never used, it 
is going to produce a message similar to this one:
+
+.. code-block:: none
+
+   Instance variable 'commonName' in class 'HappyBird' is never used by the 
methods in its @implementation
+
+You can add ``__attribute__((unused))`` to the instance variable declaration 
to suppress the warning.
+
+Unlocalized String
+------------------
+
+Q: How do I tell the static analyzer that I don't care about a specific 
unlocalized string?
----------------
NagyDonat wrote:

This is oddly specific advice, I don't see why is it in the "frequently" asked 
questions. (Although I'm not native to ObjCLand, maybe this is a common issue 
there...)

https://github.com/llvm/llvm-project/pull/112831
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to