1//===- RTBuilder.cpp -- Runtime Interface unit tests ----------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#include "flang/Optimizer/Builder/Runtime/RTBuilder.h"
10#include "gtest/gtest.h"
11#include "flang/Optimizer/Support/InitFIR.h"
12
13// Check that it is possible to make a difference between complex runtime
14// function using C99 complex and C++ std::complex. This is important since
15// they are layout compatible but not link time compatible (returned differently
16// in X86 32 ABI for instance). At high level fir, we need to convey that the
17// signature are different regardless of the target ABI.
18
19// Fake runtime header to be introspected.
20c_float_complex_t c99_cacosf(c_float_complex_t);
21
22TEST(RTBuilderTest, ComplexRuntimeInterface) {
23 mlir::DialectRegistry registry;
24 fir::support::registerDialects(registry);
25 mlir::MLIRContext ctx(registry);
26 fir::support::loadDialects(ctx);
27 mlir::Type c99_cacosf_signature{
28 fir::runtime::RuntimeTableKey<decltype(c99_cacosf)>::getTypeModel()(
29 &ctx)};
30 auto c99_cacosf_funcTy = c99_cacosf_signature.cast<mlir::FunctionType>();
31 EXPECT_EQ(c99_cacosf_funcTy.getNumInputs(), 1u);
32 EXPECT_EQ(c99_cacosf_funcTy.getNumResults(), 1u);
33 auto cplx_ty = fir::ComplexType::get(&ctx, 4);
34 EXPECT_EQ(c99_cacosf_funcTy.getInput(0), cplx_ty);
35 EXPECT_EQ(c99_cacosf_funcTy.getResult(0), cplx_ty);
36}
37

source code of flang/unittests/Optimizer/RTBuilder.cpp