Skip to content

Commit cfb38e4

Browse files
authored
Merge branch 'main' into powero2
2 parents 53177f3 + 0a85b31 commit cfb38e4

File tree

119 files changed

+5376
-1222
lines changed

Some content is hidden

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

119 files changed

+5376
-1222
lines changed

clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ on the control flow of the function, an overload where all problematic
4242

4343
This issue can also be resolved by adding ``[[clang::lifetimebound]]``. Clang
4444
enable ``-Wdangling`` warning by default which can detect mis-uses of the
45-
annotated function. See `lifetimebound attribute <https://clang.llvm.org/docs/AttributeReference.html#id11>`_
45+
annotated function. See `lifetimebound attribute <https://clang.llvm.org/docs/AttributeReference.html#lifetimebound>`_
4646
for details.
4747

4848
.. code-block:: c++

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@ Bug Fixes to C++ Support
830830
- Clang modules now allow a module and its user to differ on TrivialAutoVarInit*
831831
- Fixed an access checking bug when initializing non-aggregates in default arguments (#GH62444), (#GH83608)
832832
- Fixed a pack substitution bug in deducing class template partial specializations. (#GH53609)
833+
- Fixed a crash when constant evaluating some explicit object member assignment operators. (#GH142835)
833834

834835
Bug Fixes to AST Handling
835836
^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1049,7 +1050,7 @@ Sanitizers
10491050
----------
10501051

10511052
- ``-fsanitize=vptr`` is no longer a part of ``-fsanitize=undefined``.
1052-
- Sanitizer ignorelists now support the syntax ``src:*=sanitize``,
1053+
- Sanitizer ignorelists now support the syntax ``src:*=sanitize``,
10531054
``type:*=sanitize``, ``fun:*=sanitize``, ``global:*=sanitize``,
10541055
and ``mainfile:*=sanitize``.
10551056

clang/docs/UsersManual.rst

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,12 +2300,14 @@ are listed below.
23002300
.. option:: -f[no-]unique-source-file-names
23012301

23022302
When enabled, allows the compiler to assume that each object file
2303-
passed to the linker has been compiled using a unique source file
2304-
path. This is useful for reducing link times when doing ThinLTO
2305-
in combination with whole-program devirtualization or CFI.
2303+
passed to the linker has a unique identifier. The identifier for
2304+
an object file is either the source file path or the value of the
2305+
argument `-funique-source-file-identifier` if specified. This is
2306+
useful for reducing link times when doing ThinLTO in combination with
2307+
whole-program devirtualization or CFI.
23062308

2307-
The full source path passed to the compiler must be unique. This
2308-
means that, for example, the following is a usage error:
2309+
The full source path or identifier passed to the compiler must be
2310+
unique. This means that, for example, the following is a usage error:
23092311

23102312
.. code-block:: console
23112313
@@ -2327,6 +2329,11 @@ are listed below.
23272329
A misuse of this flag may result in a duplicate symbol error at
23282330
link time.
23292331

2332+
.. option:: -funique-source-file-identifier=IDENTIFIER
2333+
2334+
Used with `-funique-source-file-names` to specify a source file
2335+
identifier.
2336+
23302337
.. option:: -fforce-emit-vtables
23312338

23322339
In order to improve devirtualization, forces emitting of vtables even in

clang/include/clang/Basic/AttrDocs.td

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4396,8 +4396,6 @@ annotated parameter.
43964396
addToSet(str, s); // Not detected.
43974397
}
43984398
}
4399-
4400-
.. _`lifetimebound`: https://clang.llvm.org/docs/AttributeReference.html#lifetimebound
44014399
}];
44024400
}
44034401

