clang/gcc: Fix compilation issues with clang 3.0 and gcc 4.6

This patch addresses a number of minor issues that cause problems when
compiling with clang >= 3.0 and gcc >= 4.6. Most importantly, it
avoids using the deprecated ext/hash_map and instead uses
unordered_map (and similarly so for the hash_set). To make use of the
new STL containers, g++ and clang has to be invoked with "-std=c++0x",
and this is now added for all gcc versions >= 4.6, and for clang >=
3.0. For gcc >= 4.3 and <= 4.5 and clang <= 3.0 we use the tr1
unordered_map to avoid the deprecation warning.

The addition of c++0x in turn causes a few problems, as the
compiler is more stringent and adds a number of new warnings. Below,
the most important issues are enumerated:

1) the use of namespaces is more strict, e.g. for isnan, and all
   headers opening the entire namespace std are now fixed.

2) another other issue caused by the more stringent compiler is the
   narrowing of the embedded python, which used to be a char array,
   and is now unsigned char since there were values larger than 128.

3) a particularly odd issue that arose with the new c++0x behaviour is
   found in range.hh, where the operator< causes gcc to complain about
   the template type parsing (the "<" is interpreted as the beginning
   of a template argument), and the problem seems to be related to the
   begin/end members introduced for the range-type iteration, which is
   a new feature in c++11.

As a minor update, this patch also fixes the build flags for the clang
debug target that used to be shared with gcc and incorrectly use
"-ggdb".
This commit is contained in:
Andreas Hansson
2012-04-14 05:43:31 -04:00
parent 29482e90ba
commit b6aa6d55eb
34 changed files with 199 additions and 77 deletions

View File

@@ -31,6 +31,7 @@
#include <cassert>
#include <iomanip>
#include <iostream>
#include "base/hashmap.hh"
#include "mem/ruby/common/TypeDefines.hh"
@@ -201,8 +202,7 @@ Address::shiftLowOrderBits(int number) const
return (m_address >> number);
}
class Address;
namespace __hash_namespace {
__hash_namespace_begin
template <> struct hash<Address>
{
size_t
@@ -211,7 +211,7 @@ template <> struct hash<Address>
return (size_t)s.getAddress();
}
};
} // namespace __hash_namespace
__hash_namespace_end
namespace std {
template <> struct equal_to<Address>

View File

@@ -26,6 +26,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <algorithm>
#include "mem/ruby/common/NetDest.hh"
NetDest::NetDest()

View File

@@ -37,11 +37,8 @@
* Proceedings of the 48th Design Automation Conference (DAC'11)
*/
// C includes
#include <assert.h>
#include <stdio.h>
// C++ includes
#include <cassert>
#include <fstream>
#include <iostream>
#include <vector>
@@ -50,6 +47,8 @@
#include "FaultModel.hh"
#include "base/misc.hh"
using namespace std;
#define MAX(a,b) ((a > b) ? (a) : (b))

View File

@@ -47,7 +47,6 @@
// C++ includes
#include <string>
using namespace std;
// GEM5 includes
#include "params/FaultModel.hh"
@@ -112,7 +111,7 @@ class FaultModel : public SimObject
int number_of_buff_per_data_vc,
int number_of_buff_per_ctrl_vc);
string fault_type_to_string(int fault_type_index);
std::string fault_type_to_string(int fault_type_index);
// the following 2 functions are called at runtime, to get the probability
// of each fault type (fault_vector) or the aggregate fault probability
@@ -134,9 +133,9 @@ class FaultModel : public SimObject
void print(void);
private:
vector <system_conf> configurations;
vector <system_conf> routers;
vector <int> temperature_weights;
std::vector <system_conf> configurations;
std::vector <system_conf> routers;
std::vector <int> temperature_weights;
};
#endif // __MEM_RUBY_NETWORK_FAULT_MODEL_HH__

View File

