[PATCH] D61165: Fix a crash where a [[no_destroy]] destructor was not emitted in an array

Erik Pilkington via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 26 14:29:13 PDT 2019


erik.pilkington added a comment.

JF, Michael, and I were talking about this offline, and we think that the right choice of semantics for the static local case is to call the destructors.

  struct HoldsResource {
    HoldsResource() { tryToAcquireItMayThrow(); }
    ~HoldsResource() { releaseIt(); }
  };
  
  void doSomeThings() {
    try { 
      [[clang::no_destroy]] static HoldsResource MyResources[10];
    } catch (...) {
      /* recover gracefully somehow.... */
    }
  }

Here, its possible to call `doSomeThings` many times, until it actually manages to construct `MyResources`. Just not calling the dtor doesn't seem right since we'd be leaking resources. Calling `terminate` doesn't make sense either, since its possible to recover from this and try again or continue. `no_destroy` doesn't mean don't destroy (lol), it means don't register exit-time dtors, that's why it only applies to static/thread local declarations. @rjmccall: WDYT? This is obviously a pretty narrow edge-case.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61165





More information about the cfe-commits mailing list