From: Chuanqi Xu Date: Wed, 4 Jan 2023 10:57:33 +0000 (+0800) Subject: [NFC] let FunctionDecl::isReservedGlobalPlacementOperator return false when the funct... X-Git-Tag: upstream/17.0.6~22198 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8a06b2362a4b4da835d7d6041d1c0d706b5281b7;p=platform%2Fupstream%2Fllvm.git [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. --- 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;