Skip to content

Commit 2e51dcf

Browse files
committed
Merge branch 'master' into release-0.16.0
2 parents 8dcb5d6 + 51f10d5 commit 2e51dcf

File tree

10 files changed

+216
-93
lines changed

10 files changed

+216
-93
lines changed

appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ after_build:
108108
ninja install > $null
109109
copy bin\ldc2.pdb ..\ldc-x64\bin
110110
cd ..\ldc-x64
111+
(gc etc\ldc2.conf).replace('c:/projects/ldc-x64/', '%%ldcbinarypath%%/../') | sc etc\ldc2.conf
111112
$artifactFilename = "LDC-Win64-master-$Env:APPVEYOR_BUILD_NUMBER.7z"
112113
7z a "..\$artifactFilename" * > $null
113114
cd ..

driver/cl_options.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,18 @@ cl::opt<unsigned, true> nestedTemplateDepth("template-depth",
435435
cl::location(global.params.nestedTmpl),
436436
cl::init(500));
437437

438+
#if LDC_LLVM_VER < 307
438439
cl::opt<bool, true, FlagParser<bool> > color("color",
439440
cl::desc("Force colored console output"),
440441
cl::location(global.params.color));
442+
#else
443+
void CreateColorOption()
444+
{
445+
new cl::opt<bool, true, FlagParser<bool> >("color",
446+
cl::desc("Force colored console output"),
447+
cl::location(global.params.color));
448+
}
449+
#endif
441450

