[cfe-dev] Bug in clang parsing pointer to an array in function parameter list

Justin Handville uniheliodem at gmail.com
Sat Sep 8 21:39:13 PDT 2007

The following code snippet generates an assert when compiled with
clang -emit-llvm

int main(int argc, char* argv[])
  return 0;


Assertion failed: (getOperand(0)->getType() ==
cast<PointerType>(getOperand(1)->getType())->getElementType() && "Ptr
must be a pointer to Val type!"), function AssertOK, file
Instructions.cpp, line 796.

The problem here is at line 116 of CGDecl.cpp:

    if (LTy->isFirstClassType()) {
      // TODO: Alignment
      DeclPtr = new llvm::AllocaInst(LTy, 0, std::string(D.getName())+".addr",

      // Store the initial value into the alloca.
      Builder.CreateStore(Arg, DeclPtr);  //attempting to store
char*[] as char**

The problem is that llvm treats char*[] and char** as two distinct
types as far as I can tell.  EmitParmDecl should convert the type to a
char** before calling CreateStore, since this is how the argument
would be passed in C ABI.

I assume that a transform step should be added before the CreateStore
that could normalize the argument to match the declptr.  I assume a
good approach would be to descend through both Arg and DeclPtr,
transforming Arg to match DeclPtr where compatible, or raising an
appropriate diagnostic error if such a transformation is not possible.

If I can get some approval that this route would work in this case,
then I will go ahead and submit the patch.


More information about the cfe-dev mailing list