[llvm] Remove cl::callback from AArch64CodeLayoutOpt and AddressSanitizer (PR #226757)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 26 22:38:12 PDT 2026


https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/226757

cl::callback will be removed to enable migration to TableGen based
representation

LLM-aided

>From 0688c3f60bc162b950d5eb02657b0bba2a94b47f Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Sat, 26 Sep 2026 22:29:58 -0700
Subject: [PATCH] Remove cl::callback from AArch64CodeLayoutOpt and
 AddressSanitizer

cl::callback will be removed to enable migration to TableGen based
representation

LLM-aided
---
 llvm/lib/Target/AArch64/AArch64CodeLayoutOpt.cpp       |  9 ++++-----
 .../Transforms/Instrumentation/AddressSanitizer.cpp    | 10 +++-------
 2 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/llvm/lib/Target/AArch64/AArch64CodeLayoutOpt.cpp b/llvm/lib/Target/AArch64/AArch64CodeLayoutOpt.cpp
index 76ba3f38be549..582dff927e07d 100644
--- a/llvm/lib/Target/AArch64/AArch64CodeLayoutOpt.cpp
+++ b/llvm/lib/Target/AArch64/AArch64CodeLayoutOpt.cpp
@@ -56,11 +56,7 @@ static cl::opt<unsigned> FunctionAlignBytes(
     "aarch64-code-layout-opt-align-functions", cl::Hidden,
     cl::desc("Function alignment in bytes for code layout optimization "
              "(must be a power of 2)"),
-    cl::init(64), cl::callback([](const unsigned &Val) {
-      if (!isPowerOf2_32(Val))
-        report_fatal_error(
-            "aarch64-code-layout-opt-align must be a power of 2");
-    }));
+    cl::init(64));
 
 STATISTIC(NumFunctionsAligned,
           "Number of functions with aligned (to 64-bytes by default)");
@@ -267,6 +263,9 @@ bool AArch64CodeLayoutOpt::optimizeForCodeLayout(MachineFunction &MF,
   if (!Changed)
     return false;
 
+  if (!isPowerOf2_32(FunctionAlignBytes))
+    reportFatalUsageError(
+        "aarch64-code-layout-opt-align-functions must be a power of 2");
   if (MF.getAlignment() < Align(FunctionAlignBytes)) {
     MF.setAlignment(Align(FunctionAlignBytes));
     ++NumFunctionsAligned;
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index 3e9b0b3d39c47..6e028b5659fed 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -20,7 +20,6 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DepthFirstIterator.h"
 #include "llvm/ADT/SmallPtrSet.h"
-#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/StringExtras.h"
@@ -443,13 +442,10 @@ static cl::opt<AsanDtorKind> ClOverrideDestructorKind(
                           "Use global destructors")),
     cl::init(AsanDtorKind::Invalid), cl::Hidden);
 
-static SmallSet<unsigned, 8> SrcAddrSpaces;
 static cl::list<unsigned> ClAddrSpaces(
     "asan-instrument-address-spaces",
     cl::desc("Only instrument variables in the specified address spaces."),
-    cl::Hidden, cl::CommaSeparated, cl::callback([](const unsigned &AddrSpace) {
-      SrcAddrSpaces.insert(AddrSpace);
-    }));
+    cl::Hidden, cl::CommaSeparated);
 
 // Debug flags.
 
@@ -1411,8 +1407,8 @@ static bool isSupportedAddrspace(const Triple &TargetTriple, Value *Addr) {
   Type *PtrTy = cast<PointerType>(Addr->getType()->getScalarType());
   unsigned int AddrSpace = PtrTy->getPointerAddressSpace();
 
-  if (!SrcAddrSpaces.empty())
-    return SrcAddrSpaces.count(AddrSpace);
+  if (!ClAddrSpaces.empty())
+    return is_contained(ClAddrSpaces, AddrSpace);
 
   if (TargetTriple.isAMDGPU())
     return !isUnsupportedAMDGPUAddrspace(Addr);



More information about the llvm-commits mailing list