[LLVMdev] Dereferencing NULL pointer in IndVarSimplify.cpp?

Andrew Trick atrick at apple.com
Thu Oct 23 20:32:20 PDT 2014


> On Oct 17, 2014, at 5:21 PM, Liang Wang <netcasper at gmail.com> wrote:
> 
> Hi,
> 
> Here is the code in IndVarSimplify.cpp.
> 
>    SmallVector<WeakVH, 16> DeadInsts;
> 
> 
>  while (!DeadInsts.empty())
>    if (Instruction *Inst =
>          dyn_cast_or_null<Instruction>(&*DeadInsts.pop_back_val()))
>      RecursivelyDeleteTriviallyDeadInstructions(Inst, TLI);
> 
> Since DeadInsts.pop_back_val() is WeakVH which could hold a NULL
> pointer, the expression, &*DeadInsts.pop_back_val(), could be &*NULL.
> Then NULL pointer is dereferenced here.
> 
> I wrote a small test case and it works just fine. But is this a
> well-defined behavior in the standard?

Try clang-dev or a c++ list for questions about the standard.

I think it would have been nicer to write (Value*)DeadInsts.pop_back_val()
-Andy

> 
> 
> Thanks,
> Liang
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list