Skip to content

Commit 16edbe1

Browse files
Merge branch 'llvm:main' into gh-101657
2 parents 7a2d01a + 4cde945 commit 16edbe1

File tree

114 files changed

+1223
-669
lines changed

Some content is hidden

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

114 files changed

+1223
-669
lines changed

clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp

Lines changed: 177 additions & 177 deletions
Large diffs are not rendered by default.

clang-tools-extra/clangd/unittests/XRefsTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ TEST(LocateSymbol, All) {
10911091
)objc",
10921092
R"cpp(
10931093
struct PointerIntPairInfo {
1094-
static void *getPointer(void *Value);
1094+
static void *$decl[[getPointer]](void *Value);
10951095
};
10961096
10971097
template <typename Info = PointerIntPairInfo> struct PointerIntPair {

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ Changes in existing checks
151151
<clang-tidy/checks/bugprone/unsafe-functions>` check to allow specifying
152152
additional C++ member functions to match.
153153

154+
- Improved :doc:`cert-err33-c
155+
<clang-tidy/checks/cert/err33-c>` check by fixing false positives when
156+
a function name is just prefixed with a targeted function name.
157+
154158
- Improved :doc:`misc-const-correctness
155159
<clang-tidy/checks/misc/const-correctness>` check by adding the option
156160
`AllowedTypes`, that excludes specified types from const-correctness

clang-tools-extra/test/clang-tidy/checkers/cert/err33-c.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,12 @@ void test_wscanf_s(void) {
2323
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors
2424
// CHECK-MESSAGES: [[@LINE-2]]:3: note: cast the expression to void to silence this warning
2525
}
26+
27+
int remove(const char *path);
28+
int removeNonStdLibFunc(const char *path);
29+
void test_remove(void) {
30+
remove("123");
31+
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors
32+
// CHECK-MESSAGES: [[@LINE-2]]:3: note: cast the expression to void to silence this warning
33+
removeNonStdLibFunc("123");
34+
}

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ Bug Fixes to C++ Support
452452
- Fixed a Clang regression in C++20 mode where unresolved dependent call expressions were created inside non-dependent contexts (#GH122892)
453453
- Clang now emits the ``-Wunused-variable`` warning when some structured bindings are unused
454454
and the ``[[maybe_unused]]`` attribute is not applied. (#GH125810)
455+
- Declarations using class template argument deduction with redundant
456+
parentheses around the declarator are no longer rejected. (#GH39811)
455457
- Fixed a crash caused by invalid declarations of ``std::initializer_list``. (#GH132256)
456458
- Clang no longer crashes when establishing subsumption between some constraint expressions. (#GH122581)
457459
- Clang now issues an error when placement new is used to modify a const-qualified variable

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2617,10 +2617,9 @@ def err_decltype_auto_initializer_list : Error<
26172617
"cannot deduce 'decltype(auto)' from initializer list">;
26182618

26192619
// C++17 deduced class template specialization types
2620-
def err_deduced_class_template_compound_type : Error<
2621-
"cannot %select{form pointer to|form reference to|form array of|"
2622-
"form function returning|use parentheses when declaring variable with}0 "
2623-
"deduced class template specialization type">;
2620+
def err_deduced_class_template_compound_type
2621+
: Error<"cannot form %select{pointer to|reference to|array of|function "
2622+
"returning}0 deduced class template specialization type">;
26242623
def err_deduced_non_class_or_alias_template_specialization_type : Error<
26252624
"%select{<error>|function template|variable template|alias template|"
26262625
"template template parameter|concept|template}0 %1 requires template "

clang/include/clang/Sema/HeuristicResolver.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ class HeuristicResolver {
8181
// could look up the name appearing on the RHS.
8282
const QualType getPointeeType(QualType T) const;
8383

84+
// Heuristically resolve a possibly-dependent type `T` to a TagDecl
85+
// in which a member's name can be looked up.
86+
TagDecl *resolveTypeToTagDecl(QualType T) const;
87+
88+
// Simplify the type `Type`.
89+
// `E` is the expression whose type `Type` is, if known. This sometimes
90+
// contains information relevant to the type that's not stored in `Type`
91+
// itself.
92+
// If `UnwrapPointer` is true, exactly only pointer type will be unwrapped
93+
// during simplification, and the operation fails if no pointer type is found.
94+
QualType simplifyType(QualType Type, const Expr *E, bool UnwrapPointer);
95+
8496
private:
8597
ASTContext &Ctx;
8698
};

clang/include/clang/Sema/Sema.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ class FileNullabilityMap {
291291
/// parameter. This avoids updating the type on hot paths in the parser.
292292
class PreferredTypeBuilder {
293293
public:
294-
PreferredTypeBuilder(bool Enabled) : Enabled(Enabled) {}
294+
PreferredTypeBuilder(ASTContext *Ctx, bool Enabled)
295+
: Ctx(Ctx), Enabled(Enabled) {}
295296

296297
void enterCondition(Sema &S, SourceLocation Tok);
297298
void enterReturn(Sema &S, SourceLocation Tok);
@@ -337,6 +338,7 @@ class PreferredTypeBuilder {
337338
}
338339

339340
private:
341+
ASTContext *Ctx;
340342
bool Enabled;
341343
/// Start position of a token for which we store expected type.
342344
SourceLocation ExpectedLoc;

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3629,15 +3629,22 @@ template <class Emitter>
36293629
bool Compiler<Emitter>::VisitCXXTypeidExpr(const CXXTypeidExpr *E) {
36303630
const Type *TypeInfoType = E->getType().getTypePtr();
36313631

3632+
auto canonType = [](const Type *T) {
3633+
return T->getCanonicalTypeUnqualified().getTypePtr();
3634+
};
3635+
36323636
if (!E->isPotentiallyEvaluated()) {
36333637
if (DiscardResult)
36343638
return true;
36353639

36363640
if (E->isTypeOperand())
36373641
return this->emitGetTypeid(
3638-
E->getTypeOperand(Ctx.getASTContext()).getTypePtr(), TypeInfoType, E);
3639-
return this->emitGetTypeid(E->getExprOperand()->getType().getTypePtr(),
3640-
TypeInfoType, E);
3642+
canonType(E->getTypeOperand(Ctx.getASTContext()).getTypePtr()),
3643+
TypeInfoType, E);
3644+
3645+
return this->emitGetTypeid(
3646+
canonType(E->getExprOperand()->getType().getTypePtr()), TypeInfoType,
3647+
E);
36413648
}
36423649

36433650
// Otherwise, we need to evaluate the expression operand.

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,23 @@ bool GetTypeidPtr(InterpState &S, CodePtr OpPC, const Type *TypeInfoType) {
18481848
if (!P.isBlockPointer())
18491849
return false;
18501850

1851-
S.Stk.push<Pointer>(P.getType().getTypePtr(), TypeInfoType);
1851+
// Pick the most-derived type.
1852+
const Type *T = P.getDeclPtr().getType().getTypePtr();
1853+
// ... unless we're currently constructing this object.
1854+
// FIXME: We have a similar check to this in more places.
1855+
if (S.Current->getFunction()) {
1856+
for (const InterpFrame *Frame = S.Current; Frame; Frame = Frame->Caller) {
1857+
if (const Function *Func = Frame->getFunction();
1858+
Func && (Func->isConstructor() || Func->isDestructor()) &&
1859+
P.block() == Frame->getThis().block()) {
1860+
T = Func->getParentDecl()->getTypeForDecl();
1861+
break;
1862+
}
1863+
}
1864+
}
1865+
1866+
S.Stk.push<Pointer>(T->getCanonicalTypeUnqualified().getTypePtr(),
1867+
TypeInfoType);
18521868
return true;
18531869
}
18541870

0 commit comments

Comments
 (0)