Skip to content

Commit 4ecb2f7

Browse files
committed
Merge branch 'master' into release-0.17.0
2 parents 5b6f07e + 4bbf89b commit 4ecb2f7

26 files changed

+552
-254
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ env:
5252
matrix:
5353
allow_failures:
5454
- env: LLVM_CONFIG="llvm-config-3.9"
55-
- os: osx
56-
env: LLVM_CONFIG="llvm-config-3.6" TEST_CONFIG="Release"
5755
exclude:
5856
- os: linux
5957
env: LLVM_CONFIG="llvm-config-3.6" TEST_CONFIG="Debug"

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ include(CheckCXXCompilerFlag)
1616
#
1717

1818
find_package(LLVM 3.5 REQUIRED
19-
all-targets analysis asmparser asmprinter bitreader bitwriter codegen core debuginfodwarf instcombine ipa ipo instrumentation irreader linker lto mc mcdisassembler mcparser objcarcopts object option profiledata scalaropts selectiondag support tablegen target transformutils vectorize ${EXTRA_LLVM_MODULES})
19+
all-targets analysis asmparser asmprinter bitreader bitwriter codegen core debuginfocodeview debuginfodwarf debuginfopdb instcombine ipa ipo instrumentation irreader linker lto mc mcdisassembler mcparser objcarcopts object option profiledata scalaropts selectiondag support tablegen target transformutils vectorize ${EXTRA_LLVM_MODULES})
2020
math(EXPR LDC_LLVM_VER ${LLVM_VERSION_MAJOR}*100+${LLVM_VERSION_MINOR})
2121
# Remove LLVMTableGen library from list of libraries
2222
string(REGEX MATCH "^-.*LLVMTableGen[^;]*;|;-.*LLVMTableGen[^;]*" LLVM_TABLEGEN_LIBRARY "${LLVM_LIBRARIES}")

cmake/Modules/FindLLVM.cmake

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,17 @@ if ((WIN32 AND NOT(MINGW OR CYGWIN)) OR NOT LLVM_CONFIG)
6868
if(TARGET_AArch64 GREATER -1)
6969
list(APPEND LLVM_FIND_COMPONENTS AArch64Utils)
7070
endif()
71-
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "backend" index)
72-
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-2][\\.0-9A-Za-z]*")
73-
# Versions below 3.3 do not support components objcarcopts, option
74-
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "objcarcopts" index)
75-
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "option" index)
76-
endif()
77-
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-4][\\.0-9A-Za-z]*")
78-
# Versions below 3.5 do not support components lto, profiledata
79-
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "lto" index)
80-
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "profiledata" index)
81-
endif()
8271
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-6][\\.0-9A-Za-z]*")
83-
# Versions below 3.7 do not support components debuginfodwarf
72+
# Versions below 3.7 do not support components debuginfo[dwarf|pdb]
8473
# Only debuginfo is available
8574
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfodwarf" index)
75+
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfopdb" index)
8676
list(APPEND LLVM_FIND_COMPONENTS "debuginfo")
8777
endif()
78+
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-8][\\.0-9A-Za-z]*")
79+
# Versions below 3.9 do not support components debuginfocodeview
80+
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfocodeview" index)
81+
endif()
8882
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[8-9][\\.0-9A-Za-z]*")
8983
# Versions beginning with 3.8 do not support component ipa
9084
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "ipa" index)
@@ -153,22 +147,17 @@ else()
153147
llvm_set(ROOT_DIR prefix true)
154148
llvm_set(ENABLE_ASSERTIONS assertion-mode)
155149

156-
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-2][\\.0-9A-Za-z]*")
157-
# Versions below 3.3 do not support components objcarcopts, option
158-
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "objcarcopts" index)
159-
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "option" index)
160-
endif()
161-
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-4][\\.0-9A-Za-z]*")
162-
# Versions below 3.5 do not support components lto, profiledata
163-
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "lto" index)
164-
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "profiledata" index)
165-
endif()
166150
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-6][\\.0-9A-Za-z]*")
167-
# Versions below 3.7 do not support components debuginfodwarf
151+
# Versions below 3.7 do not support components debuginfo[dwarf|pdb]
168152
# Only debuginfo is available
169153
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfodwarf" index)
154+
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfopdb" index)
170155
list(APPEND LLVM_FIND_COMPONENTS "debuginfo")
171156
endif()
157+
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-8][\\.0-9A-Za-z]*")
158+
# Versions below 3.9 do not support components debuginfocodeview
159+
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfocodeview" index)
160+
endif()
172161
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[8-9][\\.0-9A-Za-z]*")
173162
# Versions beginning with 3.8 do not support component ipa
174163
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "ipa" index)
@@ -183,6 +172,8 @@ else()
183172
endif()
184173
llvm_set(LIBRARY_DIRS libdir true)
185174
llvm_set_libs(LIBRARIES libs)
175+
llvm_set(TARGETS_TO_BUILD targets-built)
176+
string(REGEX MATCHALL "${pattern}[^ ]+" LLVM_TARGETS_TO_BUILD ${LLVM_TARGETS_TO_BUILD})
186177
endif()
187178

