blob: 8ff2c30f4925a71fc443b97cb504e969cf5ddaee [file] [log] [blame]
Nico Weber8a953292018-05-15 16:30:30 +00001//===- llvm/unittest/Support/DynamicLibrary/PipSqueak.cpp -----------------===//
Frederich Munchc1db8cf2017-04-27 16:55:24 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Frederich Munchc1db8cf2017-04-27 16:55:24 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "PipSqueak.h"
Frederich Munchd0c07002017-04-27 17:33:50 +000010
Frederich Munchc1db8cf2017-04-27 16:55:24 +000011struct Global {
12 std::string *Str;
Frederich Munchad125802017-06-05 16:26:58 +000013 std::vector<std::string> *Vec;
14 Global() : Str(nullptr), Vec(nullptr) {}
Frederich Munchc1db8cf2017-04-27 16:55:24 +000015 ~Global() {
Frederich Munchad125802017-06-05 16:26:58 +000016 if (Str) {
17 if (Vec)
18 Vec->push_back(*Str);
Frederich Munchc1db8cf2017-04-27 16:55:24 +000019 *Str = "Global::~Global";
Frederich Munchad125802017-06-05 16:26:58 +000020 }
Frederich Munchc1db8cf2017-04-27 16:55:24 +000021 }
22};
23
Frederich Munchc1db8cf2017-04-27 16:55:24 +000024static Global Glb;
25
Frederich Munchad125802017-06-05 16:26:58 +000026struct Local {
27 std::string &Str;
28 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 }
33 ~Local() { Str = "Local::~Local"; }
34};
35
36
Frederich Munchc1db8cf2017-04-27 16:55:24 +000037extern "C" PIPSQUEAK_EXPORT void SetStrings(std::string &GStr,
38 std::string &LStr) {
Frederich Munchc1db8cf2017-04-27 16:55:24 +000039 Glb.Str = &GStr;
Frederich Munchad125802017-06-05 16:26:58 +000040 static Local Lcl(LStr);
41}
42
43extern "C" PIPSQUEAK_EXPORT void TestOrder(std::vector<std::string> &V) {
44 Glb.Vec = &V;
Frederich Munchc1db8cf2017-04-27 16:55:24 +000045}
46
Frederich Munch6391c7e2017-06-13 19:05:24 +000047#define PIPSQUEAK_TESTA_RETURN "LibCall"
Nico Weber8a953292018-05-15 16:30:30 +000048#include "ExportedFuncs.cpp"