Skip to content

Commit cee3bff

Browse files
Merge branch 'llvm:main' into cfi-show
2 parents eb400ed + 96d5567 commit cee3bff

File tree

532 files changed

+20604
-15691
lines changed

Some content is hidden

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

532 files changed

+20604
-15691
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ Bug Fixes to Attribute Support
324324
is skipped, such as error recovery and code completion. (#GH153551)
325325
- Using ``[[gnu::cleanup(some_func)]]`` where some_func is annotated with
326326
``[[gnu::error("some error")]]`` now correctly triggers an error. (#GH146520)
327+
- Fix a crash when the function name is empty in the `swift_name` attribute. (#GH157075)
327328

328329
Bug Fixes to C++ Support
329330
^^^^^^^^^^^^^^^^^^^^^^^^
@@ -349,6 +350,8 @@ Bug Fixes to C++ Support
349350
authentication enabled. (#GH152601)
350351
- Fix the check for narrowing int-to-float conversions, so that they are detected in
351352
cases where converting the float back to an integer is undefined behaviour (#GH157067).
353+
- Fix an assertion failure when a ``constexpr`` variable is only referenced through
354+
``__builtin_addressof``, and related issues with builtin arguments. (#GH154034)
352355

353356
Bug Fixes to AST Handling
354357
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/ABI.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ enum CXXCtorType {
2727
Ctor_Comdat, ///< The COMDAT used for ctors
2828
Ctor_CopyingClosure, ///< Copying closure variant of a ctor
2929
Ctor_DefaultClosure, ///< Default closure variant of a ctor
30+
Ctor_Unified, ///< GCC-style unified dtor
3031
};
3132

3233
/// C++ destructor types.
3334
enum CXXDtorType {
34-
Dtor_Deleting, ///< Deleting dtor
35-
Dtor_Complete, ///< Complete object dtor
36-
Dtor_Base, ///< Base object dtor
37-
Dtor_Comdat ///< The COMDAT used for dtors
35+
Dtor_Deleting, ///< Deleting dtor
36+
Dtor_Complete, ///< Complete object dtor
37+
Dtor_Base, ///< Base object dtor
38+
Dtor_Comdat, ///< The COMDAT used for dtors
39+
Dtor_Unified, ///< GCC-style unified dtor
3840
};
3941

4042
} // end namespace clang

clang/include/clang/Basic/Attr.td

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,9 +1454,13 @@ def ConstInit : InheritableAttr {
14541454

14551455
def Constructor : InheritableAttr {
14561456
let Spellings = [GCC<"constructor">];
1457-
let Args = [DefaultIntArgument<"Priority", 65535>];
1457+
let Args = [ExprArgument<"Priority", 1>];
14581458
let Subjects = SubjectList<[Function]>;
1459+
let TemplateDependent = 1;
14591460
let Documentation = [CtorDtorDocs];
1461+
let AdditionalMembers = [{
1462+
static constexpr unsigned DefaultPriority = 65535;
1463+
}];
14601464
}
14611465

14621466
def CPUSpecific : InheritableAttr {
@@ -1795,9 +1799,13 @@ def Deprecated : InheritableAttr {
17951799

17961800
def Destructor : InheritableAttr {
17971801
let Spellings = [GCC<"destructor">];
1798-
let Args = [DefaultIntArgument<"Priority", 65535>];
1802+
let Args = [ExprArgument<"Priority", 1>];
17991803
let Subjects = SubjectList<[Function]>;
1804+
let TemplateDependent = 1;
18001805
let Documentation = [CtorDtorDocs];
1806+
let AdditionalMembers = [{
1807+
static constexpr unsigned int DefaultPriority = 65535;
1808+
}];
18011809
}
18021810

18031811
def EmptyBases : InheritableAttr, TargetSpecificAttr<TargetMicrosoftRecordLayout> {

clang/include/clang/Basic/DebugOptions.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ DEBUGOPT(DebugNameTable, 2, 0, Compatible)
125125
/// Whether to use DWARF base address specifiers in .debug_ranges.
126126
DEBUGOPT(DebugRangesBaseAddress, 1, 0, Compatible)
127127

128+
/// Whether to add linkage names to constructor/destructor declarations.
129+
/// This is an escape hatch for cases where attaching the additional linkage
130+
/// names would increase debug-info size (particularly the .debug_str section)
131+
/// too much.
132+
DEBUGOPT(DebugStructorDeclLinkageNames, 1, 0, Benign)
133+
128134
/// Whether to embed source in DWARF debug line section.
129135
DEBUGOPT(EmbedSource, 1, 0, Compatible)
130136

clang/include/clang/Driver/Options.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4789,6 +4789,18 @@ def gembed_source : Flag<["-"], "gembed-source">, Group<g_flags_Group>,
47894789
def gno_embed_source : Flag<["-"], "gno-embed-source">, Group<g_flags_Group>,
47904790
Flags<[NoXarchOption]>,
47914791
HelpText<"Restore the default behavior of not embedding source text in DWARF debug sections">;
4792+
defm structor_decl_linkage_names
4793+
: BoolGOption<"structor-decl-linkage-names",
4794+
CodeGenOpts<"DebugStructorDeclLinkageNames">, DefaultTrue,
4795+
NegFlag<SetFalse>,
4796+
PosFlag<SetTrue, [], [],
4797+
"Attach linkage names to C++ constructor/destructor "
4798+
"declarations in DWARF."
4799+
"Implies -g.">,
4800+
BothFlags<[], [ClangOption, CLOption, CC1Option]>>,
4801+
DocBrief<[{On some ABIs (e.g., Itanium), constructors and destructors may have multiple variants. Historically, when generating DWARF, Clang did not attach ``DW_AT_linkage_name``s to structor DIEs because there were multiple possible manglings (depending on the structor variant) that could be used. With ``-gstructor-decl-linkage-names``, for ABIs with structor variants, we attach a "unified" mangled name to structor declarations DIEs which debuggers can use to look up all the definitions for a structor declaration. E.g., a "unified" mangled name ``_ZN3FooC4Ev`` may have multiple definitions associated with it such as ``_ZN3FooC1Ev`` and ``_ZN3FooC2Ev``.
4802+
4803+
Enabling this flag results in a better interactive debugging experience (both GDB and LLDB have support for understanding these "unified" linkage names). However, it comes with a significant increase in debug-info size (particularly the `.debug_str` section). As an escape hatch, users can disable this feature using ``-gno-structor-decl-linkage-names``.}]>;
47924804
defm key_instructions : BoolGOption<"key-instructions",
47934805
CodeGenOpts<"DebugKeyInstructions">, DefaultFalse,
47944806
NegFlag<SetFalse>, PosFlag<SetTrue, [], [],

clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "llvm/Support/BuryPointer.h"
2727
#include "llvm/Support/FileSystem.h"
2828
#include "llvm/Support/VirtualFileSystem.h"
29+
#include "llvm/Support/VirtualOutputBackend.h"
2930
#include <cassert>
3031
#include <list>
3132
#include <memory>
@@ -97,6 +98,9 @@ class CompilerInstance : public ModuleLoader {
9798
/// The file manager.
9899
IntrusiveRefCntPtr<FileManager> FileMgr;
99100

101+
/// The output manager.
102+
IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutputMgr;
103+
100104
/// The source manager.
101105
IntrusiveRefCntPtr<SourceManager> SourceMgr;
102106

@@ -180,22 +184,8 @@ class CompilerInstance : public ModuleLoader {
180184
/// The stream for verbose output.
181185
raw_ostream *VerboseOutputStream = &llvm::errs();
182186

183-
/// Holds information about the output file.
184-
///
185-
/// If TempFilename is not empty we must rename it to Filename at the end.
186-
/// TempFilename may be empty and Filename non-empty if creating the temporary
187-
/// failed.
188-
struct OutputFile {
189-
std::string Filename;
190-
std::optional<llvm::sys::fs::TempFile> File;
191-
192-
OutputFile(std::string filename,
193-
std::optional<llvm::sys::fs::TempFile> file)
194-
: Filename(std::move(filename)), File(std::move(file)) {}
195-
};
196-
197187
/// The list of active output files.
198-
std::list<OutputFile> OutputFiles;
188+
std::list<llvm::vfs::OutputFile> OutputFiles;
199189

200190
/// Force an output buffer.
201191
std::unique_ptr<llvm::raw_pwrite_stream> OutputStream;
@@ -448,6 +438,22 @@ class CompilerInstance : public ModuleLoader {
448438
/// Replace the current file manager and virtual file system.
449439
void setFileManager(IntrusiveRefCntPtr<FileManager> Value);
450440

441+
/// @}
442+
/// @name Output Manager
443+
/// @{
444+
445+
/// Set the output manager.
446+
void
447+
setOutputManager(IntrusiveRefCntPtr<llvm::vfs::OutputBackend> NewOutputs);
448+
449+
/// Create an output manager.
450+
void createOutputManager();
451+
452+
bool hasOutputManager() const { return bool(OutputMgr); }
453+
454+
llvm::vfs::OutputBackend &getOutputManager();
455+
llvm::vfs::OutputBackend &getOrCreateOutputManager();
456+
451457
/// @}
452458
/// @name Source Manager
453459
/// @{

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6026,6 +6026,8 @@ void CXXNameMangler::mangleCXXCtorType(CXXCtorType T,
60266026
// ::= CI2 <type> # base inheriting constructor
60276027
//
60286028
// In addition, C5 is a comdat name with C1 and C2 in it.
6029+
// C4 represents a ctor declaration and is used by debuggers to look up
6030+
// the various ctor variants.
60296031
Out << 'C';
60306032
if (InheritedFrom)
60316033
Out << 'I';
@@ -6036,6 +6038,9 @@ void CXXNameMangler::mangleCXXCtorType(CXXCtorType T,
60366038
case Ctor_Base:
60376039
Out << '2';
60386040
break;
6041+
case Ctor_Unified:
6042+
Out << '4';
6043+
break;
60396044
case Ctor_Comdat:
60406045
Out << '5';
60416046
break;
@@ -6053,6 +6058,8 @@ void CXXNameMangler::mangleCXXDtorType(CXXDtorType T) {
60536058
// ::= D2 # base object destructor
60546059
//
60556060
// In addition, D5 is a comdat name with D1, D2 and, if virtual, D0 in it.
6061+
// D4 represents a dtor declaration and is used by debuggers to look up
6062+
// the various dtor variants.
60566063
switch (T) {
60576064
case Dtor_Deleting:
60586065
Out << "D0";
@@ -6063,6 +6070,9 @@ void CXXNameMangler::mangleCXXDtorType(CXXDtorType T) {
60636070
case Dtor_Base:
60646071
Out << "D2";
60656072
break;
6073+
case Dtor_Unified:
6074+
Out << "D4";
6075+
break;
60666076
case Dtor_Comdat:
60676077
Out << "D5";
60686078
break;

clang/lib/AST/Mangle.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,37 @@ bool MangleContext::shouldMangleDeclName(const NamedDecl *D) {
152152
return shouldMangleCXXName(D);
153153
}
154154

155+
static llvm::StringRef g_lldb_func_call_label_prefix = "$__lldb_func:";
156+
157+
/// Given an LLDB function call label, this function prints the label
158+
/// into \c Out, together with the structor type of \c GD (if the
159+
/// decl is a constructor/destructor). LLDB knows how to handle mangled
160+
/// names with this encoding.
161+
///
162+
/// Example input label:
163+
/// $__lldb_func::123:456:~Foo
164+
///
165+
/// Example output:
166+
/// $__lldb_func:D1:123:456:~Foo
167+
///
168+
static void emitLLDBAsmLabel(llvm::StringRef label, GlobalDecl GD,
169+
llvm::raw_ostream &Out) {
170+
assert(label.starts_with(g_lldb_func_call_label_prefix));
171+
172+
Out << g_lldb_func_call_label_prefix;
173+
174+
if (auto *Ctor = llvm::dyn_cast<clang::CXXConstructorDecl>(GD.getDecl())) {
175+
Out << "C";
176+
if (Ctor->getInheritedConstructor().getConstructor())
177+
Out << "I";
178+
Out << GD.getCtorType();
179+
} else if (llvm::isa<clang::CXXDestructorDecl>(GD.getDecl())) {
180+
Out << "D" << GD.getDtorType();
181+
}
182+
183+
Out << label.substr(g_lldb_func_call_label_prefix.size());
184+
}
185+
155186
void MangleContext::mangleName(GlobalDecl GD, raw_ostream &Out) {
156187
const ASTContext &ASTContext = getASTContext();
157188
const NamedDecl *D = cast<NamedDecl>(GD.getDecl());
@@ -185,7 +216,11 @@ void MangleContext::mangleName(GlobalDecl GD, raw_ostream &Out) {
185216
if (!UserLabelPrefix.empty())
186217
Out << '\01'; // LLVM IR Marker for __asm("foo")
187218

188-
Out << ALA->getLabel();
219+
if (ALA->getLabel().starts_with(g_lldb_func_call_label_prefix))
220+
emitLLDBAsmLabel(ALA->getLabel(), GD, Out);
221+
else
222+
Out << ALA->getLabel();
223+
189224
return;
190225
}
191226

clang/lib/AST/MicrosoftMangle.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,8 @@ void MicrosoftCXXNameMangler::mangleCXXDtorType(CXXDtorType T) {
14961496
// it.
14971497
case Dtor_Comdat:
14981498
llvm_unreachable("not expecting a COMDAT");
1499+
case Dtor_Unified:
1500+
llvm_unreachable("not expecting a unified dtor type");
14991501
}
15001502
llvm_unreachable("Unsupported dtor type?");
15011503
}

clang/lib/CodeGen/CGClass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,8 @@ void CodeGenFunction::EmitDestructorBody(FunctionArgList &Args) {
14811481
// we'd introduce *two* handler blocks. In the Microsoft ABI, we
14821482
// always delegate because we might not have a definition in this TU.
14831483
switch (DtorType) {
1484+
case Dtor_Unified:
1485+
llvm_unreachable("not expecting a unified dtor");
14841486
case Dtor_Comdat: llvm_unreachable("not expecting a COMDAT");
14851487
case Dtor_Deleting: llvm_unreachable("already handled deleting case");
14861488

0 commit comments

Comments
 (0)