Skip to content

Commit c6c111d

Browse files
authored
Merge branch 'main' into objc_make_exception_ptr_fix
2 parents 25bdfd9 + d7c7c46 commit c6c111d

File tree

282 files changed

+5732
-2405
lines changed

Some content is hidden

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

282 files changed

+5732
-2405
lines changed

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
12201220
// Storage for parsed fields.
12211221
StringRef EventName;
12221222
std::optional<Location> Addr[3];
1223-
int64_t Counters[2];
1223+
int64_t Counters[2] = {0};
12241224

12251225
while (Type == INVALID || Type == EVENT_NAME) {
12261226
while (checkAndConsumeFS()) {

bolt/test/X86/entry-point-fallthru.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
# RUN: link_fdata %s %t %t.preagg PREAGG
77
# RUN: perf2bolt %t -p %t.preagg --pa -o %t.fdata | FileCheck %s
88
# CHECK: traces mismatching disassembled function contents: 0
9+
# RUN: FileCheck %s --check-prefix=CHECK-FDATA --input-file %t.fdata
10+
# CHECK-FDATA: 1 main 0 1 main 6 0 1
11+
# CHECK-FDATA-NEXT: 1 main e 1 main 11 0 1
12+
# CHECK-FDATA-NEXT: 1 main 11 1 main 0 0 1
913

1014
.globl main
1115
main:

clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
170170

171171
const auto PointerToStructType =
172172
hasUnqualifiedDesugaredType(pointerType(pointee(recordType())));
173-
const auto PointerToStructTypeWithBinding =
174-
type(PointerToStructType).bind("struct-type");
175173
const auto PointerToStructExpr =
176174
expr(hasType(hasCanonicalType(PointerToStructType)));
177175

@@ -188,12 +186,10 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
188186
ignoringParenImpCasts(unaryOperator(hasOperatorName("*")));
189187

190188
Finder->addMatcher(
191-
expr(sizeOfExpr(anyOf(has(ignoringParenImpCasts(
192-
expr(PointerToDetectedExpr, unless(DerefExpr),
193-
unless(SubscriptExprWithZeroIndex),
194-
unless(VarWithConstStrLiteralDecl),
195-
unless(cxxThisExpr())))),
196-
has(PointerToStructTypeWithBinding))))
189+
expr(sizeOfExpr(has(ignoringParenImpCasts(expr(
190+
PointerToDetectedExpr, unless(DerefExpr),
191+
unless(SubscriptExprWithZeroIndex),
192+
unless(VarWithConstStrLiteralDecl), unless(cxxThisExpr()))))))
197193
.bind("sizeof-pointer"),
198194
this);
199195
}
@@ -354,16 +350,9 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
354350
"suspicious usage of 'sizeof(char*)'; do you mean 'strlen'?")
355351
<< E->getSourceRange();
356352
} else if (const auto *E = Result.Nodes.getNodeAs<Expr>("sizeof-pointer")) {
357-
if (Result.Nodes.getNodeAs<Type>("struct-type")) {
358-
diag(E->getBeginLoc(),
359-
"suspicious usage of 'sizeof(A*)' on pointer-to-aggregate type; did "
360-
"you mean 'sizeof(A)'?")
361-
<< E->getSourceRange();
362-
} else {
363-
diag(E->getBeginLoc(), "suspicious usage of 'sizeof()' on an expression "
364-
"of pointer type")
365-
<< E->getSourceRange();
366-
}
353+
diag(E->getBeginLoc(), "suspicious usage of 'sizeof()' on an expression "
354+
"of pointer type")
355+
<< E->getSourceRange();
367356
} else if (const auto *E = Result.Nodes.getNodeAs<BinaryOperator>(
368357
"sizeof-compare-constant")) {
369358
diag(E->getOperatorLoc(),

clang/docs/LanguageExtensions.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3074,6 +3074,41 @@ following way:
30743074
30753075
Query for this feature with ``__has_builtin(__builtin_offsetof)``.
30763076
3077+
``__builtin_get_vtable_pointer``
3078+
--------------------------------
3079+
3080+
``__builtin_get_vtable_pointer`` loads and authenticates the primary vtable
3081+
pointer from an instance of a polymorphic C++ class. This builtin is needed
3082+
for directly loading the vtable pointer when on platforms using
3083+
:doc:`PointerAuthentication`.
3084+
3085+
**Syntax**:
3086+
3087+
.. code-block:: c++
3088+
3089+
__builtin_get_vtable_pointer(PolymorphicClass*)
3090+
3091+
**Example of Use**:
3092+
3093+
.. code-block:: c++
3094+
3095+
struct PolymorphicClass {
3096+
virtual ~PolymorphicClass();
3097+
};
3098+
3099+
PolymorphicClass anInstance;
3100+
const void* vtablePointer = __builtin_get_vtable_pointer(&anInstance);
3101+
3102+
**Description**:
3103+
3104+
The ``__builtin_get_vtable_pointer`` builtin loads the primary vtable
3105+
pointer from a polymorphic C++ type. If the target platform authenticates
3106+
vtable pointers, this builtin will perform the authentication and produce
3107+
the underlying raw pointer. The object being queried must be polymorphic,
3108+
and so must also be a complete type.
3109+
3110+
Query for this feature with ``__has_builtin(__builtin_get_vtable_pointer)``.
3111+
30773112
``__builtin_call_with_static_chain``
30783113
------------------------------------
30793114

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ Non-comprehensive list of changes in this release
317317
``sizeof`` or ``typeof`` expression. (#GH138444)
318318
- Deprecation warning is emitted for the deprecated ``__reference_binds_to_temporary`` intrinsic.
319319
``__reference_constructs_from_temporary`` should be used instead. (#GH44056)
320+
- Added `__builtin_get_vtable_pointer` to directly load the primary vtable pointer from a
321+
polymorphic object.
320322

321323
New Compiler Flags
322324
------------------
@@ -612,6 +614,8 @@ Improvements to Clang's diagnostics
612614
diagnostic group ``-Wimplicit-int-comparison-on-negation``, grouped under
613615
``-Wimplicit-int-conversion``, so user can turn it off independently.
614616

617+
- Improved the FixIts for unused lambda captures.
618+
615619
Improvements to Clang's time-trace
616620
----------------------------------
617621

clang/include/clang/Basic/Builtins.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,12 @@ def IsWithinLifetime : LangBuiltin<"CXX_LANG"> {
970970
let Prototype = "bool(void*)";
971971
}
972972

973+
def GetVtablePointer : LangBuiltin<"CXX_LANG"> {
974+
let Spellings = ["__builtin_get_vtable_pointer"];
975+
let Attributes = [CustomTypeChecking, NoThrow, Const];
976+
let Prototype = "void*(void*)";
977+
}
978+
973979
// GCC exception builtins
974980
def EHReturn : Builtin {
975981
let Spellings = ["__builtin_eh_return"];

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12803,6 +12803,14 @@ def err_bit_cast_non_trivially_copyable : Error<
1280312803
def err_bit_cast_type_size_mismatch : Error<
1280412804
"size of '__builtin_bit_cast' source type %0 does not match destination type %1 (%2 vs %3 bytes)">;
1280512805

12806+
def err_get_vtable_pointer_incorrect_type
12807+
: Error<"__builtin_get_vtable_pointer requires an argument of%select{| "
12808+
"polymorphic}0 class pointer type"
12809+
", but %1 %select{was provided|has no virtual methods}0">;
12810+
def err_get_vtable_pointer_requires_complete_type
12811+
: Error<"__builtin_get_vtable_pointer requires an argument with a complete "
12812+
"type, but %0 is incomplete">;
12813+
1280612814
// SYCL-specific diagnostics
1280712815
def warn_sycl_kernel_num_of_template_params : Warning<
1280812816
"'sycl_kernel' attribute only applies to a function template with at least"

clang/include/clang/Basic/DiagnosticSerializationKinds.td

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ def err_fe_unable_to_read_pch_file : Error<
1313
"unable to read PCH file %0: '%1'">;
1414
def err_fe_not_a_pch_file : Error<
1515
"input is not a PCH file: '%0'">;
16-
def err_fe_pch_malformed : Error<
17-
"malformed or corrupted AST file: '%0'">, DefaultFatal;
16+
def err_fe_ast_file_malformed : Error<
17+
"malformed or corrupted precompiled file: '%0'">, DefaultFatal;
1818
def err_fe_pch_malformed_block : Error<
1919
"malformed block record in PCH file: '%0'">, DefaultFatal;
2020
def err_fe_ast_file_modified : Error<
2121
"file '%0' has been modified since the "
22-
"%select{precompiled header|module file|AST file}1 '%2' was built"
22+
"%select{precompiled header|module file|precompiled file}1 '%2' was built"
2323
": %select{size|mtime|content}3 changed%select{| (was %5, now %6)}4">,
2424
DefaultFatal;
2525
def err_fe_pch_file_overridden : Error<
@@ -31,19 +31,19 @@ def note_module_cache_path : Note<
3131
"after modifying system headers, please delete the module cache at '%0'">;
3232

3333
def err_ast_file_targetopt_mismatch : Error<
34-
"AST file '%0' was compiled for the %1 '%2' but the current translation "
34+
"precompiled file '%0' was compiled for the %1 '%2' but the current translation "
3535
"unit is being compiled for target '%3'">;
3636
def err_ast_file_targetopt_feature_mismatch : Error<
37-
"%select{AST file '%1' was|current translation unit is}0 compiled with the target "
38-
"feature '%2' but the %select{current translation unit is|AST file '%1' was}0 "
37+
"%select{precompiled file '%1' was|current translation unit is}0 compiled with the target "
38+
"feature '%2' but the %select{current translation unit is|precompiled file '%1' was}0 "
3939
"not">;
4040
def err_ast_file_langopt_mismatch : Error<"%0 was %select{disabled|enabled}1 in "
41-
"AST file '%3' but is currently %select{disabled|enabled}2">;
41+
"precompiled file '%3' but is currently %select{disabled|enabled}2">;
4242
def err_ast_file_langopt_value_mismatch : Error<
43-
"%0 differs in AST file '%1' vs. current file">;
43+
"%0 differs in precompiled file '%1' vs. current file">;
4444
def err_ast_file_diagopt_mismatch : Error<"%0 is currently enabled, but was not in "
45-
"the AST file '%1'">;
46-
def err_ast_file_modulecache_mismatch : Error<"AST file '%2' was compiled with module cache "
45+
"the precompiled file '%1'">;
46+
def err_ast_file_modulecache_mismatch : Error<"precompiled file '%2' was compiled with module cache "
4747
"path '%0', but the path is currently '%1'">;
4848
def warn_pch_vfsoverlay_mismatch : Warning<
4949
"PCH was compiled with different VFS overlay files than are currently in use">,
@@ -52,27 +52,27 @@ def note_pch_vfsoverlay_files : Note<"%select{PCH|current translation unit}0 has
5252
def note_pch_vfsoverlay_empty : Note<"%select{PCH|current translation unit}0 has no VFS overlays">;
5353

5454
def err_ast_file_version_too_old : Error<
55-
"%select{PCH|module|AST}0 file '%1' uses an older format that is no longer supported">;
55+
"%select{PCH|module|precompiled}0 file '%1' uses an older format that is no longer supported">;
5656
def err_ast_file_version_too_new : Error<
57-
"%select{PCH|module|AST}0 file '%1' uses a newer format that cannot be read">;
57+
"%select{PCH|module|precompiled }0 file '%1' uses a newer format that cannot be read">;
5858
def err_ast_file_different_branch : Error<
59-
"%select{PCH|module|AST}0 file '%1' built from a different branch (%2) than the compiler (%3)">;
59+
"%select{PCH|module|precompiled}0 file '%1' built from a different branch (%2) than the compiler (%3)">;
6060
def err_ast_file_with_compiler_errors : Error<
61-
"%select{PCH|module|AST}0 file '%1' contains compiler errors">;
61+
"%select{PCH|module|precompiled}0 file '%1' contains compiler errors">;
6262

6363
def err_module_file_conflict : Error<
6464
"module '%0' is defined in both '%1' and '%2'">, DefaultFatal;
6565
def err_ast_file_not_found : Error<
66-
"%select{PCH|module|AST}0 file '%1' not found%select{|: %3}2">, DefaultFatal;
66+
"%select{PCH|module|precompiled}0 file '%1' not found%select{|: %3}2">, DefaultFatal;
6767
def err_ast_file_out_of_date : Error<
68-
"%select{PCH|module|AST}0 file '%1' is out of date and "
68+
"%select{PCH|module|precompiled}0 file '%1' is out of date and "
6969
"needs to be rebuilt%select{|: %3}2">, DefaultFatal;
7070
def err_ast_file_invalid : Error<
71-
"file '%1' is not a valid precompiled %select{PCH|module|AST}0 file: %2">, DefaultFatal;
71+
"file '%1' is not a valid %select{PCH|module|precompiled}0 file: %2">, DefaultFatal;
7272
def note_module_file_imported_by : Note<
7373
"imported by %select{|module '%2' in }1'%0'">;
7474
def err_module_file_not_module : Error<
75-
"AST file '%0' was not built as a module">, DefaultFatal;
75+
"precompiled file '%0' was not built as a module">, DefaultFatal;
7676
def err_module_file_missing_top_level_submodule : Error<
7777
"module file '%0' is missing its top-level submodule">, DefaultFatal;
7878
def note_module_file_conflict : Note<
@@ -84,14 +84,14 @@ def remark_module_import : Remark<
8484
InGroup<ModuleImport>;
8585

8686
def err_imported_module_not_found : Error<
87-
"module '%0' in AST file '%1' %select{(imported by AST file '%2') |}4"
87+
"module '%0' in precompiled file '%1' %select{(imported by precompiled file '%2') |}4"
8888
"is not defined in any loaded module map file; "
8989
"maybe you need to load '%3'?">, DefaultFatal;
9090
def note_imported_by_pch_module_not_found : Note<
9191
"consider adding '%0' to the header search path">;
9292
def err_imported_module_modmap_changed : Error<
93-
"module '%0' %select{in|imported by}4 AST file '%1' found in a different module map file"
94-
" (%2) than when the importing AST file was built (%3)">, DefaultFatal;
93+
"module '%0' %select{in|imported by}4 precompiled file '%1' found in a different module map file"
94+
" (%2) than when the importing precompiled file was built (%3)">, DefaultFatal;
9595
def err_imported_module_relocated : Error<
9696
"module '%0' was built in directory '%1' but now resides in "
9797
"directory '%2'">, DefaultFatal;
@@ -100,18 +100,18 @@ def err_module_different_modmap : Error<
100100
"%select{| not}1 used when the module was built">;
101101

102102
def err_ast_file_macro_def_undef : Error<
103-
"macro '%0' was %select{defined|undef'd}1 in the AST file '%2' but "
103+
"macro '%0' was %select{defined|undef'd}1 in the precompiled file '%2' but "
104104
"%select{undef'd|defined}1 on the command line">;
105105
def err_ast_file_macro_def_conflict : Error<
106-
"definition of macro '%0' differs between the AST file '%3' ('%1') "
106+
"definition of macro '%0' differs between the precompiled file '%3' ('%1') "
107107
"and the command line ('%2')">;
108108
def err_ast_file_undef : Error<
109-
"%select{command line contains|AST file '%1' was built with}0 "
110-
"'-undef' but %select{AST file '%1' was not built with it|"
109+
"%select{command line contains|precompiled file '%1' was built with}0 "
110+
"'-undef' but %select{precompiled file '%1' was not built with it|"
111111
"it is not present on the command line}0">;
112112
def err_ast_file_pp_detailed_record : Error<
113-
"%select{command line contains|AST file '%1' was built with}0 "
114-
"'-detailed-preprocessing-record' but %select{AST file '%1' was not "
113+
"%select{command line contains|precompiled file '%1' was built with}0 "
114+
"'-detailed-preprocessing-record' but %select{precompiled file '%1' was not "
115115
"built with it|it is not present on the command line}0">;
116116

117117
def err_module_odr_violation_missing_decl : Error<

clang/include/clang/Sema/Sema.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,13 @@ class Sema final : public SemaBase {
972972
/// Calls \c Lexer::getLocForEndOfToken()
973973
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset = 0);
974974

975+
/// Calls \c Lexer::findNextToken() to find the next token, and if the
976+
/// locations of both ends of the token can be resolved it return that
977+
/// range; Otherwise it returns an invalid SourceRange.
978+
SourceRange getRangeForNextToken(
979+
SourceLocation Loc, bool IncludeMacros, bool IncludeComments,
980+
std::optional<tok::TokenKind> ExpectedToken = std::nullopt);
981+
975982
/// Retrieve the module loader associated with the preprocessor.
976983
ModuleLoader &getModuleLoader() const;
977984

@@ -9134,6 +9141,7 @@ class Sema final : public SemaBase {
91349141
/// Diagnose if an explicit lambda capture is unused. Returns true if a
91359142
/// diagnostic is emitted.
91369143
bool DiagnoseUnusedLambdaCapture(SourceRange CaptureRange,
9144+
SourceRange FixItRange,
91379145
const sema::Capture &From);
91389146

91399147
/// Build a FieldDecl suitable to hold the given capture.

clang/lib/AST/ByteCode/Context.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ using namespace clang;
2222
using namespace clang::interp;
2323

2424
Context::Context(ASTContext &Ctx) : Ctx(Ctx), P(new Program(*this)) {
25+
this->ShortWidth = Ctx.getTargetInfo().getShortWidth();
2526
this->IntWidth = Ctx.getTargetInfo().getIntWidth();
2627
this->LongWidth = Ctx.getTargetInfo().getLongWidth();
28+
this->LongLongWidth = Ctx.getTargetInfo().getLongLongWidth();
2729
assert(Ctx.getTargetInfo().getCharWidth() == 8 &&
2830
"We're assuming 8 bit chars");
2931
}
@@ -265,6 +267,11 @@ std::optional<PrimType> Context::classify(QualType T) const {
265267
return PT_MemberPtr;
266268

267269
// Just trying to avoid the ASTContext::getIntWidth call below.
270+
if (Kind == BuiltinType::Short)
271+
return integralTypeToPrimTypeS(this->ShortWidth);
272+
if (Kind == BuiltinType::UShort)
273+
return integralTypeToPrimTypeU(this->ShortWidth);
274+
268275
if (Kind == BuiltinType::Int)
269276
return integralTypeToPrimTypeS(this->IntWidth);
270277
if (Kind == BuiltinType::UInt)
@@ -273,6 +280,11 @@ std::optional<PrimType> Context::classify(QualType T) const {
273280
return integralTypeToPrimTypeS(this->LongWidth);
274281
if (Kind == BuiltinType::ULong)
275282
return integralTypeToPrimTypeU(this->LongWidth);
283+
if (Kind == BuiltinType::LongLong)
284+
return integralTypeToPrimTypeS(this->LongLongWidth);
285+
if (Kind == BuiltinType::ULongLong)
286+
return integralTypeToPrimTypeU(this->LongLongWidth);
287+
276288
if (Kind == BuiltinType::SChar || Kind == BuiltinType::Char_S)
277289
return integralTypeToPrimTypeS(8);
278290
if (Kind == BuiltinType::UChar || Kind == BuiltinType::Char_U ||

0 commit comments

Comments
 (0)