Skip to content

Commit e1b9ddb

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:4f98fb2e937a into amd-gfx:5c2235853bc1
Local branch amd-gfx 5c22358 Merged main:918829959f96 into amd-gfx:7ce30e5343ec Remote branch main 4f98fb2 [mlir][openacc][NFC] Remove useless OptionalAttr with UnitAttr (llvm#68337)
2 parents 5c22358 + 4f98fb2 commit e1b9ddb

File tree

83 files changed

+5554
-2273
lines changed

Some content is hidden

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

83 files changed

+5554
-2273
lines changed

clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "clang/Lex/Preprocessor.h"
3131
#include "clang/Tooling/Core/Replacement.h"
3232
#include "clang/Tooling/Inclusions/HeaderIncludes.h"
33+
#include "clang/Tooling/Inclusions/StandardLibrary.h"
3334
#include "llvm/ADT/DenseSet.h"
3435
#include "llvm/ADT/STLExtras.h"
3536
#include "llvm/ADT/SmallVector.h"
@@ -97,9 +98,12 @@ bool IncludeCleanerCheck::shouldIgnore(const include_cleaner::Header &H) {
9798
return llvm::any_of(IgnoreHeadersRegex, [&H](const llvm::Regex &R) {
9899
switch (H.kind()) {
99100
case include_cleaner::Header::Standard:
101+
// We don't trim angle brackets around standard library headers
102+
// deliberately, so that they are only matched as <vector>, otherwise
103+
// having just `.*/vector` might yield false positives.
100104
return R.match(H.standard().name());
101105
case include_cleaner::Header::Verbatim:
102-
return R.match(H.verbatim());
106+
return R.match(H.verbatim().trim("<>\""));
103107
case include_cleaner::Header::Physical:
104108
return R.match(H.physical().getFileEntry().tryGetRealPathName());
105109
}
@@ -179,12 +183,14 @@ void IncludeCleanerCheck::check(const MatchFinder::MatchResult &Result) {
179183
if (getCurrentMainFile().endswith(PHeader))
180184
continue;
181185
}
182-
183-
if (llvm::none_of(
184-
IgnoreHeadersRegex,
185-
[Resolved = (*I.Resolved).getFileEntry().tryGetRealPathName()](
186-
const llvm::Regex &R) { return R.match(Resolved); }))
187-
Unused.push_back(&I);
186+
auto StdHeader = tooling::stdlib::Header::named(
187+
I.quote(), PP->getLangOpts().CPlusPlus ? tooling::stdlib::Lang::CXX
188+
: tooling::stdlib::Lang::C);
189+
if (StdHeader && shouldIgnore(*StdHeader))
190+
continue;
191+
if (shouldIgnore(*I.Resolved))
192+
continue;
193+
Unused.push_back(&I);
188194
}
189195

190196
llvm::StringRef Code = SM->getBufferData(SM->getMainFileID());

clang-tools-extra/docs/ReleaseNotes.rst

+4-6
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,12 @@ Changes in existing checks
249249
- Improved :doc:`misc-const-correctness
250250
<clang-tidy/checks/misc/const-correctness>` check to avoid false positive when
251251
using pointer to member function.
252-
253-
- Improved :doc:`misc-include-cleaner
254-
<clang-tidy/checks/misc/include-cleaner>` check by adding option
255-
`DeduplicateFindings` to output one finding per symbol occurrence.
256252

257253
- Improved :doc:`misc-include-cleaner
258-
<clang-tidy/checks/misc/include-cleaner>` check to avoid fixes insert
259-
same include header multiple times.
254+
<clang-tidy/checks/misc/include-cleaner>` check by adding option
255+
`DeduplicateFindings` to output one finding per symbol occurrence, avoid
256+
inserting the same header multiple times, fix a bug where `IgnoreHeaders`
257+
option won't work with verbatim/std headers.
260258

261259
- Improved :doc:`misc-redundant-expression
262260
<clang-tidy/checks/misc/redundant-expression>` check to ignore

clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,20 @@ TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
5959
#include "foo/qux.h"
6060
#include "baz/qux/qux.h"
6161
#include <vector>
62+
#include <list>
6263
)";
6364

6465
const char *PostCode = R"(
6566
#include "bar.h"
6667
#include "foo/qux.h"
6768
#include <vector>
69+
#include <list>
6870
)";
6971

7072
std::vector<ClangTidyError> Errors;
7173
ClangTidyOptions Opts;
7274
Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{llvm::formatv(
73-
"bar.h;{0};{1};vector",
75+
"bar.h;{0};{1};vector;<list>;",
7476
llvm::Regex::escape(appendPathFileSystemIndependent({"foo", "qux.h"})),
7577
llvm::Regex::escape(appendPathFileSystemIndependent({"baz", "qux"})))};
7678
EXPECT_EQ(
@@ -79,6 +81,7 @@ TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
7981
PreCode, &Errors, "file.cpp", std::nullopt, Opts,
8082
{{"bar.h", "#pragma once"},
8183
{"vector", "#pragma once"},
84+
{"list", "#pragma once"},
8285
{appendPathFileSystemIndependent({"foo", "qux.h"}), "#pragma once"},
8386
{appendPathFileSystemIndependent({"baz", "qux", "qux.h"}),
8487
"#pragma once"}}));
@@ -163,30 +166,37 @@ TEST(IncludeCleanerCheckTest, SuppressMissingIncludes) {
163166
int BarResult = bar();
164167
int BazResult = baz();
165168
int QuxResult = qux();
169+
int PrivResult = test();
170+
std::vector x;
166171
)";
167172

168173
ClangTidyOptions Opts;
169174
Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{
170-
"baz.h;" +
175+
"public.h;<vector>;baz.h;" +
171176
llvm::Regex::escape(appendPathFileSystemIndependent({"foo", "qux.h"}))};
172177
std::vector<ClangTidyError> Errors;
173178
EXPECT_EQ(PreCode, runCheckOnCode<IncludeCleanerCheck>(
174179
PreCode, &Errors, "file.cpp", std::nullopt, Opts,
175180
{{"bar.h", R"(#pragma once
176181
#include "baz.h"
177182
#include "foo/qux.h"
183+
#include "private.h"
178184
int bar();
185+
namespace std { struct vector {}; }
179186
)"},
180187
{"baz.h", R"(#pragma once
181188
int baz();
182189
)"},
190+
{"private.h", R"(#pragma once
191+
// IWYU pragma: private, include "public.h"
192+
int test();
193+
)"},
183194
{appendPathFileSystemIndependent({"foo", "qux.h"}),
184195
R"(#pragma once
185196
int qux();
186197
)"}}));
187198
}
188199

189-
190200
TEST(IncludeCleanerCheckTest, MultipleTimeMissingInclude) {
191201
const char *PreCode = R"(
192202
#include "bar.h"

clang/docs/ReleaseNotes.rst

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ C23 Feature Support
145145
previous placeholder value. Clang continues to accept ``-std=c2x`` and
146146
``-std=gnu2x`` as aliases for C23 and GNU C23, respectively.
147147
- Clang now supports `requires c23` for module maps.
148+
- Clang now supports ``N3007 Type inference for object definitions``.
148149

149150
Non-comprehensive list of changes in this release
150151
-------------------------------------------------

clang/include/clang/Basic/DiagnosticSemaKinds.td

+10-4
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ def ext_imaginary_constant : Extension<
240240
"imaginary constants are a GNU extension">, InGroup<GNUImaginaryConstant>;
241241
def ext_integer_complex : Extension<
242242
"complex integer types are a GNU extension">, InGroup<GNUComplexInteger>;
243+
def ext_c23_auto_non_plain_identifier : Extension<
244+
"type inference of a declaration other than a plain identifier with optional "
245+
"trailing attributes is a Clang extension">,
246+
InGroup<DiagGroup<"auto-decl-extensions">>;
243247

244248
def err_invalid_saturation_spec : Error<"'_Sat' specifier is only valid on "
245249
"'_Fract' or '_Accum', not '%0'">;
@@ -2388,7 +2392,8 @@ def err_auto_not_allowed : Error<
23882392
"|in conversion function type|here|in lambda parameter"
23892393
"|in type allocated by 'new'|in K&R-style function parameter"
23902394
"|in template parameter|in friend declaration|in function prototype that is "
2391-
"not a function declaration|in requires expression parameter}1">;
2395+
"not a function declaration|in requires expression parameter"
2396+
"|in array declaration}1">;
23922397
def err_dependent_deduced_tst : Error<
23932398
"typename specifier refers to "
23942399
"%select{class template|function template|variable template|alias template|"
@@ -2461,7 +2466,8 @@ def err_implied_std_initializer_list_not_found : Error<
24612466
def err_malformed_std_initializer_list : Error<
24622467
"std::initializer_list must be a class template with a single type parameter">;
24632468
def err_auto_init_list_from_c : Error<
2464-
"cannot use __auto_type with initializer list in C">;
2469+
"cannot use %select{'auto'|<ERROR>|'__auto_type'}0 with "
2470+
"%select{initializer list|array}1 in C">;
24652471
def err_auto_bitfield : Error<
24662472
"cannot pass bit-field as __auto_type initializer in C">;
24672473

@@ -6664,8 +6670,8 @@ def err_func_def_incomplete_result : Error<
66646670
def err_atomic_specifier_bad_type
66656671
: Error<"_Atomic cannot be applied to "
66666672
"%select{incomplete |array |function |reference |atomic |qualified "
6667-
"|sizeless ||integer }0type "
6668-
"%1 %select{|||||||which is not trivially copyable|}0">;
6673+
"|sizeless ||integer |}0type "
6674+
"%1 %select{|||||||which is not trivially copyable||in C23}0">;
66696675
def warn_atomic_member_access : Warning<
66706676
"accessing a member of an atomic structure or union is undefined behavior">,
66716677
InGroup<DiagGroup<"atomic-access">>, DefaultError;

clang/include/clang/Serialization/ModuleFileExtension.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class ModuleFileExtension
8686
/// The default implementation of this function simply does nothing, so the
8787
/// presence/absence of this extension does not distinguish module files.
8888
using ExtensionHashBuilder =
89-
llvm::HashBuilder<llvm::MD5, llvm::support::endian::system_endianness()>;
89+
llvm::HashBuilder<llvm::MD5, llvm::endianness::native>;
9090
virtual void hashExtension(ExtensionHashBuilder &HBuilder) const;
9191

9292
/// Create a new module file extension writer, which will be

clang/lib/Parse/ParseDecl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4038,7 +4038,7 @@ void Parser::ParseDeclarationSpecifiers(
40384038
isStorageClass = true;
40394039
break;
40404040
case tok::kw_auto:
4041-
if (getLangOpts().CPlusPlus11) {
4041+
if (getLangOpts().CPlusPlus11 || getLangOpts().C23) {
40424042
if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) {
40434043
isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_auto, Loc,
40444044
PrevSpec, DiagID, Policy);

clang/lib/Sema/DeclSpec.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1375,8 +1375,9 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) {
13751375
StorageClassSpecLoc = SourceLocation();
13761376
}
13771377
// Diagnose if we've recovered from an ill-formed 'auto' storage class
1378-
// specifier in a pre-C++11 dialect of C++.
1379-
if (!S.getLangOpts().CPlusPlus11 && TypeSpecType == TST_auto)
1378+
// specifier in a pre-C++11 dialect of C++ or in a pre-C23 dialect of C.
1379+
if (!S.getLangOpts().CPlusPlus11 && !S.getLangOpts().C23 &&
1380+
TypeSpecType == TST_auto)
13801381
S.Diag(TSTLoc, diag::ext_auto_type_specifier);
13811382
if (S.getLangOpts().CPlusPlus && !S.getLangOpts().CPlusPlus11 &&
13821383
StorageClassSpec == SCS_auto)

clang/lib/Sema/SemaDecl.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -12863,6 +12863,15 @@ QualType Sema::deduceVarTypeFromInitializer(VarDecl *VDecl,
1286312863
DeducedType *Deduced = Type->getContainedDeducedType();
1286412864
assert(Deduced && "deduceVarTypeFromInitializer for non-deduced type");
1286512865

12866+
// Diagnose auto array declarations in C23, unless it's a supported extension.
12867+
if (getLangOpts().C23 && Type->isArrayType() &&
12868+
!isa_and_present<StringLiteral, InitListExpr>(Init)) {
12869+
Diag(Range.getBegin(), diag::err_auto_not_allowed)
12870+
<< (int)Deduced->getContainedAutoType()->getKeyword()
12871+
<< /*in array decl*/ 23 << Range;
12872+
return QualType();
12873+
}
12874+
1286612875
// C++11 [dcl.spec.auto]p3
1286712876
if (!Init) {
1286812877
assert(VDecl && "no init for init capture deduction?");

clang/lib/Sema/SemaTemplateDeduction.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -4842,9 +4842,25 @@ Sema::DeduceAutoType(TypeLoc Type, Expr *Init, QualType &Result,
48424842
return TDK_Success;
48434843
}
48444844

4845+
// Make sure that we treat 'char[]' equaly as 'char*' in C23 mode.
4846+
auto *String = dyn_cast<StringLiteral>(Init);
4847+
if (getLangOpts().C23 && String && Type.getType()->isArrayType()) {
4848+
Diag(Type.getBeginLoc(), diag::ext_c23_auto_non_plain_identifier);
4849+
TypeLoc TL = TypeLoc(Init->getType(), Type.getOpaqueData());
4850+
Result = SubstituteDeducedTypeTransform(*this, DependentResult).Apply(TL);
4851+
assert(!Result.isNull() && "substituting DependentTy can't fail");
4852+
return TDK_Success;
4853+
}
4854+
4855+
// Emit a warning if 'auto*' is used in pedantic and in C23 mode.
4856+
if (getLangOpts().C23 && Type.getType()->isPointerType()) {
4857+
Diag(Type.getBeginLoc(), diag::ext_c23_auto_non_plain_identifier);
4858+
}
4859+
48454860
auto *InitList = dyn_cast<InitListExpr>(Init);
48464861
if (!getLangOpts().CPlusPlus && InitList) {
4847-
Diag(Init->getBeginLoc(), diag::err_auto_init_list_from_c);
4862+
Diag(Init->getBeginLoc(), diag::err_auto_init_list_from_c)
4863+
<< (int)AT->getKeyword() << getLangOpts().C23;
48484864
return TDK_AlreadyDiagnosed;
48494865
}
48504866

clang/lib/Sema/SemaType.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -9880,11 +9880,14 @@ QualType Sema::BuildAtomicType(QualType T, SourceLocation Loc) {
98809880
DisallowedKind = 5;
98819881
else if (T->isSizelessType())
98829882
DisallowedKind = 6;
9883-
else if (!T.isTriviallyCopyableType(Context))
9883+
else if (!T.isTriviallyCopyableType(Context) && getLangOpts().CPlusPlus)
98849884
// Some other non-trivially-copyable type (probably a C++ class)
98859885
DisallowedKind = 7;
98869886
else if (T->isBitIntType())
98879887
DisallowedKind = 8;
9888+
else if (getLangOpts().C23 && T->isUndeducedAutoType())
9889+
// _Atomic auto is prohibited in C23
9890+
DisallowedKind = 9;
98889891

98899892
if (DisallowedKind != -1) {
98909893
Diag(Loc, diag::err_atomic_specifier_bad_type) << DisallowedKind << T;

0 commit comments

Comments
 (0)