Skip to content

Commit 97a440d

Browse files
committed
Merge branch 'main' into merge-functions
2 parents a6f6b3c + 1858a4e commit 97a440d

File tree

333 files changed

+14699
-2169
lines changed

Some content is hidden

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

333 files changed

+14699
-2169
lines changed

.ci/generate_test_report.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def junit_from_xml(xml):
1818

1919
class TestReports(unittest.TestCase):
2020
def test_title_only(self):
21-
self.assertEqual(_generate_report("Foo", []), ("", None))
21+
self.assertEqual(_generate_report("Foo", []), ("", "success"))
2222

2323
def test_no_tests_in_testsuite(self):
2424
self.assertEqual(
@@ -336,7 +336,7 @@ def _generate_report(title, junit_objects, size_limit=1024 * 1024, list_failures
336336
)
337337

338338
if not tests_run:
339-
return ("", style)
339+
return ("", None)
340340

341341
style = "error" if tests_failed else "success"
342342
report = [f"# {title}", ""]

.github/new-issues-labeler.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@
3030

3131
'infra:commit-access-request':
3232
- '/Request Commit Access/'
33+
34+
'false-positive':
35+
- '\bfalse[- ]positive\b'
36+
37+
'false-negative':
38+
- '\bfalse[- ]negative\b'

clang/docs/ReleaseNotes.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,35 @@ C++ Specific Potentially Breaking Changes
158158

159159
Previously, this code was erroneously accepted.
160160

161+
- Clang will now consider the implicitly deleted destructor of a union or
162+
a non-union class without virtual base class to be ``constexpr`` in C++20
163+
mode (Clang 19 only did so in C++23 mode but the standard specification for
164+
this changed in C++20). (#GH85550)
165+
166+
.. code-block:: c++
167+
168+
struct NonLiteral {
169+
NonLiteral() {}
170+
~NonLiteral() {}
171+
};
172+
173+
template <class T>
174+
struct Opt {
175+
union {
176+
char c;
177+
T data;
178+
};
179+
bool engaged = false;
180+
181+
constexpr Opt() {}
182+
constexpr ~Opt() {
183+
if (engaged)
184+
data.~T();
185+
}
186+
};
187+
188+
// Previously only accepted in C++23 and later, now also accepted in C++20.
189+
consteval void foo() { Opt<NonLiteral>{}; }
161190

162191
ABI Changes in This Version
163192
---------------------------
@@ -444,6 +473,11 @@ Attribute Changes in Clang
444473
- The ``hybrid_patchable`` attribute is now supported on ARM64EC targets. It can be used to specify
445474
that a function requires an additional x86-64 thunk, which may be patched at runtime.
446475

476+
- The attribute ``[[clang::no_specializations]]`` has been added to warn
477+
users that a specific template shouldn't be specialized. This is useful for
478+
e.g. standard library type traits, where adding a specialization results in
479+
undefined behaviour.
480+
447481
- ``[[clang::lifetimebound]]`` is now explicitly disallowed on explicit object member functions
448482
where they were previously silently ignored.
449483

clang/docs/UsersManual.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,7 +2660,7 @@ usual build cycle when using sample profilers for optimization:
26602660
26612661
> clang-cl /O2 -gdwarf -gline-tables-only ^
26622662
/clang:-fdebug-info-for-profiling /clang:-funique-internal-linkage-names ^
2663-
/fprofile-sample-use=code.prof code.cc /Fe:code /fuse-ld=lld /link /debug:dwarf
2663+
-fprofile-sample-use=code.prof code.cc /Fe:code -fuse-ld=lld /link /debug:dwarf
26642664
26652665
[OPTIONAL] Sampling-based profiles can have inaccuracies or missing block/
26662666
edge counters. The profile inference algorithm (profi) can be used to infer
@@ -2679,7 +2679,7 @@ usual build cycle when using sample profilers for optimization:
26792679
26802680
> clang-cl /clang:-fsample-profile-use-profi /O2 -gdwarf -gline-tables-only ^
26812681
/clang:-fdebug-info-for-profiling /clang:-funique-internal-linkage-names ^
2682-
/fprofile-sample-use=code.prof code.cc /Fe:code /fuse-ld=lld /link /debug:dwarf
2682+
-fprofile-sample-use=code.prof code.cc /Fe:code -fuse-ld=lld /link /debug:dwarf
26832683
26842684
Sample Profile Formats
26852685
""""""""""""""""""""""

clang/include/clang/AST/DeclCXX.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,13 @@ class CXXRecordDecl : public RecordDecl {
890890
needsOverloadResolutionForDestructor()) &&
891891
"destructor should not be deleted");
892892
data().DefaultedDestructorIsDeleted = true;
893+
// C++23 [dcl.constexpr]p3.2:
894+
// if the function is a constructor or destructor, its class does not have
895+
// any virtual base classes.
896+
// C++20 [dcl.constexpr]p5:
897+
// The definition of a constexpr destructor whose function-body is
898+
// not = delete shall additionally satisfy...
899+
data().DefaultedDestructorIsConstexpr = data().NumVBases == 0;
893900
}
894901

895902
/// Determine whether this class should get an implicit move

clang/include/clang/Basic/Attr.td

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ def NonParmVar : SubsetSubject<Var,
103103
def NonLocalVar : SubsetSubject<Var,
104104
[{!S->hasLocalStorage()}],
105105
"variables with non-local storage">;
106+
def VarTmpl : SubsetSubject<Var, [{S->getDescribedVarTemplate()}],
107+
"variable templates">;
108+
106109
def NonBitField : SubsetSubject<Field,
107110
[{!S->isBitField()}],
108111
"non-bit-field non-static data members">;
@@ -3260,33 +3263,28 @@ def Target : InheritableAttr {
32603263
let Subjects = SubjectList<[Function], ErrorDiag>;
32613264
let Documentation = [TargetDocs];
32623265
let AdditionalMembers = [{
3263-
StringRef getArchitecture() const {
3266+
std::optional<StringRef> getX86Architecture() const {
32643267
StringRef Features = getFeaturesStr();
3265-
if (Features == "default") return {};
3266-
3267-
SmallVector<StringRef, 1> AttrFeatures;
3268-
Features.split(AttrFeatures, ",");
3269-
3270-
for (auto &Feature : AttrFeatures) {
3268+
SmallVector<StringRef, 4> AttrFeatures;
3269+
Features.split(AttrFeatures, ',');
3270+
for (StringRef Feature : AttrFeatures) {
32713271
Feature = Feature.trim();
32723272
if (Feature.starts_with("arch="))
32733273
return Feature.drop_front(sizeof("arch=") - 1);
32743274
}
3275-
return "";
3275+
return std::nullopt;
32763276
}
32773277

32783278
// Gets the list of features as simple string-refs with no +/- or 'no-'.
32793279
// Only adds the items to 'Out' that are additions.
3280-
void getAddedFeatures(llvm::SmallVectorImpl<StringRef> &Out) const {
3280+
void getX86AddedFeatures(llvm::SmallVectorImpl<StringRef> &Out) const {
3281+
if (isDefaultVersion())
3282+
return;
32813283
StringRef Features = getFeaturesStr();
3282-
if (Features == "default") return;
3283-
3284-
SmallVector<StringRef, 1> AttrFeatures;
3285-
Features.split(AttrFeatures, ",");
3286-
3284+
SmallVector<StringRef, 4> AttrFeatures;
3285+
Features.split(AttrFeatures, ',');
32873286
for (auto &Feature : AttrFeatures) {
32883287
Feature = Feature.trim();
3289-
32903288
if (!Feature.starts_with("no-") && !Feature.starts_with("arch=") &&
32913289
!Feature.starts_with("fpmath=") && !Feature.starts_with("tune="))
32923290
Out.push_back(Feature);
@@ -3304,17 +3302,17 @@ def TargetVersion : InheritableAttr, TargetSpecificAttr<TargetArch<!listconcat(T
33043302
let Documentation = [TargetVersionDocs];
33053303
let AdditionalMembers = [{
33063304
StringRef getName() const { return getNamesStr().trim(); }
3307-
bool isDefaultVersion() const {
3308-
return getName() == "default";
3309-
}
3310-
void getFeatures(llvm::SmallVectorImpl<StringRef> &Out) const {
3311-
if (isDefaultVersion()) return;
3312-
StringRef Features = getName();
33133305

3314-
SmallVector<StringRef, 8> AttrFeatures;
3315-
Features.split(AttrFeatures, "+");
3306+
bool isDefaultVersion() const { return getName() == "default"; }
33163307

3317-
for (auto &Feature : AttrFeatures) {
3308+
void getFeatures(llvm::SmallVectorImpl<StringRef> &Out,
3309+
char Delim = '+') const {
3310+
if (isDefaultVersion())
3311+
return;
3312+
StringRef Features = getName();
3313+
SmallVector<StringRef, 4> AttrFeatures;
3314+
Features.split(AttrFeatures, Delim);
3315+
for (StringRef Feature : AttrFeatures) {
33183316
Feature = Feature.trim();
33193317
Out.push_back(Feature);
33203318
}
@@ -3331,20 +3329,40 @@ def TargetClones : InheritableAttr {
33313329
StringRef getFeatureStr(unsigned Index) const {
33323330
return *(featuresStrs_begin() + Index);
33333331
}
3332+
33343333
bool isDefaultVersion(unsigned Index) const {
33353334
return getFeatureStr(Index) == "default";
33363335
}
3336+
33373337
void getFeatures(llvm::SmallVectorImpl<StringRef> &Out,
3338-
unsigned Index) const {
3339-
if (isDefaultVersion(Index)) return;
3338+
unsigned Index, char Delim = '+') const {
3339+
if (isDefaultVersion(Index))
3340+
return;
33403341
StringRef Features = getFeatureStr(Index);
3341-
SmallVector<StringRef, 8> AttrFeatures;
3342-
Features.split(AttrFeatures, "+");
3343-
for (auto &Feature : AttrFeatures) {
3342+
SmallVector<StringRef, 4> AttrFeatures;
3343+
Features.split(AttrFeatures, Delim);
3344+
for (StringRef Feature : AttrFeatures) {
33443345
Feature = Feature.trim();
33453346
Out.push_back(Feature);
33463347
}
33473348
}
3349+
3350+
std::optional<StringRef> getX86Architecture(unsigned Index) const {
3351+
StringRef Feature = getFeatureStr(Index);
3352+
if (Feature.starts_with("arch="))
3353+
return Feature.drop_front(sizeof("arch=") - 1);
3354+
return std::nullopt;
3355+
}
3356+
3357+
void getX86Feature(llvm::SmallVectorImpl<StringRef> &Out,
3358+
unsigned Index) const {
3359+
if (isDefaultVersion(Index))
3360+
return;
3361+
if (getX86Architecture(Index))
3362+
return;
3363+
Out.push_back(getFeatureStr(Index));
3364+
}
3365+
33483366
// Given an index into the 'featuresStrs' sequence, compute a unique
33493367
// ID to be used with function name mangling for the associated variant.
33503368
// This mapping is necessary due to a requirement that the mangling ID
@@ -3428,6 +3446,15 @@ def DiagnoseIf : InheritableAttr {
34283446
let Documentation = [DiagnoseIfDocs];
34293447
}
34303448

3449+
def NoSpecializations : InheritableAttr {
3450+
let Spellings = [Clang<"no_specializations", /*AllowInC*/0>];
3451+
let Args = [StringArgument<"Message", 1>];
3452+
let Subjects = SubjectList<[ClassTmpl, FunctionTmpl, VarTmpl]>;
3453+
let Documentation = [NoSpecializationsDocs];
3454+
let MeaningfulToClassTemplateDefinition = 1;
3455+
let TemplateDependent = 1;
3456+
}
3457+
34313458
def ArcWeakrefUnavailable : InheritableAttr {
34323459
let Spellings = [Clang<"objc_arc_weak_reference_unavailable">];
34333460
let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;

clang/include/clang/Basic/AttrDocs.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,15 @@ Query for this feature with ``__has_attribute(diagnose_if)``.
11551155
}];
11561156
}
11571157

1158+
def NoSpecializationsDocs : Documentation {
1159+
let Category = DocCatDecl;
1160+
let Content = [{
1161+
``[[clang::no_specializations]]`` can be applied to function, class, or variable
1162+
templates which should not be explicitly specialized by users. This is primarily
1163+
used to diagnose user specializations of standard library type traits.
1164+
}];
1165+
}
1166+
11581167
def PassObjectSizeDocs : Documentation {
11591168
let Category = DocCatVariable; // Technically it's a parameter doc, but eh.
11601169
let Heading = "pass_object_size, pass_dynamic_object_size";

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1589,4 +1589,3 @@ def ExplicitSpecializationStorageClass : DiagGroup<"explicit-specialization-stor
15891589

15901590
// A warning for options that enable a feature that is not yet complete
15911591
def ExperimentalOption : DiagGroup<"experimental-option">;
1592-

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5445,6 +5445,10 @@ def note_dependent_function_template_spec_discard_reason : Note<
54455445
"candidate ignored: %select{not a function template|"
54465446
"not a member of the enclosing %select{class template|"
54475447
"namespace; did you mean to explicitly qualify the specialization?}1}0">;
5448+
def warn_invalid_specialization : Warning<
5449+
"%0 cannot be specialized%select{|: %2}1">,
5450+
DefaultError, InGroup<DiagGroup<"invalid-specialization">>;
5451+
def note_marked_here : Note<"marked %0 here">;
54485452

54495453
// C++ class template specializations and out-of-line definitions
54505454
def err_template_spec_needs_header : Error<

clang/include/clang/Basic/TargetInfo.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,14 +1525,10 @@ class TargetInfo : public TransferrableTargetInfo,
15251525

15261526
// Return the target-specific priority for features/cpus/vendors so
15271527
// that they can be properly sorted for checking.
1528-
virtual unsigned multiVersionSortPriority(StringRef Name) const {
1528+
virtual unsigned getFMVPriority(ArrayRef<StringRef> Features) const {
15291529
return 0;
15301530
}
15311531

1532-
// Return the target-specific cost for feature
1533-
// that taken into account in priority sorting.
1534-
virtual unsigned multiVersionFeatureCost() const { return 0; }
1535-
15361532
// Validate the contents of the __builtin_cpu_is(const char*)
15371533
// argument.
15381534
virtual bool validateCpuIs(StringRef Name) const { return false; }

0 commit comments

Comments
 (0)