[all-commits] [llvm/llvm-project] cc9221: [libc] Remove global constructors on File type

Joseph Huber via All-commits all-commits at lists.llvm.org
Thu Jul 20 06:11:35 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: cc92212d75dff07644e478c55a6f145c020f6f8e
      https://github.com/llvm/llvm-project/commit/cc92212d75dff07644e478c55a6f145c020f6f8e
  Author: Joseph Huber <jhuber6 at vols.utk.edu>
  Date:   2023-07-20 (Thu, 20 Jul 2023)

  Changed paths:
    M libc/src/__support/File/file.h

  Log Message:
  -----------
  [libc] Remove global constructors on File type

The `File` interface currently has a destructor to delete the buffer if
it is owned by the file. This is problematic for the globally allocated
`stdout`, `stdin`, and `stderr` files. This causes the file interface to
have global constructors to initialize the destructors to use these.
However, these never use the destructors because they don't own the
buffer. This patch removes the destructor and calls in manually in the
close implementation. The platform close should never need to access the
buffer and it needs to be done before clearing the whole thing, so this
should work.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D155762


  Commit: ed7ade9cfa56acae3c67bdf837dec05555769e3c
      https://github.com/llvm/llvm-project/commit/ed7ade9cfa56acae3c67bdf837dec05555769e3c
  Author: Joseph Huber <jhuber6 at vols.utk.edu>
  Date:   2023-07-20 (Thu, 20 Jul 2023)

  Changed paths:
    M libc/src/unistd/getopt.cpp
    M libc/src/unistd/getopt.h
    M libc/test/src/unistd/getopt_test.cpp

  Log Message:
  -----------
  [libc] Remove global constructor in `getopt` implementation

This file required a global constructor due to copying the file stream
and have a non-constexpr constructor for the wrapper type. Also, I
changes the `opterr` to be a pointer, because it seemed like it wasn't
being set correctly as an externally visibile variable if we just
captured it by value.

Reviewed By: abrachet

Differential Revision: https://reviews.llvm.org/D155766


Compare: https://github.com/llvm/llvm-project/compare/60152f198333...ed7ade9cfa56


More information about the All-commits mailing list