From d78b389c47eee7c85580938b9123af1f3a41a208 Mon Sep 17 00:00:00 2001 From: Vaibhav Thakkar Date: Mon, 26 Feb 2024 12:41:46 +0100 Subject: [PATCH] Fix builtin macros for memory operations --- lib/Differentiator/CladUtils.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/Differentiator/CladUtils.cpp b/lib/Differentiator/CladUtils.cpp index 3d1a872c9..5d4ae1cdc 100644 --- a/lib/Differentiator/CladUtils.cpp +++ b/lib/Differentiator/CladUtils.cpp @@ -8,6 +8,7 @@ #include "clang/AST/RecursiveASTVisitor.h" #include "clang/Basic/SourceLocation.h" #include "clang/Sema/Lookup.h" +#include "clang/Basic/Builtins.h" #include "llvm/ADT/SmallVector.h" #include "clad/Differentiator/Compatibility.h" @@ -643,17 +644,31 @@ namespace clad { } bool IsMemoryAllocationFunction(const clang::FunctionDecl* FD) { + + #if CLANG_VERSION_MAJOR > 12 if (FD->getBuiltinID() == Builtin::BImalloc) return true; - if (FD->getBuiltinID() == Builtin::BIcalloc) + if (FD->getBuiltinID() == Builtin::ID::BIcalloc) + return true; + if (FD->getBuiltinID() == Builtin::ID::BIrealloc) + return true; + #else + if (FD->getNameAsString() == "malloc") + return true; + if (FD->getNameAsString() == "calloc") return true; - if (FD->getBuiltinID() == Builtin::BIrealloc) + if (FD->getNameAsString() == "realloc") return true; + #endif return false; } bool IsMemoryDeallocationFunction(const clang::FunctionDecl* FD) { - return FD->getBuiltinID() == Builtin::BIfree; + #if CLANG_VERSION_MAJOR > 12 + return FD->getBuiltinID() == Builtin::ID::BIfree; + #else + return FD->getNameAsString() == "free"; + #endif } } // namespace utils } // namespace clad