Skip to content

Commit 2b3ae75

Browse files
author
kr-2003
committed
clang-tidy
1 parent 75f72fc commit 2b3ae75

File tree

8 files changed

+28
-24
lines changed

8 files changed

+28
-24
lines changed

lib/CppInterOp/CppInterOp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include <algorithm>
5656
#include <cassert>
5757
#include <cstddef>
58+
#include <cstdio>
5859
#include <deque>
5960
#include <iterator>
6061
#include <map>

lib/CppInterOp/CppInterOpInterpreter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@
3939
#include "llvm/Support/raw_ostream.h"
4040
#include "llvm/TargetParser/Triple.h"
4141

42-
#include <fcntl.h>
4342
#ifndef _WIN32
4443
#include <unistd.h>
4544
#endif
4645
#include <algorithm>
4746
#include <cstdio>
4847
#include <utility>
4948
#include <vector>
49+
#include <stdio.h>
5050

5151
namespace clang {
5252
class CompilerInstance;
@@ -148,7 +148,7 @@ namespace Cpp {
148148
class Interpreter {
149149
private:
150150
struct FileDeleter {
151-
void operator()(FILE* f) {
151+
void operator()(FILE* f /* owns */) {
152152
if (f)
153153
fclose(f);
154154
}

unittests/CppInterOp/FunctionReflectionTest.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ TEST(FunctionReflectionTest, GetFunctionAddress) {
14031403
#ifdef _WIN32
14041404
GTEST_SKIP() << "Disabled on Windows. Needs fixing.";
14051405
#endif
1406-
if (TestUtils::g_use_oop_jit) {
1406+
if (TestUtils::use_oop_jit()) {
14071407
GTEST_SKIP() << "Test fails for OOP JIT builds";
14081408
}
14091409
std::vector<Decl*> Decls, SubDecls;
@@ -1452,7 +1452,7 @@ TEST(FunctionReflectionTest, JitCallAdvanced) {
14521452
GTEST_SKIP() << "Test fails for Emscipten builds";
14531453
#endif
14541454
#endif
1455-
if (TestUtils::g_use_oop_jit) {
1455+
if (TestUtils::use_oop_jit()) {
14561456
GTEST_SKIP() << "Test fails for OOP JIT builds";
14571457
}
14581458
if (llvm::sys::RunningOnValgrind())
@@ -1503,7 +1503,7 @@ TEST(FunctionReflectionTest, JitCallDebug) {
15031503
GTEST_SKIP() << "Test fails for Emscipten builds";
15041504
#endif
15051505
#endif
1506-
if (TestUtils::g_use_oop_jit) {
1506+
if (TestUtils::use_oop_jit()) {
15071507
GTEST_SKIP() << "Test fails for OOP JIT builds";
15081508
}
15091509
if (llvm::sys::RunningOnValgrind())
@@ -1597,7 +1597,7 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) {
15971597
#ifdef EMSCRIPTEN
15981598
GTEST_SKIP() << "Test fails for Emscipten builds";
15991599
#endif
1600-
if (TestUtils::g_use_oop_jit) {
1600+
if (TestUtils::use_oop_jit()) {
16011601
GTEST_SKIP() << "Test fails for OOP JIT builds";
16021602
}
16031603
if (llvm::sys::RunningOnValgrind())
@@ -2127,7 +2127,7 @@ TEST(FunctionReflectionTest, Construct) {
21272127
GTEST_SKIP() << "Test fails for Emscipten builds";
21282128
#endif
21292129
#endif
2130-
if (TestUtils::g_use_oop_jit) {
2130+
if (TestUtils::use_oop_jit()) {
21312131
GTEST_SKIP() << "Test fails for OOP JIT builds";
21322132
}
21332133
if (llvm::sys::RunningOnValgrind())
@@ -2211,7 +2211,7 @@ TEST(FunctionReflectionTest, ConstructPOD) {
22112211
GTEST_SKIP() << "Test fails for Emscipten builds";
22122212
#endif
22132213
#endif
2214-
if (TestUtils::g_use_oop_jit) {
2214+
if (TestUtils::use_oop_jit()) {
22152215
GTEST_SKIP() << "Test fails for OOP JIT builds";
22162216
}
22172217
if (llvm::sys::RunningOnValgrind())
@@ -2262,7 +2262,7 @@ TEST(FunctionReflectionTest, ConstructNested) {
22622262
#ifdef _WIN32
22632263
GTEST_SKIP() << "Disabled on Windows. Needs fixing.";
22642264
#endif
2265-
if (TestUtils::g_use_oop_jit) {
2265+
if (TestUtils::use_oop_jit()) {
22662266
GTEST_SKIP() << "Test fails for OOP JIT builds";
22672267
}
22682268

@@ -2328,7 +2328,7 @@ TEST(FunctionReflectionTest, ConstructArray) {
23282328
#if defined(__APPLE__) && (CLANG_VERSION_MAJOR == 16)
23292329
GTEST_SKIP() << "Test fails on Clang16 OS X";
23302330
#endif
2331-
if (TestUtils::g_use_oop_jit) {
2331+
if (TestUtils::use_oop_jit()) {
23322332
GTEST_SKIP() << "Test fails for OOP JIT builds";
23332333
}
23342334

@@ -2384,7 +2384,7 @@ TEST(FunctionReflectionTest, Destruct) {
23842384
#ifdef _WIN32
23852385
GTEST_SKIP() << "Disabled on Windows. Needs fixing.";
23862386
#endif
2387-
if (TestUtils::g_use_oop_jit) {
2387+
if (TestUtils::use_oop_jit()) {
23882388
GTEST_SKIP() << "Test fails for OOP JIT builds";
23892389
}
23902390

@@ -2461,7 +2461,7 @@ TEST(FunctionReflectionTest, DestructArray) {
24612461
#if defined(__APPLE__) && (CLANG_VERSION_MAJOR == 16)
24622462
GTEST_SKIP() << "Test fails on Clang16 OS X";
24632463
#endif
2464-
if (TestUtils::g_use_oop_jit) {
2464+
if (TestUtils::use_oop_jit()) {
24652465
GTEST_SKIP() << "Test fails for OOP JIT builds";
24662466
}
24672467

unittests/CppInterOp/InterpreterTest.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ TEST(InterpreterTest, Evaluate) {
6565
#ifdef _WIN32
6666
GTEST_SKIP() << "Disabled on Windows. Needs fixing.";
6767
#endif
68-
if (TestUtils::g_use_oop_jit) {
68+
if (TestUtils::use_oop_jit()) {
6969
GTEST_SKIP() << "Test fails for OOP JIT builds";
7070
}
7171

@@ -85,7 +85,7 @@ TEST(InterpreterTest, Evaluate) {
8585
}
8686

8787
TEST(InterpreterTest, DeleteInterpreter) {
88-
if (TestUtils::g_use_oop_jit) {
88+
if (TestUtils::use_oop_jit()) {
8989
GTEST_SKIP() << "Test fails for OOP JIT builds";
9090
}
9191
auto* I1 = TestUtils::CreateInterpreter();
@@ -109,7 +109,7 @@ TEST(InterpreterTest, ActivateInterpreter) {
109109
#ifdef EMSCRIPTEN_STATIC_LIBRARY
110110
GTEST_SKIP() << "Test fails for Emscipten static library build";
111111
#endif
112-
if (TestUtils::g_use_oop_jit) {
112+
if (TestUtils::use_oop_jit()) {
113113
GTEST_SKIP() << "Test fails for OOP JIT builds";
114114
}
115115
EXPECT_FALSE(Cpp::ActivateInterpreter(nullptr));
@@ -152,7 +152,7 @@ TEST(InterpreterTest, Process) {
152152
EXPECT_FALSE(Cpp::Process("int f(); int res = f();") == 0);
153153

154154
// C API
155-
if (!TestUtils::g_use_oop_jit) {
155+
if (!TestUtils::use_oop_jit()) {
156156
auto* CXI = clang_createInterpreterFromRawPtr(I);
157157
clang_Interpreter_declare(CXI, "#include <iostream>", false);
158158
clang_Interpreter_process(CXI, "int c = 42;");
@@ -281,7 +281,7 @@ TEST(InterpreterTest, DetectSystemCompilerIncludePaths) {
281281
}
282282

283283
TEST(InterpreterTest, IncludePaths) {
284-
if (TestUtils::g_use_oop_jit) {
284+
if (TestUtils::use_oop_jit()) {
285285
GTEST_SKIP() << "Test fails for OOP JIT builds";
286286
}
287287
std::vector<std::string> includes;

unittests/CppInterOp/JitTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ TEST(JitTest, InsertOrReplaceJitSymbol) {
2020
#ifdef _WIN32
2121
GTEST_SKIP() << "Disabled on Windows. Needs fixing.";
2222
#endif
23-
if (TestUtils::g_use_oop_jit) {
23+
if (TestUtils::use_oop_jit()) {
2424
GTEST_SKIP() << "Test fails for OOP JIT builds";
2525
}
2626
std::vector<Decl*> Decls;
@@ -45,7 +45,7 @@ TEST(JitTest, InsertOrReplaceJitSymbol) {
4545
TEST(Streams, StreamRedirect) {
4646
// printf and etc are fine here.
4747
// NOLINTBEGIN(cppcoreguidelines-pro-type-vararg)
48-
if (TestUtils::g_use_oop_jit) {
48+
if (TestUtils::use_oop_jit()) {
4949
GTEST_SKIP() << "Test fails for OOP JIT builds";
5050
}
5151
Cpp::BeginStdStreamCapture(Cpp::kStdOut);
@@ -98,7 +98,7 @@ TEST(Streams, StreamRedirectJIT) {
9898
printf("%s\n", "Hello World");
9999
fflush(stdout);
100100
)");
101-
std::string CapturedStringErr = Cpp::EndStdStreamCapture();
101+
std::string _ = Cpp::EndStdStreamCapture();
102102
std::string CapturedStringOut = Cpp::EndStdStreamCapture();
103103

104104
EXPECT_STREQ(CapturedStringOut.c_str(), "Hello World\n");

unittests/CppInterOp/Utils.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
using namespace clang;
1717
using namespace llvm;
1818

19-
bool TestUtils::g_use_oop_jit = false;
19+
bool& TestUtils::use_oop_jit() {
20+
static bool flag = false;
21+
return flag;
22+
}
2023

2124
void TestUtils::GetAllTopLevelDecls(
2225
const std::string& code, std::vector<Decl*>& Decls,
@@ -62,7 +65,7 @@ void TestUtils::GetAllSubDecls(Decl* D, std::vector<Decl*>& SubDecls,
6265
TInterp_t TestUtils::CreateInterpreter(const std::vector<const char*>& Args,
6366
const std::vector<const char*>& GpuArgs) {
6467
auto mergedArgs = Args;
65-
if (TestUtils::g_use_oop_jit) {
68+
if (TestUtils::use_oop_jit()) {
6669
mergedArgs.push_back("--use-oop-jit");
6770
}
6871
return Cpp::CreateInterpreter(mergedArgs, GpuArgs);

unittests/CppInterOp/Utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Decl;
2020
}
2121
#define Interp (static_cast<compat::Interpreter*>(Cpp::GetInterpreter()))
2222
namespace TestUtils {
23-
extern bool g_use_oop_jit;
23+
bool& use_oop_jit();
2424
void GetAllTopLevelDecls(const std::string& code,
2525
std::vector<clang::Decl*>& Decls,
2626
bool filter_implicitGenerated = false,

unittests/CppInterOp/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ void parseCustomArguments(int argc, char** argv) {
55
for (int i = 1; i < argc; ++i) {
66
std::string arg(argv[i]);
77
if (arg == "--use-oop-jit") {
8-
TestUtils::g_use_oop_jit = true;
8+
TestUtils::use_oop_jit() = true;
99
}
1010
}
1111
}

0 commit comments

Comments
 (0)