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

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 5 23:05:01 PST 2023


ahatanak added inline comments.


================
Comment at: clang/tools/driver/driver.cpp:251
+                     std::string &OptFile) {
+  T OptVal = ::getenv(EnvOptSet);
+  if (OptVal) {
----------------
SeanP wrote:
> 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.
Thank you for notifying me of the bug. It should be fixed in https://github.com/llvm/llvm-project/commit/34aa2e24c89ae39c0db4254d8aafcae0285dbe34


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