Skip to content

Commit 37b5ebc

Browse files
authored
Merge branch 'main' into hxie/product_iterator
2 parents 61f498a + 532facc commit 37b5ebc

File tree

84 files changed

+1034
-1177
lines changed

Some content is hidden

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

84 files changed

+1034
-1177
lines changed

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ class MCPlusBuilder {
405405

406406
bool equals(const MCExpr &A, const MCExpr &B, CompFuncTy Comp) const;
407407

408-
virtual bool equals(const MCTargetExpr &A, const MCTargetExpr &B,
408+
virtual bool equals(const MCSpecifierExpr &A, const MCSpecifierExpr &B,
409409
CompFuncTy Comp) const;
410410

411411
virtual bool isBranch(const MCInst &Inst) const {

bolt/lib/Core/HashUtilities.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ std::string hashExpr(BinaryContext &BC, const MCExpr &Expr) {
6767
.append(hashInteger(BinaryExpr.getOpcode()))
6868
.append(hashExpr(BC, *BinaryExpr.getRHS()));
6969
}
70+
case MCExpr::Specifier:
7071
case MCExpr::Target:
7172
return std::string();
7273
}

bolt/lib/Core/MCPlusBuilder.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,19 @@ bool MCPlusBuilder::equals(const MCExpr &A, const MCExpr &B,
114114
equals(*BinaryA.getRHS(), *BinaryB.getRHS(), Comp);
115115
}
116116

117-
case MCExpr::Target: {
118-
const auto &TargetExprA = cast<MCTargetExpr>(A);
119-
const auto &TargetExprB = cast<MCTargetExpr>(B);
117+
case MCExpr::Specifier: {
118+
const auto &TargetExprA = cast<MCSpecifierExpr>(A);
119+
const auto &TargetExprB = cast<MCSpecifierExpr>(B);
120120
return equals(TargetExprA, TargetExprB, Comp);
121121
}
122+
case MCExpr::Target:
123+
llvm_unreachable("Not implemented");
122124
}
123125

124126
llvm_unreachable("Invalid expression kind!");
125127
}
126128

127-
bool MCPlusBuilder::equals(const MCTargetExpr &A, const MCTargetExpr &B,
129+
bool MCPlusBuilder::equals(const MCSpecifierExpr &A, const MCSpecifierExpr &B,
128130
CompFuncTy Comp) const {
129131
llvm_unreachable("target-specific expressions are unsupported");
130132
}

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
177177
return true;
178178
}
179179

180-
bool equals(const MCTargetExpr &A, const MCTargetExpr &B,
180+
bool equals(const MCSpecifierExpr &A, const MCSpecifierExpr &B,
181181
CompFuncTy Comp) const override {
182182
const auto &AArch64ExprA = cast<AArch64MCExpr>(A);
183183
const auto &AArch64ExprB = cast<AArch64MCExpr>(B);

bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class RISCVMCPlusBuilder : public MCPlusBuilder {
3131
public:
3232
using MCPlusBuilder::MCPlusBuilder;
3333

34-
bool equals(const MCTargetExpr &A, const MCTargetExpr &B,
34+
bool equals(const MCSpecifierExpr &A, const MCSpecifierExpr &B,
3535
CompFuncTy Comp) const override {
3636
const auto &RISCVExprA = cast<RISCVMCExpr>(A);
3737
const auto &RISCVExprB = cast<RISCVMCExpr>(B);

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ AST_MATCHER(QualType, isPointerType) {
5757

5858
} // namespace
5959

60+
MultiLevelImplicitPointerConversionCheck::
61+
MultiLevelImplicitPointerConversionCheck(StringRef Name,
62+
ClangTidyContext *Context)
63+
: ClangTidyCheck(Name, Context), EnableInC(Options.get("EnableInC", true)) {
64+
}
65+
66+
void MultiLevelImplicitPointerConversionCheck::storeOptions(
67+
ClangTidyOptions::OptionMap &Opts) {
68+
Options.store(Opts, "EnableInC", EnableInC);
69+
}
70+
6071
void MultiLevelImplicitPointerConversionCheck::registerMatchers(
6172
MatchFinder *Finder) {
6273
Finder->addMatcher(

clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@ namespace clang::tidy::bugprone {
2121
class MultiLevelImplicitPointerConversionCheck : public ClangTidyCheck {
2222
public:
2323
MultiLevelImplicitPointerConversionCheck(StringRef Name,
24-
ClangTidyContext *Context)
25-
: ClangTidyCheck(Name, Context) {}
24+
ClangTidyContext *Context);
25+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
2626
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
2727
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
2828
std::optional<TraversalKind> getCheckTraversalKind() const override;
29+
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
30+
return EnableInC ? true : LangOpts.CPlusPlus;
31+
}
32+
33+
private:
34+
bool const EnableInC;
2935
};
3036

3137
} // namespace clang::tidy::bugprone

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ Changes in existing checks
159159
false positives on deleted constructors that cannot be used to construct
160160
objects, even if they have public or protected access.
161161

162+
- Added an option to :doc:`bugprone-multi-level-implicit-pointer-conversion
163+
<clang-tidy/checks/bugprone/multi-level-implicit-pointer-conversion>` to
164+
choose whether to enable the check in C code or not.
165+
162166
- Improved :doc:`bugprone-optional-value-conversion
163167
<clang-tidy/checks/bugprone/optional-value-conversion>` check to detect
164168
conversion in argument of ``std::make_optional``.

clang-tools-extra/docs/clang-tidy/checks/bugprone/multi-level-implicit-pointer-conversion.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,11 @@ Additionally, it is recommended that developers thoroughly check and verify the
4242
safety of the conversion before using an explicit cast. This extra level of
4343
caution can help catch potential issues early on in the development process,
4444
improving the overall reliability and maintainability of the code.
45+
46+
Options
47+
-------
48+
49+
.. option:: EnableInC
50+
51+
If `true`, enables the check in C code (it is always enabled in C++ code).
52+
Default is `true`.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %check_clang_tidy -check-suffixes=ENABLE-IN-C %s bugprone-multi-level-implicit-pointer-conversion %t -- -config="{CheckOptions: {bugprone-multi-level-implicit-pointer-conversion.EnableInC: true}}"
2+
// RUN: %check_clang_tidy -check-suffixes=DISABLE-IN-C %s bugprone-multi-level-implicit-pointer-conversion %t -- -config="{CheckOptions: {bugprone-multi-level-implicit-pointer-conversion.EnableInC: false}}"
3+
4+
void free(void*);
5+
6+
void test() {
7+
char **p;
8+
free(p);
9+
// CHECK-MESSAGES-ENABLE-IN-C: :[[@LINE-1]]:8: warning: multilevel pointer conversion from 'char **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
10+
free((void *)p);
11+
}

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ Bug Fixes to AST Handling
842842
- Fixed type checking when a statement expression ends in an l-value of atomic type. (#GH106576)
843843
- Fixed uninitialized use check in a lambda within CXXOperatorCallExpr. (#GH129198)
844844
- Fixed a malformed printout of ``CXXParenListInitExpr`` in certain contexts.
845+
- Fixed a malformed printout of certain calling convention function attributes. (#GH143160)
845846

846847
Miscellaneous Bug Fixes
847848
^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/AST/ExprConcepts.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -514,10 +514,6 @@ class RequiresExpr final : public Expr,
514514
return NumLocalParameters;
515515
}
516516

517-
unsigned numTrailingObjects(OverloadToken<concepts::Requirement *>) const {
518-
return NumRequirements;
519-
}
520-
521517
RequiresExpr(ASTContext &C, SourceLocation RequiresKWLoc,
522518
RequiresExprBodyDecl *Body, SourceLocation LParenLoc,
523519
ArrayRef<ParmVarDecl *> LocalParameters,
@@ -540,13 +536,13 @@ class RequiresExpr final : public Expr,
540536
unsigned NumRequirements);
541537

542538
ArrayRef<ParmVarDecl *> getLocalParameters() const {
543-
return {getTrailingObjects<ParmVarDecl *>(), NumLocalParameters};
539+
return getTrailingObjects<ParmVarDecl *>(NumLocalParameters);
544540
}
545541

546542
RequiresExprBodyDecl *getBody() const { return Body; }
547543

548544
ArrayRef<concepts::Requirement *> getRequirements() const {
549-
return {getTrailingObjects<concepts::Requirement *>(), NumRequirements};
545+
return getTrailingObjects<concepts::Requirement *>(NumRequirements);
550546
}
551547

552548
/// \brief Whether or not the requires clause is satisfied.

clang/include/clang/AST/ExprObjC.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,10 @@ class ObjCArrayLiteral final
217217
SourceRange getSourceRange() const LLVM_READONLY { return Range; }
218218

219219
/// Retrieve elements of array of literals.
220-
Expr **getElements() { return getTrailingObjects<Expr *>(); }
220+
Expr **getElements() { return getTrailingObjects(); }
221221

222222
/// Retrieve elements of array of literals.
223-
const Expr * const *getElements() const {
224-
return getTrailingObjects<Expr *>();
225-
}
223+
const Expr *const *getElements() const { return getTrailingObjects(); }
226224

227225
/// getNumElements - Return number of elements of objective-c array literal.
228226
unsigned getNumElements() const { return NumElements; }

clang/include/clang/AST/StmtCXX.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ class CXXTryStmt final : public Stmt,
8080
CXXTryStmt(EmptyShell Empty, unsigned numHandlers)
8181
: Stmt(CXXTryStmtClass), NumHandlers(numHandlers) { }
8282

83-
Stmt *const *getStmts() const { return getTrailingObjects<Stmt *>(); }
84-
Stmt **getStmts() { return getTrailingObjects<Stmt *>(); }
83+
Stmt *const *getStmts() const { return getTrailingObjects(); }
84+
Stmt **getStmts() { return getTrailingObjects(); }
8585

8686
public:
8787
static CXXTryStmt *Create(const ASTContext &C, SourceLocation tryLoc,
@@ -339,9 +339,9 @@ class CoroutineBodyStmt final
339339
friend class ASTReader;
340340
friend TrailingObjects;
341341

342-
Stmt **getStoredStmts() { return getTrailingObjects<Stmt *>(); }
342+
Stmt **getStoredStmts() { return getTrailingObjects(); }
343343

344-
Stmt *const *getStoredStmts() const { return getTrailingObjects<Stmt *>(); }
344+
Stmt *const *getStoredStmts() const { return getTrailingObjects(); }
345345

346346
public:
347347

clang/include/clang/AST/StmtObjC.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ class ObjCAtTryStmt final
166166
: public Stmt,
167167
private llvm::TrailingObjects<ObjCAtTryStmt, Stmt *> {
168168
friend TrailingObjects;
169-
size_t numTrailingObjects(OverloadToken<Stmt *>) const {
169+
170+
size_t numTrailingStatements() const {
170171
return 1 + NumCatchStmts + HasFinally;
171172
}
172173

@@ -185,8 +186,8 @@ class ObjCAtTryStmt final
185186
/// The order of the statements in memory follows the order in the source,
186187
/// with the \@try body first, followed by the \@catch statements (if any)
187188
/// and, finally, the \@finally (if it exists).
188-
Stmt **getStmts() { return getTrailingObjects<Stmt *>(); }
189-
Stmt *const *getStmts() const { return getTrailingObjects<Stmt *>(); }
189+
Stmt **getStmts() { return getTrailingObjects(); }
190+
Stmt *const *getStmts() const { return getTrailingObjects(); }
190191

191192
ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt,
192193
Stmt **CatchStmts, unsigned NumCatchStmts,
@@ -262,8 +263,7 @@ class ObjCAtTryStmt final
262263
}
263264

264265
child_range children() {
265-
return child_range(
266-
getStmts(), getStmts() + numTrailingObjects(OverloadToken<Stmt *>()));
266+
return child_range(getStmts(), getStmts() + numTrailingStatements());
267267
}
268268

269269
const_child_range children() const {

clang/include/clang/Sema/ParsedAttr.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,6 @@ class ParsedAttr final
130130
size_t numTrailingObjects(OverloadToken<ParsedType>) const {
131131
return HasParsedType;
132132
}
133-
size_t numTrailingObjects(OverloadToken<detail::PropertyData>) const {
134-
return IsProperty;
135-
}
136133

137134
private:
138135
IdentifierInfo *MacroII = nullptr;

clang/include/clang/Sema/ParsedTemplate.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,7 @@ namespace clang {
190190
bool ArgsInvalid;
191191

192192
/// Retrieves a pointer to the template arguments
193-
ParsedTemplateArgument *getTemplateArgs() {
194-
return getTrailingObjects<ParsedTemplateArgument>();
195-
}
193+
ParsedTemplateArgument *getTemplateArgs() { return getTrailingObjects(); }
196194

197195
/// Creates a new TemplateIdAnnotation with NumArgs arguments and
198196
/// appends it to List.

clang/lib/AST/TypePrinter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,13 +1095,13 @@ void TypePrinter::printFunctionAfter(const FunctionType::ExtInfo &Info,
10951095
OS << " __attribute__((pcs(\"aapcs-vfp\")))";
10961096
break;
10971097
case CC_AArch64VectorCall:
1098-
OS << "__attribute__((aarch64_vector_pcs))";
1098+
OS << " __attribute__((aarch64_vector_pcs))";
10991099
break;
11001100
case CC_AArch64SVEPCS:
1101-
OS << "__attribute__((aarch64_sve_pcs))";
1101+
OS << " __attribute__((aarch64_sve_pcs))";
11021102
break;
11031103
case CC_DeviceKernel:
1104-
OS << "__attribute__((device_kernel))";
1104+
OS << " __attribute__((device_kernel))";
11051105
break;
11061106
case CC_IntelOclBicc:
11071107
OS << " __attribute__((intel_ocl_bicc))";
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %clang_cc1 -triple aarch64 -ast-dump -ast-dump-filter foo %s \
2+
// RUN: | FileCheck --strict-whitespace %s
3+
4+
// CHECK: foo1 'void () __attribute__((device_kernel))'{{$}}
5+
void foo1() __attribute__((device_kernel));
6+
7+
// CHECK: foo2 'void () __attribute__((aarch64_vector_pcs))'{{$}}
8+
void foo2() __attribute__((aarch64_vector_pcs));
9+
10+
// CHECK: foo3 'void () __attribute__((aarch64_sve_pcs))'{{$}}
11+
void foo3() __attribute__((aarch64_sve_pcs));

clang/tools/clang-format/ClangFormat.cpp

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -244,17 +244,17 @@ static bool fillRanges(MemoryBuffer *Code,
244244
DiagnosticsEngine Diagnostics(
245245
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), DiagOpts);
246246
SourceManager Sources(Diagnostics, Files);
247-
FileID ID = createInMemoryFile("<irrelevant>", *Code, Sources, Files,
248-
InMemoryFileSystem.get());
247+
const auto ID = createInMemoryFile("<irrelevant>", *Code, Sources, Files,
248+
InMemoryFileSystem.get());
249249
if (!LineRanges.empty()) {
250250
if (!Offsets.empty() || !Lengths.empty()) {
251251
errs() << "error: cannot use -lines with -offset/-length\n";
252252
return true;
253253
}
254254

255-
for (unsigned i = 0, e = LineRanges.size(); i < e; ++i) {
255+
for (const auto &LineRange : LineRanges) {
256256
unsigned FromLine, ToLine;
257-
if (parseLineRange(LineRanges[i], FromLine, ToLine)) {
257+
if (parseLineRange(LineRange, FromLine, ToLine)) {
258258
errs() << "error: invalid <start line>:<end line> pair\n";
259259
return true;
260260
}
@@ -266,45 +266,38 @@ static bool fillRanges(MemoryBuffer *Code,
266266
errs() << "error: start line should not exceed end line\n";
267267
return true;
268268
}
269-
SourceLocation Start = Sources.translateLineCol(ID, FromLine, 1);
270-
SourceLocation End = Sources.translateLineCol(ID, ToLine, UINT_MAX);
269+
const auto Start = Sources.translateLineCol(ID, FromLine, 1);
270+
const auto End = Sources.translateLineCol(ID, ToLine, UINT_MAX);
271271
if (Start.isInvalid() || End.isInvalid())
272272
return true;
273-
unsigned Offset = Sources.getFileOffset(Start);
274-
unsigned Length = Sources.getFileOffset(End) - Offset;
273+
const auto Offset = Sources.getFileOffset(Start);
274+
const auto Length = Sources.getFileOffset(End) - Offset;
275275
Ranges.push_back(tooling::Range(Offset, Length));
276276
}
277277
return false;
278278
}
279279

280280
if (Offsets.empty())
281281
Offsets.push_back(0);
282-
if (Offsets.size() != Lengths.size() &&
283-
!(Offsets.size() == 1 && Lengths.empty())) {
282+
if (Offsets.size() == 1 && Lengths.empty()) {
283+
Lengths.push_back(Sources.getFileOffset(Sources.getLocForEndOfFile(ID)) -
284+
Offsets[0]);
285+
} else if (Offsets.size() != Lengths.size()) {
284286
errs() << "error: number of -offset and -length arguments must match.\n";
285287
return true;
286288
}
287-
for (unsigned i = 0, e = Offsets.size(); i != e; ++i) {
288-
if (Offsets[i] >= Code->getBufferSize()) {
289-
errs() << "error: offset " << Offsets[i] << " is outside the file\n";
289+
for (unsigned I = 0, E = Offsets.size(); I < E; ++I) {
290+
const auto Offset = Offsets[I];
291+
if (Offset >= Code->getBufferSize()) {
292+
errs() << "error: offset " << Offset << " is outside the file\n";
290293
return true;
291294
}
292-
SourceLocation Start =
293-
Sources.getLocForStartOfFile(ID).getLocWithOffset(Offsets[i]);
294-
SourceLocation End;
295-
if (i < Lengths.size()) {
296-
if (Offsets[i] + Lengths[i] > Code->getBufferSize()) {
297-
errs() << "error: invalid length " << Lengths[i]
298-
<< ", offset + length (" << Offsets[i] + Lengths[i]
299-
<< ") is outside the file.\n";
300-
return true;
301-
}
302-
End = Start.getLocWithOffset(Lengths[i]);
303-
} else {
304-
End = Sources.getLocForEndOfFile(ID);
295+
const auto Length = Lengths[I];
296+
if (Offset + Length > Code->getBufferSize()) {
297+
errs() << "error: invalid length " << Length << ", offset + length ("
298+
<< Offset + Length << ") is outside the file.\n";
299+
return true;
305300
}
306-
unsigned Offset = Sources.getFileOffset(Start);
307-
unsigned Length = Sources.getFileOffset(End) - Offset;
308301
Ranges.push_back(tooling::Range(Offset, Length));
309302
}
310303
return false;

0 commit comments

Comments
 (0)