Skip to content

"freeing without malloc" and "unknown tbaa call" warnings #2490

@jeffpollock9

Description

@jeffpollock9

Hi, I have the following minimal code example:

#include <cmath>
#include <print>

#include <Eigen/Dense>  // 3.4.0
#include <enzyme/enzyme>

struct Objective {
    double operator()(const double x) const {
        Eigen::VectorXd y = Eigen::VectorXd::Zero(2);
        y[0] = std::exp(x);
        return y.sum();
    }
};

int main() {
    const auto result = enzyme::autodiff<enzyme::ReverseWithPrimal>(Objective{}, enzyme::Active(1.0));

    const auto g = enzyme::get<0>(result);
    const auto v = enzyme::get<1>(result);

    std::println("value: {}", v);
    std::println("g(0): {}", enzyme::get<0>(g));
}

I can produce different sets of warnings with different compiler flags e.g.:

clang++ -DEIGEN_DONT_VECTORIZE -isystem /usr/include/eigen3 -O3 -DNDEBUG -std=c++23 -fplugin=/home/jeff/.local/lib/ClangEnzyme-20.so enzyme_issue.cpp

unknown tbaa call instruction user inst:   %17 = call double @exp(double noundef %1) #33, !tbaa !13 vdptr: {[]:Pointer, [-1]:Integer}
unknown tbaa call instruction user inst:   %24 = call double @exp(double noundef %1) #33, !tbaa !13 vdptr: {[]:Pointer, [-1]:Integer}
unknown tbaa call instruction user inst:   %12 = call double @exp(double noundef %1) #34, !tbaa !13 vdptr: {[]:Pointer, [-1]:Integer}
unknown tbaa call instruction user inst:   %19 = call double @exp(double noundef %1) #34, !tbaa !13 vdptr: {[]:Pointer, [-1]:Integer}
freeing without malloc   %18 = load ptr, ptr %0, align 8, !tbaa !14
freeing without malloc   %18 = load ptr, ptr %0, align 8, !tbaa !14
freeing without malloc   %33 = phi ptr [ %17, %15 ], [ %11, %10 ], [ %17, %31 ]
clang++ -DEIGEN_DONT_VECTORIZE -isystem /usr/include/eigen3 -O3 -std=c++23 -fplugin=/home/jeff/.local/lib/ClangEnzyme-20.so enzyme_issue.cpp

unknown tbaa call instruction user inst:   %3 = tail call double @exp(double noundef %1) #31, !tbaa !5 vdptr: {[]:Pointer, [-1]:Integer}
unknown tbaa call instruction user inst:   %3 = tail call double @exp(double noundef %1) #32, !tbaa !5 vdptr: {[]:Pointer, [-1]:Integer}
clang++ -DEIGEN_DONT_VECTORIZE -isystem /usr/include/eigen3 -O3 -DNDEBUG -ffast-math -std=c++23 -fplugin=/home/jeff/.local/lib/ClangEnzyme-20.so enzyme_issue.cpp

freeing without malloc   %18 = load ptr, ptr %0, align 8, !tbaa !14
freeing without malloc   %18 = load ptr, ptr %0, align 8, !tbaa !14
freeing without malloc   %33 = phi ptr [ %17, %15 ], [ %11, %10 ], [ %17, %31 ]

Also if I remove the Eigen::Zeros call, so re-write to something like:

    double operator()(const double x) const {
        Eigen::VectorXd y(2);
        y[0] = std::exp(x);
        y[1] = 0.0;
        return y.sum();
    }

then the "freeing without malloc" errors seem to go away.

It would be great to figure out and fix what is happening, or just to get any advice on what to do here.

If there is anything I could do to help with testing etc, please let me know. Thanks!

$ clang++ --version
Ubuntu clang version 20.1.2 (0ubuntu1)

$ git branch  # Enzyme checkout
* (HEAD detached at v0.0.203)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions