diff options
| -rw-r--r-- | cmake/Findllvm.cmake | 8 | ||||
| -rw-r--r-- | lib/libc/mingw/lib32/user32.def | 998 | ||||
| -rw-r--r-- | lib/std/build.zig | 8 | ||||
| -rw-r--r-- | lib/std/builtin.zig | 1 | ||||
| -rw-r--r-- | src/Compilation.zig | 3 | ||||
| -rw-r--r-- | src/link.zig | 1 | ||||
| -rw-r--r-- | src/link/Elf.zig | 5 | ||||
| -rw-r--r-- | src/main.zig | 9 | ||||
| -rw-r--r-- | src/mingw.zig | 11 | ||||
| -rw-r--r-- | src/stage1/ir.cpp | 141 | ||||
| -rw-r--r-- | test/compile_errors.zig | 47 | ||||
| -rw-r--r-- | test/stage1/behavior/type.zig | 27 | ||||
| -rw-r--r-- | test/stage1/behavior/type_info.zig | 8 |
13 files changed, 1234 insertions, 33 deletions
diff --git a/cmake/Findllvm.cmake b/cmake/Findllvm.cmake index 6bee52c315..59d8e1352b 100644 --- a/cmake/Findllvm.cmake +++ b/cmake/Findllvm.cmake @@ -55,13 +55,13 @@ elseif("${ZIG_TARGET_TRIPLE}" STREQUAL "native") OUTPUT_STRIP_TRAILING_WHITESPACE) if("${LLVM_CONFIG_VERSION}" VERSION_LESS 10) - message(FATAL_ERROR "expected LLVM 10.x but found ${LLVM_CONFIG_VERSION}") + message(FATAL_ERROR "expected LLVM 10.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}") endif() if("${LLVM_CONFIG_VERSION}" VERSION_EQUAL 11) - message(FATAL_ERROR "expected LLVM 10.x but found ${LLVM_CONFIG_VERSION}") + message(FATAL_ERROR "expected LLVM 10.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}") endif() if("${LLVM_CONFIG_VERSION}" VERSION_GREATER 11) - message(FATAL_ERROR "expected LLVM 10.x but found ${LLVM_CONFIG_VERSION}") + message(FATAL_ERROR "expected LLVM 10.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}") endif() execute_process( @@ -72,7 +72,7 @@ elseif("${ZIG_TARGET_TRIPLE}" STREQUAL "native") function(NEED_TARGET TARGET_NAME) list (FIND LLVM_TARGETS_BUILT "${TARGET_NAME}" _index) if (${_index} EQUAL -1) - message(FATAL_ERROR "LLVM is missing target ${TARGET_NAME}. Zig requires LLVM to be built with all default targets enabled.") + message(FATAL_ERROR "LLVM (according to ${LLVM_CONFIG_EXE}) is missing target ${TARGET_NAME}. Zig requires LLVM to be built with all default targets enabled.") endif() endfunction(NEED_TARGET) NEED_TARGET("AArch64") diff --git a/lib/libc/mingw/lib32/user32.def b/lib/libc/mingw/lib32/user32.def new file mode 100644 index 0000000000..c20d16835a --- /dev/null +++ b/lib/libc/mingw/lib32/user32.def @@ -0,0 +1,998 @@ +LIBRARY USER32.dll +EXPORTS +;ord_1500@16 @1500 +;ord_1501@4 @1501 +;ord_1502@12 @1502 +ActivateKeyboardLayout@8 +AddClipboardFormatListener@4 +AdjustWindowRect@12 +AdjustWindowRectEx@16 +AlignRects@16 +AllowForegroundActivation@0 +AllowSetForegroundWindow@4 +AnimateWindow@12 +AnyPopup@0 +AppendMenuA@16 +AppendMenuW@16 +ArrangeIconicWindows@4 +AttachThreadInput@12 +BeginDeferWindowPos@4 +BeginPaint@8 +BlockInput@4 +BringWindowToTop@4 +BroadcastSystemMessage@20 +BroadcastSystemMessageA@20 +BroadcastSystemMessageExA@24 +BroadcastSystemMessageExW@24 +BroadcastSystemMessageW@20 +BuildReasonArray@12 +CalcChildScroll@8 +CalcMenuBar@20 +CalculatePopupWindowPosition@20 +CallMsgFilter@8 +CallMsgFilterA@8 +CallMsgFilterW@8 +CallNextHookEx@16 +CallWindowProcA@20 +CallWindowProcW@20 +CancelShutdown@0 +CascadeChildWindows@8 +CascadeWindows@20 +ChangeClipboardChain@8 +ChangeDisplaySettingsA@8 +ChangeDisplaySettingsExA@20 +ChangeDisplaySettingsExW@20 +ChangeDisplaySettingsW@8 +ChangeMenuA@20 +ChangeMenuW@20 +ChangeWindowMessageFilter@8 +ChangeWindowMessageFilterEx@16 +CharLowerA@4 +CharLowerBuffA@8 +CharLowerBuffW@8 +CharLowerW@4 +CharNextA@4 +;ord_1550@12 @1550 +;ord_1551@8 @1551 +;ord_1552@8 @1552 +;ord_1553@12 @1553 +;ord_1554@8 @1554 +;ord_1555@16 @1555 +;ord_1556@4 @1556 +CharNextExA@12 +CharNextW@4 +CharPrevA@8 +CharPrevExA@16 +CharPrevW@8 +CharToOemA@8 +CharToOemBuffA@12 +CharToOemBuffW@12 +CharToOemW@8 +CharUpperA@4 +CharUpperBuffA@8 +CharUpperBuffW@8 +CharUpperW@4 +CheckDesktopByThreadId@4 +CheckDBCSEnabledExt@0 +CheckDlgButton@12 +CheckMenuItem@12 +CheckMenuRadioItem@20 +CheckProcessForClipboardAccess@8 +CheckProcessSession@4 +CheckRadioButton@16 +CheckWindowThreadDesktop@8 +ChildWindowFromPoint@12 +ChildWindowFromPointEx@16 +CliImmSetHotKey@16 +ClientThreadSetup@0 +ClientToScreen@8 +ClipCursor@4 +CloseClipboard@0 +CloseDesktop@4 +CloseGestureInfoHandle@4 +CloseTouchInputHandle@4 +CloseWindow@4 +CloseWindowStation@4 +ConsoleControl@12 +ControlMagnification@8 +CopyAcceleratorTableA@12 +CopyAcceleratorTableW@12 +CopyIcon@4 +CopyImage@20 +CopyRect@8 +CountClipboardFormats@0 +CreateAcceleratorTableA@8 +CreateAcceleratorTableW@8 +CreateCaret@16 +CreateCursor@28 +CreateDCompositionHwndTarget@12 +CreateDesktopA@24 +CreateDesktopExA@32 +CreateDesktopExW@32 +CreateDesktopW@24 +CreateDialogIndirectParamA@20 +CreateDialogIndirectParamAorW@24 +CreateDialogIndirectParamW@20 +CreateDialogParamA@20 +CreateDialogParamW@20 +CreateIcon@28 +CreateIconFromResource@16 +CreateIconFromResourceEx@28 +CreateIconIndirect@4 +CreateMDIWindowA@40 +CreateMDIWindowW@40 +CreateMenu@0 +CreatePopupMenu@0 +CreateSystemThreads@16 ; ReactOS has the @8 variant +CreateWindowExA@48 +CreateWindowExW@48 +CreateWindowInBand@52 +CreateWindowIndirect@4 +CreateWindowStationA@16 +CreateWindowStationW@16 +CsrBroadcastSystemMessageExW@24 +CtxInitUser32@0 +DdeAbandonTransaction@12 +DdeAccessData@8 +DdeAddData@16 +DdeClientTransaction@32 +DdeCmpStringHandles@8 +DdeConnect@16 +DdeConnectList@20 +DdeCreateDataHandle@28 +DdeCreateStringHandleA@12 +DdeCreateStringHandleW@12 +DdeDisconnect@4 +DdeDisconnectList@4 +DdeEnableCallback@12 +DdeFreeDataHandle@4 +DdeFreeStringHandle@8 +DdeGetData@16 +DdeGetLastError@4 +DdeGetQualityOfService@12 +DdeImpersonateClient@4 +DdeInitializeA@16 +DdeInitializeW@16 +DdeKeepStringHandle@8 +DdeNameService@16 +DdePostAdvise@12 +DdeQueryConvInfo@12 +DdeQueryNextServer@8 +DdeQueryStringA@20 +DdeQueryStringW@20 +DdeReconnect@4 +DdeSetQualityOfService@12 +DdeSetUserHandle@12 +DdeUnaccessData@4 +DdeUninitialize@4 +DefDlgProcA@16 +DefDlgProcW@16 +DefFrameProcA@20 +DefFrameProcW@20 +DefMDIChildProcA@16 +DefMDIChildProcW@16 +DefRawInputProc@12 +DefWindowProcA@16 +DefWindowProcW@16 +DeferWindowPos@32 +DeferWindowPosAndBand@36 +DeleteMenu@12 +DeregisterShellHookWindow@4 +DestroyAcceleratorTable@4 +DestroyCaret@0 +DestroyCursor@4 +DestroyDCompositionHwndTarget@8 +DestroyIcon@4 +DestroyMenu@4 +DestroyReasons@4 +DestroyWindow@4 +DeviceEventWorker@24 ; No documentation whatsoever, ReactOS has a stub with @20 - https://www.reactos.org/archives/public/ros-diffs/2011-February/040308.html +DialogBoxIndirectParamA@20 +DialogBoxIndirectParamAorW@24 +DialogBoxIndirectParamW@20 +DialogBoxParamA@20 +DialogBoxParamW@20 +DisableProcessWindowsGhosting@0 +DispatchMessageA@4 +DispatchMessageW@4 +DisplayConfigGetDeviceInfo@4 +DisplayConfigSetDeviceInfo@4 +DisplayExitWindowsWarnings@4 +DlgDirListA@20 +DlgDirListComboBoxA@20 +DlgDirListComboBoxW@20 +DlgDirListW@20 +DlgDirSelectComboBoxExA@16 +DlgDirSelectComboBoxExW@16 +DlgDirSelectExA@16 +DlgDirSelectExW@16 +DoSoundConnect@0 +DoSoundDisconnect@0 +DragDetect@12 +DragObject@20 +DrawAnimatedRects@16 +DrawCaption@16 +DrawCaptionTempA@28 +DrawCaptionTempW@28 +DrawEdge@16 +DrawFocusRect@8 +DrawFrame@16 +DrawFrameControl@16 +DrawIcon@16 +DrawIconEx@36 +DrawMenuBar@4 +DrawMenuBarTemp@20 +DrawStateA@40 +DrawStateW@40 +DrawTextA@20 +DrawTextExA@24 +DrawTextExW@24 +DrawTextW@20 +DwmGetDxSharedSurface@24 +DwmGetRemoteSessionOcclusionEvent@0 +DwmGetRemoteSessionOcclusionState@0 +DwmLockScreenUpdates@4 +DwmStartRedirection@8 ; Mentioned on http://habrahabr.ru/post/145174/ , enables GDI virtualization (for security purposes) +DwmStopRedirection@0 +DwmValidateWindow@8 +EditWndProc@16 +EmptyClipboard@0 +EnableMenuItem@12 +EnableMouseInPointer@4 +EnableScrollBar@12 +EnableSessionForMMCSS@4 +EnableWindow@8 +EndDeferWindowPos@4 +EndDeferWindowPosEx@8 +EndDialog@8 +EndMenu@0 +EndPaint@8 +EndTask@12 +EnterReaderModeHelper@4 +EnumChildWindows@12 +EnumClipboardFormats@4 +EnumDesktopWindows@12 +EnumDesktopsA@12 +EnumDesktopsW@12 +EnumDisplayDevicesA@16 +EnumDisplayDevicesW@16 +EnumDisplayMonitors@16 +EnumDisplaySettingsA@12 +EnumDisplaySettingsExA@16 +EnumDisplaySettingsExW@16 +EnumDisplaySettingsW@12 +EnumPropsA@8 +EnumPropsExA@12 +EnumPropsExW@12 +EnumPropsW@8 +EnumThreadWindows@12 +EnumWindowStationsA@8 +EnumWindowStationsW@8 +EnumWindows@8 +EqualRect@8 +EvaluateProximityToPolygon@16 +EvaluateProximityToRect@12 +ExcludeUpdateRgn@8 +ExitWindowsEx@8 +FillRect@12 +FindWindowA@8 +FindWindowExA@16 +FindWindowExW@16 +FindWindowW@8 +FlashWindow@8 +FlashWindowEx@4 +FrameRect@12 +FreeDDElParam@8 +FrostCrashedWindow@8 +GetActiveWindow@0 +GetAltTabInfo@20 +GetAltTabInfoA@20 +GetAltTabInfoW@20 +GetAncestor@8 +GetAppCompatFlags2@4 +GetAppCompatFlags@8 ; ReactOS has @4 version http://doxygen.reactos.org/d9/d71/undocuser_8h_a9b76cdc68c523a061c86a40367049ed2.html +GetAsyncKeyState@4 +GetAutoRotationState@4 +GetCIMSSM@4 +GetCapture@0 +GetCaretBlinkTime@0 +GetCaretPos@4 +GetClassInfoA@12 +GetClassInfoExA@12 +GetClassInfoExW@12 +GetClassInfoW@12 +GetClassLongA@8 +GetClassLongW@8 +GetClassNameA@12 +GetClassNameW@12 +GetClassWord@8 +GetClientRect@8 +GetClipCursor@4 +GetClipboardAccessToken@8 +GetClipboardData@4 +GetClipboardFormatNameA@12 +GetClipboardFormatNameW@12 +GetClipboardOwner@0 +GetClipboardSequenceNumber@0 +GetClipboardViewer@0 +GetComboBoxInfo@8 +GetCurrentInputMessageSource@4 +GetCursor@0 +GetCursorFrameInfo@20 +GetCursorInfo@4 +GetCursorPos@4 +GetDC@4 +GetDCEx@12 +GetDesktopID@8 +GetDesktopWindow@0 +GetDialogBaseUnits@0 +GetDisplayAutoRotationPreferences@4 +GetDisplayConfigBufferSizes@12 +GetDlgCtrlID@4 +GetDlgItem@8 +GetDlgItemInt@16 +GetDlgItemTextA@16 +GetDlgItemTextW@16 +GetDoubleClickTime@0 +GetDpiForMonitorInternal@16 +GetFocus@0 +GetForegroundWindow@0 +GetGUIThreadInfo@8 +GetGestureConfig@24 +GetGestureExtraArgs@12 +GetGestureInfo@8 +GetGuiResources@8 +GetIconInfo@8 +GetIconInfoExA@8 +GetIconInfoExW@8 +GetInputDesktop@0 +GetInputLocaleInfo@8 +GetInputState@0 +GetInternalWindowPos@12 +GetKBCodePage@0 +GetKeyNameTextA@12 +GetKeyNameTextW@12 +GetKeyState@4 +GetKeyboardLayout@4 +GetKeyboardLayoutList@8 +GetKeyboardLayoutNameA@4 +GetKeyboardLayoutNameW@4 +GetKeyboardState@4 +GetKeyboardType@4 +GetLastActivePopup@4 +GetLastInputInfo@4 +GetLayeredWindowAttributes@16 +GetListBoxInfo@4 +GetMagnificationDesktopColorEffect@4 +GetMagnificationDesktopMagnification@12 +GetMagnificationLensCtxInformation@16 +GetMenu@4 +GetMenuBarInfo@16 +GetMenuCheckMarkDimensions@0 +GetMenuContextHelpId@4 +GetMenuDefaultItem@12 +GetMenuInfo@8 +GetMenuItemCount@4 +GetMenuItemID@8 +GetMenuItemInfoA@16 +GetMenuItemInfoW@16 +GetMenuItemRect@16 +GetMenuState@12 +GetMenuStringA@20 +GetMenuStringW@20 +GetMessageA@16 +GetMessageExtraInfo@0 +GetMessagePos@0 +GetMessageTime@0 +GetMessageW@16 +GetMonitorInfoA@8 +GetMonitorInfoW@8 +GetMouseMovePointsEx@20 +GetNextDlgGroupItem@12 +GetNextDlgTabItem@12 +GetOpenClipboardWindow@0 +GetParent@4 +GetPhysicalCursorPos@4 +GetPointerCursorId@8 +GetPointerDevice@8 +GetPointerDeviceCursors@12 +GetPointerDeviceProperties@12 +GetPointerDeviceRects@12 +GetPointerDevices@8 +GetPointerFrameInfo@12 +GetPointerFrameInfoHistory@16 +GetPointerFramePenInfo@12 +GetPointerFramePenInfoHistory@16 +GetPointerFrameTouchInfo@12 +GetPointerFrameTouchInfoHistory@16 +GetPointerInfo@8 +GetPointerInfoHistory@12 +GetPointerInputTransform@12 +GetPointerPenInfo@8 +GetPointerPenInfoHistory@12 +GetPointerTouchInfo@8 +GetPointerTouchInfoHistory@12 +GetPointerType@8 +GetPriorityClipboardFormat@8 +GetProcessDefaultLayout@4 +GetProcessDpiAwarenessInternal@8 +GetProcessWindowStation@0 +GetProgmanWindow@0 +GetPropA@8 +GetPropW@8 +GetQueueStatus@4 +GetRawInputBuffer@12 +GetRawInputData@20 +GetRawInputDeviceInfoA@16 +GetRawInputDeviceInfoW@16 +GetRawInputDeviceList@12 +GetRawPointerDeviceData@20 +GetReasonTitleFromReasonCode@12 +GetRegisteredRawInputDevices@12 +GetQueueStatus@4 +GetScrollBarInfo@12 +GetScrollInfo@12 +GetScrollPos@8 +GetScrollRange@16 +GetSendMessageReceiver@4 +GetShellWindow@0 +GetSubMenu@8 +GetSysColor@4 +GetSysColorBrush@4 +GetSystemMenu@8 +GetSystemMetrics@4 +GetTabbedTextExtentA@20 +GetTabbedTextExtentW@20 +GetTaskmanWindow@0 +GetThreadDesktop@4 +GetTitleBarInfo@8 +GetTopLevelWindow@4 +GetTopWindow@4 +GetTouchInputInfo@16 +GetUnpredictedMessagePos@0 +GetUpdateRect@12 +GetUpdateRgn@12 +GetUpdatedClipboardFormats@12 +GetUserObjectInformationA@20 +GetUserObjectInformationW@20 +GetUserObjectSecurity@20 +GetWinStationInfo@4 +GetWindow@8 +GetWindowBand@8 +GetWindowCompositionAttribute@8 +GetWindowCompositionInfo@8 +GetWindowContextHelpId@4 +GetWindowDC@4 +GetWindowDisplayAffinity@8 +GetWindowFeedbackSetting@20 +GetWindowInfo@8 +GetWindowLongA@8 +GetWindowLongW@8 +GetWindowMinimizeRect@8 +GetWindowModuleFileName@12 +GetWindowModuleFileNameA@12 +GetWindowModuleFileNameW@12 +GetWindowPlacement@8 +GetWindowRect@8 +GetWindowRgn@8 +GetWindowRgnBox@8 +GetWindowRgnEx@12 +GetWindowTextA@12 +GetWindowTextLengthA@4 +GetWindowTextLengthW@4 +GetWindowTextW@12 +GetWindowThreadProcessId@8 +GetWindowWord@8 +GhostWindowFromHungWindow@4 +GrayStringA@36 +GrayStringW@36 +HideCaret@4 +HiliteMenuItem@16 +HungWindowFromGhostWindow@4 +IMPGetIMEA@8 +IMPGetIMEW@8 +IMPQueryIMEA@4 +IMPQueryIMEW@4 +IMPSetIMEA@8 +IMPSetIMEW@8 +ImpersonateDdeClientWindow@8 +InSendMessage@0 +InSendMessageEx@4 +InflateRect@12 +InitializeLpkHooks@4 +InitializeWin32EntryTable@4 +InitializeTouchInjection@8 +InjectTouchInput@8 +InsertMenuA@20 +InsertMenuItemA@16 +InsertMenuItemW@16 +InsertMenuW@20 +InternalGetWindowIcon@8 +;ord_2001@4 @2001 +;ord_2002@4 @2002 +InternalGetWindowText@12 +IntersectRect@12 +;ord_2005@4 @2005 +InvalidateRect@12 +InvalidateRgn@12 +InvertRect@8 +IsCharAlphaA@4 +;ord_2010@16 @2010 +IsCharAlphaNumericA@4 +IsCharAlphaNumericW@4 +IsCharAlphaW@4 +IsCharLowerA@4 +IsCharLowerW@4 +IsCharUpperA@4 +IsCharUpperW@4 +IsChild@8 +IsClipboardFormatAvailable@4 +IsDialogMessage@8 +IsDialogMessageA@8 +IsDialogMessageW@8 +IsDlgButtonChecked@8 +IsGUIThread@4 +IsHungAppWindow@4 +IsIconic@4 +IsImmersiveProcess@4 +IsInDesktopWindowBand@4 +IsMenu@4 +IsProcess16Bit@0 +IsMouseInPointerEnabled@0 +IsProcessDPIAware@0 +IsQueueAttached@0 +IsRectEmpty@4 +IsSETEnabled@0 +IsServerSideWindow@4 +IsThreadDesktopComposited@0 +IsTopLevelWindow@4 +IsTouchWindow@8 +IsWinEventHookInstalled@4 +IsWindow@4 +IsWindowEnabled@4 +IsWindowInDestroy@4 +IsWindowRedirectedForPrint@4 +IsWindowUnicode@4 +IsWindowVisible@4 +IsWow64Message@0 +IsZoomed@4 +KillSystemTimer@8 +KillTimer@8 +LoadAcceleratorsA@8 +LoadAcceleratorsW@8 +LoadBitmapA@8 +LoadBitmapW@8 +LoadCursorA@8 +LoadCursorFromFileA@4 +LoadCursorFromFileW@4 +;ord_2000@0 @2000 +;ord_2001@4 @2001 +;ord_2002@4 @2002 +LoadCursorW@8 +LoadIconA@8 +;ord_2005@4 @2005 +LoadIconW@8 +LoadImageA@24 +LoadImageW@24 +LoadKeyboardLayoutA@8 +LoadKeyboardLayoutEx@12 +LoadKeyboardLayoutW@8 +LoadLocalFonts@0 +LoadMenuA@8 +LoadMenuIndirectA@4 +LoadMenuIndirectW@4 +LoadMenuW@8 +LoadRemoteFonts@0 +LoadStringA@16 +LoadStringW@16 +LockSetForegroundWindow@4 +LockWindowStation@4 +LockWindowUpdate@4 +LockWorkStation@0 +LogicalToPhysicalPoint@8 +LogicalToPhysicalPointForPerMonitorDPI@8 +LookupIconIdFromDirectory@8 +LookupIconIdFromDirectoryEx@20 +MBToWCSEx@24 +MBToWCSExt@20 +MB_GetString@4 +MapDialogRect@8 +MapVirtualKeyA@8 +MapVirtualKeyExA@12 +MapVirtualKeyExW@12 +MapVirtualKeyW@8 +MapWindowPoints@16 +MenuItemFromPoint@16 +MenuWindowProcA@20 +MenuWindowProcW@20 +MessageBeep@4 +MessageBoxA@16 +MessageBoxExA@20 +MessageBoxExW@20 +MessageBoxIndirectA@4 +MessageBoxIndirectW@4 +MessageBoxTimeoutA@24 +MessageBoxTimeoutW@24 +MessageBoxW@16 +ModifyMenuA@20 +ModifyMenuW@20 +MonitorFromPoint@12 +MonitorFromRect@8 +MonitorFromWindow@8 +MoveWindow@24 +MsgWaitForMultipleObjects@20 +MsgWaitForMultipleObjectsEx@20 +NotifyOverlayWindow@8 +NotifyWinEvent@16 +OemKeyScan@4 +OemToCharA@8 +OemToCharBuffA@12 +OemToCharBuffW@12 +OemToCharW@8 +OffsetRect@12 +OpenClipboard@4 +OpenDesktopA@16 +OpenDesktopW@16 +OpenIcon@4 +OpenInputDesktop@12 +OpenThreadDesktop@16 +OpenWindowStationA@12 +OpenWindowStationW@12 +PackDDElParam@12 +PackTouchHitTestingProximityEvaluation@8 +PaintDesktop@4 +PaintMenuBar@24 +PaintMonitor@12 +PeekMessageA@20 +PeekMessageW@20 +PhysicalToLogicalPoint@8 +PhysicalToLogicalPointForPerMonitorDPI@8 +PostMessageA@16 +PostMessageW@16 +PostQuitMessage@4 +PostThreadMessageA@16 +PostThreadMessageW@16 +PrintWindow@12 +PrivateExtractIconExA@20 +PrivateExtractIconExW@20 +PrivateExtractIconsA@32 +PrivateExtractIconsW@32 +PrivateSetDbgTag@8 +PrivateSetRipFlags@8 +PrivateRegisterICSProc@4 +PtInRect@12 +QueryBSDRWindow@0 +QueryDisplayConfig@24 +QuerySendMessage@4 +QueryUserCounters@20 +RealChildWindowFromPoint@12 +RealGetWindowClass@12 +RealGetWindowClassA@12 +RealGetWindowClassW@12 +ReasonCodeNeedsBugID@4 +ReasonCodeNeedsComment@4 +RecordShutdownReason@4 +RedrawWindow@16 +RegisterBSDRWindow@8 +RegisterClassA@4 +RegisterClassExA@4 +RegisterClassExW@4 +RegisterClassW@4 +RegisterClipboardFormatA@4 +RegisterClipboardFormatW@4 +RegisterDeviceNotificationA@12 +RegisterDeviceNotificationW@12 +RegisterErrorReportingDialog@8 +RegisterFrostWindow@8 +RegisterGhostWindow@8 +RegisterHotKey@16 +RegisterPowerSettingNotification@12 +RegisterLogonProcess@8 +RegisterMessagePumpHook@4 +RegisterPointerDeviceNotifications@8 +RegisterPointerInputTarget@8 +RegisterPowerSettingNotification@12 +RegisterRawInputDevices@12 +RegisterServicesProcess@4 +RegisterSessionPort@4 ; Undocumented, rumored to be related to ALPC - http://blogs.msdn.com/b/ntdebugging/archive/2007/07/26/lpc-local-procedure-calls-part-1-architecture.aspx +RegisterShellHookWindow@4 +RegisterSuspendResumeNotification@8 +RegisterSystemThread@8 +RegisterTasklist@4 +RegisterTouchHitTestingWindow@8 +RegisterTouchWindow@8 +RegisterUserApiHook@4 ; Prototype changed in 2003 - https://www.reactos.org/wiki/Techwiki:RegisterUserApiHook +RegisterWindowMessageA@4 +RegisterWindowMessageW@4 +ReleaseCapture@0 +ReleaseDC@8 +RemoveClipboardFormatListener@4 +RemoveMenu@12 +RemovePropA@8 +RemovePropW@8 +ReplyMessage@4 +ResolveDesktopForWOW@4 +ReuseDDElParam@20 +ScreenToClient@8 +ScrollChildren@12 +ScrollDC@28 +ScrollWindow@20 +ScrollWindowEx@32 +SendDlgItemMessageA@20 +SendDlgItemMessageW@20 +SendIMEMessageExA@8 +SendIMEMessageExW@8 +SendInput@12 +SendMessageA@16 +SendMessageCallbackA@24 +SendMessageCallbackW@24 +SendMessageTimeoutA@28 +SendMessageTimeoutW@28 +SendMessageW@16 +SendNotifyMessageA@16 +SendNotifyMessageW@16 +SetActiveWindow@4 +SetCapture@4 +SetCaretBlinkTime@4 +SetCaretPos@8 +SetClassLongA@12 +SetClassLongW@12 +SetClassWord@12 +SetClipboardData@8 +SetClipboardViewer@4 +SetConsoleReserveKeys@8 +SetCoalescableTimer@20 +SetCursor@4 +SetCursorContents@8 +SetCursorPos@8 +SetDebugErrorLevel@4 +SetDeskWallpaper@4 +SetDisplayAutoRotationPreferences@4 +SetDisplayConfig@20 +SetDlgItemInt@16 +SetDlgItemTextA@12 +SetDlgItemTextW@12 +SetDoubleClickTime@4 +SetFocus@4 +SetForegroundWindow@4 +SetGestureConfig@20 +SetImmersiveBackgroundWindow@4 +SetInternalWindowPos@16 +SetKeyboardState@4 +SetLastErrorEx@8 +SetLayeredWindowAttributes@16 +SetLogonNotifyWindow@4 +SetMagnificationDesktopColorEffect@4 +SetMagnificationDesktopMagnification@16 +SetMagnificationLensCtxInformation@16 +SetMenu@8 +SetMenuContextHelpId@8 +SetMenuDefaultItem@12 +SetMenuInfo@8 +SetMenuItemBitmaps@20 +SetMenuItemInfoA@16 +SetMenuItemInfoW@16 +SetMessageExtraInfo@4 +SetMessageQueue@4 +SetMirrorRendering@8 +SetParent@8 +SetPhysicalCursorPos@8 +SetProcessDPIAware@0 +SetProcessDefaultLayout@4 +SetProcessDpiAwarenessInternal@4 +SetProcessRestrictionExemption@4 +SetProcessWindowStation@4 +SetProgmanWindow@4 +SetPropA@12 +SetPropW@12 +SetRect@20 +SetRectEmpty@4 +SetScrollInfo@16 +SetScrollPos@16 +SetScrollRange@20 +SetShellWindow@4 +SetShellWindowEx@8 +SetSysColors@12 +SetSysColorsTemp@12 +SetSystemCursor@8 +SetSystemMenu@8 +SetSystemTimer@16 +SetTaskmanWindow@4 +SetThreadDesktop@4 +SetThreadInputBlocked@8 +SetTimer@16 +SetUserObjectInformationA@16 +SetUserObjectInformationW@16 +SetUserObjectSecurity@12 +SetWinEventHook@28 +SetWindowBand@12 +SetWindowCompositionAttribute@8 +SetWindowCompositionTransition@28 +SetWindowContextHelpId@8 +SetWindowDisplayAffinity@8 +SetWindowFeedbackSetting@20 +SetWindowLongA@12 +SetWindowLongW@12 +SetWindowPlacement@8 +SetWindowPos@28 +SetWindowRgn@12 +SetWindowRgnEx@12 +SetWindowStationUser@16 +SetWindowTextA@8 +SetWindowTextW@8 +SetWindowWord@12 +SetWindowsHookA@8 +SetWindowsHookExA@16 +SetWindowsHookExW@16 +SetWindowsHookW@8 +SfmDxBindSwapChain@12 +SfmDxGetSwapChainStats@8 +SfmDxOpenSwapChain@16 +SfmDxQuerySwapChainBindingStatus@12 +SfmDxReleaseSwapChain@8 +SfmDxReportPendingBindingsToDwm@0 +SfmDxSetSwapChainBindingStatus@8 +SfmDxSetSwapChainStats@8 +ShowCaret@4 +ShowCursor@4 +ShowOwnedPopups@8 +ShowScrollBar@12 +ShowStartGlass@4 +ShowSystemCursor@4 +ShowWindow@8 +ShowWindowAsync@8 +ShutdownBlockReasonCreate@8 +ShutdownBlockReasonDestroy@4 +ShutdownBlockReasonQuery@12 +SignalRedirectionStartComplete@0 +SkipPointerFrameMessages@4 +SoftModalMessageBox@4 +SoundSentry@0 +SubtractRect@12 +SwapMouseButton@4 +SwitchDesktop@4 +SwitchDesktopWithFade@12 ; Same as SwithDesktop(), only with fade (done at log-in), only usable by winlogon - http://blog.airesoft.co.uk/2010/08/things-microsoft-can-do-that-you-cant/ +SwitchToThisWindow@8 +SystemParametersInfoA@16 +SystemParametersInfoW@16 +TabbedTextOutA@32 +TabbedTextOutW@32 +TileChildWindows@8 +TileWindows@20 +ToAscii@20 +ToAsciiEx@24 +ToUnicode@24 +ToUnicodeEx@28 +TrackMouseEvent@4 +TrackPopupMenu@28 +TrackPopupMenuEx@24 +TranslateAccelerator@12 +TranslateAcceleratorA@12 +TranslateAcceleratorW@12 +TranslateMDISysAccel@8 +TranslateMessage@4 +TranslateMessageEx@8 +UnhookWinEvent@4 +UnhookWindowsHook@8 +UnhookWindowsHookEx@4 +UnionRect@12 +UnloadKeyboardLayout@4 +UnlockWindowStation@4 +UnpackDDElParam@16 +UnregisterClassA@8 +UnregisterClassW@8 +UnregisterDeviceNotification@4 +UnregisterHotKey@8 +UnregisterMessagePumpHook@0 +UnregisterPointerInputTarget@8 +UnregisterPowerSettingNotification@4 +UnregisterSessionPort@0 +UnregisterSuspendResumeNotification@4 +UnregisterTouchWindow@4 +UnregisterUserApiHook@0 +UpdateDefaultDesktopThumbnail@20 +UpdateLayeredWindow@36 +UpdateLayeredWindowIndirect@8 +UpdatePerUserSystemParameters@4 ; Undocumented, seems to apply certain registry settings to desktop, etc. ReactOS has @8 version - http://doxygen.reactos.org/d0/d92/win32ss_2user_2user32_2misc_2misc_8c_a1ff565f0af6bac6dce604f9f4473fe79.html ; @4 is rumored to be without the first DWORD +UpdateWindow@4 +UpdateWindowInputSinkHints@8 +UpdateWindowTransform@12 +User32InitializeImmEntryTable@4 +UserClientDllInitialize@12 +UserHandleGrantAccess@12 +UserLpkPSMTextOut@24 +UserLpkTabbedTextOut@48 +UserRealizePalette@4 +UserRegisterWowHandlers@8 +VRipOutput@0 +VTagOutput@0 +ValidateRect@8 +ValidateRgn@8 +VkKeyScanA@4 +VkKeyScanExA@8 +VkKeyScanExW@8 +VkKeyScanW@4 +WCSToMBEx@24 +WINNLSEnableIME@8 +WINNLSGetEnableStatus@4 +WINNLSGetIMEHotkey@4 +WaitForInputIdle@8 +WaitForRedirectionStartComplete@0 +WaitMessage@0 +Win32PoolAllocationStats@24 +WinHelpA@16 +WinHelpW@16 +WindowFromDC@4 +WindowFromPhysicalPoint@8 +WindowFromPoint@8 +_UserTestTokenForInteractive@8 +gSharedInfo DATA +gapfnScSendMessage DATA +keybd_event@16 +mouse_event@20 +wsprintfA +wsprintfW +wvsprintfA@12 +wvsprintfW@12 +;ord_2500@16 @2500 +;ord_2501@12 @2501 +;ord_2502@8 @2502 +;ord_2503@24 @2503 +;ord_2504@8 @2504 +;ord_2505@8 @2505 +;ord_2506@12 @2506 +;ord_2507@4 @2507 +;ord_2508@8 @2508 +;ord_2509@4 @2509 +;ord_2510@12 @2510 +;ord_2511@8 @2511 +;ord_2512@12 @2512 +;ord_2513@4 @2513 +;ord_2514@8 @2514 +;ord_2515@8 @2515 +;ord_2516@12 @2516 +;ord_2517@4 @2517 +;ord_2518@0 @2518 +;ord_2519@4 @2519 +;ord_2520@0 @2520 +;ord_2521@8 @2521 +;ord_2522@4 @2522 +;ord_2523@8 @2523 +;ord_2524@8 @2524 +;ord_2525@12 @2525 +;ord_2526@12 @2526 +;ord_2527@12 @2527 +IsThreadMessageQueueAttached@4 +;ord_2529@4 @2529 +;ord_2530@8 @2530 +;ord_2531@16 @2531 +;ord_2532@8 @2532 +;ord_2533@4 @2533 +;ord_2534@8 @2534 +;ord_2535@0 @2535 +;ord_2536@8 @2536 +;ord_2537@16 @2537 +;ord_2538@4 @2538 +;ord_2539@4 @2539 +;ord_2540@4 @2540 +;ord_2541@0 @2541 +;ord_2544@4 @2544 +;ord_2545@8 @2545 +;ord_2546@4 @2546 +;ord_2547@4 @2547 +;ord_2548@4 @2548 +;ord_2549@4 @2549 +;ord_2550@8 @2550 +;ord_2551@20 @2551 +;ord_2552@8 @2552 +;ord_2553@32 @2553 +;ord_2554@12 @2554 +;ord_2555@16 @2555 +;ord_2556@8 @2556 +;ord_2557@12 @2557 +;ord_2558@12 @2558 +;ord_2559@16 @2559 +;ord_2560@20 @2560 +;ord_2561@0 @2561 +;ord_2562@0 @2562 +;ord_2563@0 @2563 diff --git a/lib/std/build.zig b/lib/std/build.zig index 7e3c75bc78..8749c7ce2d 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -1239,6 +1239,7 @@ pub const LibExeObjStep = struct { /// Create a .eh_frame_hdr section and a PT_GNU_EH_FRAME segment in the ELF /// file. link_eh_frame_hdr: bool = false, + link_emit_relocs: bool = false, /// Place every function in its own section so that unused ones may be /// safely garbage-collected during the linking phase. @@ -2075,6 +2076,9 @@ pub const LibExeObjStep = struct { if (self.link_eh_frame_hdr) { try zig_args.append("--eh-frame-hdr"); } + if (self.link_emit_relocs) { + try zig_args.append("--emit-relocs"); + } if (self.link_function_sections) { try zig_args.append("-ffunction-sections"); } @@ -2168,8 +2172,8 @@ pub const LibExeObjStep = struct { } if (self.linker_script) |linker_script| { - zig_args.append("--linker-script") catch unreachable; - zig_args.append(builder.pathFromRoot(linker_script)) catch unreachable; + try zig_args.append("--script"); + try zig_args.append(builder.pathFromRoot(linker_script)); } if (self.version_script) |version_script| { diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index d80d0e88fe..92fa78bc39 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -343,6 +343,7 @@ pub const TypeInfo = union(enum) { /// therefore must be kept in sync with the compiler implementation. pub const Fn = struct { calling_convention: CallingConvention, + alignment: comptime_int, is_generic: bool, is_var_args: bool, return_type: ?type, diff --git a/src/Compilation.zig b/src/Compilation.zig index 623635a6b0..fc801c7789 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -352,6 +352,7 @@ pub const InitOptions = struct { time_report: bool = false, stack_report: bool = false, link_eh_frame_hdr: bool = false, + link_emit_relocs: bool = false, linker_script: ?[]const u8 = null, version_script: ?[]const u8 = null, override_soname: ?[]const u8 = null, @@ -447,6 +448,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { options.system_libs.len != 0 or options.link_libc or options.link_libcpp or options.link_eh_frame_hdr or + options.link_emit_relocs or options.output_mode == .Lib or options.lld_argv.len != 0 or options.linker_script != null or options.version_script != null) @@ -769,6 +771,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { .version_script = options.version_script, .gc_sections = options.linker_gc_sections, .eh_frame_hdr = options.link_eh_frame_hdr, + .emit_relocs = options.link_emit_relocs, .rdynamic = options.rdynamic, .extra_lld_args = options.lld_argv, .override_soname = options.override_soname, diff --git a/src/link.zig b/src/link.zig index 4d28c8a1a7..3b00684170 100644 --- a/src/link.zig +++ b/src/link.zig @@ -60,6 +60,7 @@ pub const Options = struct { link_libcpp: bool, function_sections: bool, eh_frame_hdr: bool, + emit_relocs: bool, rdynamic: bool, z_nodelete: bool, z_defs: bool, diff --git a/src/link/Elf.zig b/src/link/Elf.zig index 38b9b1acca..8e7a02114e 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -1286,6 +1286,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { man.hash.add(stack_size); man.hash.add(gc_sections); man.hash.add(self.base.options.eh_frame_hdr); + man.hash.add(self.base.options.emit_relocs); man.hash.add(self.base.options.rdynamic); man.hash.addListOfBytes(self.base.options.extra_lld_args); man.hash.addListOfBytes(self.base.options.lib_dirs); @@ -1364,6 +1365,10 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { if (self.base.options.eh_frame_hdr) { try argv.append("--eh-frame-hdr"); } + + if (self.base.options.emit_relocs) { + try argv.append("--emit-relocs"); + } if (self.base.options.rdynamic) { try argv.append("--export-dynamic"); diff --git a/src/main.zig b/src/main.zig index d421322c17..d1017a911d 100644 --- a/src/main.zig +++ b/src/main.zig @@ -273,6 +273,7 @@ const usage_build_generic = \\ -rdynamic Add all symbols to the dynamic symbol table \\ -rpath [path] Add directory to the runtime library search path \\ --eh-frame-hdr Enable C++ exception handling by passing --eh-frame-hdr to linker + \\ --emit-relocs Enable output of relocation sections for post build tools \\ -dynamic Force output to be dynamically linked \\ -static Force output to be statically linked \\ -Bsymbolic Bind global references locally @@ -438,6 +439,7 @@ fn buildOutputType( var use_lld: ?bool = null; var use_clang: ?bool = null; var link_eh_frame_hdr = false; + var link_emit_relocs = false; var each_lib_rpath = false; var libc_paths_file: ?[]const u8 = null; var machine_code_model: std.builtin.CodeModel = .default; @@ -838,6 +840,8 @@ fn buildOutputType( function_sections = true; } else if (mem.eql(u8, arg, "--eh-frame-hdr")) { link_eh_frame_hdr = true; + } else if (mem.eql(u8, arg, "--emit-relocs")) { + link_emit_relocs = true; } else if (mem.eql(u8, arg, "-Bsymbolic")) { linker_bind_global_refs_locally = true; } else if (mem.eql(u8, arg, "--verbose-link")) { @@ -1206,6 +1210,10 @@ fn buildOutputType( fatal("translate-c expects exactly 1 source file (found {})", .{c_source_files.items.len}); } + if (root_src_file == null and (arg_mode == .zig_test or arg_mode == .run)) { + fatal("one zig source file is required to run this command", .{}); + } + const root_name = if (provided_name) |n| n else blk: { if (arg_mode == .zig_test) { break :blk "test"; @@ -1580,6 +1588,7 @@ fn buildOutputType( .linker_z_nodelete = linker_z_nodelete, .linker_z_defs = linker_z_defs, .link_eh_frame_hdr = link_eh_frame_hdr, + .link_emit_relocs = link_emit_relocs, .stack_size_override = stack_size_override, .strip = strip, .single_threaded = single_threaded, diff --git a/src/mingw.zig b/src/mingw.zig index b6c8591ea4..ff4156cfb9 100644 --- a/src/mingw.zig +++ b/src/mingw.zig @@ -32,6 +32,8 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { var args = std.ArrayList([]const u8).init(arena); try add_cc_args(comp, arena, &args); try args.appendSlice(&[_][]const u8{ + "-D_SYSCRT=1", + "-DCRTDLL=1", "-U__CRTDLL__", "-D__MSVCRT__", // Uncomment these 3 things for crtu @@ -53,6 +55,8 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { var args = std.ArrayList([]const u8).init(arena); try add_cc_args(comp, arena, &args); try args.appendSlice(&[_][]const u8{ + "-D_SYSCRT=1", + "-DCRTDLL=1", "-U__CRTDLL__", "-D__MSVCRT__", }); @@ -437,11 +441,8 @@ fn findDef(comp: *Compilation, allocator: *Allocator, lib_name: []const u8) ![]u const lib_path = switch (target.cpu.arch) { .i386 => "lib32", .x86_64 => "lib64", - .arm, .armeb => switch (target.cpu.arch.ptrBitWidth()) { - 32 => "libarm32", - 64 => "libarm64", - else => unreachable, - }, + .arm, .armeb, .thumb, .thumbeb, .aarch64_32 => "libarm32", + .aarch64, .aarch64_be => "libarm64", else => unreachable, }; diff --git a/src/stage1/ir.cpp b/src/stage1/ir.cpp index 8da207cab7..045f1ad784 100644 --- a/src/stage1/ir.cpp +++ b/src/stage1/ir.cpp @@ -25564,7 +25564,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy result->special = ConstValSpecialStatic; result->type = ir_type_info_get_type(ira, "Fn", nullptr); - ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 5); + ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 6); result->data.x_struct.fields = fields; // calling_convention: TypeInfo.CallingConvention @@ -25572,38 +25572,42 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy fields[0]->special = ConstValSpecialStatic; fields[0]->type = get_builtin_type(ira->codegen, "CallingConvention"); bigint_init_unsigned(&fields[0]->data.x_enum_tag, type_entry->data.fn.fn_type_id.cc); + // alignment: u29 + ensure_field_index(result->type, "alignment", 1); + fields[1]->special = ConstValSpecialStatic; + fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int; + bigint_init_unsigned(&fields[1]->data.x_bigint, type_entry->data.fn.fn_type_id.alignment); // is_generic: bool - ensure_field_index(result->type, "is_generic", 1); + ensure_field_index(result->type, "is_generic", 2); bool is_generic = type_entry->data.fn.is_generic; - fields[1]->special = ConstValSpecialStatic; - fields[1]->type = ira->codegen->builtin_types.entry_bool; - fields[1]->data.x_bool = is_generic; - // is_varargs: bool - ensure_field_index(result->type, "is_var_args", 2); - bool is_varargs = type_entry->data.fn.fn_type_id.is_var_args; fields[2]->special = ConstValSpecialStatic; fields[2]->type = ira->codegen->builtin_types.entry_bool; - fields[2]->data.x_bool = type_entry->data.fn.fn_type_id.is_var_args; - // return_type: ?type - ensure_field_index(result->type, "return_type", 3); + fields[2]->data.x_bool = is_generic; + // is_varargs: bool + ensure_field_index(result->type, "is_var_args", 3); + bool is_varargs = type_entry->data.fn.fn_type_id.is_var_args; fields[3]->special = ConstValSpecialStatic; - fields[3]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type); + fields[3]->type = ira->codegen->builtin_types.entry_bool; + fields[3]->data.x_bool = is_varargs; + // return_type: ?type + ensure_field_index(result->type, "return_type", 4); + fields[4]->special = ConstValSpecialStatic; + fields[4]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type); if (type_entry->data.fn.fn_type_id.return_type == nullptr) - fields[3]->data.x_optional = nullptr; + fields[4]->data.x_optional = nullptr; else { ZigValue *return_type = ira->codegen->pass1_arena->create<ZigValue>(); return_type->special = ConstValSpecialStatic; return_type->type = ira->codegen->builtin_types.entry_type; return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type; - fields[3]->data.x_optional = return_type; + fields[4]->data.x_optional = return_type; } // args: []TypeInfo.FnArg ZigType *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr); if ((err = type_resolve(ira->codegen, type_info_fn_arg_type, ResolveStatusSizeKnown))) { zig_unreachable(); } - size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count - - (is_varargs && type_entry->data.fn.fn_type_id.cc != CallingConventionC); + size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count; ZigValue *fn_arg_array = ira->codegen->pass1_arena->create<ZigValue>(); fn_arg_array->special = ConstValSpecialStatic; @@ -25611,7 +25615,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy fn_arg_array->data.x_array.special = ConstArraySpecialNone; fn_arg_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(fn_arg_count); - init_const_slice(ira->codegen, fields[4], fn_arg_array, 0, fn_arg_count, false); + init_const_slice(ira->codegen, fields[5], fn_arg_array, 0, fn_arg_count, false); for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) { FnTypeParamInfo *fn_param_info = &type_entry->data.fn.fn_type_id.param_info[fn_arg_index]; @@ -26327,10 +26331,105 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI return entry; } case ZigTypeIdFn: - case ZigTypeIdBoundFn: - ir_add_error(ira, source_instr, buf_sprintf( - "@Type not available for 'TypeInfo.%s'", type_id_name(tagTypeId))); - return ira->codegen->invalid_inst_gen->value->type; + case ZigTypeIdBoundFn: { + assert(payload->special == ConstValSpecialStatic); + assert(payload->type == ir_type_info_get_type(ira, "Fn", nullptr)); + + ZigValue *cc_value = get_const_field(ira, source_instr->source_node, payload, "calling_convention", 0); + if (cc_value == nullptr) + return ira->codegen->invalid_inst_gen->value->type; + assert(cc_value->special == ConstValSpecialStatic); + assert(cc_value->type == get_builtin_type(ira->codegen, "CallingConvention")); + CallingConvention cc = (CallingConvention)bigint_as_u32(&cc_value->data.x_enum_tag); + + BigInt *alignment = get_const_field_lit_int(ira, source_instr->source_node, payload, "alignment", 1); + if (alignment == nullptr) + return ira->codegen->invalid_inst_gen->value->type; + + Error err; + bool is_generic; + if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_generic", 2, &is_generic))) + return ira->codegen->invalid_inst_gen->value->type; + if (is_generic) { + ir_add_error(ira, source_instr, buf_sprintf("TypeInfo.Fn.is_generic must be false for @Type")); + return ira->codegen->invalid_inst_gen->value->type; + } + + bool is_var_args; + if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_var_args", 3, &is_var_args))) + return ira->codegen->invalid_inst_gen->value->type; + if (is_var_args && cc != CallingConventionC) { + ir_add_error(ira, source_instr, buf_sprintf("varargs functions must have C calling convention")); + return ira->codegen->invalid_inst_gen->value->type; + } + + ZigType *return_type = get_const_field_meta_type_optional(ira, source_instr->source_node, payload, "return_type", 4); + if (return_type == nullptr) { + ir_add_error(ira, source_instr, buf_sprintf("TypeInfo.Fn.return_type must be non-null for @Type")); + return ira->codegen->invalid_inst_gen->value->type; + } + + ZigValue *args_value = get_const_field(ira, source_instr->source_node, payload, "args", 5); + if (args_value == nullptr) + return ira->codegen->invalid_inst_gen->value->type; + assert(args_value->special == ConstValSpecialStatic); + assert(is_slice(args_value->type)); + ZigValue *args_ptr = args_value->data.x_struct.fields[slice_ptr_index]; + ZigValue *args_len_value = args_value->data.x_struct.fields[slice_len_index]; + size_t args_len = bigint_as_usize(&args_len_value->data.x_bigint); + + FnTypeId fn_type_id = {}; + fn_type_id.return_type = return_type; + fn_type_id.param_info = heap::c_allocator.allocate<FnTypeParamInfo>(args_len); + fn_type_id.param_count = args_len; + fn_type_id.next_param_index = args_len; + fn_type_id.is_var_args = is_var_args; + fn_type_id.cc = cc; + fn_type_id.alignment = bigint_as_u32(alignment); + + assert(args_ptr->data.x_ptr.special == ConstPtrSpecialBaseArray); + assert(args_ptr->data.x_ptr.data.base_array.elem_index == 0); + ZigValue *args_arr = args_ptr->data.x_ptr.data.base_array.array_val; + assert(args_arr->special == ConstValSpecialStatic); + assert(args_arr->data.x_array.special == ConstArraySpecialNone); + for (size_t i = 0; i < args_len; i++) { + ZigValue *arg_value = &args_arr->data.x_array.data.s_none.elements[i]; + assert(arg_value->type == ir_type_info_get_type(ira, "FnArg", nullptr)); + FnTypeParamInfo *info = &fn_type_id.param_info[i]; + Error err; + bool is_generic; + if ((err = get_const_field_bool(ira, source_instr->source_node, arg_value, "is_generic", 0, &is_generic))) + return ira->codegen->invalid_inst_gen->value->type; + if (is_generic) { + ir_add_error(ira, source_instr, buf_sprintf("TypeInfo.FnArg.is_generic must be false for @Type")); + return ira->codegen->invalid_inst_gen->value->type; + } + if ((err = get_const_field_bool(ira, source_instr->source_node, arg_value, "is_noalias", 1, &info->is_noalias))) + return ira->codegen->invalid_inst_gen->value->type; + ZigType *type = get_const_field_meta_type_optional( + ira, source_instr->source_node, arg_value, "arg_type", 2); + if (type == nullptr) { + ir_add_error(ira, source_instr, buf_sprintf("TypeInfo.FnArg.arg_type must be non-null for @Type")); + return ira->codegen->invalid_inst_gen->value->type; + } + info->type = type; + } + + ZigType *entry = get_fn_type(ira->codegen, &fn_type_id); + + switch (tagTypeId) { + case ZigTypeIdFn: + return entry; + case ZigTypeIdBoundFn: { + ZigType *bound_fn_entry = new_type_table_entry(ZigTypeIdBoundFn); + bound_fn_entry->name = *buf_sprintf("(bound %s)", buf_ptr(&entry->name)); + bound_fn_entry->data.bound_fn.fn_type = entry; + return bound_fn_entry; + } + default: + zig_unreachable(); + } + } } zig_unreachable(); } diff --git a/test/compile_errors.zig b/test/compile_errors.zig index d3be0e060b..816d569b4d 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -125,6 +125,53 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "tmp.zig:15:23: error: enum field missing: 'arst'", "tmp.zig:27:24: note: referenced here", }); + cases.add("@Type(.Fn) with is_generic = true", + \\const Foo = @Type(.{ + \\ .Fn = .{ + \\ .calling_convention = .Unspecified, + \\ .alignment = 0, + \\ .is_generic = true, + \\ .is_var_args = false, + \\ .return_type = u0, + \\ .args = &[_]@import("builtin").TypeInfo.FnArg{}, + \\ }, + \\}); + \\comptime { _ = Foo; } + , &[_][]const u8{ + "tmp.zig:1:20: error: TypeInfo.Fn.is_generic must be false for @Type", + }); + + cases.add("@Type(.Fn) with is_var_args = true and non-C callconv", + \\const Foo = @Type(.{ + \\ .Fn = .{ + \\ .calling_convention = .Unspecified, + \\ .alignment = 0, + \\ .is_generic = false, + \\ .is_var_args = true, + \\ .return_type = u0, + \\ .args = &[_]@import("builtin").TypeInfo.FnArg{}, + \\ }, + \\}); + \\comptime { _ = Foo; } + , &[_][]const u8{ + "tmp.zig:1:20: error: varargs functions must have C calling convention", + }); + + cases.add("@Type(.Fn) with return_type = null", + \\const Foo = @Type(.{ + \\ .Fn = .{ + \\ .calling_convention = .Unspecified, + \\ .alignment = 0, + \\ .is_generic = false, + \\ .is_var_args = false, + \\ .return_type = null, + \\ .args = &[_]@import("builtin").TypeInfo.FnArg{}, + \\ }, + \\}); + \\comptime { _ = Foo; } + , &[_][]const u8{ + "tmp.zig:1:20: error: TypeInfo.Fn.return_type must be non-null for @Type", + }); cases.add("@Type for union with opaque field", \\const TypeInfo = @import("builtin").TypeInfo; diff --git a/test/stage1/behavior/type.zig b/test/stage1/behavior/type.zig index 1bb0823e74..60a23ffa94 100644 --- a/test/stage1/behavior/type.zig +++ b/test/stage1/behavior/type.zig @@ -416,3 +416,30 @@ test "Type.Union from regular enum" { _ = T; _ = @typeInfo(T).Union; } + +test "Type.Fn" { + // wasm doesn't support align attributes on functions + if (builtin.arch == .wasm32 or builtin.arch == .wasm64) return error.SkipZigTest; + + const foo = struct { + fn func(a: usize, b: bool) align(4) callconv(.C) usize { + return 0; + } + }.func; + const Foo = @Type(@typeInfo(@TypeOf(foo))); + const foo_2: Foo = foo; +} + +test "Type.BoundFn" { + // wasm doesn't support align attributes on functions + if (builtin.arch == .wasm32 or builtin.arch == .wasm64) return error.SkipZigTest; + + const TestStruct = packed struct { + pub fn foo(self: *const @This()) align(4) callconv(.Unspecified) void {} + }; + const test_instance: TestStruct = undefined; + testing.expect(std.meta.eql( + @typeName(@TypeOf(test_instance.foo)), + @typeName(@Type(@typeInfo(@TypeOf(test_instance.foo)))), + )); +} diff --git a/test/stage1/behavior/type_info.zig b/test/stage1/behavior/type_info.zig index f5b37fe3f0..8b413bf031 100644 --- a/test/stage1/behavior/type_info.zig +++ b/test/stage1/behavior/type_info.zig @@ -266,6 +266,8 @@ const TestStruct = packed struct { }; test "type info: function type info" { + // wasm doesn't support align attributes on functions + if (builtin.arch == .wasm32 or builtin.arch == .wasm64) return error.SkipZigTest; testFunction(); comptime testFunction(); } @@ -273,11 +275,14 @@ test "type info: function type info" { fn testFunction() void { const fn_info = @typeInfo(@TypeOf(foo)); expect(fn_info == .Fn); + expect(fn_info.Fn.alignment == 0); expect(fn_info.Fn.calling_convention == .C); expect(!fn_info.Fn.is_generic); expect(fn_info.Fn.args.len == 2); expect(fn_info.Fn.is_var_args); expect(fn_info.Fn.return_type.? == usize); + const fn_aligned_info = @typeInfo(@TypeOf(fooAligned)); + expect(fn_aligned_info.Fn.alignment == 4); const test_instance: TestStruct = undefined; const bound_fn_info = @typeInfo(@TypeOf(test_instance.foo)); @@ -285,7 +290,8 @@ fn testFunction() void { expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct); } -extern fn foo(a: usize, b: bool, ...) usize; +extern fn foo(a: usize, b: bool, ...) callconv(.C) usize; +extern fn fooAligned(a: usize, b: bool, ...) align(4) callconv(.C) usize; test "typeInfo with comptime parameter in struct fn def" { const S = struct { |