188179
# On CMake builds of LLVM, the output of llvm-config --cxxflags does not

driver/linker.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ static bool endsWith(const std::string &str, const std::string &end) {
3737
//////////////////////////////////////////////////////////////////////////////
3838

3939
static void CreateDirectoryOnDisk(llvm::StringRef fileName) {
40-
llvm::StringRef dir(llvm::sys::path::parent_path(fileName));
40+
auto dir = llvm::sys::path::parent_path(fileName);
4141
if (!dir.empty() && !llvm::sys::fs::exists(dir)) {
42-
std::error_code ec = llvm::sys::fs::create_directory(dir);
43-
if (ec) {
42+
if (auto ec = llvm::sys::fs::create_directory(dir)) {
4443
error(Loc(), "failed to create path to file: %s\n%s", dir.data(),
4544
ec.message().c_str());
4645
fatal();

driver/targetmachine.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,27 @@ llvm::TargetMachine *createTargetMachine(
505505
features.getString().c_str());
506506
}
507507

508-
if (triple.isMacOSX() && relocModel == llvm::Reloc::Default) {
509-
// OS X defaults to PIC (and as of 10.7.5/LLVM 3.1-3.3, TLS use leads
510-
// to crashes for non-PIC code). LLVM doesn't handle this.
511-
relocModel = llvm::Reloc::PIC_;
508+
// Handle cases where LLVM picks wrong default relocModel
509+
if (relocModel == llvm::Reloc::Default) {
510+
if (triple.isOSDarwin()) {
511+
// Darwin defaults to PIC (and as of 10.7.5/LLVM 3.1-3.3, TLS use leads
512+
// to crashes for non-PIC code). LLVM doesn't handle this.
513+
relocModel = llvm::Reloc::PIC_;
514+
} else if (triple.getEnvironment() == llvm::Triple::Android) {
515+
relocModel = llvm::Reloc::PIC_;
516+
} else {
517+
// ARM for other than Darwin or Android defaults to static
518+
switch (triple.getArch()) {
519+
default:
520+
break;
521+
case llvm::Triple::arm:
522+
case llvm::Triple::armeb:
523+
case llvm::Triple::thumb:
524+
case llvm::Triple::thumbeb:
525+
relocModel = llvm::Reloc::Static;
526+
break;
527+
}
528+
}
512529
}
513530

514531
if (floatABI == FloatABI::Default) {

driver/toobj.cpp

Lines changed: 26 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -346,51 +346,41 @@ void writeModule(llvm::Module *m, std::string filename) {
346346
global.params.targetTriple.getOS() == llvm::Triple::AIX);
347347

348348
// eventually do our own path stuff, dmd's is a bit strange.
349-
typedef llvm::SmallString<128> LLPath;
349+
using LLPath = llvm::SmallString<128>;
350+
351+
#if LDC_LLVM_VER >= 306
352+
using ErrorInfo = std::error_code;
353+
#define ERRORINFO_STRING(errinfo) errinfo.message().c_str()
354+
#else
355+
using ErrorInfo = std::string;
356+
#define ERRORINFO_STRING(errinfo) errinfo.c_str()
357+
#endif
350358

351359
// write LLVM bitcode
352360
if (global.params.output_bc) {
353-
LLPath bcpath = LLPath(filename);
361+
LLPath bcpath(filename);
354362
llvm::sys::path::replace_extension(bcpath, global.bc_ext);
355363
Logger::println("Writing LLVM bitcode to: %s\n", bcpath.c_str());
356-
#if LDC_LLVM_VER >= 306
357-
std::error_code errinfo;
358-
#else
359-
std::string errinfo;
360-
#endif
364+
ErrorInfo errinfo;
361365
llvm::raw_fd_ostream bos(bcpath.c_str(), errinfo, llvm::sys::fs::F_None);
362366
if (bos.has_error()) {
363367
error(Loc(), "cannot write LLVM bitcode file '%s': %s", bcpath.c_str(),
364-
#if LDC_LLVM_VER >= 306
365-
errinfo
366-
#else
367-
errinfo.c_str()
368-
#endif
369-
);
368+
ERRORINFO_STRING(errinfo));
370369
fatal();
371370
}
372371
llvm::WriteBitcodeToFile(m, bos);
373372
}
374373

375374
// write LLVM IR
376375
if (global.params.output_ll) {
377-
LLPath llpath = LLPath(filename);
376+
LLPath llpath(filename);
378377
llvm::sys::path::replace_extension(llpath, global.ll_ext);
379378
Logger::println("Writing LLVM asm to: %s\n", llpath.c_str());
380-
#if LDC_LLVM_VER >= 306
381-
std::error_code errinfo;
382-
#else
383-
std::string errinfo;
384-
#endif
379+
ErrorInfo errinfo;
385380
llvm::raw_fd_ostream aos(llpath.c_str(), errinfo, llvm::sys::fs::F_None);
386381
if (aos.has_error()) {
387382
error(Loc(), "cannot write LLVM asm file '%s': %s", llpath.c_str(),
388-
#if LDC_LLVM_VER >= 306
389-
errinfo
390-
#else
391-
errinfo.c_str()
392-
#endif
393-
);
383+
ERRORINFO_STRING(errinfo));
394384
fatal();
395385
}
396386
AssemblyAnnotator annotator;
@@ -399,18 +389,14 @@ void writeModule(llvm::Module *m, std::string filename) {
399389

400390
// write native assembly
401391
if (global.params.output_s || assembleExternally) {
402-
LLPath spath = LLPath(filename);
392+
LLPath spath(filename);
403393
llvm::sys::path::replace_extension(spath, global.s_ext);
404394
if (!global.params.output_s) {
405395
llvm::sys::fs::createUniqueFile("ldc-%%%%%%%.s", spath);
406396
}
407397

408398
Logger::println("Writing native asm to: %s\n", spath.c_str());
409-
#if LDC_LLVM_VER >= 306
410-
std::error_code errinfo;
411-
#else
412-
std::string errinfo;
413-
#endif
399+
ErrorInfo errinfo;
414400
{
415401
llvm::raw_fd_ostream out(spath.c_str(), errinfo, llvm::sys::fs::F_None);
416402
#if LDC_LLVM_VER >= 306
@@ -422,20 +408,13 @@ void writeModule(llvm::Module *m, std::string filename) {
422408
codegenModule(*gTargetMachine, *m, out,
423409
llvm::TargetMachine::CGFT_AssemblyFile);
424410
} else {
425-
error(Loc(), "cannot write native asm: %s",
426-
#if LDC_LLVM_VER >= 306
427-
errinfo
428-
#else
429-
errinfo.c_str()
430-
#endif
431-
);
411+
error(Loc(), "cannot write native asm: %s", ERRORINFO_STRING(errinfo));
432412
fatal();
433413
}
434414
}
435415

436416
if (assembleExternally) {
437-
LLPath objpath(filename);
438-
assemble(spath.str(), objpath.str());
417+
assemble(spath.str(), filename);
439418
}
440419

441420
if (!global.params.output_s) {
@@ -444,15 +423,11 @@ void writeModule(llvm::Module *m, std::string filename) {
444423
}
445424

446425
if (global.params.output_o && !assembleExternally) {
447-
LLPath objpath = LLPath(filename);
448-
Logger::println("Writing object file to: %s\n", objpath.c_str());
449-
#if LDC_LLVM_VER >= 306
450-
std::error_code errinfo;
451-
#else
452-
std::string errinfo;
453-
#endif
426+
Logger::println("Writing object file to: %s\n", filename.c_str());
427+
ErrorInfo errinfo;
454428
{
455-
llvm::raw_fd_ostream out(objpath.c_str(), errinfo, llvm::sys::fs::F_None);
429+
llvm::raw_fd_ostream out(filename.c_str(), errinfo,
430+
llvm::sys::fs::F_None);
456431
#if LDC_LLVM_VER >= 306
457432
if (!errinfo)
458433
#else
@@ -462,15 +437,11 @@ void writeModule(llvm::Module *m, std::string filename) {
462437
codegenModule(*gTargetMachine, *m, out,
463438
llvm::TargetMachine::CGFT_ObjectFile);
464439
} else {
465-
error(Loc(), "cannot write object file: %s",
466-
#if LDC_LLVM_VER >= 306
467-
errinfo
468-
#else
469-
errinfo.c_str()
470-
#endif
471-
);
440+
error(Loc(), "cannot write object file: %s", ERRORINFO_STRING(errinfo));
472441
fatal();
473442
}
474443
}
475444
}
445+
446+
#undef ERRORINFO_STRING
476447
}

gen/abi-aarch64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct AArch64TargetABI : TargetABI {
8282
// and set 'ap' to its address.
8383
LLValue *valistmem = DtoRawAlloca(getValistType(), 0, "__va_list_mem");
8484
valistmem = DtoBitCast(valistmem, getVoidPtrType());
85-
DtoStore(valistmem, pAp); // ap = (void*)__va_list_mem
85+
DtoStore(valistmem, DtoBitCast(pAp, getPtrToType(getVoidPtrType())));
8686

8787
// pass a void* pointer to the actual struct to LLVM's va_start intrinsic
8888
return valistmem;

0 commit comments

Comments
 (0)