Skip to content

pal.h: only emit MSVC #pragma warning lines for MSVC - #1087

Open
Jason Sandlin (jasonsandlin) wants to merge 6 commits into
mainfrom
user/jasonsa/pal-msvc-only-pragmas
Open

Jason Sandlin (jasonsandlin) wants to merge 6 commits into
mainfrom
user/jasonsa/pal-msvc-only-pragmas

Conversation

@jasonsandlin

@jasonsandlin Jason Sandlin (jasonsandlin) commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 69ccc6cdf1515e872e86c06ba20076c376fce015

Dimension Assessment Rationale
Change confidence 8.5/10 ↑ MSVC still gets the pragmas (gated on _MSC_VER); MSVC x64 Debug TE build is warning-free.
↑ New header check passes for native Linux and Generic; portable suite 242/242.
↑ TSan exit-race fix: Windows TE suite 268/268; Linux TSan taskqueue label 30/30 locally.
↓ The TSan flake didn't reproduce locally without the fix either (0/30), so the fix isn't proven by a red run.
↑ vcpkg restore retry: both scripts verified locally (success with -Force; a forced failure retries 3 times and exits 1).
↓ CI for this revision is pending. The previous run passed everything except one job hit by a vcpkg.exe download error (HTTP 618).
Diagnosis confidence 9/10 ↑ Red run of the new Generic header check failed with the exact pal.h:9/10 unknown-pragma errors from the issue.
↑ CI TSan stacks show the timer worker releasing the last queue ref while exit destructors free g_timerQueue and ApiRefs::g_waitCv.
↓ The TSan race isn't reproduced locally.
Evidence fit 9/10 ↑ Same diagnostics as the issue's PS5 repro; clang with HC_PLATFORM_SONY_PLAYSTATION_5 and NINTENDO_SWITCH no longer reports them.
↓ Not verified with the actual PS5 SDK toolchain.

Fixes #1084

Problem

pal.h disabled MSVC warnings C4062/C4702 behind a platform deny-list (not Android/Linux/Apple), so non-MSVC compilers for any other platform (PlayStation, Switch, Generic) saw the MSVC-only #pragma warning. pal.h is included by every public header, so every consumer TU got -Wunknown-pragmas, and -Werror builds failed.

Fix

Gate on the compiler: #if defined(_MSC_VER), matching json_cpp/details/json_parsing.hpp. MSVC behavior is unchanged.

Test (red → green)

Adds libHttpClient.PublicHeaderCheck.Native / .Generic to the shared CMake unit-test function (Build/libHttpClient.CMake/UnitTests.cmake), so it builds in the Linux, Linux sanitizer and macOS CI legs. These compile-only targets include every public header in a consumer TU with -Werror=unknown-pragmas, once for the native platform and once with HC_PLATFORM=HC_PLATFORM_GENERIC as a stand-in for console platforms. Not added for MSVC builds.

  • Red (before the fix): the Generic variant fails with pal.h:9:9 and pal.h:10:9 unknown pragma ignored [-Werror,-Wunknown-pragmas].
  • Green: both variants build; portable suite 242/242 (clang, ASan+UBSan); MSVC TE build warning-free.

#1085 (-Wundef) is a stacked follow-up that extends this check.

CI fix: TSan exit race

taskqueue-poll-strand-linux (and, on main, taskqueue-concurrent-submit-linux) flaked under TSan: a closed queue's last reference can be released on the timer worker or a pool thread after the standalone test's main() returns, racing exit-time destruction of g_timerQueue / ApiRefs::g_waitCv. The final ApiRefs::GlobalRelease decrement and notify now run in one critical section so XTaskQueueUninitialize is a real barrier, and the three XTaskQueue standalone tests call it before exiting.

CI fix: vcpkg download retries

GitHub intermittently rejects release downloads (vcpkg.exe, ninja) with HTTP 618, which vcpkg treats as permanent, so random Windows jobs failed during the dependency restore. Restore-Vcpkg.ps1 and restore-vcpkg.sh now retry the bootstrap and vcpkg install up to 4 times with a 15/30/60 s backoff.

pal.h disabled C4062/C4702 behind a platform deny-list (not Android, Linux
or Apple), so non-MSVC compilers for any other platform (PlayStation,
Switch, Generic) saw the MSVC-only pragmas. pal.h is included by every
public header, so every consumer TU got -Wunknown-pragmas, and -Werror
builds failed. Gate on _MSC_VER instead, like json_cpp already does.

Add libHttpClient.PublicHeaderCheck.Native/.Generic to the shared CMake
unit-test function (Linux, macOS and sanitizer CI legs): compile-only
targets that include every public header with -Werror=unknown-pragmas, for
the native platform and for HC_PLATFORM_GENERIC as a stand-in for console
platforms. The Generic variant fails without this fix.

Fixes #1084

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Eight preprocessor conditionals used `#if _WIN32`. Non-Windows toolchains
don't define _WIN32, so clang/gcc report -Wundef for each. pal.h is included
by every public header, so every consumer TU got the warning and -Werror
builds failed. Use `#if defined(_WIN32)` like the rest of the codebase;
behavior is identical on every platform.

Sites: Include/httpClient/pal.h, Source/Common/utils.h,
Source/Logger/trace.cpp and five in Source/Task/AsyncLib.cpp.

Extend the public header check with -Werror=undef so the public headers stay
-Wundef clean on the native and Generic platforms.

Fixes #1085

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A closed queue's last reference can be released on the timer worker or a pool thread after the standalone test's main() returns, racing process-exit destruction of TaskQueue/WaitTimer globals (TSan: data race / heap-use-after-free on g_timerQueue and ApiRefs::g_waitCv).

- Make the final ApiRefs::GlobalRelease decrement and its notify one critical section under g_waitMutex, and use a predicate wait, so XTaskQueueUninitialize is a real barrier.
- Call XTaskQueueUninitialize(5000) before exiting the poll-strand, starvation and concurrent-submit standalone tests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
GitHub intermittently rejects release downloads (vcpkg.exe, ninja) with HTTP 618, which vcpkg treats as permanent, failing CI jobs at random. Restore-Vcpkg.ps1 and restore-vcpkg.sh now retry the bootstrap and vcpkg install up to 4 times with a 15/30/60s backoff.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pal.h emits MSVC-only #pragma warning on non-MSVC compilers (-Wunknown-pragmas)

2 participants