[PATCH] [CGP] Fix a crash when "Result" is a nullptr.

Chandler Carruth chandlerc at google.com
Tue May 13 08:11:04 PDT 2014


Looks good, please submit.


On Tue, May 13, 2014 at 9:07 AM, Joey Gouly <joey.gouly at gmail.com> wrote:

> r205941 changed the logic, so that a cast happens *before* 'Result' is
> compared to 'AddrMode.BaseReg'.
> In the case that 'AddrMode.BaseReg' is nullptr, 'Result' will also be
> nullptr, so the cast causes an assertion.
> We should use dyn_cast_or_null here to check 'Result' is not null and it
> is an instruction.
>
> Bug found by Mats Petersson, and I reduced his IR to get a test case.
>
> Also r205941 didn't have a test case, so it'd be good to get one for that
> commit too.
>
> http://reviews.llvm.org/D3746
>
> Files:
>   lib/CodeGen/CodeGenPrepare.cpp
>   test/CodeGen/X86/codegen-prepare-crash.ll
>
> Index: lib/CodeGen/CodeGenPrepare.cpp
> ===================================================================
> --- lib/CodeGen/CodeGenPrepare.cpp
> +++ lib/CodeGen/CodeGenPrepare.cpp
> @@ -2759,7 +2759,7 @@
>          // the original IR value was tossed in favor of a constant back
> when
>          // the AddrMode was created we need to bail out gracefully if
> widths
>          // do not match instead of extending it.
> -        Instruction *I = dyn_cast<Instruction>(Result);
> +        Instruction *I = dyn_cast_or_null<Instruction>(Result);
>          if (I && (Result != AddrMode.BaseReg))
>            I->eraseFromParent();
>          return false;
> Index: test/CodeGen/X86/codegen-prepare-crash.ll
> ===================================================================
> --- /dev/null
> +++ test/CodeGen/X86/codegen-prepare-crash.ll
> @@ -0,0 +1,14 @@
> +; RUN: llc < %s
> +target triple = "x86_64-unknown-linux-gnu"
> +
> + at g = external global [10 x i32]
> +
> +define void @f(i32 %u) {
> +  %1 = add i32 %u, 4
> +  br label %P.Proc8.exit
> +
> +P.Proc8.exit:
> +  %valueindex35.i = getelementptr [10 x i32]* @g, i32 0, i32 %1
> +  store i32 %u, i32* %valueindex35.i
> +  ret void
> +}
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140513/6a109cf9/attachment.html>


More information about the llvm-commits mailing list