From 29df2351c9ef5bb1399c42b03340799ea55e1b22 Mon Sep 17 00:00:00 2001 From: Scott Ehlert Date: Sat, 23 Apr 2011 21:35:10 -0500 Subject: [PATCH] Added detection for clang compiler and fixed various warnings triggered by it (bug 4877, r=dvander). --- AMBuildScript | 19 ++++++++++++------- core-legacy/CSmmAPI.cpp | 2 +- core-legacy/sourcehook/sh_string.h | 2 +- core-legacy/sourcehook/sh_vector.h | 2 +- core-legacy/util.cpp | 2 +- core/metamod.cpp | 2 +- core/metamod_plugins.cpp | 2 +- core/metamod_util.cpp | 4 ++-- core/sourcehook/sh_string.h | 2 +- core/sourcehook/sh_vector.h | 2 +- loader/utility.cpp | 4 ++-- 11 files changed, 24 insertions(+), 19 deletions(-) diff --git a/AMBuildScript b/AMBuildScript index 2b09e43..533e0c5 100644 --- a/AMBuildScript +++ b/AMBuildScript @@ -67,15 +67,18 @@ class MMS: #Set up defines cxx = self.compiler.cxx - if isinstance(cxx, Cpp.GCC): - self.vendor = 'gcc' + if isinstance(cxx, Cpp.CompatGCC): + if isinstance(cxx, Cpp.GCC): + self.vendor = 'gcc' + elif isinstance(cxx, Cpp.Clang): + self.vendor = 'clang' self.compiler.AddToListVar('CDEFINES', 'stricmp=strcasecmp') self.compiler.AddToListVar('CDEFINES', '_stricmp=strcasecmp') self.compiler.AddToListVar('CDEFINES', '_snprintf=snprintf') self.compiler.AddToListVar('CDEFINES', '_vsnprintf=vsnprintf') self.compiler.AddToListVar('CFLAGS', '-pipe') self.compiler.AddToListVar('CFLAGS', '-fno-strict-aliasing') - if cxx.majorVersion >= 4: + if (self.vendor == 'gcc' and cxx.majorVersion >= 4) or self.vendor == 'clang': self.compiler.AddToListVar('CFLAGS', '-fvisibility=hidden') self.compiler.AddToListVar('CXXFLAGS', '-fvisibility-inlines-hidden') self.compiler.AddToListVar('CFLAGS', '-Wall') @@ -83,16 +86,18 @@ class MMS: self.compiler.AddToListVar('CFLAGS', '-Wno-uninitialized') self.compiler.AddToListVar('CFLAGS', '-Wno-unused') self.compiler.AddToListVar('CFLAGS', '-Wno-switch') - self.compiler.AddToListVar('CFLAGS', '-mfpmath=sse') self.compiler.AddToListVar('CFLAGS', '-msse') self.compiler.AddToListVar('CFLAGS', '-m32') self.compiler.AddToListVar('POSTLINKFLAGS', '-m32') - self.compiler.AddToListVar('CFLAGS', '-static-libgcc') self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions') self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti') self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics') self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor') + self.compiler.AddToListVar('CXXFLAGS', '-Wno-overloaded-virtual') self.compiler.AddToListVar('CDEFINES', 'HAVE_STDINT_H') + if self.vendor == 'gcc': + self.compiler.AddToListVar('CFLAGS', '-mfpmath=sse') + self.compiler.AddToListVar('CFLAGS', '-static-libgcc') elif isinstance(cxx, Cpp.MSVC): self.vendor = 'msvc' if AMBuild.options.debug == '1': @@ -128,7 +133,7 @@ class MMS: #Optimization if AMBuild.options.opt == '1': self.compiler.AddToListVar('CDEFINES', 'NDEBUG') - if self.vendor == 'gcc': + if self.vendor == 'gcc' or self.vendor == 'clang': self.compiler.AddToListVar('CFLAGS', '-O3') elif self.vendor == 'msvc': self.compiler.AddToListVar('CFLAGS', '/Ox') @@ -139,7 +144,7 @@ class MMS: if AMBuild.options.debug == '1': self.compiler.AddToListVar('CDEFINES', 'DEBUG') self.compiler.AddToListVar('CDEFINES', '_DEBUG') - if self.vendor == 'gcc': + if self.vendor == 'gcc' or self.vendor == 'clang': self.compiler.AddToListVar('CFLAGS', '-g3') elif self.vendor == 'msvc': self.compiler.AddToListVar('CFLAGS', '/Od') diff --git a/core-legacy/CSmmAPI.cpp b/core-legacy/CSmmAPI.cpp index 247a53c..c4d7678 100644 --- a/core-legacy/CSmmAPI.cpp +++ b/core-legacy/CSmmAPI.cpp @@ -470,7 +470,7 @@ void CSmmAPI::LoadAsVSP() /* Chop off the "engine" file part */ len = strlen(engine_file); - for (size_t i = len - 1; i >= 0 && i < len; i--) + for (size_t i = len - 1; i < len; i--) { if (engine_file[i] == '/' || engine_file[i] == '\\') diff --git a/core-legacy/sourcehook/sh_string.h b/core-legacy/sourcehook/sh_string.h index 79f96b8..9bb4624 100755 --- a/core-legacy/sourcehook/sh_string.h +++ b/core-legacy/sourcehook/sh_string.h @@ -230,7 +230,7 @@ public: if (is_space(v[len-1])) { - for (i=len-1; i>=0; i--) + for (i=len-1; i= 0; i--) + for (size_t i = len - 1; i < len; i--) { if (isspace((unsigned char) buffer[i])) { diff --git a/core/metamod.cpp b/core/metamod.cpp index db1364d..90e6e15 100644 --- a/core/metamod.cpp +++ b/core/metamod.cpp @@ -326,7 +326,7 @@ void InitializeVSP() /* Chop off the "engine" file part */ len = strlen(engine_file); - for (size_t i = len - 1; i >= 0 && i < len; i--) + for (size_t i = len - 1; i < len; i--) { if (engine_file[i] == '/' || engine_file[i] == '\\') { diff --git a/core/metamod_plugins.cpp b/core/metamod_plugins.cpp index 1aa204b..a70b7be 100644 --- a/core/metamod_plugins.cpp +++ b/core/metamod_plugins.cpp @@ -445,7 +445,7 @@ CPluginManager::CPlugin *CPluginManager::_Load(const char *file, PluginId source char file_path[256]; size_t len = g_Metamod.PathFormat(file_path, sizeof(file_path), "%s", file); - for (size_t i = len - 1; i >= 0 && i < len; i--) + for (size_t i = len - 1; i < len; i--) { if (_IsPathSepChar(file_path[i])) { diff --git a/core/metamod_util.cpp b/core/metamod_util.cpp index cd9575a..9a9c55e 100644 --- a/core/metamod_util.cpp +++ b/core/metamod_util.cpp @@ -87,7 +87,7 @@ void UTIL_TrimRight(char *buffer) size_t len = strlen(buffer); /* Loop through buffer backwards while replacing whitespace chars with null chars */ - for (size_t i = len - 1; i >= 0; i--) + for (size_t i = len - 1; i < len; i--) { if (isspace((unsigned char) buffer[i])) { @@ -138,7 +138,7 @@ bool UTIL_PathCmp(const char *path1, const char *path2) /* If we're at a different non-alphanumeric, the next character MUST match */ if ((((unsigned)path1[pos1] & 0x80) && path1[pos1] != path2[pos2]) || - !isalpha(path1[pos1]) && (path1[pos1] != path2[pos2]) + (!isalpha(path1[pos1]) && (path1[pos1] != path2[pos2])) ) { return false; diff --git a/core/sourcehook/sh_string.h b/core/sourcehook/sh_string.h index 6d6a8a5..36e1fef 100755 --- a/core/sourcehook/sh_string.h +++ b/core/sourcehook/sh_string.h @@ -230,7 +230,7 @@ public: if (is_space(v[len-1])) { - for (i=len-1; i>=0; i--) + for (i=len-1; i= 0; i--) + for (size_t i = len - 1; i < len; i--) { if (isspace((unsigned char) buffer[i])) buffer[i] = '\0'; @@ -245,7 +245,7 @@ mm_PathCmp(const char *path1, const char *path2) /* If we're at a different non-alphanumeric, the next character MUST match */ if ((((unsigned)path1[pos1] & 0x80) && path1[pos1] != path2[pos2]) || - !isalpha(path1[pos1]) && (path1[pos1] != path2[pos2]) + (!isalpha(path1[pos1]) && (path1[pos1] != path2[pos2])) ) { return false;