Why does GEP allow src and destination type to have different address spaces?

The GEP constructor does not assert that the source and destination types match. Of course, this is incorrect and causes random failures somewhere down the line.

Could I add general sanity checks to the GEP constructor?

In general, is an Instruction allowed to be in an inconsistent state? If so, is there some well known method to “verify” whether an instruction is consistent or not?


Adding this assert SGTM, but it looks like something like this is already there?

  static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
                                   ArrayRef<Value *> IdxList,
                                   const Twine &NameStr = "",
                                   Instruction *InsertBefore = nullptr) {
    unsigned Values = 1 + unsigned(IdxList.size());
    if (!PointeeType)
      PointeeType =
          PointeeType ==
    return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
                                          NameStr, InsertBefore);

Or did I misunderstand what you're suggesting?

-- Sanjoy

The mail subject mentioned “address space”, I don’t know if Siddharth want to check getPointerAddressSpace equal or not.