Skip to content

Conversation

@melver
Copy link
Contributor

@melver melver commented Nov 24, 2025

In preparation of moving AllocToken instrumentation to backend LTO
phases, we need to make this option a frontend option that can be
converted to the appropriate linker plugin command line option.

This removes the need to use -Xclang when setting the mode; document
it and update the existing tests.


This change is part of the following series:

  1. [InstCombine][MemProf] Preserve all metadata #169242
  2. [Clang][MemProf] Add end-to-end test for PGHO rewriting #169243
  3. [LTO][AllocToken] Support AllocToken instrumentation in backend #169358
  4. [Clang] Make -falloc-token-mode a hidden frontend option #169359
  5. [Clang][CodeGen] Remove explicit insertion of AllocToken pass #169360

Created using spr 1.3.8-beta.1
@melver melver marked this pull request as ready for review November 24, 2025 16:48
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Nov 24, 2025
@melver melver requested review from fmayer and vitalybuka November 24, 2025 16:48
@llvmbot
Copy link
Member

llvmbot commented Nov 24, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Marco Elver (melver)

Changes

In preparation of moving AllocToken instrumentation to backend LTO
phases, we need to make this option a frontend option that can be
converted to the appropriate linker plugin command line option.

This removes the need to use -Xclang when setting the mode; document
it and update the existing tests.


This change is part of the following series:

  1. [InstCombine][MemProf] Preserve all metadata #169242
  2. [Clang][MemProf] Add end-to-end test for PGHO rewriting #169243
  3. [LTO][AllocToken] Support AllocToken instrumentation in backend #169358
  4. [Clang] Make -falloc-token-mode a hidden frontend option #169359
  5. [Clang][CodeGen] Remove explicit insertion of AllocToken pass #169360

Full diff: https://github.com/llvm/llvm-project/pull/169359.diff

4 Files Affected:

  • (modified) clang/docs/AllocToken.rst (+2-2)
  • (modified) clang/include/clang/Options/Options.td (+1-1)
  • (modified) clang/lib/Driver/ToolChains/Clang.cpp (+1)
  • (modified) clang/test/Driver/fsanitize-alloc-token.c (+5-5)
diff --git a/clang/docs/AllocToken.rst b/clang/docs/AllocToken.rst
index 3f319e8be6421..b591c39057cdc 100644
--- a/clang/docs/AllocToken.rst
+++ b/clang/docs/AllocToken.rst
@@ -37,8 +37,8 @@ The default mode to calculate tokens is:
   pointers.
 
 Other token ID assignment modes are supported, but they may be subject to
-change or removal. These may (experimentally) be selected with ``-Xclang
--falloc-token-mode=<mode>``:
+change or removal. These may (experimentally) be selected with
+``-falloc-token-mode=<mode>``:
 
 * ``typehash``: This mode assigns a token ID based on the hash of the allocated
   type's name.
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index 34a6651d2445c..fb10973a6e581 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -2767,7 +2767,7 @@ def falloc_token_max_EQ : Joined<["-"], "falloc-token-max=">,
   HelpText<"Limit to maximum N allocation tokens (0 = target SIZE_MAX)">;
 
 def falloc_token_mode_EQ : Joined<["-"], "falloc-token-mode=">,
-  Group<f_Group>, Visibility<[CC1Option]>,
+  Group<f_Group>, Visibility<[ClangOption, CC1Option]>, Flags<[HelpHidden]>,
   HelpText<"Set the allocation token mode (experimental)">;
 
 def fallow_runtime_check_skip_hot_cutoff_EQ
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 2f0aec3ec3c37..b1b41e4c24b81 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7584,6 +7584,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   SanitizeArgs.addArgs(TC, Args, CmdArgs, InputType);
 
   Args.AddLastArg(CmdArgs, options::OPT_falloc_token_max_EQ);
+  Args.AddLastArg(CmdArgs, options::OPT_falloc_token_mode_EQ);
 
 #if CLANG_ENABLE_CIR
   // Forward -mmlir arguments to to the MLIR option parser.
diff --git a/clang/test/Driver/fsanitize-alloc-token.c b/clang/test/Driver/fsanitize-alloc-token.c
index 0ffe9abad8053..073b211d7b671 100644
--- a/clang/test/Driver/fsanitize-alloc-token.c
+++ b/clang/test/Driver/fsanitize-alloc-token.c
@@ -43,13 +43,13 @@
 // RUN: not %clang --target=x86_64-linux-gnu -fsanitize=alloc-token -falloc-token-max=-1 %s 2>&1 | FileCheck -check-prefix=CHECK-INVALID-MAX %s
 // CHECK-INVALID-MAX: error: invalid value
 
-// RUN: %clang --target=x86_64-linux-gnu -Xclang -falloc-token-mode=increment %s -### 2>&1 | FileCheck -check-prefix=CHECK-MODE-INCREMENT %s
+// RUN: %clang --target=x86_64-linux-gnu -falloc-token-mode=increment %s -### 2>&1 | FileCheck -check-prefix=CHECK-MODE-INCREMENT %s
 // CHECK-MODE-INCREMENT: "-falloc-token-mode=increment"
-// RUN: %clang --target=x86_64-linux-gnu -Xclang -falloc-token-mode=random %s -### 2>&1 | FileCheck -check-prefix=CHECK-MODE-RANDOM %s
+// RUN: %clang --target=x86_64-linux-gnu -falloc-token-mode=random %s -### 2>&1 | FileCheck -check-prefix=CHECK-MODE-RANDOM %s
 // CHECK-MODE-RANDOM: "-falloc-token-mode=random"
-// RUN: %clang --target=x86_64-linux-gnu -Xclang -falloc-token-mode=typehash %s -### 2>&1 | FileCheck -check-prefix=CHECK-MODE-TYPEHASH %s
+// RUN: %clang --target=x86_64-linux-gnu -falloc-token-mode=typehash %s -### 2>&1 | FileCheck -check-prefix=CHECK-MODE-TYPEHASH %s
 // CHECK-MODE-TYPEHASH: "-falloc-token-mode=typehash"
-// RUN: %clang --target=x86_64-linux-gnu -Xclang -falloc-token-mode=typehashpointersplit %s -### 2>&1 | FileCheck -check-prefix=CHECK-MODE-TYPEHASHPTRSPLIT %s
+// RUN: %clang --target=x86_64-linux-gnu -falloc-token-mode=typehashpointersplit %s -### 2>&1 | FileCheck -check-prefix=CHECK-MODE-TYPEHASHPTRSPLIT %s
 // CHECK-MODE-TYPEHASHPTRSPLIT: "-falloc-token-mode=typehashpointersplit"
-// RUN: not %clang --target=x86_64-linux-gnu -Xclang -falloc-token-mode=asdf %s 2>&1 | FileCheck -check-prefix=CHECK-INVALID-MODE %s
+// RUN: not %clang --target=x86_64-linux-gnu -falloc-token-mode=asdf %s 2>&1 | FileCheck -check-prefix=CHECK-INVALID-MODE %s
 // CHECK-INVALID-MODE: error: invalid value 'asdf'

Created using spr 1.3.8-beta.1
Created using spr 1.3.8-beta.1
@melver
Copy link
Contributor Author

melver commented Nov 26, 2025

We don't strictly need this anymore, so I'm inclined to drop this PR. Unless we want to make this option more officially supported, which I think is premature as it commits us to never removing some modes, I'd postpone.

@melver melver marked this pull request as draft November 26, 2025 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants