Homework 2: Type Constraints Collector

Problem

Employ the union-find algorithm to reason the type constraints on ASTs of C++ 14 programs.

Benchmark

lambda.cc

#include <cstdio>
#include <cstdlib>

auto lambda(int n) {
    auto x = getchar();
    auto y = (int *)malloc(8);
    *y = x;
    auto z = *y;
    return x;
}

recursive.cc

auto foo = [](auto x) {
    return x;
};

auto bar = [](auto a, auto b) {
    return a + b;
};

auto zip = [](auto f1) {
    auto a = 2;
    auto b = 3;
    a = f1(a);
    b = bar(a, b);
    return bar;
};

auto test() {
    auto f2 = zip(foo);
    return f2(1, 2);
}

Submission of Manual Results

Submission of Implementation (Optional)

P.S. Though it is optional, it is recommended to practice as a side-project if you do not understand how LLVM/Clang passes or checkers are built and how can they run like plugins.

Sample