Fix free cast

This commit is contained in:
William S. Moses 2021-12-06 15:14:11 -05:00 committed by William Moses
parent 52d56133ed
commit bc543995a1
2 changed files with 25 additions and 1 deletions

View File

@ -0,0 +1,23 @@
// RUN: mlir-clang %s --function=* -S | FileCheck %s
#include <stdlib.h>
struct band {
int dimX;
};
struct dimensions {
struct band LL;
};
void writeNStage2DDWT(struct dimensions* bandDims)
{
free(bandDims);
}
// CHECK: func @writeNStage2DDWT(%arg0: !llvm.ptr<struct<(struct<(i32)>)>>) attributes {llvm.linkage = #llvm.linkage<external>} {
// CHECK-NEXT: %c1_i64 = arith.constant 1 : i64
// CHECK-NEXT: %0 = llvm.alloca %c1_i64 x !llvm.ptr<struct<(struct<(i32)>)>> : (i64) -> !llvm.ptr<ptr<struct<(struct<(i32)>)>>>
// CHECK-NEXT: llvm.store %arg0, %0 : !llvm.ptr<ptr<struct<(struct<(i32)>)>>>
// CHECK-NEXT: %1 = llvm.load %0 : !llvm.ptr<ptr<struct<(struct<(i32)>)>>>
// CHECK-NEXT: %2 = llvm.bitcast %1 : !llvm.ptr<struct<(struct<(i32)>)>> to !llvm.ptr<i8>
// CHECK-NEXT: llvm.call @free(%2) : (!llvm.ptr<i8>) -> ()
// CHECK-NEXT: return
// CHECK-NEXT: }

View File

@ -1499,7 +1499,8 @@ MLIRScanner::EmitGPUCallExpr(clang::CallExpr *expr) {
if (arg.getType().isa<mlir::LLVM::LLVMPointerType>()) {
auto callee = EmitCallee(expr->getCallee());
auto strcmpF = Glob.GetOrCreateLLVMFunction(callee);
mlir::Value args[] = {arg};
mlir::Value args[] = {builder.create<LLVM::BitcastOp>(
loc, LLVM::LLVMPointerType::get(builder.getIntegerType(8)), arg)};
builder.create<mlir::LLVM::CallOp>(loc, strcmpF, args);
} else {
builder.create<mlir::memref::DeallocOp>(loc, arg);