Skip to content

Commit

Permalink
Fix builtin macros for memory operations
Browse files Browse the repository at this point in the history
  • Loading branch information
vaithak committed Feb 26, 2024
1 parent 7e85226 commit d78b389
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions lib/Differentiator/CladUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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;

Check warning on line 659 in lib/Differentiator/CladUtils.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Differentiator/CladUtils.cpp#L659

Added line #L659 was not covered by tests
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

0 comments on commit d78b389

Please sign in to comment.