From 5b1a3deb5055ee4100adff24afd0c68717adf9bd Mon Sep 17 00:00:00 2001 From: Eyal Rozenberg Date: Tue, 25 Jan 2022 22:38:21 +0200 Subject: [PATCH] Fixes #76: Now preventing clang and gcc from replacing our aliased functions with strength-reduced actual standard library functions. --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6849eb46..cc2331d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,6 +93,12 @@ if (CMAKE_C_COMPILER_ID STREQUAL "MSVC") elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang") target_compile_options(printf PRIVATE -Wall -Wextra -pedantic -Wconversion) + if (ALIAS_STANDARD_FUNCTION_NAMES) + # This is important for preventing our aliased implementation + # from being replaced, e.g. printf("%c", 'a') by putchar('a'); + # clang and GCC apparently do this as an optimization + target_compile_options(printf PUBLIC -fno-builtin-printf) + endif() endif() if (BUILD_TESTS)