[PATCH] D137996: Add support for a backdoor driver option that enables emitting header usage information in JSON to a file

Sean via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 5 10:28:49 PST 2023


SeanP added inline comments.


================
Comment at: clang/tools/driver/driver.cpp:251
+                     std::string &OptFile) {
+  T OptVal = ::getenv(EnvOptSet);
+  if (OptVal) {
----------------
This change is not POSIX compliant.  If T is char *, the next call to getenv() on line 253 invalidates the value saved into OptVal.  getenv() is allowed to use the same buffer for the return value.  That means the value OptVal is pointing at will be overwritten by the next call.

When T is bool you need the `!!` operators to get the char * converted to bool correctly.

I suggest leaving this function as it was and calling getenv() directly for the scenario involving CC_PRINT_HEADERS_FORMAT.  Make sure you save the getenv() results into std::string so the value isn't overridden.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137996



More information about the cfe-commits mailing list