From 8a06b2362a4b4da835d7d6041d1c0d706b5281b7 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Wed, 4 Jan 2023 18:57:33 +0800 Subject: [PATCH] [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. --- clang/lib/AST/Decl.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 236d4f9..2acb391 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -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; -- 2.7.4