Created
January 10, 2013 10:45
-
-
Save dmikurube/4501181 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (getLangOpts().InterceptAllocationFunctions && | |
getLangOpts().RTTI) { | |
bool UseSize = false; | |
IdentifierInfo *DeleteInterceptInfo = | |
&PP.getIdentifierTable().get("__op_delete_intercept__"); | |
DeclareGlobalAllocatorInterceptFunctions( | |
DeclarationName(DeleteInterceptInfo), UseSize); | |
LookupResult R(*this, DeleteInterceptInfo, SourceLocation(), | |
LookupOrdinaryName); | |
LookupQualifiedName(R, Context.getTranslationUnitDecl()); | |
RecordDecl* TypeInfoDecl = getOrCreateCXXTypeInfoDecl(); | |
if (!R.empty() && !R.isAmbiguous() && TypeInfoDecl) { | |
R.suppressDiagnostics(); | |
QualType TypeInfoType = Context.getTypeDeclType(TypeInfoDecl); | |
TypeSourceInfo* TemporaryTypeSourceInfo = | |
Context.getTrivialTypeSourceInfo(Context.VoidPtrTy); | |
CXXTypeidExpr* TemporaryTypeidExpr = | |
new (Context) CXXTypeidExpr(TypeInfoType.withConst(), | |
TemporaryTypeSourceInfo, | |
SourceRange(StartLoc, StartLoc)); | |
OverloadCandidateSet Candidates(StartLoc); | |
for (LookupResult::iterator Intercept = R.begin(), InterceptEnd = R.end(); | |
Intercept != InterceptEnd; ++Intercept) { | |
// Even member operator new/delete are implicitly treated as | |
// static, so don't use AddMemberCandidate. | |
NamedDecl *D = (*Intercept)->getUnderlyingDecl(); | |
FunctionDecl *Fn = cast<FunctionDecl>(D); | |
CXXNullPtrLiteralExpr Null(Context.VoidPtrTy, SourceLocation()); | |
IntegerLiteral Size(Context, | |
llvm::APInt::getNullValue(Context.getTargetInfo().getPointerWidth(0)), | |
Context.getSizeType(), SourceLocation()); | |
Expr* InterceptArgs[3]; | |
InterceptArgs[0] = &Null; | |
InterceptArgs[1] = TemporaryTypeidExpr; | |
if (UseSize) { | |
InterceptArgs[2] = &Size; | |
AddOverloadCandidate(Fn, Intercept.getPair(), | |
llvm::makeArrayRef(InterceptArgs, 3), Candidates, | |
/*SuppressUserConversions=*/false); | |
} else { | |
AddOverloadCandidate(Fn, Intercept.getPair(), | |
llvm::makeArrayRef(InterceptArgs, 2), Candidates, | |
/*SuppressUserConversions=*/false); | |
} | |
} | |
// Do the resolution. | |
OverloadCandidateSet::iterator Best; | |
switch (Candidates.BestViableFunction(*this, StartLoc, Best)) { | |
case OR_Success: { | |
FunctionDecl* Fn = Best->Function; | |
Result->setOperatorDeleteIntercept(Fn); | |
Result->setInterceptWantsSize(UseSize); | |
MarkFunctionReferenced(StartLoc, Fn); | |
} | |
default: | |
; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (getLangOpts().InterceptAllocationFunctions && | |
getLangOpts().RTTI) { | |
bool UseSize = false; | |
IdentifierInfo *NewInterceptInfo = | |
&PP.getIdentifierTable().get("__op_new_intercept__"); | |
DeclareGlobalAllocatorInterceptFunctions( | |
DeclarationName(NewInterceptInfo), true); | |
LookupResult R(*this, NewInterceptInfo, SourceLocation(), | |
LookupOrdinaryName); | |
LookupQualifiedName(R, Context.getTranslationUnitDecl()); | |
RecordDecl* TypeInfoDecl = getOrCreateCXXTypeInfoDecl(); | |
if (!R.empty() && !R.isAmbiguous() && TypeInfoDecl) { | |
R.suppressDiagnostics(); | |
QualType TypeInfoType = Context.getTypeDeclType(TypeInfoDecl); | |
TypeSourceInfo* TemporaryTypeSourceInfo = | |
Context.getTrivialTypeSourceInfo(Context.VoidPtrTy); | |
CXXTypeidExpr* TemporaryTypeidExpr = | |
new (Context) CXXTypeidExpr(TypeInfoType.withConst(), | |
TemporaryTypeSourceInfo, | |
SourceRange(StartLoc, StartLoc)); | |
OverloadCandidateSet Candidates(StartLoc); | |
for (LookupResult::iterator Intercept = R.begin(), InterceptEnd = R.end(); | |
Intercept != InterceptEnd; ++Intercept) { | |
// Even member operator new/delete are implicitly treated as | |
// static, so don't use AddMemberCandidate. | |
NamedDecl *D = (*Intercept)->getUnderlyingDecl(); | |
FunctionDecl *Fn = cast<FunctionDecl>(D); | |
CXXNullPtrLiteralExpr Null(Context.VoidPtrTy, SourceLocation()); | |
IntegerLiteral Size(Context, | |
llvm::APInt::getNullValue(Context.getTargetInfo().getPointerWidth(0)), | |
Context.getSizeType(), | |
SourceLocation()); | |
Expr* InterceptArgs[3]; | |
InterceptArgs[0] = &Null; | |
InterceptArgs[1] = TemporaryTypeidExpr; | |
InterceptArgs[2] = &Size; | |
AddOverloadCandidate(Fn, Intercept.getPair(), | |
llvm::makeArrayRef(InterceptArgs, 3), Candidates, | |
/*SuppressUserConversions=*/false); | |
} | |
// Do the resolution. | |
OverloadCandidateSet::iterator Best; | |
switch (Candidates.BestViableFunction(*this, StartLoc, Best)) { | |
case OR_Success: { | |
FunctionDecl* Fn = Best->Function; | |
Result->setOperatorNewIntercept(Fn); | |
Result->setInterceptWantsSize(UseSize); | |
MarkFunctionReferenced(StartLoc, Fn); | |
} | |
default: | |
; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment