Skip to content

Commit b59526a

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:410f130bb99b into amd-gfx:c44543097cba
Local branch amd-gfx c445430 Merged main:57dd23bc0a2f into amd-gfx:638d807e8d80 Remote branch main 410f130 [clang][Interp] Fix classify for glvalues of function type (llvm#72269)
2 parents c445430 + 410f130 commit b59526a

File tree

89 files changed

+2529
-1466
lines changed

Some content is hidden

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

89 files changed

+2529
-1466
lines changed

clang/include/clang/Basic/riscv_vector.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ multiclass RVVVLEFFBuiltin<list<string> types> {
6969
Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
7070
IntrinsicTypes = {ResultType, Ops[3]->getType()};
7171
}
72-
Ops[1] = Builder.CreateBitCast(Ops[1], ResultType->getPointerTo());
7372
Value *NewVL = Ops[2];
7473
Ops.erase(Ops.begin() + 2);
7574
llvm::Function *F = CGM.getIntrinsic(ID, IntrinsicTypes);
@@ -150,7 +149,6 @@ let HasMaskedOffOperand = false,
150149
// Builtin: (ptr, value, vl). Intrinsic: (value, ptr, vl)
151150
std::swap(Ops[0], Ops[1]);
152151
}
153-
Ops[1] = Builder.CreateBitCast(Ops[1], Ops[0]->getType()->getPointerTo());
154152
if (IsMasked)
155153
IntrinsicTypes = {Ops[0]->getType(), Ops[3]->getType()};
156154
else
@@ -189,7 +187,6 @@ multiclass RVVVSSEBuiltin<list<string> types> {
189187
// Builtin: (ptr, stride, value, vl). Intrinsic: (value, ptr, stride, vl)
190188
std::rotate(Ops.begin(), Ops.begin() + 2, Ops.begin() + 3);
191189
}
192-
Ops[1] = Builder.CreateBitCast(Ops[1], Ops[0]->getType()->getPointerTo());
193190
if (IsMasked)
194191
IntrinsicTypes = {Ops[0]->getType(), Ops[4]->getType()};
195192
else
@@ -215,7 +212,6 @@ multiclass RVVIndexedStore<string op> {
215212
// Builtin: (ptr, index, value, vl). Intrinsic: (value, ptr, index, vl)
216213
std::rotate(Ops.begin(), Ops.begin() + 2, Ops.begin() + 3);
217214
}
218-
Ops[1] = Builder.CreateBitCast(Ops[1], Ops[0]->getType()->getPointerTo());
219215
if (IsMasked)
220216
IntrinsicTypes = {Ops[0]->getType(), Ops[2]->getType(), Ops[4]->getType()};
221217
else

clang/lib/AST/Interp/ByteCodeExprGen.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,13 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
129129

130130
/// Classifies a type.
131131
std::optional<PrimType> classify(const Expr *E) const {
132-
return E->isGLValue() ? PT_Ptr : classify(E->getType());
132+
if (E->isGLValue()) {
133+
if (E->getType()->isFunctionType())
134+
return PT_FnPtr;
135+
return PT_Ptr;
136+
}
137+
138+
return classify(E->getType());
133139
}
134140
std::optional<PrimType> classify(QualType Ty) const {
135141
return Ctx.classify(Ty);

clang/lib/Headers/llvm_libc_wrappers/ctype.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,19 @@
1313
#error "This file is for GPU offloading compilation only"
1414
#endif
1515

16+
// The GNU headers like to define 'toupper' and 'tolower' redundantly. This is
17+
// necessary to prevent it from doing that and remapping our implementation.
18+
#if (defined(__NVPTX__) || defined(__AMDGPU__)) && defined(__GLIBC__)
19+
#pragma push_macro("__USE_EXTERN_INLINES")
20+
#undef __USE_EXTERN_INLINES
21+
#endif
22+
1623
#include_next <ctype.h>
1724

25+
#if (defined(__NVPTX__) || defined(__AMDGPU__)) && defined(__GLIBC__)
26+
#pragma pop_macro("__USE_EXTERN_INLINES")
27+
#endif
28+
1829
#if __has_include(<llvm-libc-decls/ctype.h>)
1930

2031
#if defined(__HIP__) || defined(__CUDA__)

lld/ELF/InputFiles.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ template <class ELFT> void SharedFile::parse() {
15461546
SharedSymbol{*this, name, sym.getBinding(), sym.st_other,
15471547
sym.getType(), sym.st_value, sym.st_size, alignment});
15481548
if (s->file == this)
1549-
s->verdefIndex = ver;
1549+
s->versionId = ver;
15501550
}
15511551

15521552
// Also add the symbol with the versioned name to handle undefined symbols
@@ -1563,7 +1563,7 @@ template <class ELFT> void SharedFile::parse() {
15631563
SharedSymbol{*this, saver().save(name), sym.getBinding(), sym.st_other,
15641564
sym.getType(), sym.st_value, sym.st_size, alignment});
15651565
if (s->file == this)
1566-
s->verdefIndex = idx;
1566+
s->versionId = idx;
15671567
}
15681568
}
15691569

lld/ELF/Relocations.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ static void replaceWithDefined(Symbol &sym, SectionBase &sec, uint64_t value,
309309
size, &sec)
310310
.overwrite(sym);
311311

312-
sym.verdefIndex = old.verdefIndex;
313312
sym.exportDynamic = true;
314313
sym.isUsedInRegularObj = true;
315314
// A copy relocated alias may need a GOT entry.

lld/ELF/SymbolTable.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ Symbol *SymbolTable::insert(StringRef name) {
9292
memset(sym, 0, sizeof(Symbol));
9393
sym->setName(name);
9494
sym->partition = 1;
95-
sym->verdefIndex = -1;
9695
sym->versionId = VER_NDX_GLOBAL;
9796
if (pos != StringRef::npos)
9897
sym->hasVersionSuffix = true;
@@ -235,10 +234,9 @@ bool SymbolTable::assignExactVersion(SymbolVersion ver, uint16_t versionId,
235234
sym->getName().contains('@'))
236235
continue;
237236

238-
// If the version has not been assigned, verdefIndex is -1. Use an arbitrary
239-
// number (0) to indicate the version has been assigned.
240-
if (sym->verdefIndex == uint16_t(-1)) {
241-
sym->verdefIndex = 0;
237+
// If the version has not been assigned, assign versionId to the symbol.
238+
if (!sym->versionScriptAssigned) {
239+
sym->versionScriptAssigned = true;
242240
sym->versionId = versionId;
243241
}
244242
if (sym->versionId == versionId)
@@ -256,8 +254,8 @@ void SymbolTable::assignWildcardVersion(SymbolVersion ver, uint16_t versionId,
256254
// so we set a version to a symbol only if no version has been assigned
257255
// to the symbol. This behavior is compatible with GNU.
258256
for (Symbol *sym : findAllByVersion(ver, includeNonDefault))
259-
if (sym->verdefIndex == uint16_t(-1)) {
260-
sym->verdefIndex = 0;
257+
if (!sym->versionScriptAssigned) {
258+
sym->versionScriptAssigned = true;
261259
sym->versionId = versionId;
262260
}
263261
}

lld/ELF/Symbols.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,12 @@ class Symbol {
313313
uint32_t auxIdx;
314314
uint32_t dynsymIndex;
315315

316-
// This field is a index to the symbol's version definition.
317-
uint16_t verdefIndex;
318-
319-
// Version definition index.
316+
// For a Defined symbol, this represents the Verdef index (VER_NDX_LOCAL,
317+
// VER_NDX_GLOBAL, or a named version). For a SharedSymbol, this represents
318+
// the Verdef index within the input DSO, which will be converted to a Verneed
319+
// index in the output.
320320
uint16_t versionId;
321+
uint8_t versionScriptAssigned : 1;
321322

322323
void setFlags(uint16_t bits) {
323324
flags.fetch_or(bits, std::memory_order_relaxed);
@@ -357,7 +358,6 @@ class Defined : public Symbol {
357358
}
358359
void overwrite(Symbol &sym) const {
359360
Symbol::overwrite(sym, DefinedKind);
360-
sym.verdefIndex = -1;
361361
auto &s = static_cast<Defined &>(sym);
362362
s.value = value;
363363
s.size = size;

lld/ELF/SyntheticSections.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3140,10 +3140,8 @@ bool VersionTableSection::isNeeded() const {
31403140

31413141
void elf::addVerneed(Symbol *ss) {
31423142
auto &file = cast<SharedFile>(*ss->file);
3143-
if (ss->verdefIndex == VER_NDX_GLOBAL) {
3144-
ss->versionId = VER_NDX_GLOBAL;
3143+
if (ss->versionId == VER_NDX_GLOBAL)
31453144
return;
3146-
}
31473145

31483146
if (file.vernauxs.empty())
31493147
file.vernauxs.resize(file.verdefs.size());
@@ -3152,10 +3150,10 @@ void elf::addVerneed(Symbol *ss) {
31523150
// already allocated one. The verdef identifiers cover the range
31533151
// [1..getVerDefNum()]; this causes the vernaux identifiers to start from
31543152
// getVerDefNum()+1.
3155-
if (file.vernauxs[ss->verdefIndex] == 0)
3156-
file.vernauxs[ss->verdefIndex] = ++SharedFile::vernauxNum + getVerDefNum();
3153+
if (file.vernauxs[ss->versionId] == 0)
3154+
file.vernauxs[ss->versionId] = ++SharedFile::vernauxNum + getVerDefNum();
31573155

3158-
ss->versionId = file.vernauxs[ss->verdefIndex];
3156+
ss->versionId = file.vernauxs[ss->versionId];
31593157
}
31603158

31613159
template <class ELFT>

lldb/include/lldb/API/SBFormat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class LLDB_API SBFormat {
5252

5353
protected:
5454
friend class SBFrame;
55+
friend class SBThread;
5556

5657
/// \return
5758
/// The underlying shared pointer storage for this object.

lldb/include/lldb/API/SBThread.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,21 @@ class LLDB_API SBThread {
200200

201201
bool GetDescription(lldb::SBStream &description, bool stop_format) const;
202202

203+
/// Similar to \a GetDescription() but the format of the description can be
204+
/// configured via the \p format parameter. See
205+
/// https://lldb.llvm.org/use/formatting.html for more information on format
206+
/// strings.
207+
///
208+
/// \param[in] format
209+
/// The format to use for generating the description.
210+
///
211+
/// \param[out] output
212+
/// The stream where the description will be written to.
213+
///
214+
/// \return
215+
/// An error object with an error message in case of failures.
216+
SBError GetDescriptionWithFormat(const SBFormat &format, SBStream &output);
217+
203218
bool GetStatus(lldb::SBStream &status) const;
204219

205220
SBThread GetExtendedBacktraceThread(const char *type);

lldb/include/lldb/Target/Thread.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,23 @@ class Thread : public std::enable_shared_from_this<Thread>,
490490
void DumpTraceInstructions(Stream &s, size_t count,
491491
size_t start_position = 0) const;
492492

493+
/// Print a description of this thread using the provided thread format.
494+
///
495+
/// \param[out] strm
496+
/// The Stream to print the description to.
497+
///
498+
/// \param[in] frame_idx
499+
/// If not \b LLDB_INVALID_FRAME_ID, then use this frame index as context to
500+
/// generate the description.
501+
///
502+
/// \param[in] format
503+
/// The input format.
504+
///
505+
/// \return
506+
/// \b true if and only if dumping with the given \p format worked.
507+
bool DumpUsingFormat(Stream &strm, uint32_t frame_idx,
508+
const FormatEntity::Entry *format);
509+
493510
// If stop_format is true, this will be the form used when we print stop
494511
// info. If false, it will be the form we use for thread list and co.
495512
void DumpUsingSettingsFormat(Stream &strm, uint32_t frame_idx,

lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ def request_launch(
733733
enableSyntheticChildDebugging=False,
734734
commandEscapePrefix="`",
735735
customFrameFormat=None,
736+
customThreadFormat=None,
736737
):
737738
args_dict = {"program": program}
738739
if args:
@@ -776,6 +777,8 @@ def request_launch(
776777
args_dict["postRunCommands"] = postRunCommands
777778
if customFrameFormat:
778779
args_dict["customFrameFormat"] = customFrameFormat
780+
if customThreadFormat:
781+
args_dict["customThreadFormat"] = customThreadFormat
779782

780783
args_dict["enableAutoVariableSummaries"] = enableAutoVariableSummaries
781784
args_dict["enableSyntheticChildDebugging"] = enableSyntheticChildDebugging

lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ def launch(
353353
enableSyntheticChildDebugging=False,
354354
commandEscapePrefix="`",
355355
customFrameFormat=None,
356+
customThreadFormat=None,
356357
):
357358
"""Sending launch request to dap"""
358359

@@ -393,6 +394,7 @@ def cleanup():
393394
enableSyntheticChildDebugging=enableSyntheticChildDebugging,
394395
commandEscapePrefix=commandEscapePrefix,
395396
customFrameFormat=customFrameFormat,
397+
customThreadFormat=customThreadFormat,
396398
)
397399

398400
if expectFailure:
@@ -431,6 +433,7 @@ def build_and_launch(
431433
enableSyntheticChildDebugging=False,
432434
commandEscapePrefix="`",
433435
customFrameFormat=None,
436+
customThreadFormat=None,
434437
):
435438
"""Build the default Makefile target, create the DAP debug adaptor,
436439
and launch the process.
@@ -463,4 +466,5 @@ def build_and_launch(
463466
enableSyntheticChildDebugging=enableSyntheticChildDebugging,
464467
commandEscapePrefix=commandEscapePrefix,
465468
customFrameFormat=customFrameFormat,
469+
customThreadFormat=customThreadFormat,
466470
)

lldb/source/API/SBThread.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "lldb/API/SBDebugger.h"
1313
#include "lldb/API/SBEvent.h"
1414
#include "lldb/API/SBFileSpec.h"
15+
#include "lldb/API/SBFormat.h"
1516
#include "lldb/API/SBFrame.h"
1617
#include "lldb/API/SBProcess.h"
1718
#include "lldb/API/SBStream.h"
@@ -1223,17 +1224,41 @@ bool SBThread::GetDescription(SBStream &description, bool stop_format) const {
12231224
ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
12241225

12251226
if (exe_ctx.HasThreadScope()) {
1226-
exe_ctx.GetThreadPtr()->DumpUsingSettingsFormat(strm,
1227-
LLDB_INVALID_THREAD_ID,
1228-
stop_format);
1229-
// strm.Printf("SBThread: tid = 0x%4.4" PRIx64,
1230-
// exe_ctx.GetThreadPtr()->GetID());
1227+
exe_ctx.GetThreadPtr()->DumpUsingSettingsFormat(
1228+
strm, LLDB_INVALID_THREAD_ID, stop_format);
12311229
} else
12321230
strm.PutCString("No value");
12331231

12341232
return true;
12351233
}
12361234

1235+
SBError SBThread::GetDescriptionWithFormat(const SBFormat &format,
1236+
SBStream &output) {
1237+
Stream &strm = output.ref();
1238+
1239+
SBError error;
1240+
if (!format) {
1241+
error.SetErrorString("The provided SBFormat object is invalid");
1242+
return error;
1243+
}
1244+
1245+
std::unique_lock<std::recursive_mutex> lock;
1246+
ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1247+
1248+
if (exe_ctx.HasThreadScope()) {
1249+
if (exe_ctx.GetThreadPtr()->DumpUsingFormat(
1250+
strm, LLDB_INVALID_THREAD_ID, format.GetFormatEntrySP().get())) {
1251+
return error;
1252+
}
1253+
}
1254+
1255+
error.SetErrorStringWithFormat(
1256+
"It was not possible to generate a thread description with the given "
1257+
"format string '%s'",
1258+
format.GetFormatEntrySP()->string.c_str());
1259+
return error;
1260+
}
1261+
12371262
SBThread SBThread::GetExtendedBacktraceThread(const char *type) {
12381263
LLDB_INSTRUMENT_VA(this, type);
12391264

lldb/source/Target/Thread.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,12 +1589,12 @@ Status Thread::JumpToLine(const FileSpec &file, uint32_t line,
15891589
return Status();
15901590
}
15911591

1592-
void Thread::DumpUsingSettingsFormat(Stream &strm, uint32_t frame_idx,
1593-
bool stop_format) {
1592+
bool Thread::DumpUsingFormat(Stream &strm, uint32_t frame_idx,
1593+
const FormatEntity::Entry *format) {
15941594
ExecutionContext exe_ctx(shared_from_this());
15951595
Process *process = exe_ctx.GetProcessPtr();
1596-
if (process == nullptr)
1597-
return;
1596+
if (!process || !format)
1597+
return false;
15981598

15991599
StackFrameSP frame_sp;
16001600
SymbolContext frame_sc;
@@ -1606,6 +1606,14 @@ void Thread::DumpUsingSettingsFormat(Stream &strm, uint32_t frame_idx,
16061606
}
16071607
}
16081608

1609+
return FormatEntity::Format(*format, strm, frame_sp ? &frame_sc : nullptr,
1610+
&exe_ctx, nullptr, nullptr, false, false);
1611+
}
1612+
1613+
void Thread::DumpUsingSettingsFormat(Stream &strm, uint32_t frame_idx,
1614+
bool stop_format) {
1615+
ExecutionContext exe_ctx(shared_from_this());
1616+
16091617
const FormatEntity::Entry *thread_format;
16101618
if (stop_format)
16111619
thread_format = exe_ctx.GetTargetRef().GetDebugger().GetThreadStopFormat();
@@ -1614,8 +1622,7 @@ void Thread::DumpUsingSettingsFormat(Stream &strm, uint32_t frame_idx,
16141622

16151623
assert(thread_format);
16161624

1617-
FormatEntity::Format(*thread_format, strm, frame_sp ? &frame_sc : nullptr,
1618-
&exe_ctx, nullptr, nullptr, false, false);
1625+
DumpUsingFormat(strm, frame_idx, thread_format);
16191626
}
16201627

16211628
void Thread::SettingsInitialize() {}

0 commit comments

Comments
 (0)