Skip to content

Commit df731e3

Browse files
authored
Merge branch 'llvm:main' into renaming-bug-reports
2 parents 7984719 + fe4f6c1 commit df731e3

File tree

64 files changed

+1212
-225
lines changed

Some content is hidden

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

64 files changed

+1212
-225
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ Bug Fixes to Compiler Builtins
139139
Bug Fixes to Attribute Support
140140
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
141141

142+
- ``[[nodiscard]]`` is now respected on Objective-C and Objective-C++ methods.
143+
(#GH141504)
144+
142145
Bug Fixes to C++ Support
143146
^^^^^^^^^^^^^^^^^^^^^^^^
144147
- Diagnose binding a reference to ``*nullptr`` during constant evaluation. (#GH48665)

clang/include/clang/AST/Expr.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "clang/AST/APNumericStorage.h"
1717
#include "clang/AST/APValue.h"
1818
#include "clang/AST/ASTVector.h"
19+
#include "clang/AST/Attr.h"
1920
#include "clang/AST/ComputeDependence.h"
2021
#include "clang/AST/Decl.h"
2122
#include "clang/AST/DeclAccessPair.h"
@@ -262,6 +263,12 @@ class Expr : public ValueStmt {
262263
SourceRange &R1, SourceRange &R2,
263264
ASTContext &Ctx) const;
264265

266+
/// Returns the WarnUnusedResultAttr that is declared on the callee
267+
/// or its return type declaration, together with a NamedDecl that
268+
/// refers to the declaration the attribute is attached to.
269+
static std::pair<const NamedDecl *, const WarnUnusedResultAttr *>
270+
getUnusedResultAttrImpl(const Decl *Callee, QualType ReturnType);
271+
265272
/// isLValue - True if this expression is an "l-value" according to
266273
/// the rules of the current language. C and C++ give somewhat
267274
/// different rules for this concept, but in general, the result of
@@ -3190,11 +3197,13 @@ class CallExpr : public Expr {
31903197
/// type.
31913198
QualType getCallReturnType(const ASTContext &Ctx) const;
31923199

3193-
/// Returns the WarnUnusedResultAttr that is either declared on the called
3194-
/// function, or its return type declaration, together with a NamedDecl that
3195-
/// refers to the declaration the attribute is attached onto.
3196-
std::pair<const NamedDecl *, const Attr *>
3197-
getUnusedResultAttr(const ASTContext &Ctx) const;
3200+
/// Returns the WarnUnusedResultAttr that is declared on the callee
3201+
/// or its return type declaration, together with a NamedDecl that
3202+
/// refers to the declaration the attribute is attached to.
3203+
std::pair<const NamedDecl *, const WarnUnusedResultAttr *>
3204+
getUnusedResultAttr(const ASTContext &Ctx) const {
3205+
return getUnusedResultAttrImpl(getCalleeDecl(), getCallReturnType(Ctx));
3206+
}
31983207

31993208
/// Returns true if this call expression should warn on unused results.
32003209
bool hasUnusedResultAttr(const ASTContext &Ctx) const {

clang/include/clang/AST/ExprObjC.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_CLANG_AST_EXPROBJC_H
1414
#define LLVM_CLANG_AST_EXPROBJC_H
1515

16+
#include "clang/AST/Attr.h"
1617
#include "clang/AST/ComputeDependence.h"
1718
#include "clang/AST/Decl.h"
1819
#include "clang/AST/DeclObjC.h"
@@ -1234,6 +1235,19 @@ class ObjCMessageExpr final
12341235
/// of `instancetype` (in that case it's an expression type).
12351236
QualType getCallReturnType(ASTContext &Ctx) const;
12361237

1238+
/// Returns the WarnUnusedResultAttr that is declared on the callee
1239+
/// or its return type declaration, together with a NamedDecl that
1240+
/// refers to the declaration the attribute is attached to.
1241+
std::pair<const NamedDecl *, const WarnUnusedResultAttr *>
1242+
getUnusedResultAttr(ASTContext &Ctx) const {
1243+
return getUnusedResultAttrImpl(getMethodDecl(), getCallReturnType(Ctx));
1244+
}
1245+
1246+
/// Returns true if this message send should warn on unused results.
1247+
bool hasUnusedResultAttr(ASTContext &Ctx) const {
1248+
return getUnusedResultAttr(Ctx).second != nullptr;
1249+
}
1250+
12371251
/// Source range of the receiver.
12381252
SourceRange getReceiverRange() const;
12391253

clang/include/clang/Driver/Options.td

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,21 +2320,21 @@ def fsymbol_partition_EQ : Joined<["-"], "fsymbol-partition=">, Group<f_Group>,
23202320

23212321
defm atomic_remote_memory : BoolFOption<"atomic-remote-memory",
23222322
LangOpts<"AtomicRemoteMemory">, DefaultFalse,
2323-
PosFlag<SetTrue, [], [ClangOption, CC1Option], "May have">,
2324-
NegFlag<SetFalse, [], [ClangOption], "Assume no">,
2325-
BothFlags<[], [ClangOption], " atomic operations on remote memory">>;
2323+
PosFlag<SetTrue, [], [ClangOption, CC1Option, FlangOption, FC1Option], "May have">,
2324+
NegFlag<SetFalse, [], [ClangOption, FlangOption], "Assume no">,
2325+
BothFlags<[], [ClangOption, FlangOption], " atomic operations on remote memory">>;
23262326

23272327
defm atomic_fine_grained_memory : BoolFOption<"atomic-fine-grained-memory",
23282328
LangOpts<"AtomicFineGrainedMemory">, DefaultFalse,
2329-
PosFlag<SetTrue, [], [ClangOption, CC1Option], "May have">,
2330-
NegFlag<SetFalse, [], [ClangOption], "Assume no">,
2331-
BothFlags<[], [ClangOption], " atomic operations on fine-grained memory">>;
2329+
PosFlag<SetTrue, [], [ClangOption, CC1Option, FlangOption, FC1Option], "May have">,
2330+
NegFlag<SetFalse, [], [ClangOption, FlangOption], "Assume no">,
2331+
BothFlags<[], [ClangOption, FlangOption], " atomic operations on fine-grained memory">>;
23322332

23332333
defm atomic_ignore_denormal_mode : BoolFOption<"atomic-ignore-denormal-mode",
23342334
LangOpts<"AtomicIgnoreDenormalMode">, DefaultFalse,
2335-
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Allow">,
2336-
NegFlag<SetFalse, [], [ClangOption], "Disallow">,
2337-
BothFlags<[], [ClangOption], " atomic operations to ignore denormal mode">>;
2335+
PosFlag<SetTrue, [], [ClangOption, CC1Option, FlangOption, FC1Option], "Allow">,
2336+
NegFlag<SetFalse, [], [ClangOption, FlangOption], "Disallow">,
2337+
BothFlags<[], [ClangOption, FlangOption], " atomic operations to ignore denormal mode">>;
23382338

23392339
defm memory_profile : OptInCC1FFlag<"memory-profile", "Enable", "Disable", " heap memory profiling">;
23402340
def fmemory_profile_EQ : Joined<["-"], "fmemory-profile=">,
@@ -5370,9 +5370,9 @@ defm amdgpu_precise_memory_op
53705370
" precise memory mode (AMDGPU only)">;
53715371

53725372
def munsafe_fp_atomics : Flag<["-"], "munsafe-fp-atomics">,
5373-
Visibility<[ClangOption, CC1Option]>, Alias<fatomic_ignore_denormal_mode>;
5373+
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, Alias<fatomic_ignore_denormal_mode>;
53745374
def mno_unsafe_fp_atomics : Flag<["-"], "mno-unsafe-fp-atomics">,
5375-
Visibility<[ClangOption]>, Alias<fno_atomic_ignore_denormal_mode>;
5375+
Visibility<[ClangOption, FlangOption]>, Alias<fno_atomic_ignore_denormal_mode>;
53765376

53775377
def faltivec : Flag<["-"], "faltivec">, Group<f_Group>;
53785378
def fno_altivec : Flag<["-"], "fno-altivec">, Group<f_Group>;

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,8 @@ bool Compiler<Emitter>::VisitPointerArithBinOp(const BinaryOperator *E) {
10221022
if (classifyPrim(E) != PT_Ptr)
10231023
return this->emitDecayPtr(PT_Ptr, classifyPrim(E), E);
10241024
return true;
1025-
} else if (Op == BO_Sub) {
1025+
}
1026+
if (Op == BO_Sub) {
10261027
if (!this->emitSubOffset(OffsetType, E))
10271028
return false;
10281029

@@ -3703,7 +3704,7 @@ bool Compiler<Emitter>::VisitBlockExpr(const BlockExpr *E) {
37033704
return true;
37043705

37053706
const Function *Func = nullptr;
3706-
if (auto F = Ctx.getOrCreateObjCBlock(E))
3707+
if (const Function *F = Ctx.getOrCreateObjCBlock(E))
37073708
Func = F;
37083709

37093710
if (!Func)
@@ -4288,7 +4289,8 @@ bool Compiler<Emitter>::visitZeroArrayInitializer(QualType T, const Expr *E) {
42884289
return false;
42894290
}
42904291
return true;
4291-
} else if (ElemType->isRecordType()) {
4292+
}
4293+
if (ElemType->isRecordType()) {
42924294
const Record *R = getRecord(ElemType);
42934295

42944296
for (size_t I = 0; I != NumElems; ++I) {
@@ -4302,7 +4304,8 @@ bool Compiler<Emitter>::visitZeroArrayInitializer(QualType T, const Expr *E) {
43024304
return false;
43034305
}
43044306
return true;
4305-
} else if (ElemType->isArrayType()) {
4307+
}
4308+
if (ElemType->isArrayType()) {
43064309
for (size_t I = 0; I != NumElems; ++I) {
43074310
if (!this->emitConstUint32(I, E))
43084311
return false;
@@ -4774,11 +4777,10 @@ VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD,
47744777
if (!this->visit(Init))
47754778
return false;
47764779
return this->emitSetLocal(*VarT, Offset, VD) && Scope.destroyLocals();
4777-
} else {
4780+
}
47784781
if (!this->visit(Init))
47794782
return false;
47804783
return this->emitSetLocal(*VarT, Offset, VD);
4781-
}
47824784
}
47834785
} else {
47844786
if (std::optional<unsigned> Offset = this->allocateLocal(
@@ -4805,7 +4807,7 @@ bool Compiler<Emitter>::visitAPValue(const APValue &Val, PrimType ValType,
48054807
assert(!DiscardResult);
48064808
if (Val.isInt())
48074809
return this->emitConst(Val.getInt(), ValType, E);
4808-
else if (Val.isFloat()) {
4810+
if (Val.isFloat()) {
48094811
APFloat F = Val.getFloat();
48104812
return this->emitFloat(F, E);
48114813
}
@@ -4816,9 +4818,8 @@ bool Compiler<Emitter>::visitAPValue(const APValue &Val, PrimType ValType,
48164818
APValue::LValueBase Base = Val.getLValueBase();
48174819
if (const Expr *BaseExpr = Base.dyn_cast<const Expr *>())
48184820
return this->visit(BaseExpr);
4819-
else if (const auto *VD = Base.dyn_cast<const ValueDecl *>()) {
4821+
if (const auto *VD = Base.dyn_cast<const ValueDecl *>())
48204822
return this->visitDeclRef(VD, E);
4821-
}
48224823
} else if (Val.isMemberPointer()) {
48234824
if (const ValueDecl *MemberDecl = Val.getMemberPointerDecl())
48244825
return this->emitGetMemberPtr(MemberDecl, E);
@@ -4854,7 +4855,8 @@ bool Compiler<Emitter>::visitAPValueInitializer(const APValue &Val,
48544855
}
48554856
}
48564857
return true;
4857-
} else if (Val.isUnion()) {
4858+
}
4859+
if (Val.isUnion()) {
48584860
const FieldDecl *UnionField = Val.getUnionField();
48594861
const Record *R = this->getRecord(UnionField->getParent());
48604862
assert(R);
@@ -4864,7 +4866,8 @@ bool Compiler<Emitter>::visitAPValueInitializer(const APValue &Val,
48644866
if (!this->visitAPValue(F, T, E))
48654867
return false;
48664868
return this->emitInitField(T, RF->Offset, E);
4867-
} else if (Val.isArray()) {
4869+
}
4870+
if (Val.isArray()) {
48684871
const auto *ArrType = T->getAsArrayTypeUnsafe();
48694872
QualType ElemType = ArrType->getElementType();
48704873
for (unsigned A = 0, AN = Val.getArraySize(); A != AN; ++A) {
@@ -4981,12 +4984,10 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
49814984

49824985
// Calls to replaceable operator new/operator delete.
49834986
if (FuncDecl->isUsableAsGlobalAllocationFunctionInConstantEvaluation()) {
4984-
if (FuncDecl->getDeclName().isAnyOperatorNew()) {
4987+
if (FuncDecl->getDeclName().isAnyOperatorNew())
49854988
return VisitBuiltinCallExpr(E, Builtin::BI__builtin_operator_new);
4986-
} else {
4987-
assert(FuncDecl->getDeclName().getCXXOverloadedOperator() == OO_Delete);
4988-
return VisitBuiltinCallExpr(E, Builtin::BI__builtin_operator_delete);
4989-
}
4989+
assert(FuncDecl->getDeclName().getCXXOverloadedOperator() == OO_Delete);
4990+
return VisitBuiltinCallExpr(E, Builtin::BI__builtin_operator_delete);
49904991
}
49914992

49924993
// Explicit calls to trivial destructors
@@ -5455,7 +5456,9 @@ bool Compiler<Emitter>::visitReturnStmt(const ReturnStmt *RS) {
54555456
return false;
54565457
this->emitCleanup();
54575458
return this->emitRet(*ReturnType, RS);
5458-
} else if (RE->getType()->isVoidType()) {
5459+
}
5460+
5461+
if (RE->getType()->isVoidType()) {
54595462
if (!this->visit(RE))
54605463
return false;
54615464
} else {
@@ -5500,7 +5503,7 @@ template <class Emitter> bool Compiler<Emitter>::visitIfStmt(const IfStmt *IS) {
55005503
if (std::optional<bool> BoolValue = getBoolValue(IS->getCond())) {
55015504
if (*BoolValue)
55025505
return visitChildStmt(IS->getThen());
5503-
else if (const Stmt *Else = IS->getElse())
5506+
if (const Stmt *Else = IS->getElse())
55045507
return visitChildStmt(Else);
55055508
return true;
55065509
}
@@ -5992,7 +5995,7 @@ bool Compiler<Emitter>::compileConstructor(const CXXConstructorDecl *Ctor) {
59925995
if (!this->emitThis(Ctor))
59935996
return false;
59945997

5995-
auto PVD = Ctor->getParamDecl(0);
5998+
const ParmVarDecl *PVD = Ctor->getParamDecl(0);
59965999
ParamOffset PO = this->Params[PVD]; // Must exist.
59976000

59986001
if (!this->emitGetParam(PT_Ptr, PO.Offset, Ctor))
@@ -6153,7 +6156,7 @@ bool Compiler<Emitter>::compileUnionAssignmentOperator(
61536156
if (!this->emitThis(MD))
61546157
return false;
61556158

6156-
auto PVD = MD->getParamDecl(0);
6159+
const ParmVarDecl *PVD = MD->getParamDecl(0);
61576160
ParamOffset PO = this->Params[PVD]; // Must exist.
61586161

61596162
if (!this->emitGetParam(PT_Ptr, PO.Offset, MD))

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ bool CheckInit(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
845845
return true;
846846
}
847847

848-
bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
848+
static bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
849849

850850
if (F->isVirtual() && !S.getLangOpts().CPlusPlus20) {
851851
const SourceLocation &Loc = S.Current->getLocation(OpPC);

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
240240
T CB = PB.deref<T>();
241241
if (CA > CB)
242242
return returnResult(1);
243-
else if (CA < CB)
243+
if (CA < CB)
244244
return returnResult(-1);
245-
else if (CA.isZero() || CB.isZero())
245+
if (CA.isZero() || CB.isZero())
246246
return returnResult(0);
247247
});
248248
continue;
@@ -253,7 +253,7 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
253253

254254
if (CA > CB)
255255
return returnResult(1);
256-
else if (CA < CB)
256+
if (CA < CB)
257257
return returnResult(-1);
258258
if (CA == 0 || CB == 0)
259259
return returnResult(0);
@@ -1048,7 +1048,7 @@ static bool interp__builtin_atomic_lock_free(InterpState &S, CodePtr OpPC,
10481048
PtrArg = ICE->getSubExpr();
10491049
}
10501050

1051-
if (auto PtrTy = PtrArg->getType()->getAs<PointerType>()) {
1051+
if (const auto *PtrTy = PtrArg->getType()->getAs<PointerType>()) {
10521052
QualType PointeeType = PtrTy->getPointeeType();
10531053
if (!PointeeType->isIncompleteType() &&
10541054
S.getASTContext().getTypeAlignInChars(PointeeType) >= Size) {
@@ -1967,7 +1967,8 @@ static bool interp__builtin_memcmp(InterpState &S, CodePtr OpPC,
19671967
if (A < B) {
19681968
pushInteger(S, -1, Call->getType());
19691969
return true;
1970-
} else if (A > B) {
1970+
}
1971+
if (A > B) {
19711972
pushInteger(S, 1, Call->getType());
19721973
return true;
19731974
}
@@ -1979,7 +1980,8 @@ static bool interp__builtin_memcmp(InterpState &S, CodePtr OpPC,
19791980
if (A < B) {
19801981
pushInteger(S, -1, Call->getType());
19811982
return true;
1982-
} else if (A > B) {
1983+
}
1984+
if (A > B) {
19831985
pushInteger(S, 1, Call->getType());
19841986
return true;
19851987
}

clang/lib/AST/ByteCode/InterpStack.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
#define LLVM_CLANG_AST_INTERP_INTERPSTACK_H
1515

1616
#include "FixedPoint.h"
17-
#include "FunctionPointer.h"
1817
#include "IntegralAP.h"
1918
#include "MemberPointer.h"
2019
#include "PrimType.h"
21-
#include <memory>
2220
#include <vector>
2321

2422
namespace clang {

clang/lib/AST/ByteCode/Pointer.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "MemberPointer.h"
1717
#include "PrimType.h"
1818
#include "Record.h"
19+
#include "clang/AST/Expr.h"
1920
#include "clang/AST/ExprCXX.h"
2021
#include "clang/AST/RecordLayout.h"
2122

@@ -66,14 +67,14 @@ Pointer::~Pointer() {
6667
}
6768
}
6869

69-
void Pointer::operator=(const Pointer &P) {
70+
Pointer &Pointer::operator=(const Pointer &P) {
7071
// If the current storage type is Block, we need to remove
7172
// this pointer from the block.
7273
if (isBlockPointer()) {
7374
if (P.isBlockPointer() && this->block() == P.block()) {
7475
Offset = P.Offset;
7576
PointeeStorage.BS.Base = P.PointeeStorage.BS.Base;
76-
return;
77+
return *this;
7778
}
7879

7980
if (Block *Pointee = PointeeStorage.BS.Pointee) {
@@ -101,16 +102,17 @@ void Pointer::operator=(const Pointer &P) {
101102
} else {
102103
assert(false && "Unhandled storage kind");
103104
}
105+
return *this;
104106
}
105107

106-
void Pointer::operator=(Pointer &&P) {
108+
Pointer &Pointer::operator=(Pointer &&P) {
107109
// If the current storage type is Block, we need to remove
108110
// this pointer from the block.
109111
if (isBlockPointer()) {
110112
if (P.isBlockPointer() && this->block() == P.block()) {
111113
Offset = P.Offset;
112114
PointeeStorage.BS.Base = P.PointeeStorage.BS.Base;
113-
return;
115+
return *this;
114116
}
115117

116118
if (Block *Pointee = PointeeStorage.BS.Pointee) {
@@ -138,6 +140,7 @@ void Pointer::operator=(Pointer &&P) {
138140
} else {
139141
assert(false && "Unhandled storage kind");
140142
}
143+
return *this;
141144
}
142145

143146
APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
@@ -603,7 +606,7 @@ bool Pointer::pointsToStringLiteral() const {
603606
return false;
604607

605608
const Expr *E = block()->getDescriptor()->asExpr();
606-
return E && isa<StringLiteral>(E);
609+
return isa_and_nonnull<StringLiteral>(E);
607610
}
608611

609612
std::optional<std::pair<Pointer, Pointer>>

0 commit comments

Comments
 (0)