Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 10, 2025

impGetNodeAddr returns GTF_IND_COPYABLE_FLAGS (volatile, unaligned, nonfaulting, initclass) from the original access, but five call sites were ignoring these flags, potentially leading to incorrect semantics for volatile/unaligned/initclass operations.

Changes:

  • Added allowConfiguredDerefs parameter to impGetNodeAddr: When false, indirections with volatile, unaligned, or initclass flags fall through to temp creation instead of returning the address directly. Defaults to true for backward compatibility.

  • Return buffers (3 sites): Set allowConfiguredDerefs = false when obtaining addresses for return buffer arguments passed to helpers. VM helpers cannot handle addresses with volatile, unaligned, or initclass flags.

  • Struct field access on instance: Combine flags from impGetNodeAddr with prefix flags when creating the field indirection:

    GenTreeFlags objAddrFlags = GTF_EMPTY;
    obj = impGetNodeAddr(obj, CHECK_SPILL_ALL, &objAddrFlags);
    indirFlags |= objAddrFlags;  // Combine with prefix flags
  • Box-isinst optimization: Transfer flags to the hasValue field indirection:

    objToBox = impGetNodeAddr(objToBox, CHECK_SPILL_ALL, &indirFlags);
    impPushOnStack(gtNewIndir(TYP_UBYTE, objToBox, indirFlags), ...);
  • Fixed recursive call: Preserve allowConfiguredDerefs in GT_COMMA case to maintain semantics through comma expressions.

All five TODO-Bug?: verify if flags matter here comments resolved.

Original prompt

This section details on the original issue you should resolve

<issue_title>Review usages of impGetNodeAddr with ignored flags</issue_title>
<issue_description>#85562 made impGetNodeAddr return flags the original access would use. Places that use the API but ignore the returned flags have been marked with // TODO-Bug?: verify if flags matter here.
All such cases should be reviewed and either documented to be fine or fixed to not ignore the flags.
cc @SingleAccretion </issue_description>

