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 
9 #include "PipSqueak.h"
10 
11 struct Global {
12   std::string *Str;
13   std::vector<std::string> *Vec;
GlobalGlobal14   Global() : Str(nullptr), Vec(nullptr) {}
~GlobalGlobal15   ~Global() {
16     if (Str) {
17       if (Vec)
18         Vec->push_back(*Str);
19       *Str = "Global::~Global";
20     }
21   }
22 };
23 
24 static Global Glb;
25 
26 struct Local {
27   std::string &Str;
LocalLocal28   Local(std::string &S) : Str(S) {
29     Str = "Local::Local";
30     if (Glb.Str && !Glb.Str->empty())
31       Str += std::string("(") + *Glb.Str + std::string(")");
32   }
~LocalLocal33   ~Local() { Str = "Local::~Local"; }
34 };
35 
36 
SetStrings(std::string & GStr,std::string & LStr)37 extern "C" PIPSQUEAK_EXPORT void SetStrings(std::string &GStr,
38                                             std::string &LStr) {
39   Glb.Str = &GStr;
40   static Local Lcl(LStr);
41 }
42 
TestOrder(std::vector<std::string> & V)43 extern "C" PIPSQUEAK_EXPORT void TestOrder(std::vector<std::string> &V) {
44   Glb.Vec = &V;
45 }
46 
47 #define PIPSQUEAK_TESTA_RETURN "LibCall"
48 #include "ExportedFuncs.cpp"
49