From 58be504125ae187ec41027365b6931f7745fdbfa Mon Sep 17 00:00:00 2001 From: William Dawson Date: Wed, 15 Nov 2023 11:46:06 +0900 Subject: [PATCH] Extra warnings added and fixes to make them clear Credit to ChatGPT --- Source/C/TripletList_c.h | 4 ++-- Source/CPlusPlus/Logging.cc | 2 +- Source/CPlusPlus/PSMatrix.cc | 8 ++++---- Source/CPlusPlus/Permutation.cc | 4 ++-- Source/CPlusPlus/ProcessGrid.h | 6 ++++++ Source/CPlusPlus/SMatrix.cc | 8 ++++---- Source/Fortran/PSMatrixModule.F90 | 2 +- Targets/Linux.cmake | 10 ++++++++-- 8 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Source/C/TripletList_c.h b/Source/C/TripletList_c.h index d63af3a6..0a836403 100644 --- a/Source/C/TripletList_c.h +++ b/Source/C/TripletList_c.h @@ -8,7 +8,7 @@ void AppendToTripletList_r_wrp(int *ih_this, const int *index_column, void SetTripletAt_r_wrp(int *ih_this, const int *index, const int *index_column, const int *index_row, const double *point_value); void GetTripletAt_r_wrp(const int *ih_this, const int *index, int *index_column, - const int *index_row, double *point_value); + int *index_row, double *point_value); void DestructTripletList_r_wrp(int *ih_this); void SortTripletList_r_wrp(const int *ih_this, const int *matrix_size, int *h_sorted); @@ -24,7 +24,7 @@ void SetTripletAt_c_wrp(int *ih_this, const int *index, const int *index_column, const int *index_row, const double *point_value_real, const double *point_value_imag); void GetTripletAt_c_wrp(const int *ih_this, const int *index, int *index_column, - const int *index_row, const double *point_value_real, + int *index_row, const double *point_value_real, const double *point_value_imag); void DestructTripletList_c_wrp(int *ih_this); void SortTripletList_c_wrp(const int *ih_this, const int *matrix_size, diff --git a/Source/CPlusPlus/Logging.cc b/Source/CPlusPlus/Logging.cc index 65c7e3cc..87cb667d 100644 --- a/Source/CPlusPlus/Logging.cc +++ b/Source/CPlusPlus/Logging.cc @@ -13,7 +13,7 @@ void NTPoly::ActivateLogger(bool start_document) { //////////////////////////////////////////////////////////////////////////////// void NTPoly::ActivateLogger(const string file_name, bool start_document) { - int string_length = file_name.length(); + int string_length = static_cast(file_name.length()); string temp = file_name; ActivateLoggerFile_wrp(&start_document, &temp.c_str()[0], &string_length); } diff --git a/Source/CPlusPlus/PSMatrix.cc b/Source/CPlusPlus/PSMatrix.cc index fc51b1a0..c2c296bd 100644 --- a/Source/CPlusPlus/PSMatrix.cc +++ b/Source/CPlusPlus/PSMatrix.cc @@ -27,7 +27,7 @@ Matrix_ps::Matrix_ps(int matrix_dimension, const ProcessGrid &grid) { ////////////////////////////////////////////////////////////////////////////// Matrix_ps::Matrix_ps(std::string file_name, bool is_binary) { - int string_length = file_name.length(); + int string_length = static_cast(file_name.length()); if (is_binary) { ConstructMatrixFromBinary_ps_wrp(ih_this, &file_name.c_str()[0], &string_length); @@ -40,7 +40,7 @@ Matrix_ps::Matrix_ps(std::string file_name, bool is_binary) { ////////////////////////////////////////////////////////////////////////////// Matrix_ps::Matrix_ps(std::string file_name, const ProcessGrid &grid, bool is_binary) { - int string_length = file_name.length(); + int string_length = static_cast(file_name.length()); if (is_binary) { ConstructMatrixFromBinaryPG_ps_wrp(ih_this, &file_name.c_str()[0], &string_length, grid.ih_this); @@ -61,13 +61,13 @@ Matrix_ps::Matrix_ps(const Matrix_ps &matB) { ////////////////////////////////////////////////////////////////////////////// void Matrix_ps::WriteToBinary(std::string file_name) const { - int string_length = file_name.length(); + int string_length = static_cast(file_name.length()); WriteMatrixToBinary_ps_wrp(ih_this, &file_name.c_str()[0], &string_length); } ////////////////////////////////////////////////////////////////////////////// void Matrix_ps::WriteToMatrixMarket(string file_name) const { - int string_length = file_name.length(); + int string_length = static_cast(file_name.length()); WriteMatrixToMatrixMarket_ps_wrp(ih_this, &file_name.c_str()[0], &string_length); } diff --git a/Source/CPlusPlus/Permutation.cc b/Source/CPlusPlus/Permutation.cc index aeb97dd2..88af79d6 100644 --- a/Source/CPlusPlus/Permutation.cc +++ b/Source/CPlusPlus/Permutation.cc @@ -9,9 +9,9 @@ extern "C" { //////////////////////////////////////////////////////////////////////////////// namespace NTPoly { //////////////////////////////////////////////////////////////////////////////// -Permutation::Permutation(int matrix_dimension) { +Permutation::Permutation(int dimension) { was_filled = false; - this->matrix_dimension = matrix_dimension; + this->matrix_dimension = dimension; } //////////////////////////////////////////////////////////////////////////////// diff --git a/Source/CPlusPlus/ProcessGrid.h b/Source/CPlusPlus/ProcessGrid.h index a4b0f6e6..f5f98803 100644 --- a/Source/CPlusPlus/ProcessGrid.h +++ b/Source/CPlusPlus/ProcessGrid.h @@ -1,6 +1,12 @@ #ifndef PROCESSGRID_h #define PROCESSGRID_h + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-function-type" +#pragma GCC diagnostic ignored "-Wuseless-cast" +#pragma GCC diagnostic ignored "-Wold-style-cast" #include +#pragma GCC diagnostic pop #include "Wrapper.h" diff --git a/Source/CPlusPlus/SMatrix.cc b/Source/CPlusPlus/SMatrix.cc index 0e80db27..521d6546 100644 --- a/Source/CPlusPlus/SMatrix.cc +++ b/Source/CPlusPlus/SMatrix.cc @@ -21,12 +21,12 @@ Matrix_lsc::Matrix_lsc(int columns, int rows) { //////////////////////////////////////////////////////////////////////////////// Matrix_lsr::Matrix_lsr(std::string file_name) { - int string_length = file_name.length(); + int string_length = static_cast(file_name.length()); ConstructMatrixFromFile_lsr_wrp(ih_this, &file_name.c_str()[0], &string_length); } Matrix_lsc::Matrix_lsc(std::string file_name) { - int string_length = file_name.length(); + int string_length = static_cast(file_name.length()); ConstructMatrixFromFile_lsc_wrp(ih_this, &file_name.c_str()[0], &string_length); } @@ -193,12 +193,12 @@ void Matrix_lsc::Print() const { PrintMatrix_lsc_wrp(ih_this); } //////////////////////////////////////////////////////////////////////////////// void Matrix_lsr::WriteToMatrixMarket(string file_name) const { - int string_length = file_name.length(); + int string_length = static_cast(file_name.length()); PrintMatrixF_lsr_wrp(ih_this, &file_name.c_str()[0], &string_length); } void Matrix_lsc::WriteToMatrixMarket(string file_name) const { - int string_length = file_name.length(); + int string_length = static_cast(file_name.length()); PrintMatrixF_lsc_wrp(ih_this, &file_name.c_str()[0], &string_length); } diff --git a/Source/Fortran/PSMatrixModule.F90 b/Source/Fortran/PSMatrixModule.F90 index a9783ffe..2d1af9b3 100644 --- a/Source/Fortran/PSMatrixModule.F90 +++ b/Source/Fortran/PSMatrixModule.F90 @@ -650,7 +650,7 @@ RECURSIVE SUBROUTINE ConstructMatrixFromBinary_ps(this, file_name, & END IF !! Compute Offset - local_triplets = total_values / this%process_grid%total_processors + local_triplets = INT(total_values / this%process_grid%total_processors) local_offset = INT(local_triplets, KIND=NTLONG) * & & this%process_grid%global_rank header_size = 3 * bytes_per_int + bytes_per_long diff --git a/Targets/Linux.cmake b/Targets/Linux.cmake index 69989110..9222af4d 100644 --- a/Targets/Linux.cmake +++ b/Targets/Linux.cmake @@ -13,5 +13,11 @@ set(CXX_TOOLCHAINFLAGS_RELEASE "-O3 -fopenmp") set(F_TOOLCHAINFLAGS_RELEASE "-O3 -cpp -fopenmp") # Debug suggestions -set(CXX_TOOLCHAINFLAGS_DEBUG "-O0 -fopenmp -Wall") -set(F_TOOLCHAINFLAGS_DEBUG "-O0 -cpp -fcheck=all -Wall -std=f2003") +set(CXX_TOOLCHAINFLAGS_DEBUG "-O0 -fopenmp -Wall -Wextra \ + -pedantic -pedantic-errors -Wshadow -Wnull-dereference \ + -Wdouble-promotion -Woverloaded-virtual -Wmisleading-indentation \ + -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wuseless-cast \ + -Wsign-conversion -Wconversion -Wcast-align -Wold-style-cast") +set(F_TOOLCHAINFLAGS_DEBUG "-O0 -cpp -fcheck=all -Wall -Wextra -Werror \ + -pedantic -fimplicit-none -ffpe-trap=invalid,zero,overflow,underflow \ + -std=f2003")