# HG changeset patch # User smatz # Date 1329081452 0 # Node ID 6c68329f2cfbc7c0cd0b0686652dfebfb01d1671 # Parent 524da59612d02f70bcd908699c38bc51ae107153 (svn r23941) -Add: support for clang diff --git a/config.lib b/config.lib --- a/config.lib +++ b/config.lib @@ -1159,11 +1159,11 @@ if [ -z "$first_time_icc_check" ]; then first_time_icc_check=no if [ $cc_version -lt 90 ]; then - log 1 "WARNING: you seem to be using very old version of ICC" + log 1 "WARNING: you seem to be using a very old version of ICC" log 1 "WARNING: OpenTTD hasn't been tested with this version" sleep 5 elif [ $cc_version -lt 120 ]; then - log 1 "WARNING: you seem to be using unsupported ICC version" + log 1 "WARNING: you seem to be using an unsupported ICC version" log 1 "WARNING: ICC older than 12.0 is known to fail to compile OpenTTD" sleep 5 fi @@ -1236,6 +1236,58 @@ features="$features lto" fi fi + elif [ `basename $1 | grep 'clang'` ]; then + # Enable some things only for certain clang versions + cc_version="`$1 -v 2>&1 | head -n 1 | sed s@[^0-9]@@g | cut -c 1-2`" + + # aliasing rules are not held in openttd code + flags="$flags -fno-strict-aliasing" + + # -W alone doesn't enable all warnings enabled by -Wall; on the other hand, + # -Weverything enables too many useless warnings that can't be disabled (as of 3.0) + flags="$flags -Wall -W" + + # warning: unused parameter '...' + flags="$flags -Wno-unused-parameter" + + # warning: expression result unused + flags="$flags -Wno-unused-value" + + # warning: multi-character character constant + flags="$flags -Wno-multichar" + + # warning: explicitly assigning a variable of type '...' to itself + # it happens when using the FOR_ALL_WINDOWS_FROM_BACK_FROM macro + flags="$flags -Wno-self-assign" + + if [ "$cc_version" -lt "30" ]; then + # warning: equality comparison with extraneous parentheses + flags="$flags -Wno-parentheses" + # warning: operands of ? are integers of different signs: 'unsigned int' and 'int' + flags="$flags -Wno-sign-compare" + fi + + if [ "$cc_version" -ge "30" ]; then + # warning: equality comparison with extraneous parentheses + # this warning could be useful, but it warns about code in squirrel + flags="$flags -Wno-parentheses-equality" + fi + + if [ "$with_ccache" != "0" -o "$with_distcc" != "0" ]; then + # ccache and distcc run separate preprocess and compile passes, + # both are fed with the same CFLAGS. Unfortunately, clang + # complains about -I when compiling preprocessed files: + # "clang: warning: argument unused during compilation: '-I /usr/include'" + flags="$flags -Qunused-arguments" + fi + + if [ "$enable_assert" -eq "0" ]; then + # do not warn about unused variables when building without asserts + flags="$flags -Wno-unused-variable" + fi + + # rdynamic is used to get useful stack traces from crash reports. + ldflags="$ldflags -rdynamic" else # Enable some things only for certain GCC versions cc_version=`$1 -dumpversion | cut -c 1,3` diff --git a/readme.txt b/readme.txt --- a/readme.txt +++ b/readme.txt @@ -1,5 +1,5 @@ OpenTTD readme -Last updated: 2012-02-04 +Last updated: 2012-02-12 Release version: 1.2.0-beta4 ------------------------------------------------------------------------ @@ -501,6 +501,8 @@ Versions 4.4 - 4.6 give bogus warnings about freeing non-heap objects. Versions 4.5 and later give invalid warnings when lto is enabled. - Intel C++ Compiler (ICC) 12.0. + - Clang/LLVM 2.9 - 3.0 + Version 2.9 gives bogus warnings about code nonconformity. The following compilers are known not to compile OpenTTD: - Microsoft Visual C++ (MSVC) 2003 and earlier. @@ -510,7 +512,7 @@ Version 10.0 and earlier fail a configure check and fail with recent system headers. Version 10.1 fails to compile station_gui.cpp. - Version 11.1 fails with internal error when compiling network.cpp. + Version 11.1 fails with an internal error when compiling network.cpp. - Clang/LLVM 2.8 and earlier. - (Open) Watcom. diff --git a/src/core/pool_func.hpp b/src/core/pool_func.hpp --- a/src/core/pool_func.hpp +++ b/src/core/pool_func.hpp @@ -107,7 +107,11 @@ assert(sizeof(Titem) == size); item = (Titem *)this->alloc_cache; this->alloc_cache = this->alloc_cache->next; - if (Tzero) MemSetT(item, 0); + if (Tzero) { + /* Explicitly casting to (void *) prevets a clang warning - + * we are actually memsetting a (not-yet-constructed) object */ + memset((void *)item, 0, sizeof(Titem)); + } } else if (Tzero) { item = (Titem *)CallocT(size); } else { diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -2100,11 +2100,18 @@ { NetworkClientInfo *ci; FOR_ALL_CLIENT_INFOS(ci) { - IConsolePrintF(CC_INFO, _network_server ? "Client #%1d name: '%s' company: %1d IP: %s" : "Client #%1d name: '%s' company: %1d", - ci->client_id, - ci->client_name, - ci->client_playas + (Company::IsValidID(ci->client_playas) ? 1 : 0), - _network_server ? (ci->client_id == CLIENT_ID_SERVER ? "server" : NetworkClientSocket::GetByClientID(ci->client_id)->GetClientIP()) : ""); + if (_network_server) { + IConsolePrintF(CC_INFO, "Client #%1d name: '%s' company: %1d IP: %s", + ci->client_id, + ci->client_name, + ci->client_playas + (Company::IsValidID(ci->client_playas) ? 1 : 0), + ci->client_id == CLIENT_ID_SERVER ? "server" : NetworkClientSocket::GetByClientID(ci->client_id)->GetClientIP()); + } else { + IConsolePrintF(CC_INFO, "Client #%1d name: '%s' company: %1d", + ci->client_id, + ci->client_name, + ci->client_playas + (Company::IsValidID(ci->client_playas) ? 1 : 0)); + } } } diff --git a/src/script/api/script_object.hpp b/src/script/api/script_object.hpp --- a/src/script/api/script_object.hpp +++ b/src/script/api/script_object.hpp @@ -33,6 +33,7 @@ */ class ScriptObject : public SimpleCountedObject { friend class ScriptInstance; +friend class ScriptController; protected: /** * A class that handles the current active instance. By instantiating it at diff --git a/src/script/api/script_vehiclelist.cpp b/src/script/api/script_vehiclelist.cpp --- a/src/script/api/script_vehiclelist.cpp +++ b/src/script/api/script_vehiclelist.cpp @@ -123,7 +123,7 @@ const Vehicle *v; FOR_ALL_VEHICLES(v) { if (v->owner == ScriptObject::GetCompany() && v->IsPrimaryVehicle()) { - if (v->type == vehicle_type && v->group_id == ScriptGroup::GROUP_DEFAULT) this->AddItem(v->index); + if (v->type == (::VehicleType)vehicle_type && v->group_id == ScriptGroup::GROUP_DEFAULT) this->AddItem(v->index); } } } diff --git a/src/strings.cpp b/src/strings.cpp --- a/src/strings.cpp +++ b/src/strings.cpp @@ -288,7 +288,7 @@ quot = num / divisor; num = num % divisor; } - if (tot |= quot || i >= max_digits - zerofill) { + if ((tot |= quot) || i >= max_digits - zerofill) { buff += seprintf(buff, last, "%i", (int)quot); if ((i % 3) == thousands_offset && i < max_digits - 1 - fractional_digits) buff = strecpy(buff, separator, last); }