Added detection for clang compiler and fixed various warnings triggered by it (bug 4878, r=dvander).
1.1 --- a/AMBuildScript Sun Apr 17 16:12:45 2011 -0400
1.2 +++ b/AMBuildScript Sat Apr 23 21:53:53 2011 -0500
1.3 @@ -69,15 +69,18 @@
1.4
1.5 #Set up defines
1.6 cxx = self.compiler.cxx
1.7 - if isinstance(cxx, Cpp.GCC):
1.8 - self.vendor = 'gcc'
1.9 + if isinstance(cxx, Cpp.CompatGCC):
1.10 + if isinstance(cxx, Cpp.GCC):
1.11 + self.vendor = 'gcc'
1.12 + elif isinstance(cxx, Cpp.Clang):
1.13 + self.vendor = 'clang'
1.14 self.compiler.AddToListVar('CDEFINES', 'stricmp=strcasecmp')
1.15 self.compiler.AddToListVar('CDEFINES', '_stricmp=strcasecmp')
1.16 self.compiler.AddToListVar('CDEFINES', '_snprintf=snprintf')
1.17 self.compiler.AddToListVar('CDEFINES', '_vsnprintf=vsnprintf')
1.18 self.compiler.AddToListVar('CFLAGS', '-pipe')
1.19 self.compiler.AddToListVar('CFLAGS', '-fno-strict-aliasing')
1.20 - if cxx.majorVersion >= 4:
1.21 + if (self.vendor == 'gcc' and cxx.majorVersion >= 4) or self.vendor == 'clang':
1.22 self.compiler.AddToListVar('CFLAGS', '-fvisibility=hidden')
1.23 self.compiler.AddToListVar('CXXFLAGS', '-fvisibility-inlines-hidden')
1.24 self.compiler.AddToListVar('CFLAGS', '-Wall')
1.25 @@ -85,16 +88,18 @@
1.26 self.compiler.AddToListVar('CFLAGS', '-Wno-uninitialized')
1.27 self.compiler.AddToListVar('CFLAGS', '-Wno-unused')
1.28 self.compiler.AddToListVar('CFLAGS', '-Wno-switch')
1.29 - self.compiler.AddToListVar('CFLAGS', '-mfpmath=sse')
1.30 self.compiler.AddToListVar('CFLAGS', '-msse')
1.31 self.compiler.AddToListVar('CFLAGS', '-m32')
1.32 self.compiler.AddToListVar('POSTLINKFLAGS', '-m32')
1.33 - self.compiler.AddToListVar('CFLAGS', '-static-libgcc')
1.34 self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions')
1.35 self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti')
1.36 self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics')
1.37 self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor')
1.38 + self.compiler.AddToListVar('CXXFLAGS', '-Wno-overloaded-virtual')
1.39 self.compiler.AddToListVar('CDEFINES', 'HAVE_STDINT_H')
1.40 + if self.vendor == 'gcc':
1.41 + self.compiler.AddToListVar('CFLAGS', '-mfpmath=sse')
1.42 + self.compiler.AddToListVar('CFLAGS', '-static-libgcc')
1.43 elif isinstance(cxx, Cpp.MSVC):
1.44 self.vendor = 'msvc'
1.45 if AMBuild.options.debug == '1':
1.46 @@ -130,7 +135,7 @@
1.47 #Optimization
1.48 if AMBuild.options.opt == '1':
1.49 self.compiler.AddToListVar('CDEFINES', 'NDEBUG')
1.50 - if self.vendor == 'gcc':
1.51 + if self.vendor == 'gcc' or self.vendor == 'clang':
1.52 self.compiler.AddToListVar('CFLAGS', '-O3')
1.53 elif self.vendor == 'msvc':
1.54 self.compiler.AddToListVar('CFLAGS', '/Ox')
1.55 @@ -141,7 +146,7 @@
1.56 if AMBuild.options.debug == '1':
1.57 self.compiler.AddToListVar('CDEFINES', 'DEBUG')
1.58 self.compiler.AddToListVar('CDEFINES', '_DEBUG')
1.59 - if self.vendor == 'gcc':
1.60 + if self.vendor == 'gcc' or self.vendor == 'clang':
1.61 self.compiler.AddToListVar('CFLAGS', '-g3')
1.62 elif self.vendor == 'msvc':
1.63 self.compiler.AddToListVar('CFLAGS', '/Od')
2.1 --- a/core/LibrarySys.cpp Sun Apr 17 16:12:45 2011 -0400
2.2 +++ b/core/LibrarySys.cpp Sat Apr 23 21:53:53 2011 -0500
2.3 @@ -410,7 +410,7 @@
2.4 size_t length = strlen(path);
2.5
2.6 for (size_t i = length - 1;
2.7 - i >= 0 && i <= length - 1;
2.8 + i <= length - 1;
2.9 i--)
2.10 {
2.11 if (path[i] == '/'
3.1 --- a/core/logic/TextParsers.cpp Sun Apr 17 16:12:45 2011 -0400
3.2 +++ b/core/logic/TextParsers.cpp Sat Apr 23 21:53:53 2011 -0500
3.3 @@ -872,7 +872,7 @@
3.4 ptr = save_ptr;
3.5
3.6 /* Lastly, strip ending whitespace off */
3.7 - for (size_t i=len-1; i>=0 && i<len; i--)
3.8 + for (size_t i=len-1; i<len; i--)
3.9 {
3.10 if (g_ws_chartable[(unsigned char)ptr[i]])
3.11 {
4.1 --- a/core/sm_fastlink.h Sun Apr 17 16:12:45 2011 -0400
4.2 +++ b/core/sm_fastlink.h Sat Apr 23 21:53:53 2011 -0500
4.3 @@ -37,7 +37,6 @@
4.4 template <typename T>
4.5 class FastLink
4.6 {
4.7 - friend class iterator;
4.8 public:
4.9 struct FastLinkNode
4.10 {
5.1 --- a/core/sourcemod.cpp Sun Apr 17 16:12:45 2011 -0400
5.2 +++ b/core/sourcemod.cpp Sat Apr 23 21:53:53 2011 -0500
5.3 @@ -142,7 +142,7 @@
5.4
5.5 /* Store name of game directory by itself */
5.6 size_t len = strlen(gamepath);
5.7 - for (size_t i = len - 1; i >= 0; i--)
5.8 + for (size_t i = len - 1; i < len; i--)
5.9 {
5.10 if (gamepath[i] == PLATFORM_SEP_CHAR)
5.11 {
6.1 --- a/extensions/bintools/CallWrapper.cpp Sun Apr 17 16:12:45 2011 -0400
6.2 +++ b/extensions/bintools/CallWrapper.cpp Sat Apr 23 21:53:53 2011 -0500
6.3 @@ -103,7 +103,7 @@
6.4
6.5 const PassEncode *CallWrapper::GetParamInfo(unsigned int num)
6.6 {
6.7 - if (num + 1 > GetParamCount() || num < 0)
6.8 + if (num + 1 > GetParamCount())
6.9 {
6.10 return NULL;
6.11 }
6.12 @@ -170,7 +170,7 @@
6.13
6.14 const SourceHook::PassInfo * CallWrapper::GetSHParamInfo(unsigned int num)
6.15 {
6.16 - if (num + 1 > GetParamCount() || num < 0)
6.17 + if (num + 1 > GetParamCount())
6.18 {
6.19 return NULL;
6.20 }
7.1 --- a/extensions/mysql/mysql/MyBoundResults.cpp Sun Apr 17 16:12:45 2011 -0400
7.2 +++ b/extensions/mysql/mysql/MyBoundResults.cpp Sat Apr 23 21:53:53 2011 -0500
7.3 @@ -217,7 +217,7 @@
7.4 {
7.5 if (mysql_stmt_bind_result(m_stmt, m_bind) != 0)
7.6 {
7.7 - return false;
7.8 + return NULL;
7.9 }
7.10 m_bUpdatedBinds = false;
7.11 }
8.1 --- a/extensions/sdktools/AMBuilder Sun Apr 17 16:12:45 2011 -0400
8.2 +++ b/extensions/sdktools/AMBuilder Sat Apr 23 21:53:53 2011 -0500
8.3 @@ -10,8 +10,8 @@
8.4 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'public', 'jit'))
8.5 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'public', 'jit', 'x86'))
8.6
8.7 - if compiler.cc.name == 'gcc':
8.8 - compiler['CFLAGS'].append('-Wno-parentheses')
8.9 + if compiler.cc.name == 'gcc' or compiler.cc.name == 'clang':
8.10 + compiler['CFLAGS'].append('-Wno-parentheses')
8.11
8.12 if i != 'ep1':
8.13 compiler['CDEFINES'].append('HOOKING_ENABLED')
9.1 --- a/extensions/sqlite/driver/SqDriver.cpp Sun Apr 17 16:12:45 2011 -0400
9.2 +++ b/extensions/sqlite/driver/SqDriver.cpp Sat Apr 23 21:53:53 2011 -0500
9.3 @@ -167,7 +167,7 @@
9.4
9.5 /* Chop any filename off */
9.6 for (size_t i = len-1;
9.7 - i >= 0 && i <= len-1;
9.8 + i <= len-1;
9.9 i--)
9.10 {
9.11 if (IsPathSepChar(path[i]))
10.1 --- a/extensions/tf2/AMBuilder Sun Apr 17 16:12:45 2011 -0400
10.2 +++ b/extensions/tf2/AMBuilder Sat Apr 23 21:53:53 2011 -0500
10.3 @@ -3,7 +3,7 @@
10.4
10.5 sdk = SM.sdkInfo['ep2v']
10.6 compiler = SM.DefaultHL2Compiler('extensions/tf2', 'ep2v')
10.7 -if compiler.cc.name == 'gcc':
10.8 +if compiler.cc.name == 'gcc' or compiler.cc.name == 'clang':
10.9 compiler['CFLAGS'].append('-Wno-parentheses')
10.10
10.11 name = 'game.tf2.ext.' + sdk['ext']
11.1 --- a/loader/loader.cpp Sun Apr 17 16:12:45 2011 -0400
11.2 +++ b/loader/loader.cpp Sat Apr 23 21:53:53 2011 -0500
11.3 @@ -293,7 +293,7 @@
11.4 }
11.5
11.6 size_t len = strlen(thisfile);
11.7 - for (size_t iter=len-1; iter>=0 && iter<len; iter--)
11.8 + for (size_t iter=len-1; iter<len; iter--)
11.9 {
11.10 if (IsPathSepChar(thisfile[iter]))
11.11 {
12.1 --- a/sourcepawn/compiler/AMBuilder Sun Apr 17 16:12:45 2011 -0400
12.2 +++ b/sourcepawn/compiler/AMBuilder Sat Apr 23 21:53:53 2011 -0500
12.3 @@ -7,7 +7,7 @@
12.4 compiler['CINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'sourcepawn', 'compiler'))
12.5 compiler['CINCLUDES'].append(os.path.join(AMBuild.outputFolder, 'includes'))
12.6
12.7 -if compiler.cc.name == 'gcc':
12.8 +if compiler.cc.name == 'gcc' or compiler.cc.name == 'clang':
12.9 compiler['CFLAGS'].extend(['-Wno-parentheses', '-Wno-format'])
12.10 if AMBuild.target['platform'] == 'linux':
12.11 compiler['POSTLINKFLAGS'].extend(['-lgcc', '-lm'])
13.1 --- a/sourcepawn/compiler/sc1.c Sun Apr 17 16:12:45 2011 -0400
13.2 +++ b/sourcepawn/compiler/sc1.c Sat Apr 23 21:53:53 2011 -0500
13.3 @@ -579,7 +579,7 @@
13.4
13.5 binptr = NULL;
13.6 len = strlen(binfname);
13.7 - for (i = len - 1; i >= 0 && i < len; i--)
13.8 + for (i = len - 1; i < len; i--)
13.9 {
13.10 if (binfname[i] == '/'
13.11 #if defined WIN32 || defined _WIN32
14.1 --- a/sourcepawn/jit/engine2.cpp Sun Apr 17 16:12:45 2011 -0400
14.2 +++ b/sourcepawn/jit/engine2.cpp Sat Apr 23 21:53:53 2011 -0500
14.3 @@ -98,7 +98,7 @@
14.4 size_t len;
14.5
14.6 len = strlen(file);
14.7 - for (size_t i = len - 1; i >= 0 && i < len; i--)
14.8 + for (size_t i = len - 1; i < len; i--)
14.9 {
14.10 if (file[i] == '/'
14.11 #if defined WIN32