Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 579d400

Browse files
committed
Merge branch 'llvm-4.0' of https://github.com/dylanmckay/emscripten-fastcomp-clang into next-merge
2 parents 7372fbd + d339a88 commit 579d400

File tree

2,963 files changed

+218197
-72645
lines changed

Some content is hidden

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

2,963 files changed

+218197
-72645
lines changed

CMakeLists.txt

Lines changed: 122 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
1616
"--libdir"
1717
"--includedir"
1818
"--prefix"
19-
"--src-root")
19+
"--src-root"
20+
"--cmakedir")
2021
execute_process(
2122
COMMAND ${CONFIG_COMMAND}
2223
RESULT_VARIABLE HAD_ERROR
@@ -41,6 +42,7 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
4142
list(GET CONFIG_OUTPUT 3 INCLUDE_DIR)
4243
list(GET CONFIG_OUTPUT 4 LLVM_OBJ_ROOT)
4344
list(GET CONFIG_OUTPUT 5 MAIN_SRC_DIR)
45+
list(GET CONFIG_OUTPUT 6 LLVM_CMAKE_PATH)
4446

4547
if(NOT MSVC_IDE)
4648
set(LLVM_ENABLE_ASSERTIONS ${ENABLE_ASSERTIONS}
@@ -58,7 +60,6 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
5860
find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR}
5961
NO_DEFAULT_PATH)
6062

61-
set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
6263
set(LLVMCONFIG_FILE "${LLVM_CMAKE_PATH}/LLVMConfig.cmake")
6364
if(EXISTS ${LLVMCONFIG_FILE})
6465
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
@@ -124,6 +125,7 @@ Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
124125
endif()
125126

126127
if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
128+
# Note: path not really used, except for checking if lit was found
127129
set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
128130
if(NOT LLVM_UTILS_PROVIDED)
129131
add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck)
@@ -140,8 +142,10 @@ Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
140142
endif()
141143
else()
142144
# Seek installed Lit.
143-
find_program(LLVM_LIT "lit.py" ${LLVM_MAIN_SRC_DIR}/utils/lit
144-
DOC "Path to lit.py")
145+
find_program(LLVM_LIT
146+
NAMES llvm-lit lit.py lit
147+
PATHS "${LLVM_MAIN_SRC_DIR}/utils/lit"
148+
DOC "Path to lit.py")
145149
endif()
146150

147151
if(LLVM_LIT)
@@ -177,6 +181,9 @@ if (LIBXML2_FOUND)
177181
set(CLANG_HAVE_LIBXML 1)
178182
endif()
179183

184+
include(CheckIncludeFile)
185+
check_include_file(sys/resource.h CLANG_HAVE_RLIMITS)
186+
180187
set(CLANG_RESOURCE_DIR "" CACHE STRING
181188
"Relative directory from the Clang binary to its resource files.")
182189

@@ -192,13 +199,27 @@ set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOL "pass --build-id to ld")
192199
set(ENABLE_X86_RELAX_RELOCATIONS OFF CACHE BOOL
193200
"enable x86 relax relocations by default")
194201

202+
set(CLANG_DEFAULT_LINKER "" CACHE STRING
203+
"Default linker to use (linker name or absolute path, empty for platform default)")
204+
195205
set(CLANG_DEFAULT_CXX_STDLIB "" CACHE STRING
196-
"Default C++ stdlib to use (empty for architecture default, \"libstdc++\" or \"libc++\"")
206+
"Default C++ stdlib to use (\"libstdc++\" or \"libc++\", empty for platform default")
197207
if (NOT(CLANG_DEFAULT_CXX_STDLIB STREQUAL "" OR
198208
CLANG_DEFAULT_CXX_STDLIB STREQUAL "libstdc++" OR
199209
CLANG_DEFAULT_CXX_STDLIB STREQUAL "libc++"))
200-
message(WARNING "Resetting default C++ stdlib to use architecture default")
201-
set(CLANG_DEFAULT_CXX_STDLIB "")
210+
message(WARNING "Resetting default C++ stdlib to use platform default")
211+
set(CLANG_DEFAULT_CXX_STDLIB "" CACHE STRING
212+
"Default C++ stdlib to use (\"libstdc++\" or \"libc++\", empty for platform default" FORCE)
213+
endif()
214+
215+
set(CLANG_DEFAULT_RTLIB "" CACHE STRING
216+
"Default runtime library to use (\"libgcc\" or \"compiler-rt\", empty for platform default)")
217+
if (NOT(CLANG_DEFAULT_RTLIB STREQUAL "" OR
218+
CLANG_DEFAULT_RTLIB STREQUAL "libgcc" OR
219+
CLANG_DEFAULT_RTLIB STREQUAL "compiler-rt"))
220+
message(WARNING "Resetting default rtlib to use platform default")
221+
set(CLANG_DEFAULT_RTLIB "" CACHE STRING
222+
"Default runtime library to use (\"libgcc\" or \"compiler-rt\", empty for platform default)" FORCE)
202223
endif()
203224

