[all-commits] [llvm/llvm-project] 530688: [win] Add a flag to control the Control Flow Guard...

Daniel Paoliello via All-commits all-commits at lists.llvm.org
Tue Apr 14 08:57:08 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 530688456deef791dc294891e82d44ca4e6c307f
      https://github.com/llvm/llvm-project/commit/530688456deef791dc294891e82d44ca4e6c307f
  Author: Daniel Paoliello <danpao at microsoft.com>
  Date:   2026-04-14 (Tue, 14 Apr 2026)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/Basic/CodeGenOptions.def
    M clang/include/clang/Basic/CodeGenOptions.h
    M clang/include/clang/Options/Options.td
    M clang/lib/CodeGen/CodeGenModule.cpp
    M clang/lib/Driver/ToolChains/Clang.cpp
    A clang/test/CodeGen/cfguard-mechanism.c
    M clang/test/Driver/cl-options.c
    M llvm/docs/LangRef.rst
    M llvm/include/llvm/Support/CodeGen.h
    M llvm/include/llvm/Transforms/CFGuard.h
    M llvm/lib/Passes/PassBuilder.cpp
    M llvm/lib/Passes/PassRegistry.def
    M llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp
    M llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
    M llvm/lib/Target/ARM/ARMTargetMachine.cpp
    M llvm/lib/Target/X86/X86CallingConv.td
    M llvm/lib/Target/X86/X86CodeGenPassBuilder.cpp
    M llvm/lib/Target/X86/X86RegisterInfo.cpp
    M llvm/lib/Target/X86/X86TargetMachine.cpp
    M llvm/lib/Transforms/CFGuard/CFGuard.cpp
    M llvm/test/CodeGen/AArch64/cfguard-module-flag.ll
    M llvm/test/CodeGen/ARM/cfguard-module-flag.ll
    M llvm/test/CodeGen/X86/cfguard-module-flag.ll
    A llvm/test/Linker/cfguard.ll

  Log Message:
  -----------
  [win] Add a flag to control the Control Flow Guard mechanism on Windows (#176276)

Windows Control Flow Guard (CFG) has two different "mechanisms" or
"patterns":
* Dispatch: the caller calls into the CFG function, which both checks
the target callee and then calls it.
* Check: the caller calls the CFG function which only checks the target
callee and then must separately call the callee.

LLVM has followed MSVC's pattern for selecting the mechanism based on
the target architecture. These defaults in MSVC are based on tests for
performance: Dispatch produces a smaller code size, whereas Check is
more friendly to branch predictors.

It is possible, however, for a given workload, call pattern or target
CPU that someone may want to select a different mechanism to use for
their code.

This change adds a new Clang and CC1 flag to force a CFG mechanism:
`-fwin-cfg-mechanism`. This can be set to `automatic` (lets LLVM choose
a mechanism), `force-dispatch` or `force-check`.

Also adds the support for the equivalent MSVC flag
`/d2guardcfgdispatch`.

NOTE: Arm64EC only supports the check mechanism. It should be noted that
MSVC emits the "dispatch" name for the call checker (for legacy reasons)
but uses the check mechanism.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list