@@ -33,6 +33,8 @@
#include "mem/ruby/network/Topology.hh"
#include "mem/ruby/network/garnet/BaseGarnetNetwork.hh"
using namespace std;
BaseGarnetNetwork::BaseGarnetNetwork(const Params *p)
: Network(p)
{

View File

@@ -37,8 +37,6 @@
#include "mem/ruby/network/orion/Type.hh"
using namespace std;
class TechParameter;
class OrionConfig
@@ -56,12 +54,12 @@ class OrionConfig
void set_in_buf_num_set(uint32_t in_buf_num_set_);
void set_flit_width(uint32_t flit_width_);
void read_file(const string& filename_);
void print_config(ostream& out_);
void read_file(const std::string& filename_);
void print_config(std::ostream& out_);
public:
template<class T>
T get(const string& key_) const;
T get(const std::string& key_) const;
const TechParameter* get_tech_param_ptr() const { return m_tech_param_ptr; }
uint32_t get_num_in_port() const { return m_num_in_port; }
uint32_t get_num_out_port() const { return m_num_out_port; }
@@ -71,7 +69,7 @@ class OrionConfig
uint32_t get_flit_width() const { return m_flit_width; }
private:
map<string, string> m_params_map;
std::map<std::string, std::string> m_params_map;
TechParameter* m_tech_param_ptr;
uint32_t m_num_in_port;
@@ -84,28 +82,28 @@ class OrionConfig
protected:
struct key_not_found
{
string m_key;
key_not_found(const string& key_ = string()) : m_key(key_)
std::string m_key;
key_not_found(const std::string& key_ = string()) : m_key(key_)
{}
};
template<class T>
static T string_as_T(const string& str_);
static T string_as_T(const std::string& str_);
template<class T>
static string T_as_string(const T& t_);
static std::string T_as_string(const T& t_);
private:
static string ms_param_name[];
static std::string ms_param_name[];
};
template<class T>
T OrionConfig::get(const string& key_) const
{
map<string, string>::const_iterator it;
std::map<std::string, std::string>::const_iterator it;
it = m_params_map.find(key_);
if (it == m_params_map.end())
{
cerr << key_ << " NOT FOUND!" << endl;
std::cerr << key_ << " NOT FOUND!" << std::endl;
throw key_not_found(key_);
}
return string_as_T<T>(it->second);
@@ -140,7 +138,8 @@ inline bool OrionConfig::string_as_T<bool>(const string& str_)
}
else
{
cerr << "Invalid bool value: '" << str_ << "'. Treated as FALSE." << endl;
std::cerr << "Invalid bool value: '" << str_ <<
"'. Treated as FALSE." << std::endl;
ret = false;
}
return ret;

View File

@@ -43,6 +43,8 @@
#include "mem/ruby/network/orion/OrionConfig.hh"
#include "OrionRouter.hh"
using namespace std;
OrionRouter::OrionRouter(
uint32_t num_in_port_,
uint32_t num_out_port_,

View File

@@ -40,8 +40,6 @@
#include "mem/ruby/network/orion/Type.hh"
using namespace std;
class OrionConfig;
class TechParameter

View File

@@ -45,6 +45,8 @@
// Allows use of times() library call, which determines virtual runtime
#include <sys/resource.h>
#include <sys/times.h>
#include <sys/types.h>
#include <unistd.h>
#include <algorithm>
#include <fstream>

View File

@@ -188,7 +188,6 @@ PerfectCacheMemory<ENTRY>::changePermission(const Address& address,
Address line_address = address;
line_address.makeLineAddress();
PerfectCacheLineState<ENTRY>& line_state = m_map[line_address];
AccessPermission old_perm = line_state.m_permission;
line_state.m_permission = new_perm;
}

View File

@@ -408,6 +408,9 @@ void unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr);
* Created by slicc definition of Module "${{self.short}}"
*/
#include <sys/types.h>
#include <unistd.h>
#include <cassert>
#include <sstream>
#include <string>
@@ -990,6 +993,9 @@ $c_ident::${{action.ident}}(const Address& addr)
// Auto generated C++ code started by $__file__:$__line__
// ${ident}: ${{self.short}}
#include <sys/types.h>
#include <unistd.h>
#include <cassert>
#include "base/misc.hh"