From b2c569404baa6ff068bc81bc444efe7c066ec1fa Mon Sep 17 00:00:00 2001 From: Kai Nacke Date: Sat, 16 May 2015 02:49:14 +0200 Subject: [PATCH 1/6] Fix a warning about sprintf type --- gen/pragma.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gen/pragma.cpp b/gen/pragma.cpp index 33760a1e4d..1150481d4a 100644 --- a/gen/pragma.cpp +++ b/gen/pragma.cpp @@ -116,7 +116,7 @@ Pragma DtoGetPragma(Scope *sc, PragmaDeclaration *decl, std::string &arg1str) else priority = 65535; char buf[8]; - sprintf(buf, "%lu", priority); + sprintf(buf, "%llu", static_cast(priority)); arg1str = std::string(buf); return ident == Id::LDC_global_crt_ctor ? LLVMglobal_crt_ctor : LLVMglobal_crt_dtor; } From 76f543d0a7c7f074651cabdbaf5a0c6c3a3c47f3 Mon Sep 17 00:00:00 2001 From: Kai Nacke Date: Sat, 16 May 2015 18:56:38 +0200 Subject: [PATCH 2/6] Fix another sprintf warning --- gen/asmstmt.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gen/asmstmt.cpp b/gen/asmstmt.cpp index 9deaf2017b..5d0d8b0b85 100644 --- a/gen/asmstmt.cpp +++ b/gen/asmstmt.cpp @@ -458,7 +458,7 @@ static void remap_outargs(std::string& insnt, size_t nargs, size_t idx) needle = prefix + digits[i] + suffix; size_t pos = insnt.find(needle); if(std::string::npos != pos) - sprintf(buf, "%lu", idx++); + sprintf(buf, "%llu", static_cast(idx++)); while(std::string::npos != (pos = insnt.find(needle))) insnt.replace(pos, needle.size(), buf); } @@ -483,7 +483,7 @@ static void remap_inargs(std::string& insnt, size_t nargs, size_t idx) needle = prefix + digits[i] + suffix; size_t pos = insnt.find(needle); if(std::string::npos != pos) - sprintf(buf, "%lu", idx++); + sprintf(buf, "%llu", static_cast(idx++)); while(std::string::npos != (pos = insnt.find(needle))) insnt.replace(pos, needle.size(), buf); } From afe6051ead12a620f532267bde8043b37b7a91d2 Mon Sep 17 00:00:00 2001 From: Kai Nacke Date: Sat, 16 May 2015 18:56:59 +0200 Subject: [PATCH 3/6] LLVM 3.7: Fix MIPS ABI definition. Detection of EABI is still missing. --- driver/main.cpp | 11 +++++++++++ driver/targetmachine.cpp | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/driver/main.cpp b/driver/main.cpp index 15b6bd62b5..7b0539ae7a 100644 --- a/driver/main.cpp +++ b/driver/main.cpp @@ -544,6 +544,16 @@ static void initializePasses() { /// Register the MIPS ABI. static void registerMipsABI() { +#if LDC_LLVM_VER >= 307 + // FIXME: EABI? + auto dl = gTargetMachine->getDataLayout(); + if (dl->getPointerSizeInBits() == 64) + VersionCondition::addPredefinedGlobalIdent("MIPS_N64"); + else if (dl->getStackAlignment() <= 64) + VersionCondition::addPredefinedGlobalIdent("MIPS_O32"); + else + VersionCondition::addPredefinedGlobalIdent("MIPS_N32"); +#else llvm::StringRef features = gTargetMachine->getTargetFeatureString(); if (features.find("+o32") != std::string::npos) VersionCondition::addPredefinedGlobalIdent("MIPS_O32"); @@ -553,6 +563,7 @@ static void registerMipsABI() VersionCondition::addPredefinedGlobalIdent("MIPS_N64"); if (features.find("+eabi") != std::string::npos) VersionCondition::addPredefinedGlobalIdent("MIPS_EABI"); +#endif } /// Register the float ABI. diff --git a/driver/targetmachine.cpp b/driver/targetmachine.cpp index 81b0f654e9..d12bbc32d5 100644 --- a/driver/targetmachine.cpp +++ b/driver/targetmachine.cpp @@ -199,6 +199,7 @@ static FloatABI::Type getARMFloatABI(const llvm::Triple &triple, } } +#if LDC_LLVM_VER < 307 /// Sanitizes the MIPS ABI in the feature string. static void addMipsABI(const llvm::Triple &triple, std::vector &attrs) { @@ -238,6 +239,7 @@ static void addMipsABI(const llvm::Triple &triple, std::vector &att if (bits != defaultABI) attrs.push_back(is64Bit ? "-n64" : "-o32"); } +#endif /// Looks up a target based on an arch name and a target triple. /// @@ -362,11 +364,13 @@ llvm::TargetMachine* createTargetMachine( #endif } } +#if LDC_LLVM_VER < 307 if (triple.getArch() == llvm::Triple::mips || triple.getArch() == llvm::Triple::mipsel || triple.getArch() == llvm::Triple::mips64 || triple.getArch() == llvm::Triple::mips64el) addMipsABI(triple, attrs); +#endif for (unsigned i = 0; i < attrs.size(); ++i) features.AddFeature(attrs[i]); From 0e9307225963096cadefe4fd6b3e769cda9421e5 Mon Sep 17 00:00:00 2001 From: Kai Nacke Date: Sat, 16 May 2015 23:27:54 +0200 Subject: [PATCH 4/6] MIPS64: Use DataLayout.getLargestLegalIntTypeSize() to check for N32. This is more natural: if pointers are not 64bit but the largest int type is 64bit then the ABI is N32; otherwise it is O32. --- driver/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/driver/main.cpp b/driver/main.cpp index 7b0539ae7a..51d8c5d1f6 100644 --- a/driver/main.cpp +++ b/driver/main.cpp @@ -549,10 +549,10 @@ static void registerMipsABI() auto dl = gTargetMachine->getDataLayout(); if (dl->getPointerSizeInBits() == 64) VersionCondition::addPredefinedGlobalIdent("MIPS_N64"); - else if (dl->getStackAlignment() <= 64) - VersionCondition::addPredefinedGlobalIdent("MIPS_O32"); - else + else if (dl->getLargestLegalIntTypeSize() == 64) VersionCondition::addPredefinedGlobalIdent("MIPS_N32"); + else + VersionCondition::addPredefinedGlobalIdent("MIPS_O32"); #else llvm::StringRef features = gTargetMachine->getTargetFeatureString(); if (features.find("+o32") != std::string::npos) From b92e377d49ddfc682bd19dc116a54850746d7fd5 Mon Sep 17 00:00:00 2001 From: Kai Nacke Date: Sun, 17 May 2015 12:29:23 +0200 Subject: [PATCH 5/6] Fix definition of D_LP64. LP64 defines a C environment with 64bit pointers and char/short/int/long are 8/16/32/64bit. char/short/int/long have defined sizes in D. We need to look only at the pointer size. There are now 64bit environments with 32bit pointers. Examples are x32 in Intel and N32 on MIPS64. For these environments D_LP64 should not defined but the global.param.is64bit is still true. The definition of size_t is also affected. If only 32bit are addressable then size_t should also be a 32bit type. (This is not required by C standard but common practize.) The net result is that not only the definition of D_LP64 must be changed but also DtoSize_t(). --- driver/main.cpp | 29 ++++++++++++++--------------- gen/tollvm.cpp | 2 +- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/driver/main.cpp b/driver/main.cpp index 51d8c5d1f6..286df9e76e 100644 --- a/driver/main.cpp +++ b/driver/main.cpp @@ -698,7 +698,7 @@ static void registerPredefinedTargetVersions() { } // a generic 64bit version - if (global.params.is64bit) { + if (global.params.isLP64) { VersionCondition::addPredefinedGlobalIdent("D_LP64"); } @@ -1028,20 +1028,6 @@ int main(int argc, char **argv) bitness, mFloatABI, mRelocModel, mCodeModel, codeGenOptLevel(), global.params.symdebug || disableFpElim, disableLinkerStripDead); - { - llvm::Triple triple = llvm::Triple(gTargetMachine->getTargetTriple()); - global.params.targetTriple = triple; - global.params.isLinux = triple.getOS() == llvm::Triple::Linux; - global.params.isOSX = triple.isMacOSX(); - global.params.isWindows = triple.isOSWindows(); - global.params.isFreeBSD = triple.getOS() == llvm::Triple::FreeBSD; - global.params.isOpenBSD = triple.getOS() == llvm::Triple::OpenBSD; - global.params.isSolaris = triple.getOS() == llvm::Triple::Solaris; - // FIXME: Correctly handle the x32 ABI (AMD64 ILP32) here. - global.params.isLP64 = triple.isArch64Bit(); - global.params.is64bit = triple.isArch64Bit(); - } - #if LDC_LLVM_VER >= 307 gDataLayout = gTargetMachine->getDataLayout(); #elif LDC_LLVM_VER >= 306 @@ -1052,6 +1038,19 @@ int main(int argc, char **argv) gDataLayout = gTargetMachine->getTargetData(); #endif + { + llvm::Triple triple = llvm::Triple(gTargetMachine->getTargetTriple()); + global.params.targetTriple = triple; + global.params.isLinux = triple.getOS() == llvm::Triple::Linux; + global.params.isOSX = triple.isMacOSX(); + global.params.isWindows = triple.isOSWindows(); + global.params.isFreeBSD = triple.getOS() == llvm::Triple::FreeBSD; + global.params.isOpenBSD = triple.getOS() == llvm::Triple::OpenBSD; + global.params.isSolaris = triple.getOS() == llvm::Triple::Solaris; + global.params.isLP64 = gDataLayout->getPointerSizeInBits() == 64; + global.params.is64bit = triple.isArch64Bit(); + } + // allocate the target abi gABI = TargetABI::getTarget(); diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index f20739ec2d..41ec5f8a01 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -299,7 +299,7 @@ LLIntegerType* DtoSize_t() // the type of size_t does not change once set static LLIntegerType* t = NULL; if (t == NULL) - t = (global.params.is64bit) ? LLType::getInt64Ty(gIR->context()) : LLType::getInt32Ty(gIR->context()); + t = (global.params.isLP64) ? LLType::getInt64Ty(gIR->context()) : LLType::getInt32Ty(gIR->context()); return t; } From 0cadfa055c54a6e3f294a70833a33bdbf236eab5 Mon Sep 17 00:00:00 2001 From: Kai Nacke Date: Sun, 17 May 2015 13:01:15 +0200 Subject: [PATCH 6/6] LLVM 3.7: Use comparison instead of assignment. Bug spotted by Temtaime. --- driver/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver/main.cpp b/driver/main.cpp index 286df9e76e..74ba896488 100644 --- a/driver/main.cpp +++ b/driver/main.cpp @@ -573,7 +573,7 @@ static void registerPredefinedFloatABI(const char *soft, const char *hard, const // Use target floating point unit instead of s/w float routines #if LDC_LLVM_VER >= 307 // FIXME: This is a semantic change! - bool useFPU = gTargetMachine->Options.FloatABIType = llvm::FloatABI::Hard; + bool useFPU = gTargetMachine->Options.FloatABIType == llvm::FloatABI::Hard; #else bool useFPU = !gTargetMachine->Options.UseSoftFloat; #endif