Skip to content

Commit 3fb3c89

Browse files
author
z1_cciauto
authored
merge main into amd-staging (llvm#3498)
2 parents 858523c + 47c9c48 commit 3fb3c89

File tree

108 files changed

+7458
-3842
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+7458
-3842
lines changed

clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,15 +555,22 @@ bool NarrowingConversionsCheck::handleConditionalOperator(
555555
// We have an expression like so: `output = cond ? lhs : rhs`
556556
// From the point of view of narrowing conversion we treat it as two
557557
// expressions `output = lhs` and `output = rhs`.
558-
handleBinaryOperator(Context, CO->getLHS()->getExprLoc(), Lhs,
559-
*CO->getLHS());
560-
handleBinaryOperator(Context, CO->getRHS()->getExprLoc(), Lhs,
561-
*CO->getRHS());
558+
handleConditionalOperatorArgument(Context, Lhs, CO->getLHS());
559+
handleConditionalOperatorArgument(Context, Lhs, CO->getRHS());
562560
return true;
563561
}
564562
return false;
565563
}
566564

565+
void NarrowingConversionsCheck::handleConditionalOperatorArgument(
566+
const ASTContext &Context, const Expr &Lhs, const Expr *Arg) {
567+
if (const auto *ICE = llvm::dyn_cast<ImplicitCastExpr>(Arg))
568+
if (!Arg->getIntegerConstantExpr(Context))
569+
Arg = ICE->getSubExpr();
570+
571+
handleBinaryOperator(Context, Arg->getExprLoc(), Lhs, *Arg);
572+
}
573+
567574
void NarrowingConversionsCheck::handleImplicitCast(
568575
const ASTContext &Context, const ImplicitCastExpr &Cast) {
569576
if (Cast.getExprLoc().isMacroID())

clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class NarrowingConversionsCheck : public ClangTidyCheck {
8585
bool handleConditionalOperator(const ASTContext &Context, const Expr &Lhs,
8686
const Expr &Rhs);
8787

88+
void handleConditionalOperatorArgument(const ASTContext &Context,
89+
const Expr &Lhs, const Expr *Arg);
8890
void handleImplicitCast(const ASTContext &Context,
8991
const ImplicitCastExpr &Cast);
9092

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ Changes in existing checks
134134
<clang-tidy/checks/bugprone/infinite-loop>` check by adding detection for
135135
variables introduced by structured bindings.
136136

137+
- Improved :doc:`bugprone-narrowing-conversions
138+
<clang-tidy/checks/bugprone/narrowing-conversions>` check by fixing
139+
false positive from analysis of a conditional expression in C.
140+
137141
- Improved :doc:`bugprone-reserved-identifier
138142
<clang-tidy/checks/bugprone/reserved-identifier>` check by ignoring
139143
declarations in system headers.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %check_clang_tidy %s bugprone-narrowing-conversions %t -- \
2+
// RUN: -- -target x86_64-unknown-linux
3+
4+
char test_char(int cond, char c) {
5+
char ret = cond > 0 ? ':' : c;
6+
return ret;
7+
}
8+
9+
short test_short(int cond, short s) {
10+
short ret = cond > 0 ? ':' : s;
11+
return ret;
12+
}
13+
14+
int test_int(int cond, int i) {
15+
int ret = cond > 0 ? ':' : i;
16+
return ret;
17+
}
18+
19+
void test(int cond, int i) {
20+
char x = cond > 0 ? ':' : i;
21+
// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: narrowing conversion from 'int' to signed type 'char' is implementation-defined [bugprone-narrowing-conversions]
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %check_clang_tidy %s bugprone-narrowing-conversions %t -- \
2+
// RUN: -- -target x86_64-unknown-linux
3+
4+
char test_char(int cond, char c) {
5+
char ret = cond > 0 ? ':' : c;
6+
return ret;
7+
}
8+
9+
short test_short(int cond, short s) {
10+
short ret = cond > 0 ? ':' : s;
11+
return ret;
12+
}
13+
14+
int test_int(int cond, int i) {
15+
int ret = cond > 0 ? ':' : i;
16+
return ret;
17+
}
18+
19+
void test(int cond, int i) {
20+
char x = cond > 0 ? ':' : i;
21+
// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: narrowing conversion from 'int' to signed type 'char' is implementation-defined [bugprone-narrowing-conversions]
22+
}

clang/include/clang/Interpreter/RemoteJITUtils.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626

2727
llvm::Expected<std::unique_ptr<llvm::orc::SimpleRemoteEPC>>
2828
launchExecutor(llvm::StringRef ExecutablePath, bool UseSharedMemory,
29-
llvm::StringRef SlabAllocateSizeString);
29+
llvm::StringRef SlabAllocateSizeString,
30+
std::function<void()> CustomizeFork = nullptr);
3031

3132
/// Create a JITLinkExecutor that connects to the given network address
3233
/// through a TCP socket. A valid NetworkAddress provides hostname and port,
@@ -35,4 +36,13 @@ llvm::Expected<std::unique_ptr<llvm::orc::SimpleRemoteEPC>>
3536
connectTCPSocket(llvm::StringRef NetworkAddress, bool UseSharedMemory,
3637
llvm::StringRef SlabAllocateSizeString);
3738

39+
#ifdef LLVM_ON_UNIX
40+
/// Returns PID of last launched executor.
41+
pid_t getLastLaunchedExecutorPID();
42+
43+
/// Returns PID of nth launched executor.
44+
/// 1-based indexing.
45+
pid_t getNthLaunchedExecutorPID(int n);
46+
#endif
47+
3848
#endif // LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H

clang/lib/Interpreter/RemoteJITUtils.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
using namespace llvm;
3434
using namespace llvm::orc;
3535

36+
#if LLVM_ON_UNIX
37+
static std::vector<pid_t> LaunchedExecutorPID;
38+
#endif
39+
3640
Expected<uint64_t> getSlabAllocSize(StringRef SizeString) {
3741
SizeString = SizeString.trim();
3842

@@ -89,9 +93,14 @@ createSharedMemoryManager(SimpleRemoteEPC &SREPC,
8993
SlabSize, SREPC, SAs);
9094
}
9195

96+
// Launches an out-of-process executor for remote JIT. The calling program can
97+
// provide a CustomizeFork callback, which allows it to run custom code in the
98+
// child process before exec. This enables sending custom setup or code to be
99+
// executed in the child (out-of-process) executor.
92100
Expected<std::unique_ptr<SimpleRemoteEPC>>
93101
launchExecutor(StringRef ExecutablePath, bool UseSharedMemory,
94-
llvm::StringRef SlabAllocateSizeString) {
102+
llvm::StringRef SlabAllocateSizeString,
103+
std::function<void()> CustomizeFork) {
95104
#ifndef LLVM_ON_UNIX
96105
// FIXME: Add support for Windows.
97106
return make_error<StringError>("-" + ExecutablePath +
@@ -134,6 +143,9 @@ launchExecutor(StringRef ExecutablePath, bool UseSharedMemory,
134143
close(ToExecutor[WriteEnd]);
135144
close(FromExecutor[ReadEnd]);
136145

146+
if (CustomizeFork)
147+
CustomizeFork();
148+
137149
// Execute the child process.
138150
std::unique_ptr<char[]> ExecutorPath, FDSpecifier;
139151
{
@@ -158,6 +170,8 @@ launchExecutor(StringRef ExecutablePath, bool UseSharedMemory,
158170
}
159171
// else we're the parent...
160172

173+
LaunchedExecutorPID.push_back(ChildPID);
174+
161175
// Close the child ends of the pipes
162176
close(ToExecutor[ReadEnd]);
163177
close(FromExecutor[WriteEnd]);
@@ -265,3 +279,18 @@ connectTCPSocket(StringRef NetworkAddress, bool UseSharedMemory,
265279
std::move(S), *SockFD, *SockFD);
266280
#endif
267281
}
282+
283+
#if LLVM_ON_UNIX
284+
285+
pid_t getLastLaunchedExecutorPID() {
286+
if (!LaunchedExecutorPID.size())
287+
return -1;
288+
return LaunchedExecutorPID.back();
289+
}
290+
291+
pid_t getNthLaunchedExecutorPID(int n) {
292+
if (n - 1 < 0 || n - 1 >= static_cast<int>(LaunchedExecutorPID.size()))
293+
return -1;
294+
return LaunchedExecutorPID.at(n - 1);
295+
}
296+
#endif

clang/unittests/Interpreter/CMakeLists.txt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
add_distinct_clang_unittest(ClangReplInterpreterTests
1+
set(CLANG_REPL_TEST_SOURCES
22
IncrementalCompilerBuilderTest.cpp
33
IncrementalProcessingTest.cpp
44
InterpreterTest.cpp
55
InterpreterExtensionsTest.cpp
66
CodeCompletionTest.cpp
7+
)
78

9+
if(TARGET compiler-rt)
10+
list(APPEND CLANG_REPL_TEST_SOURCES
11+
OutOfProcessInterpreterTests.cpp
12+
)
13+
message(STATUS "Compiler-RT found, enabling out of process JIT tests")
14+
endif()
15+
16+
add_distinct_clang_unittest(ClangReplInterpreterTests
17+
${CLANG_REPL_TEST_SOURCES}
18+
19+
PARTIAL_SOURCES_INTENDED
820
EXPORT_SYMBOLS
921

1022
CLANG_LIBS
@@ -26,6 +38,14 @@ add_distinct_clang_unittest(ClangReplInterpreterTests
2638
TargetParser
2739
)
2840

41+
if(TARGET compiler-rt)
42+
add_dependencies(ClangReplInterpreterTests
43+
llvm-jitlink-executor
44+
compiler-rt
45+
)
46+
message(STATUS "Adding dependency on compiler-rt for out of process JIT tests")
47+
endif()
48+
2949
# Exceptions on Windows are not yet supported.
3050
if(NOT WIN32)
3151
add_subdirectory(ExceptionTests)

clang/unittests/Interpreter/InterpreterTest.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@
1515
#include "clang/AST/Decl.h"
1616
#include "clang/AST/DeclGroup.h"
1717
#include "clang/AST/Mangle.h"
18+
#include "clang/Basic/Version.h"
19+
#include "clang/Config/config.h"
1820
#include "clang/Frontend/CompilerInstance.h"
1921
#include "clang/Frontend/TextDiagnosticPrinter.h"
2022
#include "clang/Interpreter/Interpreter.h"
23+
#include "clang/Interpreter/RemoteJITUtils.h"
2124
#include "clang/Interpreter/Value.h"
2225
#include "clang/Sema/Lookup.h"
2326
#include "clang/Sema/Sema.h"
27+
#include "llvm/Support/Error.h"
28+
#include "llvm/TargetParser/Host.h"
2429

2530
#include "llvm/TargetParser/Host.h"
2631

@@ -34,6 +39,12 @@ int Global = 42;
3439
REPL_EXTERNAL_VISIBILITY int getGlobal() { return Global; }
3540
REPL_EXTERNAL_VISIBILITY void setGlobal(int val) { Global = val; }
3641

42+
#ifdef _WIN32
43+
#define STDIN_FILENO 0
44+
#define STDOUT_FILENO 1
45+
#define STDERR_FILENO 2
46+
#endif
47+
3748
namespace {
3849

3950
class InterpreterTest : public InterpreterTestBase {

0 commit comments

Comments
 (0)