Revert "[Clang][CodeGen] Emit !alloc_token for new expressions" (#162412)

Reverts llvm/llvm-project#162099

Reason: this commit depends on #162098, which I am reverting due to
build breakage (see
https://github.com/llvm/llvm-project/pull/162098#issuecomment-3379070211).
This commit is contained in:
Thurston Dang 2025-10-08 02:24:43 +00:00 committed by GitHub
parent 1a5494ca4a
commit 34fda634f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 30 deletions

View File

@ -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) {

View File

@ -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

View File

@ -3348,9 +3348,6 @@ public:
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);