How to create global string array? (user question)

I am trying to create such module with API (it's equivalent to c++: const char* ss[] = {"s1","s2"};):

@ss = global [2 x i8*] [i8* getelementptr inbounds ([3 x i8]* @.str1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8]* @.str2, i32 0, i32 0)] ; <[2 x i8*]*> [#uses=0]
@.str1 = private constant [3 x i8] c"s1\00", align 1 ; <[3 x i8]*> [#uses=1]
@.str2 = private constant [3 x i8] c"s2\00", align 1 ; <[3 x i8]*> [#uses=1]

Code below doesn't compile because to initialize GlobalVariable I need ConstantArray*, ConstantArray::get requires vector<Constant*>, but getelementptr is an instruction and it's not Constant*, but Value*.

What is the correct way to create such module? It's really tye


--- c++ code ---
#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Constants.h"
#include "llvm/Instructions.h"
#include "llvm/Analysis/Verifier.h"
#include <stdio.h>
#include <vector>
using namespace llvm;
using namespace std;

Constant* mk_string(Module *M, LLVMContext &Context, const string &svalue) {
   ArrayType *Ty = ArrayType::get(Type::getInt8Ty(Context),svalue.size()+1);
   GlobalVariable *GV = new llvm::GlobalVariable(

   vector<Constant*> idxs;
   idxs.push_back(ConstantInt::get(Type::getInt32Ty(Context), 0, false));
   return (GetElementPtrInst::Create(

main() {
   LLVMContext Context;
   Module *M = new Module("test", Context);
   vector<Constant*> strs;
   strs.push_back(mk_string(M, Context, "s1"));
   strs.push_back(mk_string(M, Context, "s2"));
   ArrayType *Ty = ArrayType::get(Type::getInt8Ty(Context)->getPointerTo(),2);
   new llvm::GlobalVariable(
   delete M;

I think ConstantExpr::getGetElementPtr() returns a Constant*.

I have found an invaluable way to find an answer (not necessarily the best answer, but an initial answer at least) is to write a simple c source file, compile it to bitcode (clang -S -emit-llvm sourcefile.c), then get llc to produce a cpp file containing the calls required to produce that bitcode (llc -march=cpp sourcefile.s). I find that the resulting source file (sourcefile.s.cpp) is usually enough to make an initial start on figuring out how to do what I want if I can't otherwise find it in the docs.

In your case sourcefile.c would simply be:
const char* ss[] = {"s1","s2"};