From 4ef7c5f835e4a3c7300cec68907662451e7485f5 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 24 Jun 2025 21:58:07 +0200 Subject: [PATCH 1/2] Disable msvc warnings in source files ...instead of from the cmake build file. --- CMakeLists.txt | 17 ----------------- amalgam.js | 3 +++ cutils.c | 1 + libregexp.c | 1 + libunicode.c | 1 + msvc-pragmas.h | 19 +++++++++++++++++++ qjs.c | 1 + qjsc.c | 1 + quickjs-libc.c | 1 + quickjs.c | 1 + run-test262.c | 1 + 11 files changed, 30 insertions(+), 17 deletions(-) create mode 100644 msvc-pragmas.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 91c6c683e..11a8e943c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,23 +64,6 @@ if(MSVC) xcheck_add_c_compiler_flag(-Wno-reserved-identifier) xcheck_add_c_compiler_flag(-Wdeprecated-declarations) xcheck_add_c_compiler_flag(/experimental:c11atomics) - xcheck_add_c_compiler_flag(/wd4018) # -Wno-sign-conversion - xcheck_add_c_compiler_flag(/wd4061) # -Wno-implicit-fallthrough - xcheck_add_c_compiler_flag(/wd4100) # -Wno-unused-parameter - xcheck_add_c_compiler_flag(/wd4200) # -Wno-zero-length-array - xcheck_add_c_compiler_flag(/wd4242) # -Wno-shorten-64-to-32 - xcheck_add_c_compiler_flag(/wd4244) # -Wno-shorten-64-to-32 - xcheck_add_c_compiler_flag(/wd4245) # -Wno-sign-compare - xcheck_add_c_compiler_flag(/wd4267) # -Wno-shorten-64-to-32 - xcheck_add_c_compiler_flag(/wd4388) # -Wno-sign-compare - xcheck_add_c_compiler_flag(/wd4389) # -Wno-sign-compare - xcheck_add_c_compiler_flag(/wd4456) # Hides previous local declaration - xcheck_add_c_compiler_flag(/wd4457) # Hides function parameter - xcheck_add_c_compiler_flag(/wd4710) # Function not inlined - xcheck_add_c_compiler_flag(/wd4711) # Function was inlined - xcheck_add_c_compiler_flag(/wd4820) # Padding added after construct - xcheck_add_c_compiler_flag(/wd4996) # -Wdeprecated-declarations - xcheck_add_c_compiler_flag(/wd5045) # Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified endif() # Set a 8MB default stack size on Windows. diff --git a/amalgam.js b/amalgam.js index 87b0e8876..03f476233 100644 --- a/amalgam.js +++ b/amalgam.js @@ -9,6 +9,7 @@ const libunicode_c = loadFile("libunicode.c") const libunicode_h = loadFile("libunicode.h") const libunicode_table_h = loadFile("libunicode-table.h") const list_h = loadFile("list.h") +const msvc_pragmas_h = loadFile("msvc-pragmas.h") const quickjs_atom_h = loadFile("quickjs-atom.h") const quickjs_c = loadFile("quickjs.c") const quickjs_c_atomics_h = loadFile("quickjs-c-atomics.h") @@ -23,6 +24,7 @@ const gen_builtin_array_fromasync_h = loadFile("builtin-array-fromasync.h") let source = "#if defined(QJS_BUILD_LIBC) && defined(__linux__) && !defined(_GNU_SOURCE)\n" + "#define _GNU_SOURCE\n" + "#endif\n" + + msvc_pragmas_h + quickjs_c_atomics_h + cutils_h + list_h @@ -40,6 +42,7 @@ let source = "#if defined(QJS_BUILD_LIBC) && defined(__linux__) && !defined(_GNU + quickjs_libc_h + quickjs_libc_c + "#endif // QJS_BUILD_LIBC\n" +source = source.replace(/#include "msvc-pragmas.h"/g, "") source = source.replace(/#include "quickjs-atom.h"/g, quickjs_atom_h) source = source.replace(/#include "quickjs-opcode.h"/g, quickjs_opcode_h) source = source.replace(/#include "libregexp-opcode.h"/g, libregexp_opcode_h) diff --git a/cutils.c b/cutils.c index 65f23d077..8bfcd04b0 100644 --- a/cutils.c +++ b/cutils.c @@ -22,6 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "msvc-pragmas.h" #include #include #include diff --git a/libregexp.c b/libregexp.c index 26d96edcf..5b9f986eb 100644 --- a/libregexp.c +++ b/libregexp.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "msvc-pragmas.h" #include #include #include diff --git a/libunicode.c b/libunicode.c index a621c5235..843cde6a2 100644 --- a/libunicode.c +++ b/libunicode.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "msvc-pragmas.h" #include #include #include diff --git a/msvc-pragmas.h b/msvc-pragmas.h new file mode 100644 index 000000000..50cbd60c7 --- /dev/null +++ b/msvc-pragmas.h @@ -0,0 +1,19 @@ +#ifdef _MSC_VER +#pragma warning(disable: 4018) // -Wno-sign-conversion +#pragma warning(disable: 4061) // -Wno-implicit-fallthrough +#pragma warning(disable: 4100) // -Wno-unused-parameter +#pragma warning(disable: 4200) // -Wno-zero-length-array +#pragma warning(disable: 4242) // -Wno-shorten-64-to-32 +#pragma warning(disable: 4244) // -Wno-shorten-64-to-32 +#pragma warning(disable: 4245) // -Wno-sign-compare +#pragma warning(disable: 4267) // -Wno-shorten-64-to-32 +#pragma warning(disable: 4388) // -Wno-sign-compare +#pragma warning(disable: 4389) // -Wno-sign-compare +#pragma warning(disable: 4456) // Hides previous local declaration +#pragma warning(disable: 4457) // Hides function parameter +#pragma warning(disable: 4710) // Function not inlined +#pragma warning(disable: 4711) // Function was inlined +#pragma warning(disable: 4820) // Padding added after construct +#pragma warning(disable: 4996) // -Wdeprecated-declarations +#pragma warning(disable: 5045) // Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified +#endif diff --git a/qjs.c b/qjs.c index 4aed6837e..66561e0de 100644 --- a/qjs.c +++ b/qjs.c @@ -22,6 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "msvc-pragmas.h" #include #include #include diff --git a/qjsc.c b/qjsc.c index 395bcb34d..b026060dd 100644 --- a/qjsc.c +++ b/qjsc.c @@ -23,6 +23,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "msvc-pragmas.h" #include #include #include diff --git a/quickjs-libc.c b/quickjs-libc.c index 7485001eb..96a91367b 100644 --- a/quickjs-libc.c +++ b/quickjs-libc.c @@ -22,6 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "msvc-pragmas.h" #include "quickjs.h" #include #include diff --git a/quickjs.c b/quickjs.c index 28bd70d94..7ec624ad5 100644 --- a/quickjs.c +++ b/quickjs.c @@ -24,6 +24,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "msvc-pragmas.h" #include #include #include diff --git a/run-test262.c b/run-test262.c index 5dfeb5008..7f07e1e24 100644 --- a/run-test262.c +++ b/run-test262.c @@ -22,6 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "msvc-pragmas.h" #include #include #include From efdc9529c70277a4ec48839d2e3f90fa1162a8c3 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sun, 27 Jul 2025 22:25:09 +0200 Subject: [PATCH 2/2] squash! more source file fixups --- api-test.c | 1 + examples/fib.c | 1 + examples/point.c | 1 + 3 files changed, 3 insertions(+) diff --git a/api-test.c b/api-test.c index 950b4156c..8d01685f8 100644 --- a/api-test.c +++ b/api-test.c @@ -1,3 +1,4 @@ +#include "msvc-pragmas.h" #ifdef NDEBUG #undef NDEBUG #endif diff --git a/examples/fib.c b/examples/fib.c index b965acc5b..a7bf69c17 100644 --- a/examples/fib.c +++ b/examples/fib.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "../msvc-pragmas.h" #include "../quickjs.h" #define countof(x) (sizeof(x) / sizeof((x)[0])) diff --git a/examples/point.c b/examples/point.c index a82df1519..c14fd1d86 100644 --- a/examples/point.c +++ b/examples/point.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "../msvc-pragmas.h" #include "../quickjs.h" #include