[SERVER-72878] Windows compilation fails with cl Version 19.34.31937 for x64 Created: 16/Jan/23  Updated: 02/Feb/24

Status: In Code Review
Project: Core Server
Component/s: Query Execution
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Marcos José Grillo Ramirez Assignee: Justin Seyster
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by WT-11718 Update WT_READ_ONCE to use _Generics ... Blocked
Related
Assigned Teams:
Query Execution
Sprint: QE 2023-05-15, QE 2023-05-29, QE 2023-06-12, QE 2023-06-26, QE 2023-07-10, QE 2023-07-24, QE 2023-08-07, QE 2023-08-21, QE 2023-09-04, QE 2023-09-18, QE 2023-10-02, QE 2023-10-16, QE 2023-10-30, QE 2023-11-13, QE 2023-11-27, QE 2023-12-11, QE 2023-12-25, QE 2024-01-08, QE 2024-01-22, QE 2024-02-05, QE 2024-02-19
Participants:

 Description   

After updating to Visual Studio ver. 17.4.3 there are some compilation errors that seem related to SERVER-65148, the error shown when trying to build is the following:

> ninja install-core
[1/4] Compiled build\debug\third_party\mozjs\platform\x86_64\windows\build\jit\Unified_cpp_js_src_jit2.obj
FAILED: build/debug/third_party/mozjs/platform/x86_64/windows/build/jit/Unified_cpp_js_src_jit2.obj
cmd.exe /c del /q build\debug\third_party\mozjs\platform\x86_64\windows\build\jit\Unified_cpp_js_src_jit2.obj >nul 2>&1 & cl @build\debug\third_party\mozjs\platform\x86_64\windows\build\jit\Unified_cpp_js_src_jit2.obj.rsp
src\third_party\mozjs\extract\js\src\jit/CacheIRCompiler.h(1135,3): fatal error C1001: Internal compiler error.
(compiler file '_work\1\s\src\vctools\Compiler\CxxFE\sl\p1\c\main.c', line 2018)
 To work around this problem, try simplifying or changing the program near the locations listed above.
