diff --git a/mlir/include/mlir-c/IR.h b/mlir/include/mlir-c/IR.h --- a/mlir/include/mlir-c/IR.h +++ b/mlir/include/mlir-c/IR.h @@ -162,6 +162,11 @@ MLIR_CAPI_EXPORTED MlirLocation mlirLocationCallSiteGet(MlirLocation callee, MlirLocation caller); +/// Creates a fused location with an array of locations and metadata. +MLIR_CAPI_EXPORTED MlirLocation +mlirLocationFusedGet(MlirContext ctx, intptr_t nLocations, + MlirLocation const *locations, MlirAttribute metadata); + /// Creates a name location owned by the given context. Providing null location /// for childLoc is allowed and if childLoc is null location, then the behavior /// is the same as having unknown child location. diff --git a/mlir/lib/CAPI/IR/IR.cpp b/mlir/lib/CAPI/IR/IR.cpp --- a/mlir/lib/CAPI/IR/IR.cpp +++ b/mlir/lib/CAPI/IR/IR.cpp @@ -132,6 +132,14 @@ return wrap(Location(CallSiteLoc::get(unwrap(callee), unwrap(caller)))); } +MlirLocation mlirLocationFusedGet(MlirContext ctx, MlirAttribute metadata, + intptr_t nLocations, + MlirLocation const *locations) { + SmallVector locs; + ArrayRef unwrappedLocs = unwrapList(nLocations, locations, locs); + return wrap(FusedLoc::get(unwrappedLocs, unwrap(metadata), unwrap(ctx))); +} + MlirLocation mlirLocationNameGet(MlirContext context, MlirStringRef name, MlirLocation childLoc) { if (mlirLocationIsNull(childLoc)) diff --git a/mlir/test/CAPI/ir.c b/mlir/test/CAPI/ir.c --- a/mlir/test/CAPI/ir.c +++ b/mlir/test/CAPI/ir.c @@ -1708,6 +1708,10 @@ MlirLocation nameLoc = mlirLocationNameGet(ctx, mlirStringRefCreateFromCString("named"), null); mlirEmitError(nameLoc, "test diagnostics"); + MlirLocation locs[2] = {nameLoc, callSiteLoc}; + MlirAttribute nullAttr = {0}; + MlirLocation fusedLoc = mlirLocationFusedGet(ctx, 2, locs, nullAttr); + mlirEmitError(fusedLoc, "test diagnostics"); mlirContextDetachDiagnosticHandler(ctx, id); mlirEmitError(unknownLoc, "more test diagnostics"); // CHECK-LABEL: @test_diagnostics @@ -1727,6 +1731,9 @@ // CHECK: test diagnostics // CHECK: loc("named") // CHECK: >> end of diagnostic (userData: 42) + // CHECK: processing diagnostic (userData: 42) << + // CHECK: test diagnostics + // CHECK: loc(fused["named", callsite("other-file.c":2:3 at "file.c":1:2)]) // CHECK: deleting user data (userData: 42) // CHECK-NOT: processing diagnostic // CHECK: more test diagnostics