Skip to content

Commit c40810b

Browse files
authored
merge main into amd-staging (llvm#3830)
2 parents 42e815b + 9288382 commit c40810b

File tree

130 files changed

+3221
-2419
lines changed

Some content is hidden

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

130 files changed

+3221
-2419
lines changed

clang/docs/LanguageExtensions.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,6 +2046,9 @@ The following type trait primitives are supported by Clang. Those traits marked
20462046
Returns true if a reference ``T`` can be copy-initialized from a temporary of type
20472047
a non-cv-qualified ``U``.
20482048
* ``__underlying_type`` (C++, GNU, Microsoft)
2049+
* ``__builtin_lt_synthesises_from_spaceship``, ``__builtin_gt_synthesises_from_spaceship``,
2050+
``__builtin_le_synthesises_from_spaceship``, ``__builtin_ge_synthesises_from_spaceship`` (Clang):
2051+
These builtins can be used to determine whether the corresponding operator is synthesised from a spaceship operator.
20492052

20502053
In addition, the following expression traits are supported:
20512054

clang/docs/ReleaseNotes.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ What's New in Clang |release|?
107107
C++ Language Changes
108108
--------------------
109109

110+
- A new family of builtins ``__builtin_*_synthesises_from_spaceship`` has been added. These can be queried to know
111+
whether the ``<`` (``lt``), ``>`` (``gt``), ``<=`` (``le``), or ``>=`` (``ge``) operators are synthesised from a
112+
``<=>``. This makes it possible to optimize certain facilities by using the ``<=>`` operation directly instead of
113+
doing multiple comparisons.
114+
110115
C++2c Feature Support
111116
^^^^^^^^^^^^^^^^^^^^^
112117

@@ -487,7 +492,7 @@ Improvements to Clang's diagnostics
487492
"format specifies type 'unsigned int' but the argument has type 'int', which differs in signedness [-Wformat-signedness]"
488493
"signedness of format specifier 'u' is incompatible with 'c' [-Wformat-signedness]"
489494
and the API-visible diagnostic id will be appropriate.
490-
495+
491496
- Fixed false positives in ``-Waddress-of-packed-member`` diagnostics when
492497
potential misaligned members get processed before they can get discarded.
493498
(#GH144729)
@@ -511,6 +516,10 @@ Improvements to Clang's diagnostics
511516
decorated with the ``alloc_size`` attribute don't allocate enough space for
512517
the target pointer type.
513518

519+
- The :doc:`ThreadSafetyAnalysis` attributes ``ACQUIRED_BEFORE(...)`` and
520+
``ACQUIRED_AFTER(...)`` have been moved to the stable feature set and no
521+
longer require ``-Wthread-safety-beta`` to be used.
522+
514523
Improvements to Clang's time-trace
515524
----------------------------------
516525

@@ -521,7 +530,7 @@ Bug Fixes in This Version
521530
-------------------------
522531
- Fix a crash when marco name is empty in ``#pragma push_macro("")`` or
523532
``#pragma pop_macro("")``. (#GH149762).
524-
- Fix a crash in variable length array (e.g. ``int a[*]``) function parameter type
533+
- Fix a crash in variable length array (e.g. ``int a[*]``) function parameter type
525534
being used in ``_Countof`` expression. (#GH152826).
526535
- ``-Wunreachable-code`` now diagnoses tautological or contradictory
527536
comparisons such as ``x != 0 || x != 1.0`` and ``x == 0 && x == 1.0`` on
@@ -612,7 +621,7 @@ X86 Support
612621
arithmetic can now be used in C++ constant expressions.
613622
- Some SSE, AVX and AVX512 intrinsics have been converted to wrap
614623
generic __builtin intrinsics.
615-
- NOTE: Please avoid use of the __builtin_ia32_* intrinsics - these are not
624+
- NOTE: Please avoid use of the __builtin_ia32_* intrinsics - these are not
616625
guaranteed to exist in future releases, or match behaviour with previous
617626
releases of clang or other compilers.
618627

clang/include/clang/Basic/TokenKinds.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,10 @@ TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX)
552552
TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
553553
TYPE_TRAIT_2(__reference_constructs_from_temporary, ReferenceConstructsFromTemporary, KEYCXX)
554554
TYPE_TRAIT_2(__reference_converts_from_temporary, ReferenceConvertsFromTemporary, KEYCXX)
555+
TYPE_TRAIT_2(__builtin_lt_synthesises_from_spaceship, LtSynthesisesFromSpaceship, KEYCXX)
556+
TYPE_TRAIT_2(__builtin_le_synthesises_from_spaceship, LeSynthesisesFromSpaceship, KEYCXX)
557+
TYPE_TRAIT_2(__builtin_gt_synthesises_from_spaceship, GtSynthesisesFromSpaceship, KEYCXX)
558+
TYPE_TRAIT_2(__builtin_ge_synthesises_from_spaceship, GeSynthesisesFromSpaceship, KEYCXX)
555559
// IsDeducible is only used internally by clang for CTAD implementation and
556560
// is not exposed to users.
557561
TYPE_TRAIT_2(/*EmptySpellingName*/, IsDeducible, KEYCXX)

clang/include/clang/Frontend/ASTUnit.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,17 @@ class ASTUnit {
629629
return StoredDiagnostics.end();
630630
}
631631

632+
using diags_range = llvm::iterator_range<stored_diag_iterator>;
633+
using const_diags_range = llvm::iterator_range<stored_diag_const_iterator>;
634+
635+
diags_range storedDiagnostics() {
636+
return {stored_diag_begin(), stored_diag_end()};
637+
}
638+
639+
const_diags_range storedDiagnostics() const {
640+
return {stored_diag_begin(), stored_diag_end()};
641+
}
642+
632643
unsigned stored_diag_size() const { return StoredDiagnostics.size(); }
633644

634645
stored_diag_iterator stored_diag_afterDriver_begin() {

clang/include/clang/Tooling/Tooling.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "clang/AST/ASTConsumer.h"
3333
#include "clang/Basic/FileManager.h"
3434
#include "clang/Basic/LLVM.h"
35+
#include "clang/Frontend/ASTUnit.h"
3536
#include "clang/Frontend/FrontendAction.h"
3637
#include "clang/Frontend/PCHContainerOperations.h"
3738
#include "clang/Tooling/ArgumentsAdjusters.h"
@@ -239,7 +240,8 @@ std::unique_ptr<ASTUnit> buildASTFromCodeWithArgs(
239240
const FileContentMappings &VirtualMappedFiles = FileContentMappings(),
240241
DiagnosticConsumer *DiagConsumer = nullptr,
241242
IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS =
242-
llvm::vfs::getRealFileSystem());
243+
llvm::vfs::getRealFileSystem(),
244+
CaptureDiagsKind CaptureKind = CaptureDiagsKind::None);
243245

244246
/// Utility to run a FrontendAction in a single clang invocation.
245247
class ToolInvocation {

clang/lib/Sema/SemaTypeTraits.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,51 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT,
18251825

18261826
return Self.HLSL().IsScalarizedLayoutCompatible(LhsT, RhsT);
18271827
}
1828+
case BTT_LtSynthesisesFromSpaceship:
1829+
case BTT_LeSynthesisesFromSpaceship:
1830+
case BTT_GtSynthesisesFromSpaceship:
1831+
case BTT_GeSynthesisesFromSpaceship: {
1832+
EnterExpressionEvaluationContext UnevaluatedContext(
1833+
Self, Sema::ExpressionEvaluationContext::Unevaluated);
1834+
Sema::SFINAETrap SFINAE(Self, /*ForValidityCheck=*/true);
1835+
Sema::ContextRAII TUContext(Self, Self.Context.getTranslationUnitDecl());
1836+
1837+
OpaqueValueExpr LHS(KeyLoc, LhsT.getNonReferenceType(),
1838+
LhsT->isLValueReferenceType() ? ExprValueKind::VK_LValue
1839+
: LhsT->isRValueReferenceType()
1840+
? ExprValueKind::VK_XValue
1841+
: ExprValueKind::VK_PRValue);
1842+
OpaqueValueExpr RHS(KeyLoc, RhsT.getNonReferenceType(),
1843+
RhsT->isLValueReferenceType() ? ExprValueKind::VK_LValue
1844+
: RhsT->isRValueReferenceType()
1845+
? ExprValueKind::VK_XValue
1846+
: ExprValueKind::VK_PRValue);
1847+
1848+
auto OpKind = [&] {
1849+
switch (BTT) {
1850+
case BTT_LtSynthesisesFromSpaceship:
1851+
return BinaryOperatorKind::BO_LT;
1852+
case BTT_LeSynthesisesFromSpaceship:
1853+
return BinaryOperatorKind::BO_LE;
1854+
case BTT_GtSynthesisesFromSpaceship:
1855+
return BinaryOperatorKind::BO_GT;
1856+
case BTT_GeSynthesisesFromSpaceship:
1857+
return BinaryOperatorKind::BO_GE;
1858+
default:
1859+
llvm_unreachable("Trying to Synthesize non-comparison operator?");
1860+
}
1861+
}();
1862+
1863+
UnresolvedSet<16> Functions;
1864+
Self.LookupBinOp(Self.TUScope, KeyLoc, OpKind, Functions);
1865+
1866+
ExprResult Result =
1867+
Self.CreateOverloadedBinOp(KeyLoc, OpKind, Functions, &LHS, &RHS);
1868+
if (Result.isInvalid() || SFINAE.hasErrorOccurred())
1869+
return false;
1870+
1871+
return isa<CXXRewrittenBinaryOperator>(Result.get());
1872+
}
18281873
default:
18291874
llvm_unreachable("not a BTT");
18301875
}

clang/lib/Tooling/Tooling.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,13 @@ namespace {
644644

645645
class ASTBuilderAction : public ToolAction {
646646
std::vector<std::unique_ptr<ASTUnit>> &ASTs;
647+
CaptureDiagsKind CaptureKind;
647648

648649
public:
649-
ASTBuilderAction(std::vector<std::unique_ptr<ASTUnit>> &ASTs) : ASTs(ASTs) {}
650+
ASTBuilderAction(
651+
std::vector<std::unique_ptr<ASTUnit>> &ASTs,
652+
CaptureDiagsKind CaptureDiagnosticsKind = CaptureDiagsKind::None)
653+
: ASTs(ASTs), CaptureKind(CaptureDiagnosticsKind) {}
650654

651655
bool runInvocation(std::shared_ptr<CompilerInvocation> Invocation,
652656
FileManager *Files,
@@ -658,7 +662,7 @@ class ASTBuilderAction : public ToolAction {
658662
Invocation->getDiagnosticOpts(),
659663
DiagConsumer,
660664
/*ShouldOwnClient=*/false),
661-
Files);
665+
Files, false, CaptureKind);
662666
if (!AST)
663667
return false;
664668

@@ -693,9 +697,12 @@ std::unique_ptr<ASTUnit> buildASTFromCodeWithArgs(
693697
StringRef ToolName, std::shared_ptr<PCHContainerOperations> PCHContainerOps,
694698
ArgumentsAdjuster Adjuster, const FileContentMappings &VirtualMappedFiles,
695699
DiagnosticConsumer *DiagConsumer,
696-
IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS) {
700+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS,
701+
CaptureDiagsKind CaptureKind) {
697702
std::vector<std::unique_ptr<ASTUnit>> ASTs;
698-
ASTBuilderAction Action(ASTs);
703+
704+
ASTBuilderAction Action(ASTs, CaptureKind);
705+
699706
auto OverlayFileSystem =
700707
llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>(
701708
std::move(BaseFS));

0 commit comments

Comments
 (0)