[-Wunsafe-buffer-usage] Check source location validity before using `TypeLoc`s
authorziqingluo-90 <ziqing@udel.edu>
Wed, 19 Jul 2023 22:00:10 +0000 (15:00 -0700)
committerziqingluo-90 <ziqing@udel.edu>
Wed, 19 Jul 2023 22:04:42 +0000 (15:04 -0700)
commita6302b6934b349fff122eeb6c4b39eff580c4b1b
tree8e2540d359ecc3d09ad9866a735799155dc95abc
parentdc37d5ec800b2d32baa0432304382b812b89cd0d
[-Wunsafe-buffer-usage] Check source location validity before using `TypeLoc`s

The safe-buffer analysis analyzes TypeLocs of types of variable
declarations in order to get source locations of them.

However, in some cases, the source locations of a TypeLoc are not
valid. Using invalid source locations results in assertion violation
or incorrect analysis or fix-its.

It is still not clear to me in what circumstances a TypeLoc does not
have valid source locations (it looks like a bug in Clang to me, but
it is not our responsibility to fix it). So we will conservatively
give up the analysis when required source locations are not valid.

Reviewed By: NoQ (Artem Dergachev)

Differential Revision: https://reviews.llvm.org/D155667
clang/lib/Analysis/UnsafeBufferUsage.cpp
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-unsupported.cpp