@@ -9042,14 +9040,14 @@ def CoroLifetimeBoundDoc : Documentation {
90429040
let Category = DocCatDecl;
90439041
let Content = [{
90449042
The ``[[clang::coro_lifetimebound]]`` is a class attribute which can be applied
9045-
to a coroutine return type (`CRT`_) (i.e.
9043+
to a coroutine return type (`coro_return_type, coro_wrapper`_) (i.e.
90469044
it should also be annotated with ``[[clang::coro_return_type]]``).
90479045

90489046
All parameters of a function are considered to be lifetime bound if the function returns a
90499047
coroutine return type (CRT) annotated with ``[[clang::coro_lifetimebound]]``.
90509048
This lifetime bound analysis can be disabled for a coroutine wrapper or a coroutine by annotating the function
90519049
with ``[[clang::coro_disable_lifetimebound]]`` function attribute .
9052-
See `documentation`_ of ``[[clang::lifetimebound]]`` for details about lifetime bound analysis.
9050+
See documentation of `lifetimebound`_ for details about lifetime bound analysis.
90539051

90549052

90559053
Reference parameters of a coroutine are susceptible to capturing references to temporaries or local variables.
@@ -9109,9 +9107,6 @@ but do not pass them to the underlying coroutine or pass them by value.
91099107
void use() {
91109108
auto task = coro_wrapper(1); // use of temporary is fine as the argument is not lifetime bound.
91119109
}
9112-
9113-
.. _`documentation`: https://clang.llvm.org/docs/AttributeReference.html#lifetimebound
9114-
.. _`CRT`: https://clang.llvm.org/docs/AttributeReference.html#coro-return-type
91159110
}];
91169111
}
91179112

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,6 @@ CODEGENOPT(SanitizeCfiICallNormalizeIntegers, 1, 0) ///< Normalize integer types
278278
///< CFI icall function signatures
279279
CODEGENOPT(SanitizeCfiCanonicalJumpTables, 1, 0) ///< Make jump table symbols canonical
280280
///< instead of creating a local jump table.
281-
CODEGENOPT(UniqueSourceFileNames, 1, 0) ///< Allow the compiler to assume that TUs
282-
///< have unique source file names at link time
283281
CODEGENOPT(SanitizeKcfiArity, 1, 0) ///< Embed arity in KCFI patchable function prefix
284282
CODEGENOPT(SanitizeCoverageType, 2, 0) ///< Type of sanitizer coverage
285283
///< instrumentation.

clang/include/clang/Basic/CodeGenOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
338338
/// -fsymbol-partition (see https://lld.llvm.org/Partitions.html).
339339
std::string SymbolPartition;
340340

341+
/// If non-empty, allow the compiler to assume that the given source file
342+
/// identifier is unique at link time.
343+
std::string UniqueSourceFileIdentifier;
344+
341345
enum RemarkKind {
342346
RK_Missing, // Remark argument not present on the command line.
343347
RK_Enabled, // Remark enabled via '-Rgroup'.

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ def err_drv_cannot_open_randomize_layout_seed_file : Error<
206206
"cannot read randomize layout seed file '%0'">;
207207
def err_drv_invalid_version_number : Error<
208208
"invalid version number in '%0'">;
209+
def err_drv_missing_version_number : Error<"missing version number in '%0'">;
209210
def err_drv_kcfi_arity_unsupported_target : Error<
210211
"target '%0' is unsupported by -fsanitize-kcfi-arity">;
211212
def err_drv_no_linker_llvm_support : Error<
@@ -478,6 +479,9 @@ def warn_ignoring_ftabstop_value : Warning<
478479
def warn_drv_overriding_option : Warning<
479480
"overriding '%0' option with '%1'">,
480481
InGroup<DiagGroup<"overriding-option">>;
482+
def warn_drv_overriding_deployment_version
483+
: Warning<"overriding deployment version from '%0' to '%1'">,
484+
InGroup<DiagGroup<"overriding-deployment-version">>;
481485
def warn_drv_treating_input_as_cxx : Warning<
482486
"treating '%0' input as '%1' when in C++ mode, this behavior is deprecated">,
483487
InGroup<Deprecated>;

clang/include/clang/CIR/Dialect/IR/CIRTypes.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,18 @@ def CIR_RecordType : CIR_Type<"Record", "record",
474474
let genVerifyDecl = 1;
475475

476476
let builders = [
477+
// Create an identified and complete record type.
478+
TypeBuilder<(ins
479+
"llvm::ArrayRef<mlir::Type>":$members,
480+
"mlir::StringAttr":$name,
481+
"bool":$packed,
482+
"bool":$padded,
483+
"RecordKind":$kind
484+
), [{
485+
return $_get($_ctxt, members, name, /*complete=*/true, packed, padded,
486+
kind);
487+
}]>,
488+
477489
// Create an identified and incomplete record type.
478490
TypeBuilder<(ins
479491
"mlir::StringAttr":$name,

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ struct MissingFeatures {
136136
static bool cxxSupport() { return false; }
137137
static bool recordZeroInit() { return false; }
138138
static bool zeroSizeRecordMembers() { return false; }
139+
static bool recordLayoutVirtualBases() { return false; }
139140

140141
// Various handling of deferred processing in CIRGenModule.
141142
static bool cgmRelease() { return false; }

clang/include/clang/Driver/Options.td

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4204,13 +4204,15 @@ def ftrigraphs : Flag<["-"], "ftrigraphs">, Group<f_Group>,
42044204
def fno_trigraphs : Flag<["-"], "fno-trigraphs">, Group<f_Group>,
42054205
HelpText<"Do not process trigraph sequences">,
42064206
Visibility<[ClangOption, CC1Option]>;
4207-
defm unique_source_file_names: BoolOption<"f", "unique-source-file-names",
4208-
CodeGenOpts<"UniqueSourceFileNames">, DefaultFalse,
4209-
PosFlag<SetTrue, [], [CC1Option], "Allow">,
4210-
NegFlag<SetFalse, [], [], "Do not allow">,
4211-
BothFlags<[], [ClangOption], " the compiler to assume that each translation unit has a unique "
4212-
"source file name at link time">>,
4213-
Group<f_clang_Group>;
4207+
def funique_source_file_names: Flag<["-"], "funique-source-file-names">, Group<f_Group>,
4208+
HelpText<"Allow the compiler to assume that each translation unit has a unique "
4209+
"source file identifier (see -funique-source-file-identifier) at link time">;
4210+
def fno_unique_source_file_names: Flag<["-"], "fno-unique-source-file-names">;
4211+
def unique_source_file_identifier_EQ: Joined<["-"], "funique-source-file-identifier=">, Group<f_Group>,
4212+
Visibility<[ClangOption, CC1Option]>,
4213+
HelpText<"Specify the source file identifier for -funique-source-file-names; "
4214+
"uses the source file path if not specified">,
4215+
MarshallingInfoString<CodeGenOpts<"UniqueSourceFileIdentifier">>;
42144216
def funsigned_bitfields : Flag<["-"], "funsigned-bitfields">, Group<f_Group>;
42154217
def funsigned_char : Flag<["-"], "funsigned-char">, Group<f_Group>;
42164218
def fno_unsigned_char : Flag<["-"], "fno-unsigned-char">;

clang/lib/AST/ExprConstant.cpp

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6549,8 +6549,8 @@ static bool MaybeHandleUnionActiveMemberChange(EvalInfo &Info,
65496549
}
65506550

65516551
static bool EvaluateCallArg(const ParmVarDecl *PVD, const Expr *Arg,
6552-
CallRef Call, EvalInfo &Info,
6553-
bool NonNull = false) {
6552+
CallRef Call, EvalInfo &Info, bool NonNull = false,
6553+
APValue **EvaluatedArg = nullptr) {
65546554
LValue LV;
65556555
// Create the parameter slot and register its destruction. For a vararg
65566556
// argument, create a temporary.
@@ -6570,13 +6570,17 @@ static bool EvaluateCallArg(const ParmVarDecl *PVD, const Expr *Arg,
65706570
return false;
65716571
}
65726572

6573+
if (EvaluatedArg)
6574+
*EvaluatedArg = &V;
6575+
65736576
return true;
65746577
}
65756578

65766579
/// Evaluate the arguments to a function call.
65776580
static bool EvaluateArgs(ArrayRef<const Expr *> Args, CallRef Call,
65786581
EvalInfo &Info, const FunctionDecl *Callee,
6579-
bool RightToLeft = false) {
6582+
bool RightToLeft = false,
6583+
LValue *ObjectArg = nullptr) {
65806584
bool Success = true;
65816585
llvm::SmallBitVector ForbiddenNullArgs;
65826586
if (Callee->hasAttr<NonNullAttr>()) {
@@ -6599,13 +6603,16 @@ static bool EvaluateArgs(ArrayRef<const Expr *> Args, CallRef Call,
65996603
const ParmVarDecl *PVD =
66006604
Idx < Callee->getNumParams() ? Callee->getParamDecl(Idx) : nullptr;
66016605
bool NonNull = !ForbiddenNullArgs.empty() && ForbiddenNullArgs[Idx];
6602-
if (!EvaluateCallArg(PVD, Args[Idx], Call, Info, NonNull)) {
6606+
APValue *That = nullptr;
6607+
if (!EvaluateCallArg(PVD, Args[Idx], Call, Info, NonNull, &That)) {
66036608
// If we're checking for a potential constant expression, evaluate all
66046609
// initializers even if some of them fail.
66056610
if (!Info.noteFailure())
66066611
return false;
66076612
Success = false;
66086613
}
6614+
if (PVD && PVD->isExplicitObjectParameter() && That && That->isLValue())
6615+
ObjectArg->setFrom(Info.Ctx, *That);
66096616
}
66106617
return Success;
66116618
}
@@ -6633,14 +6640,15 @@ static bool handleTrivialCopy(EvalInfo &Info, const ParmVarDecl *Param,
66336640

66346641
/// Evaluate a function call.
66356642
static bool HandleFunctionCall(SourceLocation CallLoc,
6636-
const FunctionDecl *Callee, const LValue *This,
6637-
const Expr *E, ArrayRef<const Expr *> Args,
6638-
CallRef Call, const Stmt *Body, EvalInfo &Info,
6643+
const FunctionDecl *Callee,
6644+
const LValue *ObjectArg, const Expr *E,
6645+
ArrayRef<const Expr *> Args, CallRef Call,
6646+
const Stmt *Body, EvalInfo &Info,
66396647
APValue &Result, const LValue *ResultSlot) {
66406648
if (!Info.CheckCallLimit(CallLoc))
66416649
return false;
66426650

6643-
CallStackFrame Frame(Info, E->getSourceRange(), Callee, This, E, Call);
6651+
CallStackFrame Frame(Info, E->getSourceRange(), Callee, ObjectArg, E, Call);
66446652

66456653
// For a trivial copy or move assignment, perform an APValue copy. This is
66466654
// essential for unions, where the operations performed by the assignment
@@ -6653,16 +6661,20 @@ static bool HandleFunctionCall(SourceLocation CallLoc,
66536661
(MD->getParent()->isUnion() ||
66546662
(MD->isTrivial() &&
66556663
isReadByLvalueToRvalueConversion(MD->getParent())))) {
6656-
assert(This &&
6664+
unsigned ExplicitOffset = MD->isExplicitObjectMemberFunction() ? 1 : 0;
6665+
assert(ObjectArg &&
66576666
(MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator()));
66586667
APValue RHSValue;
66596668
if (!handleTrivialCopy(Info, MD->getParamDecl(0), Args[0], RHSValue,
66606669
MD->getParent()->isUnion()))
66616670
return false;
6662-
if (!handleAssignment(Info, Args[0], *This, MD->getThisType(),
6671+
6672+
LValue Obj;
6673+
if (!handleAssignment(Info, Args[ExplicitOffset], *ObjectArg,
6674+
MD->getFunctionObjectParameterReferenceType(),
66636675
RHSValue))
66646676
return false;
6665-
This->moveInto(Result);
6677+
ObjectArg->moveInto(Result);
66666678
return true;
66676679
} else if (MD && isLambdaCallOperator(MD)) {
66686680
// We're in a lambda; determine the lambda capture field maps unless we're
@@ -8289,7 +8301,7 @@ class ExprEvaluatorBase
82898301
QualType CalleeType = Callee->getType();
82908302

82918303
const FunctionDecl *FD = nullptr;
8292-
LValue *This = nullptr, ThisVal;
8304+
LValue *This = nullptr, ObjectArg;
82938305
auto Args = llvm::ArrayRef(E->getArgs(), E->getNumArgs());
82948306
bool HasQualifier = false;
82958307

@@ -8300,28 +8312,28 @@ class ExprEvaluatorBase
83008312
const CXXMethodDecl *Member = nullptr;
83018313
if (const MemberExpr *ME = dyn_cast<MemberExpr>(Callee)) {
83028314
// Explicit bound member calls, such as x.f() or p->g();
8303-
if (!EvaluateObjectArgument(Info, ME->getBase(), ThisVal))
8315+
if (!EvaluateObjectArgument(Info, ME->getBase(), ObjectArg))
83048316
return false;
83058317
Member = dyn_cast<CXXMethodDecl>(ME->getMemberDecl());
83068318
if (!Member)
83078319
return Error(Callee);
8308-
This = &ThisVal;
8320+
This = &ObjectArg;
83098321
HasQualifier = ME->hasQualifier();
83108322
} else if (const BinaryOperator *BE = dyn_cast<BinaryOperator>(Callee)) {
83118323
// Indirect bound member calls ('.*' or '->*').
83128324
const ValueDecl *D =
8313-
HandleMemberPointerAccess(Info, BE, ThisVal, false);
8325+
HandleMemberPointerAccess(Info, BE, ObjectArg, false);
83148326
if (!D)
83158327
return false;
83168328
Member = dyn_cast<CXXMethodDecl>(D);
83178329
if (!Member)
83188330
return Error(Callee);
8319-
This = &ThisVal;
8331+
This = &ObjectArg;
83208332
} else if (const auto *PDE = dyn_cast<CXXPseudoDestructorExpr>(Callee)) {
83218333
if (!Info.getLangOpts().CPlusPlus20)
83228334
Info.CCEDiag(PDE, diag::note_constexpr_pseudo_destructor);
8323-
return EvaluateObjectArgument(Info, PDE->getBase(), ThisVal) &&
8324-
HandleDestruction(Info, PDE, ThisVal, PDE->getDestroyedType());
8335+
return EvaluateObjectArgument(Info, PDE->getBase(), ObjectArg) &&
8336+
HandleDestruction(Info, PDE, ObjectArg, PDE->getDestroyedType());
83258337
} else
83268338
return Error(Callee);
83278339
FD = Member;
@@ -8358,7 +8370,7 @@ class ExprEvaluatorBase
83588370
if (const auto *MD = dyn_cast<CXXMethodDecl>(FD))
83598371
HasThis = MD->isImplicitObjectMemberFunction();
83608372
if (!EvaluateArgs(HasThis ? Args.slice(1) : Args, Call, Info, FD,
8361-
/*RightToLeft=*/true))
8373+
/*RightToLeft=*/true, &ObjectArg))
83628374
return false;
83638375
}
83648376

@@ -8373,20 +8385,20 @@ class ExprEvaluatorBase
83738385
if (Args.empty())
83748386
return Error(E);
83758387

8376-
if (!EvaluateObjectArgument(Info, Args[0], ThisVal))
8388+
if (!EvaluateObjectArgument(Info, Args[0], ObjectArg))
83778389
return false;
83788390

83798391
// If we are calling a static operator, the 'this' argument needs to be
83808392
// ignored after being evaluated.
83818393
if (MD->isInstance())
8382-
This = &ThisVal;
8394+
This = &ObjectArg;
83838395

83848396
// If this is syntactically a simple assignment using a trivial
83858397
// assignment operator, start the lifetimes of union members as needed,
83868398
// per C++20 [class.union]5.
83878399
if (Info.getLangOpts().CPlusPlus20 && OCE &&
83888400
OCE->getOperator() == OO_Equal && MD->isTrivial() &&
8389-
!MaybeHandleUnionActiveMemberChange(Info, Args[0], ThisVal))
8401+
!MaybeHandleUnionActiveMemberChange(Info, Args[0], ObjectArg))
83908402
return false;
83918403

83928404
Args = Args.slice(1);
@@ -8441,7 +8453,8 @@ class ExprEvaluatorBase
84418453
// Evaluate the arguments now if we've not already done so.
84428454
if (!Call) {
84438455
Call = Info.CurrentCall->createCall(FD);
8444-
if (!EvaluateArgs(Args, Call, Info, FD))
8456+
if (!EvaluateArgs(Args, Call, Info, FD, /*RightToLeft*/ false,
8457+
&ObjectArg))
84458458
return false;
84468459
}
84478460

@@ -8475,6 +8488,11 @@ class ExprEvaluatorBase
84758488
Stmt *Body = FD->getBody(Definition);
84768489
SourceLocation Loc = E->getExprLoc();
84778490

8491+
// Treat the object argument as `this` when evaluating defaulted
8492+
// special menmber functions
8493+
if (FD->hasCXXExplicitFunctionObjectParameter())
8494+
This = &ObjectArg;
8495+
84788496
if (!CheckConstexprFunction(Info, Loc, FD, Definition, Body) ||
84798497
!HandleFunctionCall(Loc, Definition, This, E, Args, Call, Body, Info,
84808498
Result, ResultSlot))

0 commit comments

Comments
 (0)