Add format attribute to printf-style wrappers and fix format string errors#123920
Draft
Add format attribute to printf-style wrappers and fix format string errors#123920
Conversation
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
jkotas
reviewed
Feb 3, 2026
Copilot
AI
changed the title
[WIP] Add format attribute to printf-style API wrappers
Add format attribute to printf-style wrappers and fix format string errors
Feb 3, 2026
jkotas
reviewed
Feb 3, 2026
jkoritzinsky
reviewed
Feb 3, 2026
jkotas
reviewed
Feb 3, 2026
Member
jkoritzinsky
reviewed
Feb 3, 2026
…, str) pattern Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
This was referenced Feb 3, 2026
Member
|
@copilot please fix the formatting errors in the JIT codebase. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Contributor
Author
Member
|
@copilot looks like MSVC already defines the It also looks like there's failures in Mono that need to be fixed: Also, more failures on CoreCLR's build: |
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Contributor
Author
Fixed in commit c71ed14:
|
Member
|
@copilot please remove the rest of the redefinitions of these standard macros: Also here's one more format string to fix: |
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Enabled compiler validation of printf-style format strings by adding
__attribute__ ((format (printf, ...)))to wrapper functions. Fixed 81 format string errors discovered by the compiler across CoreCLR, Mono, and Corehost.Changes
Centralized format attribute macro in
src/native/minipal/types.h:MINIPAL_ATTR_FORMAT_PRINTF(fmt_pos, arg_pos)macro for consistent usage across the codebase#ifdef __GNUC__blocks throughout the codebaseAdded format attributes to 60+ wrapper functions across 13 headers using
MINIPAL_ATTR_FORMAT_PRINTF:src/native/minipal/types.h- CentralizedMINIPAL_ATTR_FORMAT_PRINTFmacro definitionsrc/native/minipal/log.h-minipal_log_printsrc/native/corehost/hostmisc/trace.h-trace::verbose,info,warning,error,printlnsrc/native/libs/Common/pal_compiler.h-do_abort_unlesssrc/native/libs/System.Native/pal_string.h-SystemNative_SNPrintFsrc/native/libs/System.Security.Cryptography.Native/osslcompat_30.h-ERR_set_errorsrc/coreclr/inc/log.h-LogSpew,LogSpew2,LogSpewAlwayssrc/coreclr/inc/stresslog.h-StressLog::LogMsg,ThreadStressLog::LogMsgsrc/coreclr/inc/sstring.h-Printf,AppendPrintfsrc/coreclr/jit/host.h-jitprintf,logf,flogf,gcDump_logfsrc/coreclr/jit/compiler.h-printfAlloc,JitLogEEsrc/coreclr/gc/gc.h-GCLogsrc/coreclr/gc/gcpriv.h-GCLogConfigsrc/mono/mono/eglib/glib.h-g_error_new,g_set_error,g_print,g_printerr,g_log,g_assertion_message,g_async_safe_*Fixed 81 format string errors across 21 source files:
%I64d/%Id→%zd/%zuPRIX64/PRIx64/PRIu64from<inttypes.h>#and0flags(void*)cast for pointersprintf(str)→printf("%s", str)thisFiles with format errors fixed:
Example fixes:
Impact
#ifdef __GNUC__blocks via centralizedMINIPAL_ATTR_FORMAT_PRINTFmacro💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.