1 //===- RTBuilder.cpp -- Runtime Interface unit tests ----------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "flang/Optimizer/Builder/Runtime/RTBuilder.h"
10 #include "gtest/gtest.h"
11 #include "flang/Optimizer/Support/InitFIR.h"
14 // Check that it is possible to make a difference between complex runtime
15 // function using C99 complex and C++ std::complex. This is important since
16 // they are layout compatible but not link time compatible (returned differently
17 // in X86 32 ABI for instance). At high level fir, we need to convey that the
18 // signature are different regardless of the target ABI.
20 // Fake runtime header to be introspected.
21 c_float_complex_t
c99_cacosf(c_float_complex_t
);
23 TEST(RTBuilderTest
, ComplexRuntimeInterface
) {
24 mlir::DialectRegistry registry
;
25 fir::support::registerDialects(registry
);
26 mlir::MLIRContext
ctx(registry
);
27 fir::support::loadDialects(ctx
);
28 mlir::Type c99_cacosf_signature
{
29 fir::runtime::RuntimeTableKey
<decltype(c99_cacosf
)>::getTypeModel()(
31 auto c99_cacosf_funcTy
= mlir::cast
<mlir::FunctionType
>(c99_cacosf_signature
);
32 EXPECT_EQ(c99_cacosf_funcTy
.getNumInputs(), 1u);
33 EXPECT_EQ(c99_cacosf_funcTy
.getNumResults(), 1u);
34 auto cplx_ty
= mlir::ComplexType::get(mlir::FloatType::getF32(&ctx
));
35 EXPECT_EQ(c99_cacosf_funcTy
.getInput(0), cplx_ty
);
36 EXPECT_EQ(c99_cacosf_funcTy
.getResult(0), cplx_ty
);