1
0
mirror of https://github.com/open-simh/simh.git synced 2026-05-02 14:30:22 +00:00

SCP: Reduce compiler warnings on LP64 platforms

(Note: Reducing compiler warnings across all, but primarily LP64
platforms, is a long term objective.)

Reduce compiler warnings on LP64 platforms (macOS, Windows) and 32-bit
builds (Win32). Prefer 'size_t' for pointer arithmetic, array indexing
and extents; 'int' hasn't been used for these purposes for many years
and across many ANSI standards. N.B. that conversions from int or int32
to size_t cause the compiler to zero-extend the value, which is
inefficient.

Refactor printf() format modifiers into sim_printf_fmts.h. Add the
SIZE_T_FMT modifier for better portability, especially on LP64 platforms
where size_t is unsigned long and sizeof(size_t) > sizeof(int).

3B2: Fix known size_t printf() format.
This commit is contained in:
B. Scott Michel
2023-12-21 11:28:53 -08:00
committed by Paul Koning
parent d9d0e8bd74
commit a275c71170
11 changed files with 324 additions and 174 deletions

View File

@@ -104,7 +104,8 @@ if (WIN32)
endif ()
list(APPEND EXTRA_TARGET_CFLAGS
"$<$<AND:$<CONFIG:Debug>,$<BOOL:${DEBUG_WALL}>>:/W3>"
"$<$<CONFIG:Debug>:$<$<BOOL:${DEBUG_WALL}>:/W4>>"
"$<$<CONFIG:Release>:/W3>"
)
## Uncomment this line if you end up with /NODEFAULTLIB warninigs. You will also
@@ -135,7 +136,9 @@ if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")
## LIST(APPEND EXTRA_TARGET_CFLAGS "-Wall" "-fno-inline" "-fstrict-overflow" "-Wstrict-overflow=3")
LIST(APPEND EXTRA_TARGET_CFLAGS
"-U__STRICT_ANSI__"
"$<$<AND:$<CONFIG:Debug>,$<BOOL:${DEBUG_WALL}>>:-Wall>"
"$<$<CONFIG:Debug>:$<$<BOOL:${DEBUG_WALL}>:-Wall>>"
## Only add if WARNINGS_FATAL set; has undesirable consequences with LTO.
"$<$<CONFIG:Release>:-Wall>"
)
# 07 NOV 2022: Apparently, -O3 is kosher now.
@@ -170,13 +173,16 @@ if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")
string(REGEX REPLACE "-O3" "-O2" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
endif ()
if (WARNINGS_FATAL OR RELEASE_LTO)
if (WARNINGS_FATAL` OR RELEASE_LTO)
check_c_compiler_flag("-Werror" GCC_W_ERROR_FLAG)
if (GCC_W_ERROR_FLAG)
message(STATUS "WARNINGS_FATAL: Compiler warnings are errors!! (-Werror)")
list(APPEND EXTRA_TARGET_CFLAGS "-Werror")
if (WARNINGS_FATAL)
message(STATUS "WARNINGS_FATAL: Compiler warnings are errors!! (-Werror)")
list(APPEND EXTRA_TARGET_CFLAGS "-Werror")
endif ()
if (RELEASE_LTO)
list(APPEND EXTRA_TARGET_LFLAGS "-Werror")
message(STATUS "WARNINGS_FATAL: Link-time optimization warnings are errors!! (-Werror)")
list(APPEND EXTRA_TARGET_LFLAGS "-Werror")
endif ()
endif ()
endif ()