[clang] [Clang][analyzer] add documentation for optin performance padding (padding checker) #73675 (PR #86411)

via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 23 14:06:49 PDT 2024


https://github.com/komalverma04 created https://github.com/llvm/llvm-project/pull/86411

# Added documentation for optin.performance.Padding.
- Performance package has `PaddingChecker` checker.
- It checks for excessively padded structs.
   - It has one option that is `AllowedPad`, an integer option.
   - It's default value is 24 bytes.
      - Reports are generated when padding exceeds `AllowedPad`.
 ## Purpose
The purpose of this pull request is to improve the clarity and completeness of the documentation for PaddingChecker in the optin.performance.Padding checker.

Closes #73675

>From b6ca6f0ef83d03e299d6ee9a8ed9b8044477914e Mon Sep 17 00:00:00 2001
From: komalverma04 <114138604+komalverma04 at users.noreply.github.com>
Date: Sat, 23 Mar 2024 11:14:44 -0700
Subject: [PATCH 1/2] Update checkers.rst

Modification of documentation to demonstrate utilization of AllowedPad within PaddingChecker, along with its use and effects on code analysis.
---
 clang/docs/analyzer/checkers.rst | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index fe211514914272..64b09bc6ecd1d8 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -804,10 +804,28 @@ Check for performance anti-patterns when using Grand Central Dispatch.
 
 .. _optin-performance-Padding:
 
-optin.performance.Padding
-"""""""""""""""""""""""""
+optin.performance.Padding (PaddingChecker)
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 Check for excessively padded structs.
 
+.. code-block:: objc
+
+ struct TestStruct {
+      int data1;   // 4 bytes
+      char data2;  // 1 byte
+      char padding[27];  // 27 bytes of padding
+    };  // Total size: 32 bytes 
+  
+  void TestFunction() {
+      struct TestStruct struct1;  // Warning is generated due to excessive padding.
+    }
+
+   // Reports are only generated if the excessive padding exceeds 'AllowedPad' in bytes.
+
+  // AllowedPad: Default Value: 24 bytes
+
+   Usage: `AllowedPad=<value>`
+
 .. _optin-portability-UnixAPI:
 
 optin.portability.UnixAPI

>From 403115cd960653a3afe0491d2855d35d377d9312 Mon Sep 17 00:00:00 2001
From: komalverma04 <114138604+komalverma04 at users.noreply.github.com>
Date: Sat, 23 Mar 2024 11:20:46 -0700
Subject: [PATCH 2/2] Update Checkers.td

Changed NotDocumented to HasDocumentation for Padding Checker under performance checker.
---
 clang/include/clang/StaticAnalyzer/Checkers/Checkers.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 686e5e99f4a62c..c0e4e9a70c2ef3 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -908,7 +908,7 @@ def PaddingChecker : Checker<"Padding">,
                   "24",
                   Released>
   ]>,
-  Documentation<NotDocumented>;
+  Documentation<HasDocumentation>;
 
 } // end: "padding"
 



More information about the cfe-commits mailing list