<agent_instructions>For uses that end up indirecting the address, simply transfer the flags on to that indirection.
For uses that do not indirect (e.g. passing the address to a VM helper), add a new argument to impGetNodeAddr about whether volatile and unaligned addresses should be allowed, and if not, fall through to the case that copies to a local.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@ Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch See info in [area-owners.md](https://github.com/dotnet/runtime/blob/main/docs/area-owners.md) if you want to be subscribed.
Issue Details

#85562 made impGetNodeAddr return flags the original access would use. Places that use the API but ignore the returned flags have been marked with // TODO-Bug?: verify if flags matter here.
All such cases should be reviewed and either documented to be fine or fixed to not ignore the flags.
cc @SingleAccretion

Author: MichalPetryka
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Dec 10, 2025
@jakobbotsch jakobbotsch added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Dec 10, 2025
Co-authored-by: jakobbotsch <7887810+jakobbotsch@users.noreply.github.com>
Copilot AI and others added 2 commits December 10, 2025 12:08
Co-authored-by: jakobbotsch <7887810+jakobbotsch@users.noreply.github.com>
Co-authored-by: jakobbotsch <7887810+jakobbotsch@users.noreply.github.com>
Copilot AI changed the title [WIP] Review usages of impGetNodeAddr with ignored flags Fix impGetNodeAddr flag handling for volatile and unaligned accesses Dec 10, 2025
Copilot AI requested a review from jakobbotsch December 10, 2025 12:15
…IND_INITCLASS

Co-authored-by: jakobbotsch <7887810+jakobbotsch@users.noreply.github.com>
@jakobbotsch jakobbotsch marked this pull request as ready for review December 12, 2025 19:25
Copilot AI review requested due to automatic review settings December 12, 2025 19:25
Copy link
Contributor

Copilot AI left a comment

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 fixes a bug where impGetNodeAddr was returning flags (volatile, unaligned, nonfaulting, initclass) from the original access, but five call sites were ignoring these flags, potentially leading to incorrect semantics.

Key Changes

  • Added allowedMustPreserveIndirFlags parameter to impGetNodeAddr to control which flags are acceptable without creating a temp
  • Updated all call sites to pass appropriate flag masks and use the returned flags where needed
  • Introduced GTF_IND_MUST_PRESERVE_FLAGS constant to represent flags that must be preserved (volatile, unaligned, initclass)

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/coreclr/jit/gentree.h Introduces GTF_IND_MUST_PRESERVE_FLAGS constant and updates GTF_IND_COPYABLE_FLAGS to use it
src/coreclr/jit/compiler.h Updates impGetNodeAddr signature to include allowedMustPreserveIndirFlags parameter
src/coreclr/jit/importer.cpp Implements new parameter logic in impGetNodeAddr, updates all call sites to pass appropriate flags and use returned flags for indirections
src/coreclr/jit/importercalls.cpp Updates SRCSUnsafeIntrinsic call site to use the new parameter

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jakobbotsch
Copy link
Member

PTAL @dotnet/jit-contrib

No diffs. Removes a number of TODOs.

@jakobbotsch jakobbotsch requested a review from a team January 9, 2026 16:57
@jakobbotsch jakobbotsch merged commit d2f03e4 into main Jan 13, 2026
122 checks passed
@jakobbotsch jakobbotsch deleted the copilot/review-impgetnodeaddr-flags branch January 13, 2026 14:01
@MihaZupan
Copy link
Member

Looks like this broke builds on main since #122167 was merged in between

  FAILED: jit/static/CMakeFiles/clrjit_static.dir/__/importer.cpp.obj
  C:\PROGRA~1\MICROS~3\18\Insiders\VC\Tools\MSVC\1450~1.357\bin\Hostx64\x64\cl.exe  /nologo /TP -DBUILDENV_CHECKED=1 -DDEBUG -DDEBUGGING_SUPPORTED -DFEATURE_BASICFREEZE -DFEATURE_CODE_VERSIONING -DFEATURE_COLLECTIBLE_TYPES -DFEATURE_COMINTEROP -DFEATURE_COMINTEROP_APARTMENT_SUPPORT -DFEATURE_COMINTEROP_UNMANAGED_ACTIVATION -DFEATURE_COMWRAPPERS -DFEATURE_CORECLR -DFEATURE_CORECLR_FLUSH_INSTRUCTION_CACHE_TO_PROTECT_STUB_READS -DFEATURE_DATABREAKPOINT -DFEATURE_DEFAULT_INTERFACES -DFEATURE_EVENT_TRACE -DFEATURE_HIJACK -DFEATURE_HW_INTRINSICS -DFEATURE_IJW -DFEATURE_INTEROP_DEBUGGING -DFEATURE_INTERPRETER -DFEATURE_ISYM_READER -DFEATURE_JAVAMARSHAL -DFEATURE_JIT -DFEATURE_MANUALLY_MANAGED_CARD_BUNDLES -DFEATURE_MASKED_HW_INTRINSICS -DFEATURE_METADATA_UPDATER -DFEATURE_MULTICOREJIT -DFEATURE_PERFTRACING -DFEATURE_PGO -DFEATURE_PROFAPI_ATTACH_DETACH -DFEATURE_READYTORUN -DFEATURE_REJIT -DFEATURE_REMAP_FUNCTION -DFEATURE_SIMD -DFEATURE_SPECIAL_USER_MODE_APC -DFEATURE_STANDALONE_GC -DFEATURE_SVR_GC -DFEATURE_SYMDIFF -DFEATURE_TIERED_COMPILATION -DFEATURE_TYPEEQUIVALENCE -DFEATURE_USE_ASM_GC_WRITE_BARRIERS -DFEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP -DHOST_64BIT -DHOST_AMD64 -DHOST_WINDOWS -DJIT_BUILD -DNOMINMAX -DOUT_OF_PROCESS_SETTHREADCONTEXT -DPROFILING_SUPPORTED -DTARGET_64BIT -DTARGET_AMD64 -DTARGET_WINDOWS -DUNICODE -DUNIX_AMD64_ABI_ITF -DURTBLDENV_FRIENDLY=Checked -DWIN32 -DWIN32_LEAN_AND_MEAN -DWINVER=0x0602 -D_CRT_SECURE_NO_WARNINGS -D_DBG -D_DEBUG -D_FILE_OFFSET_BITS=64 -D_SECURE_SCL=0 -D_TIME_BITS=64 -D_UNICODE -D_WIN32 -D_WIN32_WINNT=0x0602 -IC:\MihaZupan\runtime-debug\artifacts\obj\coreclr\windows.x64.Checked\jit\static -IC:\MihaZupan\runtime-debug\src\coreclr\jit\static -IC:\MihaZupan\runtime-debug\src\native -IC:\MihaZupan\runtime-debug\src\native\inc -IC:\MihaZupan\runtime-debug\src\coreclr\pal\prebuilt\inc -IC:\MihaZupan\runtime-debug\artifacts\obj -IC:\MihaZupan\runtime-debug\src\coreclr\inc -IC:\MihaZupan\runtime-debug\src\coreclr\debug\inc -IC:\MihaZupan\runtime-debug\src\coreclr\debug\inc\amd64 -IC:\MihaZupan\runtime-debug\src\coreclr\debug\inc\dump -IC:\MihaZupan\runtime-debug\src\coreclr\md\inc -IC:\MihaZupan\runtime-debug\artifacts\obj\coreclr\windows.x64.Checked\inc -IC:\MihaZupan\runtime-debug\src\coreclr\hosts\inc -IC:\MihaZupan\runtime-debug\src\coreclr\interpreter\inc -IC:\MihaZupan\runtime-debug\src\coreclr\minipal -IC:\MihaZupan\runtime-debug\artifacts\obj\coreclr\windows.x64.Checked\inc\etw -IC:\MihaZupan\runtime-debug\src\coreclr\jit\.\jitstd -IC:\MihaZupan\runtime-debug\src\coreclr\jit\..\inc -IC:\MihaZupan\runtime-debug\src\coreclr\jit /DWIN32 /D_WINDOWS  /GR- -std:c++17 -MTd /O2 /EHa /nologo /W4 /WX /sdl /Oi /Oy- /Gm- /Zp8 /Gy /fp:precise /FC /MP /Zm200 /Zc:strictStrings /Zc:wchar_t /Zc:inline /Zc:forScope /wd4065 /wd4100 /wd4127 /wd4131 /wd4189 /wd4200 /wd4201 /wd4206 /wd4239 /wd4245 /wd4291 /wd4310 /wd4324 /wd4366 /wd4456 /wd4457 /wd4458 /wd4459 /wd4463 /wd4505 /wd4702 /wd4706 /wd4733 /wd4815 /wd4838 /wd4918 /wd4960 /wd4961 /wd5105 /wd5205 /we4007 /we4013 /we4102 /we4551 /we4640 /we4806 /we4018 /we4055 /we4242 /we4244 /we4267 /we4302 /we4509 /we4510 /we4610 /we4611 /we4701 /w34092 /w34121 /w34125 /w34130 /w34132 /w34212 /w34530 /w35038 /w44177 /Zi /ZH:SHA_256 /source-charset:utf-8 /guard:cf /guard:ehcont /Zl /permissive- /YuC:/MihaZupan/runtime-debug/artifacts/obj/coreclr/windows.x64.Checked/jit/static/CMakeFiles/clrjit_static.dir/cmake_pch.hxx /FpC:/MihaZupan/runtime-debug/artifacts/obj/coreclr/windows.x64.Checked/jit/static/CMakeFiles/clrjit_static.dir/./cmake_pch.cxx.pch /FIC:/MihaZupan/runtime-debug/artifacts/obj/coreclr/windows.x64.Checked/jit/static/CMakeFiles/clrjit_static.dir/cmake_pch.hxx /showIncludes /Fojit\static\CMakeFiles\clrjit_static.dir\__\importer.cpp.obj /Fdjit\static\CMakeFiles\clrjit_static.dir\ /FS -c C:\MihaZupan\runtime-debug\src\coreclr\jit\importer.cpp
  C:\MihaZupan\runtime-debug\src\coreclr\jit\importer.cpp(3401): error C2660: 'Compiler::impGetNodeAddr': function does not take 3 arguments
  C:\MihaZupan\runtime-debug\src\coreclr\jit\importer.cpp(1114): note: see declaration of 'Compiler::impGetNodeAddr'
  C:\MihaZupan\runtime-debug\src\coreclr\jit\importer.cpp(3401): note: while trying to match the argument list '(GenTree *, const unsigned int, GenTreeFlags *)'

@jakobbotsch
Copy link
Member

#123128 should fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Review usages of impGetNodeAddr with ignored flags

4 participants