Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLJB crashes when consuming the llvm IL of ternary operation with function calls #14

Open
xiacijie opened this issue Oct 17, 2019 · 1 comment

Comments

@xiacijie
Copy link

xiacijie commented Oct 17, 2019

Below is the test example I use,

int a(){
    return 1;
}


int b(){
    return 2;
}

int main(){
    int x = 1;
    int y = x==2 ? a() : b();
    return y;
}

The llvm IL of the test example:

; ModuleID = '/Users/jackxia/Project/IBM/lljb/test/cpp/ternary.cpp'
source_filename = "/Users/jackxia/Project/IBM/lljb/test/cpp/ternary.cpp"
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.14.0"

; Function Attrs: noinline nounwind optnone ssp uwtable
define i32 @_Z1av() #0 {
  ret i32 1
}

; Function Attrs: noinline nounwind optnone ssp uwtable
define i32 @_Z1bv() #0 {
  ret i32 2
}

; Function Attrs: noinline norecurse nounwind optnone ssp uwtable
define i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 0, i32* %1, align 4
  store i32 1, i32* %2, align 4
  %4 = load i32, i32* %2, align 4
  %5 = icmp eq i32 %4, 2
  br i1 %5, label %6, label %8

; <label>:6:                                      ; preds = %0
  %7 = call i32 @_Z1av()
  br label %10

; <label>:8:                                      ; preds = %0
  %9 = call i32 @_Z1bv()
  br label %10

; <label>:10:                                     ; preds = %8, %6
  %11 = phi i32 [ %7, %6 ], [ %9, %8 ]
  store i32 %11, i32* %3, align 4
  %12 = load i32, i32* %3, align 4
  ret i32 %12
}

attributes #0 = { noinline nounwind optnone ssp uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { noinline norecurse nounwind optnone ssp uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }

!llvm.module.flags = !{!0, !1}
!llvm.ident = !{!2}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"PIC Level", i32 2}
!2 = !{!"Apple LLVM version 10.0.1 (clang-1001.0.46.4)"}
@nbhuiyan
Copy link
Owner

Thanks for reporting this, @xiacijie! This crash is happening because lljb is not correctly handling phi node instruction in llvm basic block %10. I worked on a mechanism to handle all kinds of phi nodes which should fix this issue and I will notify you once I open the PR with the implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants