Skip to content

Commit a08caf6

Browse files
committed
Merge commit 'db2315afa8db' from llvm.org/main into next
2 parents 49dea8c + db2315a commit a08caf6

File tree

7 files changed

+66
-17
lines changed

7 files changed

+66
-17
lines changed

clang/lib/CodeGen/BackendUtil.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ getCodeModel(const CodeGenOptions &CodeGenOpts) {
312312
.Case("kernel", llvm::CodeModel::Kernel)
313313
.Case("medium", llvm::CodeModel::Medium)
314314
.Case("large", llvm::CodeModel::Large)
315-
.Case("default", ~1u)
315+
.Cases("default", "", ~1u)
316316
.Default(~0u);
317317
assert(CodeModel != ~0u && "invalid code model!");
318318
if (CodeModel == ~1u)
@@ -633,7 +633,8 @@ void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
633633
return;
634634
TM.reset(TheTarget->createTargetMachine(Triple, TargetOpts.CPU, FeaturesStr,
635635
Options, RM, CM, OptLevel));
636-
TM->setLargeDataThreshold(CodeGenOpts.LargeDataThreshold);
636+
if (TM)
637+
TM->setLargeDataThreshold(CodeGenOpts.LargeDataThreshold);
637638
}
638639

639640
bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,

clang/unittests/CMakeLists.txt

+52-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ if(CLANG_BUILT_STANDALONE)
1515
endif()
1616
endif()
1717

18-
# add_clang_unittest(test_name file1.cpp file2.cpp)
18+
# add_distinct_clang_unittest(test_name file1.cpp file2.cpp)
1919
#
2020
# Will compile the list of files together and link against the clang
2121
# Produces a binary named 'basename(test_name)'.
22-
function(add_clang_unittest test_name)
22+
function(add_distinct_clang_unittest test_name)
2323
cmake_parse_arguments(ARG
2424
""
2525
""
@@ -47,6 +47,34 @@ function(add_clang_unittest test_name)
4747
target_link_libraries(${test_name} PRIVATE ${ARG_LINK_LIBS})
4848
endfunction()
4949

50+
set(doc_opts BRIEF_DOCS "<internal setting>" FULL_DOCS "<internal settings>")
51+
define_property(GLOBAL PROPERTY CLANG_UNITTEST_SRCS ${doc_opts})
52+
define_property(GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS ${doc_opts})
53+
define_property(GLOBAL PROPERTY CLANG_UNITTEST_CLANG_LIBS ${doc_opts})
54+
define_property(GLOBAL PROPERTY CLANG_UNITTEST_LINK_LIBS ${doc_opts})
55+
56+
# add_clang_unittest(test_name file1.cpp file2.cpp)
57+
#
58+
# Adds unittests to the combined AllClangUnitTests binary. The unittest binary
59+
# is defined after adding all unittest subdirectories.
60+
function(add_clang_unittest test_name)
61+
cmake_parse_arguments(ARG
62+
""
63+
""
64+
"CLANG_LIBS;LINK_LIBS;LLVM_COMPONENTS"
65+
${ARGN})
66+
67+
file(RELATIVE_PATH src_prefix "${CMAKE_CURRENT_FUNCTION_LIST_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
68+
set(srcs_prefixed)
69+
foreach(src ${ARG_UNPARSED_ARGUMENTS})
70+
set(srcs_prefixed ${srcs_prefixed} "${src_prefix}/${src}")
71+
endforeach()
72+
set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_SRCS ${srcs_prefixed})
73+
set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_CLANG_LIBS ${ARG_CLANG_LIBS})
74+
set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_LINK_LIBS ${ARG_LINK_LIBS})
75+
set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS ${ARG_LLVM_COMPONENTS})
76+
endfunction()
77+
5078
add_subdirectory(Basic)
5179
add_subdirectory(CAS)
5280
add_subdirectory(Lex)
@@ -78,3 +106,25 @@ add_subdirectory(Index)
78106
add_subdirectory(InstallAPI)
79107
add_subdirectory(Serialization)
80108
add_subdirectory(Support)
109+
110+
111+
# If we're doing a single merged clang unit test binary, add that target after
112+
# all the previous subdirectories have been processed.
113+
get_property(SRCS GLOBAL PROPERTY CLANG_UNITTEST_SRCS)
114+
get_property(CLANG_LIBS GLOBAL PROPERTY CLANG_UNITTEST_CLANG_LIBS)
115+
get_property(LINK_LIBS GLOBAL PROPERTY CLANG_UNITTEST_LINK_LIBS)
116+
get_property(LLVM_COMPONENTS GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS)
117+
add_distinct_clang_unittest(AllClangUnitTests
118+
${SRCS}
119+
CLANG_LIBS
120+
${CLANG_LIBS}
121+
LINK_LIBS
122+
${LINK_LIBS}
123+
LLVM_COMPONENTS
124+
${LLVM_COMPONENTS}
125+
)
126+
127+
# The Tooling library has some internal headers. Make those work. If we like
128+
# the merged clang unit test binary, we can update the include paths and make
129+
# this the default.
130+
include_directories(Tooling)

clang/unittests/Driver/ModuleCacheTest.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ using namespace clang::driver;
1717

1818
namespace {
1919

20-
TEST(ModuleCacheTest, GetTargetAndMode) {
20+
TEST(DriverModuleCacheTest, GetTargetAndMode) {
2121
SmallString<128> Buf;
2222
Driver::getDefaultModuleCachePath(Buf);
2323
StringRef Path = Buf;

clang/unittests/Frontend/OutputStreamTest.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
#include "clang/Basic/LangStandard.h"
1010
#include "clang/CodeGen/BackendUtil.h"
11-
#include "clang/CodeGen/CodeGenAction.h"
1211
#include "clang/Frontend/CompilerInstance.h"
1312
#include "clang/Frontend/TextDiagnosticPrinter.h"
1413
#include "clang/FrontendTool/Utils.h"
1514
#include "clang/Lex/PreprocessorOptions.h"
15+
#include "llvm/Support/TargetSelect.h"
1616
#include "llvm/Support/VirtualFileSystem.h"
1717
#include "gtest/gtest.h"
1818

@@ -23,6 +23,7 @@ using namespace clang::frontend;
2323
namespace {
2424

2525
TEST(FrontendOutputTests, TestOutputStream) {
26+
llvm::InitializeAllTargetMCs();
2627
auto Invocation = std::make_shared<CompilerInvocation>();
2728
Invocation->getPreprocessorOpts().addRemappedFile(
2829
"test.cc", MemoryBuffer::getMemBuffer("").release());
@@ -47,6 +48,7 @@ TEST(FrontendOutputTests, TestOutputStream) {
4748
}
4849

4950
TEST(FrontendOutputTests, TestVerboseOutputStreamShared) {
51+
llvm::InitializeAllTargetMCs();
5052
auto Invocation = std::make_shared<CompilerInvocation>();
5153
Invocation->getPreprocessorOpts().addRemappedFile(
5254
"test.cc", MemoryBuffer::getMemBuffer("invalid").release());
@@ -77,6 +79,7 @@ TEST(FrontendOutputTests, TestVerboseOutputStreamOwned) {
7779
std::string VerboseBuffer;
7880
bool Success;
7981
{
82+
llvm::InitializeAllTargetMCs();
8083
auto Invocation = std::make_shared<CompilerInvocation>();
8184
Invocation->getPreprocessorOpts().addRemappedFile(
8285
"test.cc", MemoryBuffer::getMemBuffer("invalid").release());

clang/unittests/Interpreter/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
add_clang_unittest(ClangReplInterpreterTests
1+
add_distinct_clang_unittest(ClangReplInterpreterTests
22
IncrementalCompilerBuilderTest.cpp
33
IncrementalProcessingTest.cpp
44
InterpreterTest.cpp

clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set(LLVM_REQUIRES_EH ON)
44
set(LLVM_REQUIRES_RTTI ON)
55

6-
add_clang_unittest(ClangReplInterpreterExceptionTests
6+
add_distinct_clang_unittest(ClangReplInterpreterExceptionTests
77
InterpreterExceptionTest.cpp
88
EXPORT_SYMBOLS
99

clang/unittests/Parse/CMakeLists.txt

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
1-
set(LLVM_LINK_COMPONENTS
2-
Support
3-
)
41
add_clang_unittest(ParseTests
52
ParseHLSLRootSignatureTest.cpp
6-
)
7-
clang_target_link_libraries(ParseTests
8-
PRIVATE
3+
CLANG_LIBS
94
clangAST
105
clangBasic
116
clangLex
127
clangParse
138
clangSema
14-
)
15-
target_link_libraries(ParseTests
16-
PRIVATE
9+
LINK_LIBS
1710
LLVMTestingAnnotations
1811
LLVMTestingSupport
1912
clangTesting
13+
LLVM_COMPONENTS
14+
Support
2015
)

0 commit comments

Comments
 (0)