Commit aeeb541
committed
[memory analysis] extend GetAllocType to see through optional-like wrapper constructions
Restrict the pointer-arithmetic Unknown-downgrade in VisitBinaryOperator to
pointer-typed variables only, so unrelated scalar compound-assignments no
longer poison tracked results.
Allow AnalyzeAllocType to also traverse record-typed (class/struct) return
values, not just raw pointers, so wrapper types like std::optional<T*> get
analyzed instead of short-circuiting to None.
In handleExpr:
- Unwrap unary operator* calls (e.g. on an optional) to
recurse into the wrapped value instead of falling back to a call analysis.
- Detect nullptr/NULL literals directly via CXXNullPtrLiteralExpr/
GNUNullExpr, since the existing CK_NullToPointer cast walk cannot see
through a MaterializeTemporaryExpr (e.g. nullptr_t passed to optional's
converting constructor).
- Recognize implicit converting-constructor calls (ExprWithCleanups ->
ImplicitCastExpr(CK_ConstructorConversion) -> CXXConstructExpr) and
recurse into the constructor's argument, so New/Malloc/etc. tags
propagate through implicit wrapping (e.g. ).
- Add isNullOpt() to recognize std::nullopt/cpp::nullopt construction as
AllocType::Null.
Known limitation (documented via FIXME + test): optional's copy/move
constructor is not a converting constructor, so copying an optional loses
its tracked AllocType and reports None.
Add FunctionReflection_GetAllocType coverage (func60-func69) for: implicit
optional-wrapping of new, std::nullopt join behavior, default-constructed
empty structs, direct/list-initialized plain wrapper structs, operator*
unwrap (unary vs. binary), direct nullptr returns through optional, and
pointer arithmetic inside a for-loop increment clause.1 parent ff9874a commit aeeb541
2 files changed
Lines changed: 128 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1798 | 1798 | | |
1799 | 1799 | | |
1800 | 1800 | | |
1801 | | - | |
| 1801 | + | |
1802 | 1802 | | |
1803 | 1803 | | |
1804 | 1804 | | |
| |||
1870 | 1870 | | |
1871 | 1871 | | |
1872 | 1872 | | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
1873 | 1887 | | |
1874 | 1888 | | |
1875 | 1889 | | |
| |||
1888 | 1902 | | |
1889 | 1903 | | |
1890 | 1904 | | |
1891 | | - | |
| 1905 | + | |
| 1906 | + | |
| 1907 | + | |
| 1908 | + | |
| 1909 | + | |
| 1910 | + | |
| 1911 | + | |
1892 | 1912 | | |
| 1913 | + | |
1893 | 1914 | | |
1894 | 1915 | | |
| 1916 | + | |
| 1917 | + | |
| 1918 | + | |
1895 | 1919 | | |
1896 | 1920 | | |
1897 | 1921 | | |
1898 | 1922 | | |
1899 | 1923 | | |
1900 | 1924 | | |
1901 | 1925 | | |
| 1926 | + | |
| 1927 | + | |
| 1928 | + | |
| 1929 | + | |
| 1930 | + | |
| 1931 | + | |
| 1932 | + | |
| 1933 | + | |
| 1934 | + | |
| 1935 | + | |
| 1936 | + | |
| 1937 | + | |
| 1938 | + | |
| 1939 | + | |
| 1940 | + | |
| 1941 | + | |
| 1942 | + | |
1902 | 1943 | | |
1903 | 1944 | | |
1904 | 1945 | | |
| |||
1908 | 1949 | | |
1909 | 1950 | | |
1910 | 1951 | | |
1911 | | - | |
1912 | | - | |
| 1952 | + | |
| 1953 | + | |
1913 | 1954 | | |
1914 | 1955 | | |
1915 | 1956 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
833 | 833 | | |
834 | 834 | | |
835 | 835 | | |
| 836 | + | |
836 | 837 | | |
837 | 838 | | |
838 | 839 | | |
| |||
1206 | 1207 | | |
1207 | 1208 | | |
1208 | 1209 | | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
1209 | 1281 | | |
1210 | | - | |
| 1282 | + | |
1211 | 1283 | | |
1212 | 1284 | | |
1213 | 1285 | | |
| |||
1275 | 1347 | | |
1276 | 1348 | | |
1277 | 1349 | | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
1278 | 1360 | | |
1279 | 1361 | | |
1280 | 1362 | | |
| |||
0 commit comments