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#include <complex>
13
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.
19
20// Fake runtime header to be introspected.
21c_float_complex_t c99_cacosf(c_float_complex_t);
22
23TEST(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()(
30 &ctx)};
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::Float32Type::get(&ctx));
35 EXPECT_EQ(c99_cacosf_funcTy.getInput(0), cplx_ty);
36 EXPECT_EQ(c99_cacosf_funcTy.getResult(0), cplx_ty);
37}
38

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

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