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

Question: Without the cast operation, malloc cannot be correctly identified. #419

Open
sybs5968 opened this issue Jul 3, 2024 · 0 comments

Comments

@sybs5968
Copy link

sybs5968 commented Jul 3, 2024

void Cast1() {
    void *mem = malloc(100);
    char *arr = (char *)mem;
    arr[0] = '%'; arr[1] = '#'; arr[2] = '\0';
    printf("%s\n" , arr);
    free(mem);
}

/*
 func.func @Cast1() attributes {llvm.linkage = #llvm.linkage<external>} {
    %c0_i8 = arith.constant 0 : i8
    %c35_i8 = arith.constant 35 : i8
    %c37_i8 = arith.constant 37 : i8
    %c100_i64 = arith.constant 100 : i64
    %0 = call @malloc(%c100_i64) : (i64) -> memref<?xi8>
    affine.store %c37_i8, %0[0] : memref<?xi8>
    affine.store %c35_i8, %0[1] : memref<?xi8>
    affine.store %c0_i8, %0[2] : memref<?xi8>
    %1 = llvm.mlir.addressof @str0 : !llvm.ptr
    %2 = llvm.getelementptr %1[0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.array<4 x i8>
    %3 = "polygeist.memref2pointer"(%0) : (memref<?xi8>) -> !llvm.ptr
    %4 = llvm.call @printf(%2, %3) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, !llvm.ptr) -> i32
    memref.dealloc %0 : memref<?xi8>
    return
  }
  func.func private @malloc(i64) -> memref<?xi8> attributes {llvm.linkage = #llvm.linkage<external>}
*/

I noticed that your malloc conversion is done in VisitCastExpr, so you can only recognize malloc as a custom function if you have a special case like above.

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

1 participant