Skip to content

Commit a212b34

Browse files
authored
merge main into amd-staging (llvm#4234)
2 parents 2936301 + 0bfef09 commit a212b34

File tree

43 files changed

+1126
-867
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1126
-867
lines changed

clang/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ if(CLANG_BUILT_STANDALONE)
8080
include(GetErrcMessages)
8181
include(LLVMDistributionSupport)
8282

83+
if(CMAKE_CROSSCOMPILING)
84+
set(LLVM_USE_HOST_TOOLS ON)
85+
include(CrossCompile)
86+
llvm_create_cross_target(Clang NATIVE "" Release)
87+
endif()
88+
8389
set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
8490
set(BUG_REPORT_URL "${LLVM_PACKAGE_BUGREPORT}" CACHE STRING
8591
"Default URL where bug reports are to be submitted.")

clang/include/clang/Driver/CommonArgs.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ unsigned DwarfVersionNum(StringRef ArgValue);
118118
const llvm::opt::Arg *getDwarfNArg(const llvm::opt::ArgList &Args);
119119
unsigned getDwarfVersion(const ToolChain &TC, const llvm::opt::ArgList &Args);
120120

121+
enum class DwarfFissionKind { None, Split, Single };
122+
123+
DwarfFissionKind getDebugFissionKind(const Driver &D,
124+
const llvm::opt::ArgList &Args,
125+
llvm::opt::Arg *&Arg);
126+
127+
bool checkDebugInfoOption(const llvm::opt::Arg *A,
128+
const llvm::opt::ArgList &Args, const Driver &D,
129+
const ToolChain &TC);
130+
121131
void AddAssemblerKPIC(const ToolChain &ToolChain,
122132
const llvm::opt::ArgList &Args,
123133
llvm::opt::ArgStringList &CmdArgs);

clang/include/clang/Driver/Options.td

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4907,13 +4907,13 @@ defm column_info : BoolOption<"g", "column-info",
49074907
PosFlag<SetTrue>, BothFlags<[], [ClangOption, CLOption, DXCOption]>>,
49084908
Group<g_flags_Group>;
49094909
def gsplit_dwarf : Flag<["-"], "gsplit-dwarf">, Group<g_flags_Group>,
4910-
Visibility<[ClangOption, CLOption, DXCOption]>;
4910+
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
49114911
def gsplit_dwarf_EQ : Joined<["-"], "gsplit-dwarf=">, Group<g_flags_Group>,
4912-
Visibility<[ClangOption, CLOption, DXCOption]>,
4912+
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
49134913
HelpText<"Set DWARF fission mode">,
49144914
Values<"split,single">;
49154915
def gno_split_dwarf : Flag<["-"], "gno-split-dwarf">, Group<g_flags_Group>,
4916-
Visibility<[ClangOption, CLOption, DXCOption]>;
4916+
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
49174917
def gtemplate_alias : Flag<["-"], "gtemplate-alias">, Group<g_flags_Group>, Visibility<[ClangOption, CC1Option]>;
49184918
def gno_template_alias : Flag<["-"], "gno-template-alias">, Group<g_flags_Group>, Visibility<[ClangOption]>;
49194919
def gsimple_template_names : Flag<["-"], "gsimple-template-names">, Group<g_flags_Group>;
@@ -8599,7 +8599,7 @@ def main_file_name : Separate<["-"], "main-file-name">,
85998599
MarshallingInfoString<CodeGenOpts<"MainFileName">>;
86008600
def split_dwarf_output : Separate<["-"], "split-dwarf-output">,
86018601
HelpText<"File name to use for split dwarf debug info output">,
8602-
Visibility<[CC1Option, CC1AsOption]>,
8602+
Visibility<[CC1Option, CC1AsOption, FC1Option]>,
86038603
MarshallingInfoString<CodeGenOpts<"SplitDwarfOutput">>;
86048604

86058605
let Visibility = [CC1Option, FC1Option] in {
@@ -8631,6 +8631,10 @@ def dependent_lib : Joined<["--"], "dependent-lib=">,
86318631
HelpText<"Add dependent library">,
86328632
MarshallingInfoStringVector<CodeGenOpts<"DependentLibraries">>;
86338633

8634+
def split_dwarf_file : Separate<["-"], "split-dwarf-file">,
8635+
HelpText<"Name of the split dwarf debug info file to encode in the object file">,
8636+
MarshallingInfoString<CodeGenOpts<"SplitDwarfFile">>;
8637+
86348638
} // let Visibility = [CC1Option, FC1Option]
86358639

86368640
let Visibility = [CC1Option] in {
@@ -8641,9 +8645,6 @@ def fblocks_runtime_optional : Flag<["-"], "fblocks-runtime-optional">,
86418645
def fexternc_nounwind : Flag<["-"], "fexternc-nounwind">,
86428646
HelpText<"Assume all functions with C linkage do not unwind">,
86438647
MarshallingInfoFlag<LangOpts<"ExternCNoUnwind">>;
8644-
def split_dwarf_file : Separate<["-"], "split-dwarf-file">,
8645-
HelpText<"Name of the split dwarf debug info file to encode in the object file">,
8646-
MarshallingInfoString<CodeGenOpts<"SplitDwarfFile">>;
86478648
def fno_wchar : Flag<["-"], "fno-wchar">,
86488649
HelpText<"Disable C++ builtin type wchar_t">,
86498650
MarshallingInfoNegativeFlag<LangOpts<"WChar">, cplusplus.KeyPath>,

clang/lib/AST/ByteCode/EvalEmitter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "EvaluationResult.h"
1717
#include "InterpState.h"
1818
#include "PrimType.h"
19+
#include "Record.h"
1920
#include "Source.h"
2021

2122
namespace clang {

clang/lib/AST/ByteCode/InterpBlock.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ class Block final {
115115
return reinterpret_cast<const std::byte *>(this) + sizeof(Block);
116116
}
117117

118-
template <typename T> T deref() const {
118+
template <typename T> const T &deref() const {
119119
return *reinterpret_cast<const T *>(data());
120120
}
121+
template <typename T> T &deref() { return *reinterpret_cast<T *>(data()); }
121122

122123
/// Invokes the constructor.
123124
void invokeCtor() {

clang/lib/AST/ByteCode/InterpFrame.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
#define LLVM_CLANG_AST_INTERP_INTERPFRAME_H
1515

1616
#include "Frame.h"
17-
#include "Program.h"
17+
#include "InterpBlock.h"
18+
#include "Pointer.h"
1819

1920
namespace clang {
2021
namespace interp {
@@ -93,7 +94,7 @@ class InterpFrame final : public Frame {
9394
auto Pt = Params.find(Offset);
9495
if (Pt == Params.end())
9596
return stackRef<T>(Offset);
96-
return Pointer(reinterpret_cast<Block *>(Pt->second.get())).deref<T>();
97+
return reinterpret_cast<const Block *>(Pt->second.get())->deref<T>();
9798
}
9899

99100
/// Mutates a local copy of a parameter.
@@ -151,7 +152,7 @@ class InterpFrame final : public Frame {
151152

152153
/// Returns an offset to a local.
153154
template <typename T> T &localRef(unsigned Offset) const {
154-
return getLocalPointer(Offset).deref<T>();
155+
return localBlock(Offset)->deref<T>();
155156
}
156157

157158
/// Returns a pointer to a local's block.

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -723,16 +723,6 @@ RenderDebugEnablingArgs(const ArgList &Args, ArgStringList &CmdArgs,
723723
}
724724
}
725725

726-
static bool checkDebugInfoOption(const Arg *A, const ArgList &Args,
727-
const Driver &D, const ToolChain &TC) {
728-
assert(A && "Expected non-nullptr argument.");
729-
if (TC.supportsDebugInfoOption(A))
730-
return true;
731-
D.Diag(diag::warn_drv_unsupported_debug_info_opt_for_target)
732-
<< A->getAsString(Args) << TC.getTripleString();
733-
return false;
734-
}
735-
736726
static void RenderDebugInfoCompressionArgs(const ArgList &Args,
737727
ArgStringList &CmdArgs,
738728
const Driver &D,
@@ -4370,27 +4360,6 @@ static void RenderDiagnosticsOptions(const Driver &D, const ArgList &Args,
43704360
Args.addLastArg(CmdArgs, options::OPT_warning_suppression_mappings_EQ);
43714361
}
43724362

4373-
DwarfFissionKind tools::getDebugFissionKind(const Driver &D,
4374-
const ArgList &Args, Arg *&Arg) {
4375-
Arg = Args.getLastArg(options::OPT_gsplit_dwarf, options::OPT_gsplit_dwarf_EQ,
4376-
options::OPT_gno_split_dwarf);
4377-
if (!Arg || Arg->getOption().matches(options::OPT_gno_split_dwarf))
4378-
return DwarfFissionKind::None;
4379-
4380-
if (Arg->getOption().matches(options::OPT_gsplit_dwarf))
4381-
return DwarfFissionKind::Split;
4382-
4383-
StringRef Value = Arg->getValue();
4384-
if (Value == "split")
4385-
return DwarfFissionKind::Split;
4386-
if (Value == "single")
4387-
return DwarfFissionKind::Single;
4388-
4389-
D.Diag(diag::err_drv_unsupported_option_argument)
4390-
<< Arg->getSpelling() << Arg->getValue();
4391-
return DwarfFissionKind::None;
4392-
}
4393-
43944363
static void renderDwarfFormat(const Driver &D, const llvm::Triple &T,
43954364
const ArgList &Args, ArgStringList &CmdArgs,
43964365
unsigned DwarfVersion) {

clang/lib/Driver/ToolChains/Clang.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,6 @@ class LLVM_LIBRARY_VISIBILITY LinkerWrapper final : public Tool {
192192
const char *LinkingOutput) const;
193193
};
194194

195-
enum class DwarfFissionKind { None, Split, Single };
196-
197-
DwarfFissionKind getDebugFissionKind(const Driver &D,
198-
const llvm::opt::ArgList &Args,
199-
llvm::opt::Arg *&Arg);
200-
201195
// Calculate the output path of the module file when compiling a module unit
202196
// with the `-fmodule-output` option or `-fmodule-output=` option specified.
203197
// The behavior is:

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,6 +2412,37 @@ unsigned tools::getDwarfVersion(const ToolChain &TC,
24122412
return DwarfVersion;
24132413
}
24142414

2415+
DwarfFissionKind tools::getDebugFissionKind(const Driver &D,
2416+
const ArgList &Args, Arg *&Arg) {
2417+
Arg = Args.getLastArg(options::OPT_gsplit_dwarf, options::OPT_gsplit_dwarf_EQ,
2418+
options::OPT_gno_split_dwarf);
2419+
if (!Arg || Arg->getOption().matches(options::OPT_gno_split_dwarf))
2420+
return DwarfFissionKind::None;
2421+
2422+
if (Arg->getOption().matches(options::OPT_gsplit_dwarf))
2423+
return DwarfFissionKind::Split;
2424+
2425+
StringRef Value = Arg->getValue();
2426+
if (Value == "split")
2427+
return DwarfFissionKind::Split;
2428+
if (Value == "single")
2429+
return DwarfFissionKind::Single;
2430+
2431+
D.Diag(diag::err_drv_unsupported_option_argument)
2432+
<< Arg->getSpelling() << Arg->getValue();
2433+
return DwarfFissionKind::None;
2434+
}
2435+
2436+
bool tools::checkDebugInfoOption(const Arg *A, const ArgList &Args,
2437+
const Driver &D, const ToolChain &TC) {
2438+
assert(A && "Expected non-nullptr argument.");
2439+
if (TC.supportsDebugInfoOption(A))
2440+
return true;
2441+
D.Diag(diag::warn_drv_unsupported_debug_info_opt_for_target)
2442+
<< A->getAsString(Args) << TC.getTripleString();
2443+
return false;
2444+
}
2445+
24152446
void tools::AddAssemblerKPIC(const ToolChain &ToolChain, const ArgList &Args,
24162447
ArgStringList &CmdArgs) {
24172448
llvm::Reloc::Model RelocationModel;

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ static bool shouldLoopVersion(const ArgList &Args) {
120120
return false;
121121
}
122122

123-
void Flang::addOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
123+
void Flang::addDebugOptions(const llvm::opt::ArgList &Args, const JobAction &JA,
124+
const InputInfo &Output, const InputInfo &Input,
125+
llvm::opt::ArgStringList &CmdArgs) const {
126+
const auto &TC = getToolChain();
127+
const Driver &D = TC.getDriver();
124128
Args.addAllArgs(CmdArgs,
125129
{options::OPT_module_dir, options::OPT_fdebug_module_writer,
126130
options::OPT_fintrinsic_modules_path, options::OPT_pedantic,
@@ -138,20 +142,60 @@ void Flang::addOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
138142
}
139143

140144
llvm::codegenoptions::DebugInfoKind DebugInfoKind;
145+
bool hasDwarfNArg = getDwarfNArg(Args) != nullptr;
141146
if (Args.hasArg(options::OPT_gN_Group)) {
142147
Arg *gNArg = Args.getLastArg(options::OPT_gN_Group);
143148
DebugInfoKind = debugLevelToInfoKind(*gNArg);
144-
} else if (Args.hasArg(options::OPT_g_Group)) {
149+
} else if (Args.hasArg(options::OPT_g_Flag) || hasDwarfNArg) {
145150
DebugInfoKind = llvm::codegenoptions::FullDebugInfo;
146151
} else {
147152
DebugInfoKind = llvm::codegenoptions::NoDebugInfo;
148153
}
149154
addDebugInfoKind(CmdArgs, DebugInfoKind);
150-
if (getDwarfNArg(Args)) {
155+
if (hasDwarfNArg) {
151156
const unsigned DwarfVersion = getDwarfVersion(getToolChain(), Args);
152157
CmdArgs.push_back(
153158
Args.MakeArgString("-dwarf-version=" + Twine(DwarfVersion)));
154159
}
160+
if (Args.hasArg(options::OPT_gsplit_dwarf) ||
161+
Args.hasArg(options::OPT_gsplit_dwarf_EQ)) {
162+
// FIXME: -gsplit-dwarf on AIX is currently unimplemented.
163+
if (TC.getTriple().isOSAIX()) {
164+
D.Diag(diag::err_drv_unsupported_opt_for_target)
165+
<< Args.getLastArg(options::OPT_gsplit_dwarf)->getSpelling()
166+
<< TC.getTriple().str();
167+
return;
168+
}
169+
if (DebugInfoKind == llvm::codegenoptions::NoDebugInfo)
170+
return;
171+
172+
Arg *SplitDWARFArg;
173+
DwarfFissionKind DwarfFission = getDebugFissionKind(D, Args, SplitDWARFArg);
174+
175+
if (DwarfFission == DwarfFissionKind::None ||
176+
!checkDebugInfoOption(SplitDWARFArg, Args, D, TC))
177+
return;
178+
179+
if (!TC.getTriple().isOSBinFormatELF() &&
180+
!TC.getTriple().isOSBinFormatWasm() &&
181+
!TC.getTriple().isOSBinFormatCOFF()) {
182+
D.Diag(diag::warn_drv_unsupported_debug_info_opt_for_target)
183+
<< SplitDWARFArg->getSpelling() << TC.getTriple().str();
184+
return;
185+
}
186+
187+
if (!isa<AssembleJobAction>(JA) && !isa<CompileJobAction>(JA) &&
188+
isa<BackendJobAction>(JA))
189+
return;
190+
191+
const char *SplitDWARFOut = SplitDebugName(JA, Args, Input, Output);
192+
CmdArgs.push_back("-split-dwarf-file");
193+
CmdArgs.push_back(SplitDWARFOut);
194+
if (DwarfFission == DwarfFissionKind::Split) {
195+
CmdArgs.push_back("-split-dwarf-output");
196+
CmdArgs.push_back(SplitDWARFOut);
197+
}
198+
}
155199
}
156200

157201
void Flang::addCodegenOptions(const ArgList &Args,
@@ -953,8 +997,8 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
953997
if (willEmitRemarks(Args))
954998
renderRemarksOptions(Args, CmdArgs, Input);
955999

956-
// Add other compile options
957-
addOtherOptions(Args, CmdArgs);
1000+
// Add debug compile options
1001+
addDebugOptions(Args, JA, Output, Input, CmdArgs);
9581002

9591003
// Disable all warnings
9601004
// TODO: Handle interactions between -w, -pedantic, -Wall, -WOption

0 commit comments

Comments
 (0)