[NFC] let FunctionDecl::isReservedGlobalPlacementOperator return false when the function decl is not allocation functions

Currently `FunctionDecl::isReservedGlobalPlacementOperator` will crash
if the function is not an allocation/deallocation function, which is
surprising. Also, its semantics is not consistent with
isReplaceableGlobalAllocationFunction, which will return false if the
function is not an allocation/deallocation function.

This patch make FunctionDecl::isReservedGlobalPlacementOperator not
crash if the function is not an allocation/deallocation function, which
is consistent with isReplaceableGlobalAllocationFunction too.
This commit is contained in:
Chuanqi Xu 2023-01-04 18:57:33 +08:00
parent 8ec0a36967
commit 8a06b2362a

View File

@ -3190,11 +3190,13 @@ bool FunctionDecl::isMSVCRTEntryPoint() const {
}
bool FunctionDecl::isReservedGlobalPlacementOperator() const {
assert(getDeclName().getNameKind() == DeclarationName::CXXOperatorName);
assert(getDeclName().getCXXOverloadedOperator() == OO_New ||
getDeclName().getCXXOverloadedOperator() == OO_Delete ||
getDeclName().getCXXOverloadedOperator() == OO_Array_New ||
getDeclName().getCXXOverloadedOperator() == OO_Array_Delete);
if (getDeclName().getNameKind() != DeclarationName::CXXOperatorName)
return false;
if (getDeclName().getCXXOverloadedOperator() != OO_New &&
getDeclName().getCXXOverloadedOperator() != OO_Delete &&
getDeclName().getCXXOverloadedOperator() != OO_Array_New &&
getDeclName().getCXXOverloadedOperator() != OO_Array_Delete)
return false;
if (!getDeclContext()->getRedeclContext()->isTranslationUnit())
return false;