brintos

brintos / llvm-project-archived public Read only

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