Skip to content

Fix issues flagged by compiling clr.aot with clang on Windows - #131183

Merged
MichalStrehovsky merged 1 commit into
dotnet:mainfrom
MichalStrehovsky:clang-cl-windows-build
Jul 23, 2026
Merged

Fix issues flagged by compiling clr.aot with clang on Windows#131183
MichalStrehovsky merged 1 commit into
dotnet:mainfrom
MichalStrehovsky:clang-cl-windows-build

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

Out of curiosity I let copilot build clr.aot with clang. Most are signed/unsigned comparison mismatches that we treat as errors on Windows (/we4018) and copilot matched it with -Wsign-compare.

Out of curiosity I let copilot build clr.aot with clang.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.
Comment thread src/coreclr/utilcode/pedecoder.cpp
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts several native/runtime sources to compile cleanly under clang on Windows by addressing common warning patterns (signed/unsigned loop indices, format-string type mismatches, unreachable control-flow annotations, and header include casing).

Changes:

  • Switch loop indices to size_t where the bound is sizeof/ARRAY_SIZE-derived.
  • Adjust GUID formatting to better match snprintf’s %x expectations.
  • Minor portability/diagnostic fixes: add missing standard include, add UNREACHABLE(), fix header include casing, and mark a destructor virtual.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/native/minipal/xoshiro128pp.c Add <stddef.h> and use size_t loop index to avoid signed/unsigned comparisons.
src/native/minipal/guid.c Cast GUID components for snprintf formatting (but see review comment about completing the casts).
src/coreclr/utilcode/stacktrace.cpp Use size_t for an ARRAY_SIZE-bounded loop.
src/coreclr/utilcode/pedecoder.cpp Cast rcName to satisfy strlen’s parameter type in this context.
src/coreclr/utilcode/debug.cpp Add UNREACHABLE() after RaiseFailFastException to satisfy noreturn analysis.
src/coreclr/nativeaot/Runtime/windows/PalMinWin.cpp Remove redundant _T definition and fix include casing for NativeContext.h.
src/coreclr/nativeaot/Runtime/windows/CoffNativeCodeManager.h Mark destructor virtual to address polymorphic-type destructor diagnostics.
src/coreclr/jit/utils.cpp Fix signed/unsigned comparison by casting strBufferSize before comparing with bufferSize.
Comments suppressed due to low confidence (1)

src/native/minipal/guid.c:76

  • The snprintf format string uses %x/%02x/%04x (expects unsigned int after default promotions), but only Data1 is cast. The remaining arguments (Data2, Data3, and Data4[i]) may still be passed as int due to default promotions, which is undefined behavior and can still trigger clang -Wformat diagnostics. Casting all arguments (or switching to <inttypes.h> macros) avoids both UB and remaining warnings.
    int32_t nBytes = snprintf(guidString, len, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
        (unsigned int)guid.Data1, guid.Data2, guid.Data3,
        guid.Data4[0], guid.Data4[1],
        guid.Data4[2], guid.Data4[3],
        guid.Data4[4], guid.Data4[5],
        guid.Data4[6], guid.Data4[7]);
@MichalStrehovsky

Copy link
Copy Markdown
Member Author

/ba-g widespread wasm infra issue that doesn't produce usable output

@MichalStrehovsky
MichalStrehovsky enabled auto-merge (squash) July 23, 2026 03:24
@MichalStrehovsky
MichalStrehovsky merged commit 5f10c08 into dotnet:main Jul 23, 2026
197 of 200 checks passed
@MichalStrehovsky
MichalStrehovsky deleted the clang-cl-windows-build branch July 23, 2026 03:24
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Jul 24, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

3 participants