[llvm-dev] verifyFunction fails validation with Terminator found in the middle of a basic block
Michael Kruse via llvm-dev
llvm-dev at lists.llvm.org
Fri Oct 22 11:00:08 PDT 2021
Am Do., 21. Okt. 2021 um 20:51 Uhr schrieb Vijay via llvm-dev
<llvm-dev at lists.llvm.org>:
>
> Hi,
>
> I'm generating IR for a factorial function that looks like below. When I call the verifyFunction, it fails validation with the error message Terminator found in the middle of a basic block. label %then
>
> The resulting IR still works fine but I'm not sure if the code generation should be done in a better way for the if/then block below.
>
> Thanks in advance,
> Vijay
>
> define double @fact(double %n) {
> entry:
> %n1 = alloca double, align 8
> store double %n, double* %n1, align 8
> %n2 = load double, double* %n1, align 8
> %cmptmp = fcmp ule double %n2, 1.000000e+00
> %booltmp = uitofp i1 %cmptmp to double
> %ifcond = fcmp one double %booltmp, 0.000000e+00
> br i1 %ifcond, label %then, label %ifcont
>
> then: ; preds = %entry
> ret double 1.000000e+00
> br label %ifcont
Nothing is executed after a ret instruction, violating the definition
of a basic block (executes all instructions from beginning to end).
Passes are not expecting this situation; if something still works, it
is pure luck.
Just remove the br instruction, it's not executed anyway.
Michael
> ifcont: ; preds = %then, %entry
> %n3 = load double, double* %n1, align 8
> %n4 = load double, double* %n1, align 8
> %subtmp = fsub double %n4, 1.000000e+00
> %calltmp = call double @fact(double %subtmp)
> %multmp = fmul double %n3, %calltmp
> ret double %multmp
> }
> Validating function...
> Terminator found in the middle of a basic block!
> label %then
> Validation failed
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
More information about the llvm-dev
mailing list