442451
cl::opt<bool, true> useDIP25("dip25",
443452
cl::desc("implement http://wiki.dlang.org/DIP25 (experimental)"),

driver/cl_options.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,9 @@ namespace opts {
8585
// Arguments to -d-debug
8686
extern std::vector<std::string> debugArgs;
8787
// Arguments to -run
88+
89+
#if LDC_LLVM_VER >= 307
90+
void CreateColorOption();
91+
#endif
8892
}
8993
#endif

driver/configfile.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,18 @@ bool ConfigFile::read(const char* explicitConfFile)
224224
// handle switches
225225
if (config_setting_t *sw = config_setting_get_member(root, "switches"))
226226
{
227+
// replace all %%ldcbinarypath%% occurrences by the path to the
228+
// LDC bin directory (using forward slashes)
227229
std::string binpathkey = "%%ldcbinarypath%%";
228230

229231
std::string binpath = exe_path::getBinDir();
232+
std::replace(binpath.begin(), binpath.end(), '\\', '/');
230233

231234
int len = config_setting_length(sw);
232235
for (int i = 0; i < len; i++)
233236
{
234237
std::string v(config_setting_get_string(config_setting_get_elem(sw, i)));
235238

236-
// replace binpathkey with binpath
237239
size_t p;
238240
while (std::string::npos != (p = v.find(binpathkey)))
239241
v.replace(p, binpathkey.size(), binpath);

driver/main.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,17 @@ static void hide(llvm::StringMap<cl::Option *>& map, const char* name) {
174174
map[name]->setHiddenFlag(cl::Hidden);
175175
}
176176

177+
static void rename(llvm::StringMap<cl::Option *>& map, const char* from, const char *to) {
178+
llvm::StringMap<cl::Option*>::iterator i = map.find(from);
179+
if (i != map.end())
180+
{
181+
cl::Option *opt = i->getValue();
182+
map.erase(i);
183+
opt->setArgStr(to);
184+
map[to] = opt;
185+
}
186+
}
187+
177188
/// Removes command line options exposed from within LLVM that are unlikely
178189
/// to be useful for end users from the -help output.
179190
static void hideLLVMOptions() {
@@ -242,6 +253,14 @@ static void hideLLVMOptions() {
242253
// line has been parsed).
243254
hide(map, "fdata-sections");
244255
hide(map, "ffunction-sections");
256+
257+
#if LDC_LLVM_VER >= 307
258+
// LLVM 3.7 introduces compiling as shared library. The result
259+
// is a clash in the command line options.
260+
rename(map, "color", "llvm-color");
261+
hide(map, "llvm-color");
262+
opts::CreateColorOption();
263+
#endif
245264
}
246265
#endif
247266

gen/abi-win64.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ struct Win64TargetABI : TargetABI
4040

4141
bool passByVal(Type* t);
4242

43+
bool passThisBeforeSret(TypeFunction* tf);
44+
4345
void rewriteFunctionType(TypeFunction* tf, IrFuncTy &fty);
4446

4547
void rewriteArgument(IrFuncTy& fty, IrFuncTyArg& arg);
@@ -117,6 +119,11 @@ bool Win64TargetABI::passByVal(Type* t)
117119
return false;
118120
}
119121

122+
bool Win64TargetABI::passThisBeforeSret(TypeFunction* tf)
123+
{
124+
return tf->linkage == LINKcpp;
125+
}
126+
120127
void Win64TargetABI::rewriteFunctionType(TypeFunction* tf, IrFuncTy &fty)
121128
{
122129
// RETURN VALUE

gen/abi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ struct TargetABI
106106
/// Returns true if the type is passed by value
107107
virtual bool passByVal(Type* t) = 0;
108108

109+
// Returns true if the 'this' argument is to be passed before the 'sret' argument.
110+
virtual bool passThisBeforeSret(TypeFunction* tf) { return false; }
111+
109112
/// Called to give ABI the chance to rewrite the types
110113
virtual void rewriteFunctionType(TypeFunction* t, IrFuncTy& fty) = 0;
111114
virtual void rewriteVarargs(IrFuncTy& fty, std::vector<IrFuncTyArg*>& args);

gen/functions.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ llvm::FunctionType* DtoFunctionType(Type* type, IrFuncTy &irFty, Type* thistype,
196196
if (irFty.arg_nest) argtypes.push_back(irFty.arg_nest->ltype);
197197
if (irFty.arg_arguments) argtypes.push_back(irFty.arg_arguments->ltype);
198198

199+
if (irFty.arg_sret && irFty.arg_this && abi->passThisBeforeSret(f))
200+
std::swap(argtypes[0], argtypes[1]);
201+
199202
const size_t firstExplicitArg = argtypes.size();
200203
const size_t numExplicitLLArgs = irFty.args.size();
201204
for (size_t i = 0; i < numExplicitLLArgs; i++)
@@ -405,8 +408,18 @@ static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclarati
405408
}
406409

407410
ADD_PA(ret)
408-
ADD_PA(arg_sret)
409-
ADD_PA(arg_this)
411+
412+
if (irFty.arg_sret && irFty.arg_this && gABI->passThisBeforeSret(f))
413+
{
414+
ADD_PA(arg_this)
415+
ADD_PA(arg_sret)
416+
}
417+
else
418+
{
419+
ADD_PA(arg_sret)
420+
ADD_PA(arg_this)
421+
}
422+
410423
ADD_PA(arg_nest)
411424
ADD_PA(arg_arguments)
412425

@@ -537,7 +550,9 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
537550
// name parameters
538551
llvm::Function::arg_iterator iarg = func->arg_begin();
539552

540-
if (irFty.arg_sret) {
553+
const bool passThisBeforeSret = irFty.arg_sret && irFty.arg_this && gABI->passThisBeforeSret(f);
554+
555+
if (irFty.arg_sret && !passThisBeforeSret) {
541556
iarg->setName(".sret_arg");
542557
irFunc->retArg = iarg;
543558
++iarg;
@@ -569,6 +584,12 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
569584
++iarg;
570585
}
571586

587+
if (passThisBeforeSret) {
588+
iarg->setName(".sret_arg");
589+
irFunc->retArg = iarg;
590+
++iarg;
591+
}
592+
572593
if (irFty.arg_arguments) {
573594
iarg->setName("._arguments");
574595
irFunc->_arguments = iarg;

0 commit comments

Comments
 (0)