Hard
Three LTO builds of the same virtual call
Circle is the only class anywhere in the program that derives from Shape, and nothing is loaded dynamically. The program is built three ways with Clang at -O2: (1) -flto, (2) -flto -fwhole-program-vtables, (3) -flto -fwhole-program-vtables -fvisibility=hidden. In which builds does s->area() in total become a direct call?
shape.h
// shape.h
struct Shape {
virtual ~Shape() = default;
virtual double area() const = 0;
};
Shape* makeShape();
// circle.cpp
struct Circle : Shape {
double r = 1.0;
double area() const override { return 3.14159 * r * r; }
};
Shape* makeShape() { return new Circle; }
// total.cpp
double total(const Shape* s, int n) {
double t = 0;
for (int i = 0; i < n; ++i) t += s->area();
return t;
}
// main.cpp calls total(makeShape(), argc)36 of 44 in Compilers