204225
set(CLANG_DEFAULT_OPENMP_RUNTIME "libomp" CACHE STRING
@@ -247,22 +268,19 @@ if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
247268
endif()
248269
endif()
249270

250-
# Compute the Clang version from the LLVM version.
251-
string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION
252-
${PACKAGE_VERSION})
253-
message(STATUS "Clang version: ${CLANG_VERSION}")
254-
255-
string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" CLANG_VERSION_MAJOR
256-
${CLANG_VERSION})
257-
string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" CLANG_VERSION_MINOR
258-
${CLANG_VERSION})
259-
if (${CLANG_VERSION} MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")
260-
set(CLANG_HAS_VERSION_PATCHLEVEL 1)
261-
string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" CLANG_VERSION_PATCHLEVEL
262-
${CLANG_VERSION})
263-
else()
264-
set(CLANG_HAS_VERSION_PATCHLEVEL 0)
271+
# If CLANG_VERSION_* is specified, use it, if not use LLVM_VERSION_*.
272+
if(NOT DEFINED CLANG_VERSION_MAJOR)
273+
set(CLANG_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
274+
endif()
275+
if(NOT DEFINED CLANG_VERSION_MINOR)
276+
set(CLANG_VERSION_MINOR ${LLVM_VERSION_MINOR})
265277
endif()
278+
if(NOT DEFINED CLANG_VERSION_PATCHLEVEL)
279+
set(CLANG_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH})
280+
endif()
281+
# Unlike PACKAGE_VERSION, CLANG_VERSION does not include LLVM_VERSION_SUFFIX.
282+
set(CLANG_VERSION "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}.${CLANG_VERSION_PATCHLEVEL}")
283+
message(STATUS "Clang version: ${CLANG_VERSION}")
266284

267285
# Configure the Version.inc file.
268286
configure_file(
@@ -404,6 +422,29 @@ else()
404422
endif()
405423
add_subdirectory(examples)
406424

425+
if(APPLE)
426+
# this line is needed as a cleanup to ensure that any CMakeCaches with the old
427+
# default value get updated to the new default.
428+
if(CLANG_ORDER_FILE STREQUAL "")
429+
unset(CLANG_ORDER_FILE CACHE)
430+
unset(CLANG_ORDER_FILE)
431+
endif()
432+
433+
434+
set(CLANG_ORDER_FILE ${CMAKE_CURRENT_BINARY_DIR}/clang.order CACHE FILEPATH
435+
"Order file to use when compiling clang in order to improve startup time (Darwin Only - requires ld64).")
436+
437+
if(NOT EXISTS ${CLANG_ORDER_FILE})
438+
string(FIND "${CLANG_ORDER_FILE}" "${CMAKE_CURRENT_BINARY_DIR}" PATH_START)
439+
if(PATH_START EQUAL 0)
440+
file(WRITE ${CLANG_ORDER_FILE} "\n")
441+
else()
442+
message(FATAL_ERROR "Specified order file '${CLANG_ORDER_FILE}' does not exist.")
443+
endif()
444+
endif()
445+
endif()
446+
447+
407448
if( CLANG_INCLUDE_TESTS )
408449
if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include/gtest/gtest.h)
409450
add_subdirectory(unittests)
@@ -438,37 +479,19 @@ if( CLANG_INCLUDE_DOCS )
438479
add_subdirectory(docs)
439480
endif()
440481

482+
add_subdirectory(cmake/modules)
441483

442-
if(APPLE)
443-
# this line is needed as a cleanup to ensure that any CMakeCaches with the old
444-
# default value get updated to the new default.
445-
if(CLANG_ORDER_FILE STREQUAL "")
446-
unset(CLANG_ORDER_FILE CACHE)
447-
unset(CLANG_ORDER_FILE)
448-
endif()
449-
450-
451-
set(CLANG_ORDER_FILE ${CMAKE_CURRENT_BINARY_DIR}/clang.order CACHE FILEPATH
452-
"Order file to use when compiling clang in order to improve startup time (Darwin Only - requires ld64).")
453-
454-
if(CLANG_ORDER_FILE AND NOT EXISTS ${CLANG_ORDER_FILE})
455-
string(FIND "${CLANG_ORDER_FILE}" "${CMAKE_CURRENT_BINARY_DIR}" PATH_START)
456-
if(PATH_START EQUAL 0)
457-
file(WRITE ${CLANG_ORDER_FILE} "\n")
458-
else()
459-
message(FATAL_ERROR "Specified order file '${CLANG_ORDER_FILE}' does not exist.")
460-
endif()
461-
endif()
484+
if(CLANG_STAGE)
485+
message(STATUS "Setting current clang stage to: ${CLANG_STAGE}")
462486
endif()
463487

464-
add_subdirectory(cmake/modules)
465-
466488
if (CLANG_ENABLE_BOOTSTRAP)
467489
include(ExternalProject)
468490

491+
add_custom_target(clang-bootstrap-deps DEPENDS clang)
492+
469493
if(NOT CLANG_STAGE)
470494
set(CLANG_STAGE stage1)
471-
message(STATUS "Setting current clang stage to: ${CLANG_STAGE}")
472495
endif()
473496

474497
string(REGEX MATCH "stage([0-9]*)" MATCHED_STAGE "${CLANG_STAGE}")
@@ -491,19 +514,28 @@ if (CLANG_ENABLE_BOOTSTRAP)
491514

492515
set(STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-stamps/)
493516
set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-bins/)
494-
set(cmake_command ${CMAKE_COMMAND})
495517

