SwitchInst problem

Hi All,

Value* V;
Value* V2;
BasicBlock * BB;

unsigned j; ///number of cases

… //insert V , V2, j and BB

SwitchInst* sw= builder.CreateSwitch(V, BB, j);
ConstantInt * CI= dyn_cast(V2);
sw-> addCase( CI , BB);

At last step there is
Program received signal SIGSEGV, Segmentation fault.

What is wrong in the code?

Thanks in advance

Hi Rasha,

What is wrong in the code?

Your best bet is to run a debugger and see if the variables have
values you expect just before that last call, and then look at what's
causing the segfault in LLVM (null pointer?) code and work out where
the first place it's not doing what you expect is.
Cheers.

Tim.

Hi Rasha,

What is wrong in the code?

Your best bet is to run a debugger and see if the variables have
values you expect just before that last call, and then look at what's
causing the segfault in LLVM (null pointer?) code and work out where
the first place it's not doing what you expect is.

You may also want to use cast<> instead of dyn_cast<> if you expect the result of dyn_cast<> to be non-NULL. cast<> will assert that its result is non-NULL.

-- John T.