From 939bc00b2b45bf32623579b2bc22257df7ca3967 Mon Sep 17 00:00:00 2001 From: Scott Ehlert Date: Sat, 23 Apr 2011 21:53:53 -0500 Subject: [PATCH] Added detection for clang compiler and fixed various warnings triggered by it (bug 4878, r=dvander). --- AMBuildScript | 19 ++++++++++++------- core/LibrarySys.cpp | 2 +- core/logic/TextParsers.cpp | 2 +- core/sm_fastlink.h | 1 - core/sourcemod.cpp | 2 +- extensions/bintools/CallWrapper.cpp | 4 ++-- extensions/mysql/mysql/MyBoundResults.cpp | 2 +- extensions/sdktools/AMBuilder | 4 ++-- extensions/sqlite/driver/SqDriver.cpp | 2 +- extensions/tf2/AMBuilder | 2 +- loader/loader.cpp | 2 +- sourcepawn/compiler/AMBuilder | 2 +- sourcepawn/compiler/sc1.c | 2 +- sourcepawn/jit/engine2.cpp | 2 +- 14 files changed, 26 insertions(+), 22 deletions(-) diff --git a/AMBuildScript b/AMBuildScript index 13040ff3..73c37946 100644 --- a/AMBuildScript +++ b/AMBuildScript @@ -69,15 +69,18 @@ class SM: #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') @@ -85,16 +88,18 @@ class SM: 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': @@ -130,7 +135,7 @@ class SM: #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') @@ -141,7 +146,7 @@ class SM: 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/LibrarySys.cpp b/core/LibrarySys.cpp index 3206377d..0f486804 100644 --- a/core/LibrarySys.cpp +++ b/core/LibrarySys.cpp @@ -410,7 +410,7 @@ size_t LibrarySystem::GetFileFromPath(char *buffer, size_t maxlength, const char size_t length = strlen(path); for (size_t i = length - 1; - i >= 0 && i <= length - 1; + i <= length - 1; i--) { if (path[i] == '/' diff --git a/core/logic/TextParsers.cpp b/core/logic/TextParsers.cpp index 0be66245..abe5bffa 100644 --- a/core/logic/TextParsers.cpp +++ b/core/logic/TextParsers.cpp @@ -872,7 +872,7 @@ bool TextParsers::ParseFile_INI(const char *file, ITextListener_INI *ini_listene ptr = save_ptr; /* Lastly, strip ending whitespace off */ - for (size_t i=len-1; i>=0 && i class FastLink { - friend class iterator; public: struct FastLinkNode { diff --git a/core/sourcemod.cpp b/core/sourcemod.cpp index ad618ece..e28aa4d3 100644 --- a/core/sourcemod.cpp +++ b/core/sourcemod.cpp @@ -142,7 +142,7 @@ bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late /* Store name of game directory by itself */ size_t len = strlen(gamepath); - for (size_t i = len - 1; i >= 0; i--) + for (size_t i = len - 1; i < len; i--) { if (gamepath[i] == PLATFORM_SEP_CHAR) { diff --git a/extensions/bintools/CallWrapper.cpp b/extensions/bintools/CallWrapper.cpp index 56b22da4..4ebea203 100644 --- a/extensions/bintools/CallWrapper.cpp +++ b/extensions/bintools/CallWrapper.cpp @@ -103,7 +103,7 @@ CallConvention CallWrapper::GetCallConvention() const PassEncode *CallWrapper::GetParamInfo(unsigned int num) { - if (num + 1 > GetParamCount() || num < 0) + if (num + 1 > GetParamCount()) { return NULL; } @@ -170,7 +170,7 @@ SourceHook::ProtoInfo::CallConvention CallWrapper::GetSHCallConvention() const SourceHook::PassInfo * CallWrapper::GetSHParamInfo(unsigned int num) { - if (num + 1 > GetParamCount() || num < 0) + if (num + 1 > GetParamCount()) { return NULL; } diff --git a/extensions/mysql/mysql/MyBoundResults.cpp b/extensions/mysql/mysql/MyBoundResults.cpp index aca9f5f3..bdd8ecc0 100644 --- a/extensions/mysql/mysql/MyBoundResults.cpp +++ b/extensions/mysql/mysql/MyBoundResults.cpp @@ -217,7 +217,7 @@ IResultRow *MyBoundResults::FetchRow() { if (mysql_stmt_bind_result(m_stmt, m_bind) != 0) { - return false; + return NULL; } m_bUpdatedBinds = false; } diff --git a/extensions/sdktools/AMBuilder b/extensions/sdktools/AMBuilder index 7d5cdc2d..cffc1f68 100644 --- a/extensions/sdktools/AMBuilder +++ b/extensions/sdktools/AMBuilder @@ -10,8 +10,8 @@ for i in SM.sdkInfo: compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'public', 'jit')) compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'public', 'jit', 'x86')) - if compiler.cc.name == 'gcc': - compiler['CFLAGS'].append('-Wno-parentheses') + if compiler.cc.name == 'gcc' or compiler.cc.name == 'clang': + compiler['CFLAGS'].append('-Wno-parentheses') if i != 'ep1': compiler['CDEFINES'].append('HOOKING_ENABLED') diff --git a/extensions/sqlite/driver/SqDriver.cpp b/extensions/sqlite/driver/SqDriver.cpp index 9bf41494..beb865fc 100644 --- a/extensions/sqlite/driver/SqDriver.cpp +++ b/extensions/sqlite/driver/SqDriver.cpp @@ -167,7 +167,7 @@ IDatabase *SqDriver::Connect(const DatabaseInfo *info, bool persistent, char *er /* Chop any filename off */ for (size_t i = len-1; - i >= 0 && i <= len-1; + i <= len-1; i--) { if (IsPathSepChar(path[i])) diff --git a/extensions/tf2/AMBuilder b/extensions/tf2/AMBuilder index 2a053bf3..40d1891a 100644 --- a/extensions/tf2/AMBuilder +++ b/extensions/tf2/AMBuilder @@ -3,7 +3,7 @@ import os sdk = SM.sdkInfo['ep2v'] compiler = SM.DefaultHL2Compiler('extensions/tf2', 'ep2v') -if compiler.cc.name == 'gcc': +if compiler.cc.name == 'gcc' or compiler.cc.name == 'clang': compiler['CFLAGS'].append('-Wno-parentheses') name = 'game.tf2.ext.' + sdk['ext'] diff --git a/loader/loader.cpp b/loader/loader.cpp index f3c4bb69..894f6c41 100644 --- a/loader/loader.cpp +++ b/loader/loader.cpp @@ -293,7 +293,7 @@ DLL_EXPORT void *CreateInterface(const char *iface, int *ret) } size_t len = strlen(thisfile); - for (size_t iter=len-1; iter>=0 && iter= 0 && i < len; i--) + for (i = len - 1; i < len; i--) { if (binfname[i] == '/' #if defined WIN32 || defined _WIN32 diff --git a/sourcepawn/jit/engine2.cpp b/sourcepawn/jit/engine2.cpp index 9044aae6..4f1328bf 100644 --- a/sourcepawn/jit/engine2.cpp +++ b/sourcepawn/jit/engine2.cpp @@ -98,7 +98,7 @@ IPluginRuntime *SourcePawnEngine2::LoadPlugin(ICompilation *co, const char *file size_t len; len = strlen(file); - for (size_t i = len - 1; i >= 0 && i < len; i--) + for (size_t i = len - 1; i < len; i--) { if (file[i] == '/' #if defined WIN32