Skip to content

Commit 99e48c6

Browse files
committed
merge main into amd-staging
Reverts: more Sema changes 9e1f1cf [Clang][Sema] Handle class member access expressions with valid nested-name-specifiers that become invalid after lookup (llvm#98167) Change-Id: I80aa10cf856f4854120e2eb7446335403b163b77
2 parents 97572c0 + 015526b commit 99e48c6

File tree

174 files changed

+4885
-1228
lines changed

Some content is hidden

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

174 files changed

+4885
-1228
lines changed

bolt/include/bolt/Core/DebugData.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,6 @@ class DebugRangesSectionWriter {
233233

234234
std::mutex WriterMutex;
235235

236-
/// Current offset in the section (updated as new entries are written).
237-
/// Starts with 16 since the first 16 bytes are reserved for an empty range.
238-
uint32_t SectionOffset{0};
239-
240236
/// Offset of an empty address ranges list.
241237
static constexpr uint64_t EmptyRangesOffset{0};
242238

bolt/lib/Core/DebugData.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ DebugRangesSectionWriter::DebugRangesSectionWriter() {
138138
RangesStream = std::make_unique<raw_svector_ostream>(*RangesBuffer);
139139

140140
// Add an empty range as the first entry;
141-
SectionOffset +=
142-
writeAddressRanges(*RangesStream.get(), DebugAddressRangesVector{});
141+
writeAddressRanges(*RangesStream.get(), DebugAddressRangesVector{});
143142
Kind = RangesWriterKind::DebugRangesWriter;
144143
}
145144

@@ -166,21 +165,20 @@ uint64_t DebugRangesSectionWriter::addRanges(DebugAddressRangesVector &Ranges) {
166165
// Reading the SectionOffset and updating it should be atomic to guarantee
167166
// unique and correct offsets in patches.
168167
std::lock_guard<std::mutex> Lock(WriterMutex);
169-
const uint32_t EntryOffset = SectionOffset;
170-
SectionOffset += writeAddressRanges(*RangesStream.get(), Ranges);
168+
const uint32_t EntryOffset = RangesBuffer->size();
169+
writeAddressRanges(*RangesStream.get(), Ranges);
171170

172171
return EntryOffset;
173172
}
174173

175174
uint64_t DebugRangesSectionWriter::getSectionOffset() {
176175
std::lock_guard<std::mutex> Lock(WriterMutex);
177-
return SectionOffset;
176+
return RangesBuffer->size();
178177
}
179178

180179
void DebugRangesSectionWriter::appendToRangeBuffer(
181180
const DebugBufferVector &CUBuffer) {
182181
*RangesStream << CUBuffer;
183-
SectionOffset = RangesBuffer->size();
184182
}
185183

186184
DebugAddrWriter *DebugRangeListsSectionWriter::AddrWriter = nullptr;
@@ -327,7 +325,6 @@ void DebugRangeListsSectionWriter::finalizeSection() {
327325
*RangesStream << *Header;
328326
*RangesStream << *CUArrayBuffer;
329327
*RangesStream << *CUBodyBuffer;
330-
SectionOffset = RangesBuffer->size();
331328
}
332329

333330
void DebugRangeListsSectionWriter::initSection(DWARFUnit &Unit) {

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,10 +1342,7 @@ void DWARFRewriter::updateDWARFObjectAddressRanges(
13421342
assert(RangesWriterIterator != LegacyRangesWritersByCU.end() &&
13431343
"RangesWriter does not exist for DWOId");
13441344
RangesWriterIterator->second->setDie(&Die);
1345-
} else if (Unit.getVersion() == 5) {
1346-
DIEBldr.addValue(&Die, dwarf::DW_AT_rnglists_base,
1347-
dwarf::DW_FORM_sec_offset, DIEInteger(*RangesBase));
1348-
} else {
1345+
} else if (Unit.getVersion() >= 5) {
13491346
DIEBldr.addValue(&Die, dwarf::DW_AT_rnglists_base,
13501347
dwarf::DW_FORM_sec_offset, DIEInteger(*RangesBase));
13511348
}
@@ -1638,14 +1635,13 @@ void DWARFRewriter::finalizeCompileUnits(DIEBuilder &DIEBlder,
16381635
"RangesWriter does not exist for DWOId");
16391636
std::unique_ptr<DebugRangesSectionWriter> &LegacyRangesWriter =
16401637
RangesWriterIterator->second;
1641-
std::optional<DIE *> Die = LegacyRangesWriter->getDie();
1642-
if (!Die || !Die.value())
1638+
DIE *Die = LegacyRangesWriter->getDie();
1639+
if (!Die)
16431640
continue;
1644-
DIEValue DvalGNUBase =
1645-
Die.value()->findAttribute(dwarf::DW_AT_GNU_ranges_base);
1641+
DIEValue DvalGNUBase = Die->findAttribute(dwarf::DW_AT_GNU_ranges_base);
16461642
assert(DvalGNUBase && "GNU_ranges_base attribute does not exist for DWOId");
16471643
DIEBlder.replaceValue(
1648-
Die.value(), dwarf::DW_AT_GNU_ranges_base, DvalGNUBase.getForm(),
1644+
Die, dwarf::DW_AT_GNU_ranges_base, DvalGNUBase.getForm(),
16491645
DIEInteger(LegacyRangesSectionWriter->getSectionOffset()));
16501646
std::unique_ptr<DebugBufferVector> RangesWritersContents =
16511647
LegacyRangesWriter->releaseBuffer();

bolt/test/X86/infer_no_exits.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
# PREAGG: B X:0 #main# 1 0
1010

11-
# CHECK: BOLT-INFO: inferred profile for 1 (100.00% of profiled, 100.00% of stale) functions responsible for -nan% samples (0 out of 0)
11+
# CHECK: BOLT-INFO: inferred profile for 1 (100.00% of profiled, 100.00% of stale) functions

bolt/test/X86/jt-symbol-disambiguation-4.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
# REQUIRES: system-linux
1111

1212
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
13-
# RUN: %clang -no-pie %t.o -o %t.exe -Wl,-q
13+
# RUN: %clang %cflags -no-pie %t.o -o %t.exe -Wl,-q
1414
# RUN: llvm-bolt --funcs=main,foo/1 %t.exe -o %t.exe.bolt --print-normalized \
1515
# RUN: 2>&1 | FileCheck %s
1616

1717
.text
1818
.globl main
1919
.type main,@function
2020
main:
21-
# CHECK: Binary Function "main"
21+
# CHECK: Binary Function "main
2222
pushq %rbp
2323
movq %rsp, %rbp
2424
movq $-16, %rax

clang/docs/ReleaseNotes.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,15 @@ Attribute Changes in Clang
559559
size_t count;
560560
};
561561
562+
- The attributes ``sized_by``, ``counted_by_or_null`` and ``sized_by_or_null```
563+
have been added as variants on ``counted_by``, each with slightly different semantics.
564+
``sized_by`` takes a byte size parameter instead of an element count, allowing pointees
565+
with unknown size. The ``counted_by_or_null`` and ``sized_by_or_null`` variants are equivalent
566+
to their base variants, except the pointer can be null regardless of count/size value.
567+
If the pointer is null the size is effectively 0. ``sized_by_or_null`` is needed to properly
568+
annotate allocator functions like ``malloc`` that return a buffer of a given byte size, but can
569+
also return null.
570+
562571
- The ``guarded_by``, ``pt_guarded_by``, ``acquired_after``, ``acquired_before``
563572
attributes now support referencing struct members in C. The arguments are also
564573
now late parsed when ``-fexperimental-late-parse-attributes`` is passed like
@@ -679,6 +688,9 @@ Improvements to Clang's diagnostics
679688

680689
- Clang now shows implicit deduction guides when diagnosing overload resolution failure. #GH92393.
681690

691+
- Clang no longer emits a "no previous prototype" warning for Win32 entry points under ``-Wmissing-prototypes``.
692+
Fixes #GH94366.
693+
682694
Improvements to Clang's time-trace
683695
----------------------------------
684696

@@ -994,6 +1006,7 @@ Bug Fixes to C++ Support
9941006
evaluated to an integer. (#GH96670).
9951007
- Fixed a bug where references to lambda capture inside a ``noexcept`` specifier were not correctly
9961008
instantiated. (#GH95735).
1009+
- Fixed a CTAD substitution bug involving type aliases that reference outer template parameters. (#GH94614).
9971010

9981011
Bug Fixes to AST Handling
9991012
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/docs/StandardCPlusPlusModules.rst

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,74 @@ A high-level overview of support for standards features, including modules, can
10921092
be found on the `C++ Feature Status <https://clang.llvm.org/cxx_status.html>`_
10931093
page.
10941094

1095+
Missing VTables for classes attached to modules
1096+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1097+
1098+
Now the compiler may miss emitting the definition of vtables
1099+
for classes attached to modules, if the definition of the class
1100+
doesn't contain any key function in that module units
1101+
(The key function is the first non-pure virtual function that is
1102+
not inline at the point of class definition.)
1103+
1104+
(Note: technically, the key function is not a thing for modules.
1105+
We use the concept here for convinient.)
1106+
1107+
For example,
1108+
1109+
.. code-block:: c++
1110+
1111+
// layer1.cppm
1112+
export module foo:layer1;
1113+
struct Fruit {
1114+
virtual ~Fruit() = default;
1115+
virtual void eval() = 0;
1116+
};
1117+
struct Banana : public Fruit {
1118+
Banana() {}
1119+
void eval() override;
1120+
};
1121+
1122+
// layer2.cppm
1123+
export module foo:layer2;
1124+
import :layer1;
1125+
export void layer2_fun() {
1126+
Banana *b = new Banana();
1127+
b->eval();
1128+
}
1129+
void Banana::eval() {
1130+
}
1131+
1132+
For the above example, we can't find the definition for the vtable of
1133+
class ``Banana`` in any object files.
1134+
1135+
The expected behavior is, for dynamic classes attached to named modules,
1136+
the vtable should always be emitted to the module units the class attaches
1137+
to.
1138+
1139+
To workaround the problem, users can add the key function manually in the
1140+
corresponding module units. e.g.,
1141+
1142+
.. code-block:: c++
1143+
1144+
// layer1.cppm
1145+
export module foo:layer1;
1146+
struct Fruit {
1147+
virtual ~Fruit() = default;
1148+
virtual void eval() = 0;
1149+
};
1150+
struct Banana : public Fruit {
1151+
// Hack a key function to hint the compiler to emit the virtual table.
1152+
virtual void anchor();
1153+
1154+
Banana() {}
1155+
void eval() override;
1156+
};
1157+
1158+
void Banana::anchor() {}
1159+
1160+
This is tracked by
1161+
`#70585 <https://github.com/llvm/llvm-project/issues/70585>`_.
1162+
10951163
Including headers after import is not well-supported
10961164
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10971165

clang/include/clang/AST/DeclBase.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -670,16 +670,6 @@ class alignas(8) Decl {
670670
/// Whether this declaration comes from another module unit.
671671
bool isInAnotherModuleUnit() const;
672672

673-
/// Whether this declaration comes from the same module unit being compiled.
674-
bool isInCurrentModuleUnit() const;
675-
676-
/// Whether the definition of the declaration should be emitted in external
677-
/// sources.
678-
bool shouldEmitInExternalSource() const;
679-
680-
/// Whether this declaration comes from a named module;
681-
bool isInNamedModule() const;
682-
683673
/// Whether this declaration comes from explicit global module.
684674
bool isFromExplicitGlobalModule() const;
685675

clang/include/clang/Basic/Attr.td

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,6 +2292,36 @@ def CountedBy : DeclOrTypeAttr {
22922292
let LangOpts = [COnly];
22932293
}
22942294

2295+
def CountedByOrNull : DeclOrTypeAttr {
2296+
let Spellings = [Clang<"counted_by_or_null">];
2297+
let Subjects = SubjectList<[Field], ErrorDiag>;
2298+
let Args = [ExprArgument<"Count">, IntArgument<"NestedLevel", 1>];
2299+
let LateParsed = LateAttrParseExperimentalExt;
2300+
let ParseArgumentsAsUnevaluated = 1;
2301+
let Documentation = [CountedByDocs];
2302+
let LangOpts = [COnly];
2303+
}
2304+
2305+
def SizedBy : DeclOrTypeAttr {
2306+
let Spellings = [Clang<"sized_by">];
2307+
let Subjects = SubjectList<[Field], ErrorDiag>;
2308+
let Args = [ExprArgument<"Size">, IntArgument<"NestedLevel", 1>];
2309+
let LateParsed = LateAttrParseExperimentalExt;
2310+
let ParseArgumentsAsUnevaluated = 1;
2311+
let Documentation = [CountedByDocs];
2312+
let LangOpts = [COnly];
2313+
}
2314+
2315+
def SizedByOrNull : DeclOrTypeAttr {
2316+
let Spellings = [Clang<"sized_by_or_null">];
2317+
let Subjects = SubjectList<[Field], ErrorDiag>;
2318+
let Args = [ExprArgument<"Size">, IntArgument<"NestedLevel", 1>];
2319+
let LateParsed = LateAttrParseExperimentalExt;
2320+
let ParseArgumentsAsUnevaluated = 1;
2321+
let Documentation = [CountedByDocs];
2322+
let LangOpts = [COnly];
2323+
}
2324+
22952325
// This is a marker used to indicate that an __unsafe_unretained qualifier was
22962326
// ignored because ARC is not enabled. The usual representation for this
22972327
// qualifier is as an ObjCOwnership attribute with Kind == "none".

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6570,28 +6570,28 @@ def warn_superclass_variable_sized_type_not_at_end : Warning<
65706570
"field %0 can overwrite instance variable %1 with variable sized type %2"
65716571
" in superclass %3">, InGroup<ObjCFlexibleArray>;
65726572

6573-
def err_flexible_array_count_not_in_same_struct : Error<
6574-
"'counted_by' field %0 isn't within the same struct as the flexible array">;
6575-
def err_counted_by_attr_not_on_ptr_or_flexible_array_member : Error<
6576-
"'counted_by' only applies to pointers or C99 flexible array members">;
6573+
def err_count_attr_param_not_in_same_struct : Error<
6574+
"'%select{counted_by|sized_by|counted_by_or_null|sized_by_or_null}1' field %0 isn't within the same struct as the annotated %select{pointer|flexible array}2">;
6575+
def err_count_attr_not_on_ptr_or_flexible_array_member : Error<
6576+
"'%select{counted_by|sized_by|counted_by_or_null|sized_by_or_null}0' only applies to pointers%select{ or C99 flexible array members|||}0%select{|; did you mean to use 'counted_by'?}1">;
65776577
def err_counted_by_attr_on_array_not_flexible_array_member : Error<
65786578
"'counted_by' on arrays only applies to C99 flexible array members">;
65796579
def err_counted_by_attr_refer_to_itself : Error<
65806580
"'counted_by' cannot refer to the flexible array member %0">;
6581-
def err_counted_by_must_be_in_structure : Error<
6582-
"field %0 in 'counted_by' not inside structure">;
6583-
def err_counted_by_attr_argument_not_integer : Error<
6584-
"'counted_by' requires a non-boolean integer type argument">;
6585-
def err_counted_by_attr_only_support_simple_decl_reference : Error<
6586-
"'counted_by' argument must be a simple declaration reference">;
6587-
def err_counted_by_attr_in_union : Error<
6588-
"'counted_by' cannot be applied to a union member">;
6589-
def err_counted_by_attr_refer_to_union : Error<
6590-
"'counted_by' argument cannot refer to a union member">;
6581+
def err_count_attr_must_be_in_structure : Error<
6582+
"field %0 in '%select{counted_by|sized_by|counted_by_or_null|sized_by_or_null}1' not inside structure">;
6583+
def err_count_attr_argument_not_integer : Error<
6584+
"'%select{counted_by|sized_by|counted_by_or_null|sized_by_or_null}0' requires a non-boolean integer type argument">;
6585+
def err_count_attr_only_support_simple_decl_reference : Error<
6586+
"'%select{counted_by|sized_by|counted_by_or_null|sized_by_or_null}0' argument must be a simple declaration reference">;
6587+
def err_count_attr_in_union : Error<
6588+
"'%select{counted_by|sized_by|counted_by_or_null|sized_by_or_null}0' cannot be applied to a union member">;
6589+
def err_count_attr_refer_to_union : Error<
6590+
"'%select{counted_by|sized_by|counted_by_or_null|sized_by_or_null}0' argument cannot refer to a union member">;
65916591
def note_flexible_array_counted_by_attr_field : Note<
65926592
"field %0 declared here">;
65936593
def err_counted_by_attr_pointee_unknown_size : Error<
6594-
"'counted_by' %select{cannot|should not}3 be applied to %select{"
6594+
"'%select{counted_by|sized_by|counted_by_or_null|sized_by_or_null}4' %select{cannot|should not}3 be applied to %select{"
65956595
"a pointer with pointee|" // pointer
65966596
"an array with element}0" // array
65976597
" of unknown size because %1 is %select{"

clang/include/clang/Sema/Sema.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14608,7 +14608,9 @@ class Sema final : public SemaBase {
1460814608
SourceLocation AttrLoc);
1460914609

1461014610
QualType BuildCountAttributedArrayOrPointerType(QualType WrappedTy,
14611-
Expr *CountExpr);
14611+
Expr *CountExpr,
14612+
bool CountInBytes,
14613+
bool OrNull);
1461214614

1461314615
/// BuildAddressSpaceAttr - Builds a DependentAddressSpaceType if an
1461414616
/// expression is uninstantiated. If instantiated it will apply the

clang/include/clang/Sema/Template.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ enum class TemplateSubstitutionKind : char {
711711
VarTemplateSpecializationDecl *PrevDecl = nullptr);
712712

713713
Decl *InstantiateTypedefNameDecl(TypedefNameDecl *D, bool IsTypeAlias);
714+
Decl *InstantiateTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
714715
ClassTemplatePartialSpecializationDecl *
715716
InstantiateClassTemplatePartialSpecialization(
716717
ClassTemplateDecl *ClassTemplate,

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -721,9 +721,6 @@ enum ASTRecordTypes {
721721

722722
/// Record code for \#pragma clang unsafe_buffer_usage begin/end
723723
PP_UNSAFE_BUFFER_USAGE = 69,
724-
725-
/// Record code for vtables to emit.
726-
VTABLES_TO_EMIT = 70,
727724
};
728725

729726
/// Record types used within a source manager block.

clang/include/clang/Serialization/ASTReader.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -790,11 +790,6 @@ class ASTReader
790790
/// the consumer eagerly.
791791
SmallVector<GlobalDeclID, 16> EagerlyDeserializedDecls;
792792

793-
/// The IDs of all vtables to emit. The referenced declarations are passed
794-
/// to the consumers's HandleVTable eagerly after passing
795-
/// EagerlyDeserializedDecls.
796-
SmallVector<GlobalDeclID, 16> VTablesToEmit;
797-
798793
/// The IDs of all tentative definitions stored in the chain.
799794
///
800795
/// Sema keeps track of all tentative definitions in a TU because it has to
@@ -1505,7 +1500,6 @@ class ASTReader
15051500
bool isConsumerInterestedIn(Decl *D);
15061501
void PassInterestingDeclsToConsumer();
15071502
void PassInterestingDeclToConsumer(Decl *D);
1508-
void PassVTableToConsumer(CXXRecordDecl *RD);
15091503

15101504
void finishPendingActions();
15111505
void diagnoseOdrViolations();

clang/include/clang/Serialization/ASTWriter.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,6 @@ class ASTWriter : public ASTDeserializationListener,
500500
std::vector<SourceRange> NonAffectingRanges;
501501
std::vector<SourceLocation::UIntTy> NonAffectingOffsetAdjustments;
502502

503-
/// A list of classes which need to emit the VTable in the corresponding
504-
/// object file.
505-
llvm::SmallVector<CXXRecordDecl *> PendingEmittingVTables;
506-
507503
/// Computes input files that didn't affect compilation of the current module,
508504
/// and initializes data structures necessary for leaving those files out
509505
/// during \c SourceManager serialization.
@@ -861,8 +857,6 @@ class ASTWriter : public ASTDeserializationListener,
861857
return PredefinedDecls.count(D);
862858
}
863859

864-
void handleVTable(CXXRecordDecl *RD);
865-
866860
private:
867861
// ASTDeserializationListener implementation
868862
void ReaderInitialized(ASTReader *Reader) override;
@@ -957,7 +951,6 @@ class PCHGenerator : public SemaConsumer {
957951

958952
void InitializeSema(Sema &S) override { SemaPtr = &S; }
959953
void HandleTranslationUnit(ASTContext &Ctx) override;
960-
void HandleVTable(CXXRecordDecl *RD) override { Writer.handleVTable(RD); }
961954
ASTMutationListener *GetASTMutationListener() override;
962955
ASTDeserializationListener *GetASTDeserializationListener() override;
963956
bool hasEmittedPCH() const { return Buffer->IsComplete; }

0 commit comments

Comments
 (0)