Coverage Report

Created: 2023-09-21 18:56

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Driver/ToolChains/VEToolchain.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- VE.cpp - VE ToolChain Implementations ------------------*- C++ -*-===//
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 "VEToolchain.h"
10
#include "CommonArgs.h"
11
#include "clang/Driver/Compilation.h"
12
#include "clang/Driver/Driver.h"
13
#include "clang/Driver/Options.h"
14
#include "llvm/Option/ArgList.h"
15
#include "llvm/Support/FileSystem.h"
16
#include "llvm/Support/Path.h"
17
#include <cstdlib> // ::getenv
18
19
using namespace clang::driver;
20
using namespace clang::driver::toolchains;
21
using namespace clang;
22
using namespace llvm::opt;
23
24
/// VE tool chain
25
VEToolChain::VEToolChain(const Driver &D, const llvm::Triple &Triple,
26
                         const ArgList &Args)
27
4
    : Linux(D, Triple, Args) {
28
4
  getProgramPaths().push_back("/opt/nec/ve/bin");
29
  // ProgramPaths are found via 'PATH' environment variable.
30
31
  // Default library paths are following:
32
  //   ${RESOURCEDIR}/lib/ve-unknown-linux-gnu,
33
  // These are OK.
34
35
  // Default file paths are following:
36
  //   ${RESOURCEDIR}/lib/linux/ve, (== getArchSpecificLibPaths)
37
  //   /lib/../lib64,
38
  //   /usr/lib/../lib64,
39
  //   ${BINPATH}/../lib,
40
  //   /lib,
41
  //   /usr/lib,
42
  // These are OK for host, but no go for VE.
43
44
  // Define file paths from scratch here.
45
4
  getFilePaths().clear();
46
47
  // Add library directories:
48
  //   ${BINPATH}/../lib/ve-unknown-linux-gnu, (== getStdlibPath)
49
  //   ${RESOURCEDIR}/lib/linux/ve, (== getArchSpecificLibPaths)
50
  //   ${SYSROOT}/opt/nec/ve/lib,
51
4
  if (std::optional<std::string> Path = getStdlibPath())
52
0
    getFilePaths().push_back(std::move(*Path));
53
4
  for (const auto &Path : getArchSpecificLibPaths())
54
8
    getFilePaths().push_back(Path);
55
4
  getFilePaths().push_back(computeSysRoot() + "/opt/nec/ve/lib");
56
4
}
57
58
0
Tool *VEToolChain::buildAssembler() const {
59
0
  return new tools::gnutools::Assembler(*this);
60
0
}
61
62
2
Tool *VEToolChain::buildLinker() const {
63
2
  return new tools::gnutools::Linker(*this);
64
2
}
65
66
4
bool VEToolChain::isPICDefault() const { return false; }
67
68
6
bool VEToolChain::isPIEDefault(const llvm::opt::ArgList &Args) const {
69
6
  return false;
70
6
}
71
72
4
bool VEToolChain::isPICDefaultForced() const { return false; }
73
74
4
bool VEToolChain::SupportsProfiling() const { return false; }
75
76
0
bool VEToolChain::hasBlocksRuntime() const { return false; }
77
78
void VEToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
79
4
                                            ArgStringList &CC1Args) const {
80
4
  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
81
0
    return;
82
83
4
  if (DriverArgs.hasArg(options::OPT_nobuiltininc) &&
84
4
      
DriverArgs.hasArg(options::OPT_nostdlibinc)0
)
85
0
    return;
86
87
4
  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
88
4
    SmallString<128> P(getDriver().ResourceDir);
89
4
    llvm::sys::path::append(P, "include");
90
4
    addSystemInclude(DriverArgs, CC1Args, P);
91
4
  }
92
93
4
  if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) {
94
4
    if (const char *cl_include_dir = getenv("NCC_C_INCLUDE_PATH")) {
95
0
      SmallVector<StringRef, 4> Dirs;
96
0
      const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
97
0
      StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
98
0
      ArrayRef<StringRef> DirVec(Dirs);
99
0
      addSystemIncludes(DriverArgs, CC1Args, DirVec);
100
4
    } else {
101
4
      addSystemInclude(DriverArgs, CC1Args,
102
4
                       getDriver().SysRoot + "/opt/nec/ve/include");
103
4
    }
104
4
  }
105
4
}
106
107
void VEToolChain::addClangTargetOptions(const ArgList &DriverArgs,
108
                                        ArgStringList &CC1Args,
109
4
                                        Action::OffloadKind) const {
110
4
  CC1Args.push_back("-nostdsysteminc");
111
4
  bool UseInitArrayDefault = true;
112
4
  if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
113
4
                          options::OPT_fno_use_init_array, UseInitArrayDefault))
114
0
    CC1Args.push_back("-fno-use-init-array");
115
4
}
116
117
void VEToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
118
0
                                               ArgStringList &CC1Args) const {
119
0
  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) ||
120
0
      DriverArgs.hasArg(options::OPT_nostdlibinc) ||
121
0
      DriverArgs.hasArg(options::OPT_nostdincxx))
122
0
    return;
123
0
  if (const char *cl_include_dir = getenv("NCC_CPLUS_INCLUDE_PATH")) {
124
0
    SmallVector<StringRef, 4> Dirs;
125
0
    const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
126
0
    StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
127
0
    ArrayRef<StringRef> DirVec(Dirs);
128
0
    addSystemIncludes(DriverArgs, CC1Args, DirVec);
129
0
  } else {
130
    // Add following paths for multiple target installation.
131
    //   ${INSTALLDIR}/include/ve-unknown-linux-gnu/c++/v1,
132
    //   ${INSTALLDIR}/include/c++/v1,
133
0
    addLibCxxIncludePaths(DriverArgs, CC1Args);
134
0
  }
135
0
}
136
137
void VEToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
138
0
                                      ArgStringList &CmdArgs) const {
139
0
  assert((GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) &&
140
0
         "Only -lc++ (aka libxx) is supported in this toolchain.");
141
142
0
  tools::addArchSpecificRPath(*this, Args, CmdArgs);
143
144
0
  CmdArgs.push_back("-lc++");
145
0
  if (Args.hasArg(options::OPT_fexperimental_library))
146
0
    CmdArgs.push_back("-lc++experimental");
147
0
  CmdArgs.push_back("-lc++abi");
148
0
  CmdArgs.push_back("-lunwind");
149
  // libc++ requires -lpthread under glibc environment
150
0
  CmdArgs.push_back("-lpthread");
151
  // libunwind requires -ldl under glibc environment
152
0
  CmdArgs.push_back("-ldl");
153
0
}
154
155
llvm::ExceptionHandling
156
4
VEToolChain::GetExceptionModel(const ArgList &Args) const {
157
  // VE uses SjLj exceptions.
158
4
  return llvm::ExceptionHandling::SjLj;
159
4
}