From edeedd2bed18a0d97804c9ce0836a2b2e3764ac5 Mon Sep 17 00:00:00 2001 From: PBerger Date: Sat, 14 Sep 2013 15:56:49 +0200 Subject: [PATCH] Added ConversionHelper.h to single out the needed no-strict-aliasing target Replaced a few "auto" variables as GCC4.7 fails to infer the correct type Former-commit-id: 09a0c8dac945cb33e423269157df78752ab12413 --- CMakeLists.txt | 11 +++++++++ src/adapters/GmmxxAdapter.h | 8 ++++--- src/settings/Argument.h | 2 +- src/settings/ArgumentBuilder.h | 10 ++++----- src/settings/Option.h | 2 +- src/settings/Settings.cpp | 6 ++--- src/utility/ConversionHelper.cpp | 5 +++++ src/utility/ConversionHelper.h | 38 ++++++++++++++++++++++++++++++++ 8 files changed, 69 insertions(+), 13 deletions(-) create mode 100644 src/utility/ConversionHelper.cpp create mode 100644 src/utility/ConversionHelper.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f400fc2a..b7542a4ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,6 +85,9 @@ endif() message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") message(STATUS "CMAKE_BUILD_TYPE (ENV): $ENV{CMAKE_BUILD_TYPE}") +# Path to the no-strict-aliasing target +set(CONVERSIONHELPER_TARGET "${PROJECT_SOURCE_DIR}/src/utility/ConversionHelper.cpp") + if(CMAKE_COMPILER_IS_GNUCC) message(STATUS "Using GCC") # Set standard flags for GCC @@ -98,12 +101,17 @@ if(CMAKE_COMPILER_IS_GNUCC) if (USE_POPCNT) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpopcnt") endif(USE_POPCNT) + + # Set the no-strict-aliasing target for GCC + set_source_files_properties(${CONVERSIONHELPER_TARGET} PROPERTIES COMPILE_FLAGS " -fno-strict-aliasing ") elseif(MSVC) message(STATUS "Using MSVC") # required for GMM to compile, ugly error directive in their code add_definitions(/D_SCL_SECURE_NO_DEPRECATE) # required as the PRCTL Parser bloats object files (COFF) beyond their maximum size (see http://msdn.microsoft.com/en-us/library/8578y171(v=vs.110).aspx) add_definitions(/bigobj) + + # MSVC does not do strict-aliasing, so no option needed else(CLANG) message(STATUS "Using CLANG") # As CLANG is not set as a variable, we need to set it in case we have not matched another compiler. @@ -124,6 +132,9 @@ else(CLANG) if (USE_POPCNT) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpopcnt") endif(USE_POPCNT) + + # Set the no-strict-aliasing target for Clang + set_source_files_properties(${CONVERSIONHELPER_TARGET} PROPERTIES COMPILE_FLAGS " -fno-strict-aliasing ") endif() # Add the binary folder to the search path for include files so that we will find storm-config.h diff --git a/src/adapters/GmmxxAdapter.h b/src/adapters/GmmxxAdapter.h index abc8a3766..d60b88a7b 100644 --- a/src/adapters/GmmxxAdapter.h +++ b/src/adapters/GmmxxAdapter.h @@ -8,9 +8,11 @@ #ifndef STORM_ADAPTERS_GMMXXADAPTER_H_ #define STORM_ADAPTERS_GMMXXADAPTER_H_ -#include "src/storage/SparseMatrix.h" #include +#include "src/storage/SparseMatrix.h" +#include "src/utility/ConversionHelper.h" + #include "log4cplus/logger.h" #include "log4cplus/loggingmacros.h" @@ -66,10 +68,10 @@ public: // Move Row Indications result->jc.~vectorType_ull_t(); // Call Destructor inplace - new (&result->jc) vectorType_ull_t(std::move(matrix.rowIndications)); + new (&result->jc) vectorType_ull_t(std::move(storm::utility::ConversionHelper::toUnsignedLongLong(&matrix.rowIndications))); // Move Columns Indications result->ir.~vectorType_ull_t(); // Call Destructor inplace - new (&result->ir) vectorType_ull_t(std::move(matrix.columnIndications)); + new (&result->ir) vectorType_ull_t(std::move(storm::utility::ConversionHelper::toUnsignedLongLong(&matrix.columnIndications))); // And do the same thing with the actual values. result->pr.~vectorType_T_t(); // Call Destructor inplace new (&result->pr) vectorType_T_t(std::move(matrix.valueStorage)); diff --git a/src/settings/Argument.h b/src/settings/Argument.h index ae6328080..75044f27c 100644 --- a/src/settings/Argument.h +++ b/src/settings/Argument.h @@ -57,7 +57,7 @@ namespace storm { Argument(Argument const& other) : ArgumentBase(other.argumentName, other.argumentDescription, other.isOptional), argumentType(other.argumentType), defaultValue(other.defaultValue), hasDefaultValue(other.hasDefaultValue) { this->userValidationFunction.reserve(other.userValidationFunction.size()); - for (auto i = 0; i < other.userValidationFunction.size(); ++i) { + for (size_t i = 0; i < other.userValidationFunction.size(); ++i) { this->userValidationFunction.push_back(userValidationFunction_t(other.userValidationFunction.at(i))); } } diff --git a/src/settings/ArgumentBuilder.h b/src/settings/ArgumentBuilder.h index 26de8c31a..3bf4f7bd5 100644 --- a/src/settings/ArgumentBuilder.h +++ b/src/settings/ArgumentBuilder.h @@ -176,19 +176,19 @@ namespace storm { defaultValue_String(other.defaultValue_String), defaultValue_Integer(other.defaultValue_Integer), defaultValue_UnsignedInteger(other.defaultValue_UnsignedInteger), defaultValue_Double(other.defaultValue_Double), defaultValue_Boolean(other.defaultValue_Boolean), hasDefaultValue(other.hasDefaultValue) { // Copy all userFunctions - for (auto i = 0; i < userValidationFunction_String.size(); ++i) { + for (uint_fast64_t i = 0; i < userValidationFunction_String.size(); ++i) { this->userValidationFunction_String.push_back(storm::settings::Argument::userValidationFunction_t(other.userValidationFunction_String.at(i))); } - for (auto i = 0; i < userValidationFunction_Integer.size(); ++i) { + for (uint_fast64_t i = 0; i < userValidationFunction_Integer.size(); ++i) { this->userValidationFunction_Integer.push_back(storm::settings::Argument::userValidationFunction_t(other.userValidationFunction_Integer.at(i))); } - for (auto i = 0; i < userValidationFunction_UnsignedInteger.size(); ++i) { + for (uint_fast64_t i = 0; i < userValidationFunction_UnsignedInteger.size(); ++i) { this->userValidationFunction_UnsignedInteger.push_back(storm::settings::Argument::userValidationFunction_t(other.userValidationFunction_UnsignedInteger.at(i))); } - for (auto i = 0; i < userValidationFunction_Double.size(); ++i) { + for (uint_fast64_t i = 0; i < userValidationFunction_Double.size(); ++i) { this->userValidationFunction_Double.push_back(storm::settings::Argument::userValidationFunction_t(other.userValidationFunction_Double.at(i))); } - for (auto i = 0; i < userValidationFunction_Boolean.size(); ++i) { + for (uint_fast64_t i = 0; i < userValidationFunction_Boolean.size(); ++i) { this->userValidationFunction_Boolean.push_back(storm::settings::Argument::userValidationFunction_t(other.userValidationFunction_Boolean.at(i))); } } diff --git a/src/settings/Option.h b/src/settings/Option.h index bec6b5a45..1fabf984a 100644 --- a/src/settings/Option.h +++ b/src/settings/Option.h @@ -48,7 +48,7 @@ namespace storm { : longName(longOptionName), shortName(shortOptionName), description(optionDescription), moduleName(moduleName), isRequired(isOptionRequired), hasBeenSet(false) { // Copy all Arguments this->arguments.reserve(optionArguments.size()); - for (auto i = 0; i < optionArguments.size(); ++i) { + for (uint_fast64_t i = 0; i < optionArguments.size(); ++i) { // Clone gives a deep copy this->arguments.push_back(std::shared_ptr(optionArguments.at(i).get()->clone())); } diff --git a/src/settings/Settings.cpp b/src/settings/Settings.cpp index 5dd90a588..972c8ea84 100644 --- a/src/settings/Settings.cpp +++ b/src/settings/Settings.cpp @@ -92,7 +92,7 @@ bool storm::settings::Settings::checkArgumentSyntaxForOption(std::string const& return false; } - for (auto i = 2; i < argvString.size(); ++i) { + for (size_t i = 2; i < argvString.size(); ++i) { if (!isalpha(argvString.at(i))) { return false; } @@ -118,7 +118,7 @@ void storm::settings::Settings::parseCommandLine(int const argc, char const * co bool optionActive = false; std::string longOptionName; std::vector argCache; - for (auto i = 0; i <= stringArgv.size(); ++i) { + for (size_t i = 0; i <= stringArgv.size(); ++i) { if (i == stringArgv.size()) { if (optionActive) { this->handleAssignment(longOptionName, argCache); @@ -170,7 +170,7 @@ void storm::settings::Settings::parseCommandLine(int const argc, char const * co throw storm::exceptions::OptionParserException() << "Option \"" << it->second.get()->getLongName() << "\" is marked as required, but was not set!"; } else { // Set defaults on optional values - for (auto i = 0; i < it->second.get()->getArgumentCount(); ++i) { + for (uint_fast64_t i = 0; i < it->second.get()->getArgumentCount(); ++i) { if (it->second.get()->getArgument(i).getHasDefaultValue()) { it->second.get()->getArgument(i).setFromDefaultValue(); } diff --git a/src/utility/ConversionHelper.cpp b/src/utility/ConversionHelper.cpp new file mode 100644 index 000000000..cb87b44e1 --- /dev/null +++ b/src/utility/ConversionHelper.cpp @@ -0,0 +1,5 @@ +#include "ConversionHelper.h" + +std::vector>* storm::utility::ConversionHelper::toUnsignedLongLong(std::vector>* vectorPtr) { + return reinterpret_cast> *>(vectorPtr); +} \ No newline at end of file diff --git a/src/utility/ConversionHelper.h b/src/utility/ConversionHelper.h new file mode 100644 index 000000000..b87b520aa --- /dev/null +++ b/src/utility/ConversionHelper.h @@ -0,0 +1,38 @@ +/* + * ConversionHelper.h + * + * Created on: 14.09.2013 + * Author: Philipp Berger + * + * WARNING: This file REQUIRES -no-strict-aliasing! + */ + +#ifndef STORM_UTILITY_CONVERSIONHELPER_H_ +#define STORM_UTILITY_CONVERSIONHELPER_H_ + +#include +#include +#include + +static_assert(sizeof(unsigned long long) == sizeof(uint_fast64_t), "This program uses the GMM Backend and therefor requires unsigned long long and uint_fast64_t to be of the same size!"); + + +namespace storm { + namespace utility { + + class ConversionHelper { + public: + /*! + * Converts a pointer to a std::vector to std::vector + */ + static std::vector>* toUnsignedLongLong(std::vector>* vectorPtr); + + private: + ConversionHelper() {} + ConversionHelper(ConversionHelper& other) {} + ~ConversionHelper() {} + }; + } +} + +#endif // STORM_UTILITY_CONVERSIONHELPER_H_ \ No newline at end of file