title: How to do type checking with the LLVM C++ API?
body: <p>I've just started learning the LLVM C++ API, and I'm a bit confused about how to do type checking. There's an example my instructor has provided to me about storing a variable in stack memory as follows:</p>
  
  <pre><code>llvm::AllocaInst *Alloca;
  Alloca = llvm::Builder.CreateAlloca(llvm::IntegerType::get(getGlobalContext(), 32), nullptr, "variable_name");
  </code></pre>
  
  <p>I understand this, but in the next part it talks about type checking before assigning a value to a variable. <code>To assign a value in a Decaf statement of the type lvalue = rvalue you should get the location of lvalue from the symbol table. You can check the type of rvalue using the following API call:</code></p>
  
  <pre><code>const llvm::PointerType *ptrTy = rvalue-&gt;getType()-&gt;getPointerTo();
  ptrTy == Alloca-&gt;getType()
  </code></pre>
  
  <p>I am utterly confused at why this needs to be done for type checking. I've read the documentation and <code>getPointerTo</code> returns a PointerType object. So my first question is, the Type object of Alloca is IntegerType, so why are we creating an object of PointerType? This seems completely out of left field to me.</p>
  
  <p>The second question I have is, why are we then comparing this PointerType object with the Alloca Type object which is an IntegerType object? Is there some sort of == operator overloading? Because I was searching through the documentation and I couldn't find any.</p>