[PATCH] D153612: [clang][analyzer] Add and change NoteTags in StdLibraryFunctionsChecker.

DonĂ¡t Nagy via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 29 06:27:06 PDT 2023


donat.nagy added a comment.

Thanks for the update! I have two minor remarks (string handling is complicated in C++...) but the code looks good otherwise.



================
Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:1305
+      std::string Note =
+          llvm::formatv(Case.getNote().str().c_str(),
+                        cast<NamedDecl>(Call.getDecl())->getDeclName());
----------------
Consider using the method `StringRef::data()` which directly converts a `StringRef` to a `const char *`. Your two-step conversion has the advantage that it adds a `\0` terminator even if the `StringRef` isn't null-terminated, but I cannot imagine a "natural" code change that would introduce references to non-null-terminated char arrays as note message templates.


================
Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:1321
+              if (Node->succ_size() > 1)
+                return Note.c_str();
+              return "";
----------------
The return type of this lambda is `std::string`, so I think it's pointless to convert `std::string Note` to a C string (which will be used to implicitly construct another `std::string`). 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153612/new/

https://reviews.llvm.org/D153612



More information about the cfe-commits mailing list