Trung Ta
Trung Ta

Reputation: 1722

How to print the detailed type of a struct type in LLVM IR which is compiled from a CPP class?

After compiling a class in C++ to LLVM bitcode, I use llvm-dis or opt -S to display the textual IR, but the printed type of that class is always like: %class.A = type { i32 (...)** }

Does anyone know how to print the detailed type that is current hidden by ...?

Here is the C++ code that I use:

#include <stdio.h>
#include <stdlib.h>

class A {
  public:
    virtual int foo(int i) {
      return i + 2;
    }
};

int main() {
  A *a = new A;
  int x = a->foo(1);
  return 0;
}

And here is part of the output LLVM IR:

; ModuleID = 'logs/abstract.bc'
source_filename = "abstract.cpp"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

%class.A = type { i32 (...)** }              // How to make ... become more detailed?

$_ZN1AC2Ev = comdat any
$_ZN1A3fooEi = comdat any
$_ZN1A3barEi = comdat any
$_ZTV1A = comdat any
$_ZTS1A = comdat any
$_ZTI1A = comdat any
....

Upvotes: 0

Views: 354

Answers (1)

Anton Korobeynikov
Anton Korobeynikov

Reputation: 9324

There is nothing hidden here.

Your class contains a single virtual function. So, the corresponding struct should have a place to hold function pointer.

Upvotes: 1

Related Questions