If possible please provide a repro here: https://developercommunity.visualstudio.com
Please choose the Technical Support command on the Visual C++
 Help menu, or open the Technical Support help file for more information
  void call() {
  ^
src\third_party\mozjs\extract\js\src\jit/CacheIRCompiler.cpp(6394,64): note: see reference to function template instantiation '<Unknown>' being compiled
      callvm.call<FnBigIntString, BigIntStringEqual<NotEqual>>();
                                                               ^
ninja: build stopped: subcommand failed.

The following diff solves the issue:

diff --git a/src/third_party/mozjs/extract/js/src/jit/CacheIRCompiler.cpp b/src/third_party/mozjs/extract/js/src/jit/CacheIRCompiler.cpp
index 971cf006f8a..92bfca7d151 100644
--- a/src/third_party/mozjs/extract/js/src/jit/CacheIRCompiler.cpp
+++ b/src/third_party/mozjs/extract/js/src/jit/CacheIRCompiler.cpp
@@ -6373,66 +6373,41 @@ bool CacheIRCompiler::emitCompareBigIntStringResult(JSOp op,
   using FnStringBigInt =
       bool (*)(JSContext*, HandleString, HandleBigInt, bool*);
 
-  switch (op) {
-    case JSOp::Eq: {
 #ifndef _MSC_VER
       constexpr auto Equal = EqualityKind::Equal;
+      constexpr auto NotEqual = EqualityKind::NotEqual;
+      constexpr auto LessThan = ComparisonKind::LessThan;
+      constexpr auto GreaterThanOrEqual = ComparisonKind::GreaterThanOrEqual;
 #else
       // The static_cast works around an internal compiler error in MSVC.
       constexpr auto Equal = static_cast<bool>(EqualityKind::Equal);
+      constexpr auto NotEqual = static_cast<bool>(EqualityKind::NotEqual);
+      constexpr auto LessThan = static_cast<bool>(ComparisonKind::LessThan);
+      constexpr auto GreaterThanOrEqual =
+          static_cast<bool>(ComparisonKind::GreaterThanOrEqual);
 #endif
+  switch (op) {
+    case JSOp::Eq: {
       callvm.call<FnBigIntString, BigIntStringEqual<Equal>>();
       break;
     }
     case JSOp::Ne: {
-#ifndef _MSC_VER
-      constexpr auto NotEqual = EqualityKind::NotEqual;
-#else
-      // The static_cast works around an internal compiler error in MSVC.
-      constexpr auto NotEqual = static_cast<bool>(EqualityKind::NotEqual);
-#endif
       callvm.call<FnBigIntString, BigIntStringEqual<NotEqual>>();
       break;
     }
     case JSOp::Lt: {
-#ifndef _MSC_VER
-      constexpr auto LessThan = ComparisonKind::LessThan;
-#else
-      // The static_cast works around an internal compiler error in MSVC.
-      constexpr auto LessThan = static_cast<bool>(ComparisonKind::LessThan);
-#endif
       callvm.call<FnBigIntString, BigIntStringCompare<LessThan>>();
       break;
     }
     case JSOp::Gt: {
-#ifndef _MSC_VER
-      constexpr auto LessThan = ComparisonKind::LessThan;
-#else
-      // The static_cast works around an internal compiler error in MSVC.
-      constexpr auto LessThan = static_cast<bool>(ComparisonKind::LessThan);
-#endif
       callvm.call<FnStringBigInt, StringBigIntCompare<LessThan>>();
       break;
     }
     case JSOp::Le: {
-#ifndef _MSC_VER
-      constexpr auto GreaterThanOrEqual = ComparisonKind::GreaterThanOrEqual;
-#else
-      // The static_cast works around an internal compiler error in MSVC.
-      constexpr auto GreaterThanOrEqual =
-          static_cast<bool>(ComparisonKind::GreaterThanOrEqual);
-#endif
       callvm.call<FnStringBigInt, StringBigIntCompare<GreaterThanOrEqual>>();
       break;
     }
     case JSOp::Ge: {
-#ifndef _MSC_VER
-      constexpr auto GreaterThanOrEqual = ComparisonKind::GreaterThanOrEqual;
-#else
-      // The static_cast works around an internal compiler error in MSVC.
-      constexpr auto GreaterThanOrEqual =
-          static_cast<bool>(ComparisonKind::GreaterThanOrEqual);
-#endif
       callvm.call<FnBigIntString, BigIntStringCompare<GreaterThanOrEqual>>();
       break;
     }

Basically moving the ifdef's before the switch.



 Comments   
Comment by Githook User [ 22/Dec/23 ]

Author:

{'name': 'Justin Seyster', 'email': 'justin.seyster@mongodb.com', 'username': 'jseyster'}

Message: SERVER-72878 Work around MSVC internal compiler error in MozJS

GitOrigin-RevId: a40486e2c81a29fd91e685c1185c030d5c566116
Branch: master
https://github.com/mongodb/mongo/commit/605c1939a2be9bd54e7bf45ce7c4339534f1f6da

Comment by Andrew Morton [ 04/Oct/23 ]

Yep, I've managed to hit the same

src\third_party\mozjs\extract\js\src\jit/CacheIRCompiler.cpp(6394,64): note: see reference to function template instantiation '<Unknown>' being compiled
callvm.call<FnBigIntString, BigIntStringEqual<NotEqual>>();

error on 3 consecutive patch executions. We're using hosts with a newer Windows SDK which is likely the reason it repros reliably now.

Comment by Justin Seyster [ 03/Oct/23 ]

andrew.morton@mongodb.com Thanks for following up. Is the failure in BUILD-17821 something that reproduces consistently? This ICE has popped up a few times, but never reliably. I'm going to be making some mozjs changes when my current project wraps up, so that would be a good time for me to revisit this and test out possible workarounds. If we have a reliable repro, I may also be able to file an actionable bug report with the MSVC team.

Comment by Luke Pearson [ 17/Sep/23 ]

Bumping this ticket, we encountered this when trying to upgrade to a newer Visual studio version in BUILD-17821. It seems like it hasn't gone away at least for visual studio version vs_Professional_17.7.1.exe. Is there a path forward here?

Comment by Marcos José Grillo Ramirez [ 18/May/23 ]

kyle.suarez@mongodb.com justin.seyster@mongodb.com I've checked and it went away, I'm not sure when.

Comment by Kyle Suarez [ 18/May/23 ]

justin.seyster@mongodb.com, is this an actual active issue? Or did the compile break go away between Feb and now? CC amr.elhelw@mongodb.com

Generated at Thu Feb 08 06:23:03 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.