496-
# If the next stage is LTO we need to depend on LTO and possibly LLVMgold
497-
if(BOOTSTRAP_LLVM_ENABLE_LTO OR LLVM_ENABLE_LTO)
498-
set(LTO_DEP LTO)
518+
# If the next stage is LTO we need to depend on LTO and possibly lld or LLVMgold
519+
if(BOOTSTRAP_LLVM_ENABLE_LTO OR LLVM_ENABLE_LTO AND NOT LLVM_BUILD_INSTRUMENTED)
499520
if(APPLE)
521+
add_dependencies(clang-bootstrap-deps LTO)
500522
# on Darwin we need to set DARWIN_LTO_LIBRARY so that -flto will work
501523
# using the just-built compiler, and we need to override DYLD_LIBRARY_PATH
502524
# so that the host object file tools will use the just-built libLTO.
503-
set(LTO_LIBRARY -DDARWIN_LTO_LIBRARY=${LLVM_SHLIB_OUTPUT_INTDIR}/libLTO.dylib)
504-
set(cmake_command ${CMAKE_COMMAND} -E env DYLD_LIBRARY_PATH=${LLVM_LIBRARY_OUTPUT_INTDIR} ${CMAKE_COMMAND})
525+
# However if System Integrity Protection is enabled the DYLD variables
526+
# will be scrubbed from the environment of any base system commands. This
527+
# includes /bin/sh, which ninja uses when executing build commands. To
528+
# work around the envar being filtered away we pass it in as a CMake
529+
# variable, and have LLVM's CMake append the envar to the archiver calls.
530+
set(LTO_LIBRARY -DDARWIN_LTO_LIBRARY=${LLVM_SHLIB_OUTPUT_INTDIR}/libLTO.dylib
531+
-DDYLD_LIBRARY_PATH=${LLVM_LIBRARY_OUTPUT_INTDIR})
505532
elseif(NOT WIN32)
506-
list(APPEND LTO_DEP LLVMgold llvm-ar llvm-ranlib)
533+
add_dependencies(clang-bootstrap-deps llvm-ar llvm-ranlib)
534+
if(BOOTSTRAP_LLVM_ENABLE_LLD)
535+
add_dependencies(clang-bootstrap-deps lld)
536+
elseif(LLVM_BINUTILS_INCDIR)
537+
add_dependencies(clang-bootstrap-deps LLVMgold)
538+
endif()
507539
set(LTO_AR -DCMAKE_AR=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ar)
508540
set(LTO_RANLIB -DCMAKE_RANLIB=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ranlib)
509541
endif()
@@ -514,7 +546,7 @@ if (CLANG_ENABLE_BOOTSTRAP)
514546
)
515547
add_custom_command(
516548
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-cleared
517-
DEPENDS clang ${LTO_DEP}
549+
DEPENDS clang-bootstrap-deps
518550
COMMAND ${CMAKE_COMMAND} -E remove_directory ${BINARY_DIR}
519551
COMMAND ${CMAKE_COMMAND} -E make_directory ${BINARY_DIR}
520552
COMMAND ${CMAKE_COMMAND} -E remove_directory ${STAMP_DIR}
@@ -526,18 +558,25 @@ if (CLANG_ENABLE_BOOTSTRAP)
526558
set(verbose -DCMAKE_VERBOSE_MAKEFILE=On)
527559
endif()
528560

529-
set(BOOTSTRAP_DEFAULT_PASSTHROUGH
561+
set(_BOOTSTRAP_DEFAULT_PASSTHROUGH
530562
PACKAGE_VERSION
563+
PACKAGE_VENDOR
531564
LLVM_VERSION_MAJOR
532565
LLVM_VERSION_MINOR
533566
LLVM_VERSION_PATCH
567+
CLANG_VERSION_MAJOR
568+
CLANG_VERSION_MINOR
569+
CLANG_VERSION_PATCHLEVEL
534570
LLVM_VERSION_SUFFIX
535571
LLVM_BINUTILS_INCDIR
536572
CLANG_REPOSITORY_STRING
537-
CMAKE_MAKE_PROGRAM)
573+
CMAKE_MAKE_PROGRAM
574+
CMAKE_OSX_ARCHITECTURES)
538575

539-
if(TARGET compiler-rt)
540-
set(RUNTIME_DEP compiler-rt)
576+
# We don't need to depend on compiler-rt if we're building instrumented
577+
# because the next stage will use the same compiler used to build this stage.
578+
if(TARGET compiler-rt AND NOT LLVM_BUILD_INSTRUMENTED)
579+
add_dependencies(clang-bootstrap-deps compiler-rt)
541580
endif()
542581

543582
set(COMPILER_OPTIONS
@@ -546,18 +585,27 @@ if (CLANG_ENABLE_BOOTSTRAP)
546585
-DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
547586

548587
if(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
549-
set(PGO_DEP llvm-profdata)
588+
add_dependencies(clang-bootstrap-deps llvm-profdata)
550589
set(PGO_OPT -DLLVM_PROFDATA=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-profdata)
551590
endif()
552591

553592
if(LLVM_BUILD_INSTRUMENTED)
554-
set(PGO_DEP generate-profdata)
593+
add_dependencies(clang-bootstrap-deps generate-profdata)
555594
set(PGO_OPT -DLLVM_PROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata)
556-
set(COMPILER_OPTIONS
557-
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
558-
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
559-
-DCMAKE_ASM_COMPILER=${CMAKE_ASM_COMPILER})
560-
set(RUNTIME_DEP) # Don't set runtime dependencies
595+
# Use the current tools for LTO instead of the instrumented ones
596+
list(APPEND _BOOTSTRAP_DEFAULT_PASSTHROUGH
597+
CMAKE_CXX_COMPILER
598+
CMAKE_C_COMPILER
599+
CMAKE_ASM_COMPILER
600+
CMAKE_AR
601+
CMAKE_RANLIB
602+
DARWIN_LTO_LIBRARY
603+
DYLD_LIBRARY_PATH)
604+
605+
set(COMPILER_OPTIONS)
606+
set(LTO_LIBRARY)
607+
set(LTO_AR)
608+
set(LTO_RANLIB)
561609
endif()
562610

563611
# Find all variables that start with BOOTSTRAP_ and populate a variable with
@@ -577,16 +625,20 @@ if (CLANG_ENABLE_BOOTSTRAP)
577625
endforeach()
578626

579627
# Populate the passthrough variables
580-
foreach(variableName ${CLANG_BOOTSTRAP_PASSTHROUGH} ${BOOTSTRAP_DEFAULT_PASSTHROUGH})
581-
if(${variableName})
582-
string(REPLACE ";" "\;" value ${${variableName}})
628+
foreach(variableName ${CLANG_BOOTSTRAP_PASSTHROUGH} ${_BOOTSTRAP_DEFAULT_PASSTHROUGH})
629+
if(DEFINED ${variableName})
630+
if("${${variableName}}" STREQUAL "")
631+
set(value "")
632+
else()
633+
string(REPLACE ";" "\;" value ${${variableName}})
634+
endif()
583635
list(APPEND PASSTHROUGH_VARIABLES
584636
-D${variableName}=${value})
585637
endif()
586638
endforeach()
587639

588640
ExternalProject_Add(${NEXT_CLANG_STAGE}
589-
DEPENDS clang ${LTO_DEP} ${RUNTIME_DEP} ${PGO_DEP}
641+
DEPENDS clang-bootstrap-deps
590642
PREFIX ${NEXT_CLANG_STAGE}
591643
SOURCE_DIR ${CMAKE_SOURCE_DIR}
592644
STAMP_DIR ${STAMP_DIR}
@@ -601,7 +653,6 @@ if (CLANG_ENABLE_BOOTSTRAP)
601653
-DCLANG_STAGE=${NEXT_CLANG_STAGE}
602654
${COMPILER_OPTIONS}
603655
${LTO_LIBRARY} ${LTO_AR} ${LTO_RANLIB} ${verbose} ${PGO_OPT}
604-
CMAKE_COMMAND ${cmake_command}
605656
INSTALL_COMMAND ""
606657
STEP_TARGETS configure build
607658
USES_TERMINAL_CONFIGURE 1
@@ -612,7 +663,7 @@ if (CLANG_ENABLE_BOOTSTRAP)
612663
# exclude really-install from main target
613664
set_target_properties(${NEXT_CLANG_STAGE} PROPERTIES _EP_really-install_EXCLUDE_FROM_MAIN On)
614665
ExternalProject_Add_Step(${NEXT_CLANG_STAGE} really-install
615-
COMMAND ${cmake_command} --build <BINARY_DIR> --target install
666+
COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target install
616667
COMMENT "Performing install step for '${NEXT_CLANG_STAGE}'"
617668
DEPENDEES build
618669
USES_TERMINAL 1
@@ -628,7 +679,7 @@ if (CLANG_ENABLE_BOOTSTRAP)
628679
set_target_properties(${NEXT_CLANG_STAGE} PROPERTIES _EP_${target}_EXCLUDE_FROM_MAIN On)
629680

630681
ExternalProject_Add_Step(${NEXT_CLANG_STAGE} ${target}
631-
COMMAND ${cmake_command} --build <BINARY_DIR> --target ${target}
682+
COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target ${target}
632683
COMMENT "Performing ${target} for '${NEXT_CLANG_STAGE}'"
633684
DEPENDEES configure
634685
USES_TERMINAL 1

bindings/python/clang/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,13 @@
2020
Bindings for the Clang indexing library.
2121
"""
2222

23+
24+
# Python 3 uses unicode for strings. The bindings, in particular the interaction
25+
# with ctypes, need modifying to handle conversions between unicode and
26+
# c-strings.
27+
import sys
28+
if sys.version_info[0] != 2:
29+
raise Exception("Only Python 2 is supported.")
30+
2331
__all__ = ['cindex']
2432

0 commit comments

Comments
 (0)