Skip to content

Conversation

thurstond
Copy link
Contributor

@thurstond thurstond commented Oct 8, 2025

Reverts #162099

Reason: this commit depends on #162098, which I will be reverting due to buildbot breakage (see #162098 (comment)).

@thurstond thurstond added the skip-precommit-approval PR for CI feedback, not intended for review label Oct 8, 2025
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen IR generation bugs: mangling, exceptions, etc. labels Oct 8, 2025
@thurstond thurstond enabled auto-merge (squash) October 8, 2025 01:57
@llvmbot
Copy link
Member

llvmbot commented Oct 8, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Thurston Dang (thurstond)

Changes

Reverts llvm/llvm-project#162099

Reason: this commit depends on #162098, which I am reverting due to build breakage (see #162098 (comment)).


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

3 Files Affected:

  • (modified) clang/lib/CodeGen/CGExpr.cpp (-17)
  • (modified) clang/lib/CodeGen/CGExprCXX.cpp (+5-10)
  • (modified) clang/lib/CodeGen/CodeGenFunction.h (-3)
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index a071e801b91ec..9f30287b68c79 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -1272,23 +1272,6 @@ void CodeGenFunction::EmitBoundsCheckImpl(const Expr *E, llvm::Value *Bound,
   EmitCheck(std::make_pair(Check, CheckKind), CheckHandler, StaticData, Index);
 }
 
-void CodeGenFunction::EmitAllocToken(llvm::CallBase *CB, QualType AllocType) {
-  assert(SanOpts.has(SanitizerKind::AllocToken) &&
-         "Only needed with -fsanitize=alloc-token");
-
-  PrintingPolicy Policy(CGM.getContext().getLangOpts());
-  Policy.SuppressTagKeyword = true;
-  Policy.FullyQualifiedName = true;
-  SmallString<64> TypeName;
-  llvm::raw_svector_ostream TypeNameOS(TypeName);
-  AllocType.getCanonicalType().print(TypeNameOS, Policy);
-  auto *TypeMDS = llvm::MDString::get(CGM.getLLVMContext(), TypeNameOS.str());
-
-  // Format: !{<type-name>}
-  auto *MDN = llvm::MDNode::get(CGM.getLLVMContext(), {TypeMDS});
-  CB->setMetadata(llvm::LLVMContext::MD_alloc_token, MDN);
-}
-
 CodeGenFunction::ComplexPairTy CodeGenFunction::
 EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV,
                          bool isInc, bool isPre) {
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 290c2e0f1039c..c52526c89f171 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1655,16 +1655,11 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) {
     RValue RV =
       EmitNewDeleteCall(*this, allocator, allocatorType, allocatorArgs);
 
-    if (auto *newCall = dyn_cast<llvm::CallBase>(RV.getScalarVal())) {
-      if (auto *CGDI = getDebugInfo()) {
-        // Set !heapallocsite metadata on the call to operator new.
-        CGDI->addHeapAllocSiteMetadata(newCall, allocType, E->getExprLoc());
-      }
-      if (SanOpts.has(SanitizerKind::AllocToken)) {
-        // Set !alloc_token metadata.
-        EmitAllocToken(newCall, allocType);
-      }
-    }
+    // Set !heapallocsite metadata on the call to operator new.
+    if (getDebugInfo())
+      if (auto *newCall = dyn_cast<llvm::CallBase>(RV.getScalarVal()))
+        getDebugInfo()->addHeapAllocSiteMetadata(newCall, allocType,
+                                                 E->getExprLoc());
 
     // If this was a call to a global replaceable allocation function that does
     // not take an alignment argument, the allocator is known to produce
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index e14e60c9bdc43..99de6e177eef5 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -3348,9 +3348,6 @@ class CodeGenFunction : public CodeGenTypeCache {
   SanitizerAnnotateDebugInfo(ArrayRef<SanitizerKind::SanitizerOrdinal> Ordinals,
                              SanitizerHandler Handler);
 
-  /// Emit additional metadata used by the AllocToken instrumentation.
-  void EmitAllocToken(llvm::CallBase *CB, QualType AllocType);
-
   llvm::Value *GetCountedByFieldExprGEP(const Expr *Base, const FieldDecl *FD,
                                         const FieldDecl *CountDecl);
 

@thurstond thurstond merged commit 34fda63 into main Oct 8, 2025
13 checks passed
@thurstond thurstond deleted the revert-162099-users/melver/spr/clangcodegen-emit-alloc_token-for-new-expressions branch October 8, 2025 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen IR generation bugs: mangling, exceptions, etc. clang Clang issues not falling into any other category skip-precommit-approval PR for CI feedback, not intended for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants