Author: Chuanqi Xu Date: 2023-01-04T18:57:36+08:00 New Revision: 8a06b2362a4b4da835d7d6041d1c0d706b5281b7
URL: https://github.com/llvm/llvm-project/commit/8a06b2362a4b4da835d7d6041d1c0d706b5281b7 DIFF: https://github.com/llvm/llvm-project/commit/8a06b2362a4b4da835d7d6041d1c0d706b5281b7.diff LOG: [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. Added: Modified: clang/lib/AST/Decl.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 236d4f98bb6a7..2acb3915aa586 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; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits