PipSqueak.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //===- llvm/unittest/Support/DynamicLibrary/PipSqueak.cpp -----------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "PipSqueak.h"
  9. struct Global {
  10. std::string *Str;
  11. std::vector<std::string> *Vec;
  12. Global() : Str(nullptr), Vec(nullptr) {}
  13. ~Global() {
  14. if (Str) {
  15. if (Vec)
  16. Vec->push_back(*Str);
  17. *Str = "Global::~Global";
  18. }
  19. }
  20. };
  21. static Global Glb;
  22. struct Local {
  23. std::string &Str;
  24. Local(std::string &S) : Str(S) {
  25. Str = "Local::Local";
  26. if (Glb.Str && !Glb.Str->empty())
  27. Str += std::string("(") + *Glb.Str + std::string(")");
  28. }
  29. ~Local() { Str = "Local::~Local"; }
  30. };
  31. extern "C" PIPSQUEAK_EXPORT void SetStrings(std::string &GStr,
  32. std::string &LStr) {
  33. Glb.Str = &GStr;
  34. static Local Lcl(LStr);
  35. }
  36. extern "C" PIPSQUEAK_EXPORT void TestOrder(std::vector<std::string> &V) {
  37. Glb.Vec = &V;
  38. }
  39. #define PIPSQUEAK_TESTA_RETURN "LibCall"
  40. #include "ExportedFuncs.cpp"