[clang] [analyzer] Refactor recognition of the errno getter functions (PR #91531)

DonĂ¡t Nagy via cfe-commits cfe-commits at lists.llvm.org
Fri May 10 02:39:57 PDT 2024


================
@@ -39,10 +39,15 @@ namespace {
 // Name of the "errno" variable.
 // FIXME: Is there a system where it is not called "errno" but is a variable?
 const char *ErrnoVarName = "errno";
+
 // Names of functions that return a location of the "errno" value.
 // FIXME: Are there other similar function names?
-const char *ErrnoLocationFuncNames[] = {"__errno_location", "___errno",
-                                        "__errno", "_errno", "__error"};
+CallDescriptionSet ErrnoLocationCalls{
+    {CDM::SimpleFunc, {"__errno_location"}, 0, 0},
+    {CDM::SimpleFunc, {"___errno"}, 0, 0},
+    {CDM::SimpleFunc, {"__errno"}, 0, 0},
+    {CDM::SimpleFunc, {"_errno"}, 0, 0},
+    {CDM::SimpleFunc, {"__error"}, 0, 0}};
----------------
NagyDonat wrote:

I updated them to `CLibrary` because it's slightly better for this usecase (it won't match functions within a user-defined C++ namespace).

By the way, note that the `CLibrary` matching mode intentionally **doesn't check whether the function was declared within a system header**, because "being in a system header" is a very fragile property -- consider e.g. a case when somebody tries to submit a preprocessed source file for bug reproduction and the declaration becomes part of the (tweaked, minified) source file. I also suspect that there might be some unusual/internal functions (like these ones) whose declaration has no location, so it isn't in a system header...

https://github.com/llvm/llvm-project/pull/91531


More information about the cfe-commits mailing list