Skip to content

Commit febc397

Browse files
committed
Merge remote-tracking branch 'upstream/release/17.x' into rustc/17.0-2023-09-19
2 parents d404cba + 888437e commit febc397

File tree

60 files changed

+1333
-336
lines changed

Some content is hidden

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

60 files changed

+1333
-336
lines changed

.github/workflows/llvm-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,17 @@ jobs:
168168
uses: actions/download-artifact@v3
169169
with:
170170
name: build-baseline
171+
path: build-baseline
171172
- name: Download latest
172173
uses: actions/download-artifact@v3
173174
with:
174175
name: build-latest
176+
path: build-latest
175177
- name: Download symbol list
176178
uses: actions/download-artifact@v3
177179
with:
178180
name: symbol-list
181+
path: symbol-list
179182

180183
- name: Install abi-compliance-checker
181184
run: sudo apt-get install abi-compliance-checker

.github/workflows/release-binaries.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
matrix:
6969
target:
7070
- triple: x86_64-linux-gnu-ubuntu-22.04
71-
runs-on: ubuntu-22.04-8x32
71+
runs-on: ubuntu-22.04-16x64
7272
debian-build-deps: >
7373
chrpath
7474
gcc-multilib

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5652,7 +5652,7 @@ Examples
56525652
========
56535653

56545654
A style similar to the `Linux Kernel style
5655-
<https://www.kernel.org/doc/Documentation/CodingStyle>`_:
5655+
<https://www.kernel.org/doc/html/latest/process/coding-style.html>`_:
56565656

56575657
.. code-block:: yaml
56585658

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,8 @@ Improvements to Clang's diagnostics
475475
- ``-Wformat`` cast fix-its will now suggest ``static_cast`` instead of C-style casts
476476
for C++ code.
477477
- ``-Wformat`` will no longer suggest a no-op fix-it for fixing scoped enum format
478-
warnings. Instead, it will suggest casting the enum object to the type specified
479-
in the format string.
480-
- Clang contexpr evaluator now displays notes as well as an error when a constructor
481-
of a base class is not called in the constructor of its derived class.
478+
warnings. Instead, it will suggest casting the enum object based on its
479+
underlying type.
482480

483481
Bug Fixes in This Version
484482
-------------------------
@@ -719,6 +717,8 @@ Bug Fixes in This Version
719717
virtual member functions even if the target required a greater function
720718
alignment and/or did not have function pointers which point to function entry
721719
points (i.e., uses function descriptor objects instead).
720+
- Fixes a ``clang-17`` regression where ``LLVM_UNREACHABLE_OPTIMIZE=OFF``
721+
cannot be used with ``Release`` mode builds. (`#68237 <https://github.com/llvm/llvm-project/issues/68237>`_).
722722

723723
Bug Fixes to Compiler Builtins
724724
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ class DependencyScanningFilesystemLocalCache {
215215
public:
216216
/// Returns entry associated with the filename or nullptr if none is found.
217217
const CachedFileSystemEntry *findEntryByFilename(StringRef Filename) const {
218+
assert(llvm::sys::path::is_absolute_gnu(Filename));
218219
auto It = Cache.find(Filename);
219220
return It == Cache.end() ? nullptr : It->getValue();
220221
}
@@ -224,6 +225,7 @@ class DependencyScanningFilesystemLocalCache {
224225
const CachedFileSystemEntry &
225226
insertEntryForFilename(StringRef Filename,
226227
const CachedFileSystemEntry &Entry) {
228+
assert(llvm::sys::path::is_absolute_gnu(Filename));
227229
const auto *InsertedEntry = Cache.insert({Filename, &Entry}).first->second;
228230
assert(InsertedEntry == &Entry && "entry already present");
229231
return *InsertedEntry;
@@ -282,13 +284,14 @@ class DependencyScanningWorkerFilesystem : public llvm::vfs::ProxyFileSystem {
282284
public:
283285
DependencyScanningWorkerFilesystem(
284286
DependencyScanningFilesystemSharedCache &SharedCache,
285-
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS)
286-
: ProxyFileSystem(std::move(FS)), SharedCache(SharedCache) {}
287+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS);
287288

288289
llvm::ErrorOr<llvm::vfs::Status> status(const Twine &Path) override;
289290
llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>
290291
openFileForRead(const Twine &Path) override;
291292

293+
std::error_code setCurrentWorkingDirectory(const Twine &Path) override;
294+
292295
/// Returns entry for the given filename.
293296
///
294297
/// Attempts to use the local and shared caches first, then falls back to
@@ -304,8 +307,11 @@ class DependencyScanningWorkerFilesystem : public llvm::vfs::ProxyFileSystem {
304307
/// For a filename that's not yet associated with any entry in the caches,
305308
/// uses the underlying filesystem to either look up the entry based in the
306309
/// shared cache indexed by unique ID, or creates new entry from scratch.
310+
/// \p FilenameForLookup will always be an absolute path, and different than
311+
/// \p OriginalFilename if \p OriginalFilename is relative.
307312
llvm::ErrorOr<const CachedFileSystemEntry &>
308-
computeAndStoreResult(StringRef Filename);
313+
computeAndStoreResult(StringRef OriginalFilename,
314+
StringRef FilenameForLookup);
309315

310316
/// Scan for preprocessor directives for the given entry if necessary and
311317
/// returns a wrapper object with reference semantics.
@@ -388,6 +394,12 @@ class DependencyScanningWorkerFilesystem : public llvm::vfs::ProxyFileSystem {
388394
/// The local cache is used by the worker thread to cache file system queries
389395
/// locally instead of querying the global cache every time.
390396
DependencyScanningFilesystemLocalCache LocalCache;
397+
398+
/// The working directory to use for making relative paths absolute before
399+
/// using them for cache lookups.
400+
llvm::ErrorOr<std::string> WorkingDirForCacheLookup;
401+
402+
void updateWorkingDirForCacheLookup();
391403
};
392404

393405
} // end namespace dependencies

clang/lib/Driver/ToolChains/MinGW.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,8 +699,13 @@ void toolchains::MinGW::addClangTargetOptions(
699699
}
700700
}
701701

702-
if (Arg *A = DriverArgs.getLastArgNoClaim(options::OPT_mthreads))
703-
A->ignoreTargetSpecific();
702+
CC1Args.push_back("-fno-use-init-array");
703+
704+
for (auto Opt : {options::OPT_mthreads, options::OPT_mwindows,
705+
options::OPT_mconsole, options::OPT_mdll}) {
706+
if (Arg *A = DriverArgs.getLastArgNoClaim(Opt))
707+
A->ignoreTargetSpecific();
708+
}
704709
}
705710

706711
void toolchains::MinGW::AddClangCXXStdlibIncludeArgs(

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,12 @@ void UnwrappedLineParser::reset() {
173173
CommentsBeforeNextToken.clear();
174174
FormatTok = nullptr;
175175
MustBreakBeforeNextToken = false;
176+
IsDecltypeAutoFunction = false;
176177
PreprocessorDirectives.clear();
177178
CurrentLines = &Lines;
178179
DeclarationScopeStack.clear();
179180
NestedTooDeep.clear();
181+
NestedLambdas.clear();
180182
PPStack.clear();
181183
Line->FirstStartColumn = FirstStartColumn;
182184

@@ -1757,6 +1759,17 @@ void UnwrappedLineParser::parseStructuralElement(
17571759
if (parseStructLike())
17581760
return;
17591761
break;
1762+
case tok::kw_decltype:
1763+
nextToken();
1764+
if (FormatTok->is(tok::l_paren)) {
1765+
parseParens();
1766+
assert(FormatTok->Previous);
1767+
if (FormatTok->Previous->endsSequence(tok::r_paren, tok::kw_auto,
1768+
tok::l_paren)) {
1769+
Line->SeenDecltypeAuto = true;
1770+
}
1771+
}
1772+
break;
17601773
case tok::period:
17611774
nextToken();
17621775
// In Java, classes have an implicit static member "class".
@@ -1818,6 +1831,7 @@ void UnwrappedLineParser::parseStructuralElement(
18181831
if (NextLBracesType != TT_Unknown)
18191832
FormatTok->setFinalizedType(NextLBracesType);
18201833
if (!tryToParsePropertyAccessor() && !tryToParseBracedList()) {
1834+
IsDecltypeAutoFunction = Line->SeenDecltypeAuto;
18211835
// A block outside of parentheses must be the last part of a
18221836
// structural element.
18231837
// FIXME: Figure out cases where this is not true, and add projections
@@ -1835,6 +1849,7 @@ void UnwrappedLineParser::parseStructuralElement(
18351849
}
18361850
FormatTok->setFinalizedType(TT_FunctionLBrace);
18371851
parseBlock();
1852+
IsDecltypeAutoFunction = false;
18381853
addUnwrappedLine();
18391854
return;
18401855
}
@@ -2249,9 +2264,15 @@ bool UnwrappedLineParser::tryToParseLambda() {
22492264
return true;
22502265
}
22512266
}
2267+
22522268
FormatTok->setFinalizedType(TT_LambdaLBrace);
22532269
LSquare.setFinalizedType(TT_LambdaLSquare);
2270+
2271+
NestedLambdas.push_back(Line->SeenDecltypeAuto);
22542272
parseChildBlock();
2273+
assert(!NestedLambdas.empty());
2274+
NestedLambdas.pop_back();
2275+
22552276
return true;
22562277
}
22572278

@@ -2471,6 +2492,8 @@ bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) {
24712492
PrevPrev->endsSequence(tok::kw_constexpr, tok::kw_if))));
24722493
const bool ReturnParens =
24732494
Style.RemoveParentheses == FormatStyle::RPS_ReturnStatement &&
2495+
((NestedLambdas.empty() && !IsDecltypeAutoFunction) ||
2496+
(!NestedLambdas.empty() && !NestedLambdas.back())) &&
24742497
Prev && Prev->isOneOf(tok::kw_return, tok::kw_co_return) && Next &&
24752498
Next->is(tok::semi);
24762499
if ((DoubleParens && !Blacklisted) || ReturnParens) {
@@ -4386,6 +4409,7 @@ void UnwrappedLineParser::addUnwrappedLine(LineLevel AdjustLevel) {
43864409
Line->MatchingOpeningBlockLineIndex = UnwrappedLine::kInvalidIndex;
43874410
Line->FirstStartColumn = 0;
43884411
Line->IsContinuation = false;
4412+
Line->SeenDecltypeAuto = false;
43894413

43904414
if (ClosesWhitesmithsBlock && AdjustLevel == LineLevel::Remove)
43914415
--Line->Level;

clang/lib/Format/UnwrappedLineParser.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ struct UnwrappedLine {
6161

6262
bool MustBeDeclaration;
6363

64+
/// Whether the parser has seen \c decltype(auto) in this line.
65+
bool SeenDecltypeAuto = false;
66+
6467
/// \c True if this line should be indented by ContinuationIndent in
6568
/// addition to the normal indention level.
6669
bool IsContinuation = false;
@@ -341,6 +344,14 @@ class UnwrappedLineParser {
341344
// statement contains more than some predefined number of nested statements).
342345
SmallVector<bool, 8> NestedTooDeep;
343346

347+
// Keeps a stack of the states of nested lambdas (true if the return type of
348+
// the lambda is `decltype(auto)`).
349+
SmallVector<bool, 4> NestedLambdas;
350+
351+
// Whether the parser is parsing the body of a function whose return type is
352+
// `decltype(auto)`.
353+
bool IsDecltypeAutoFunction = false;
354+
344355
// Represents preprocessor branch type, so we can find matching
345356
// #if/#else/#endif directives.
346357
enum PPBranchKind {

clang/lib/Headers/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ set(cuda_wrapper_files
275275

276276
set(cuda_wrapper_bits_files
277277
cuda_wrappers/bits/shared_ptr_base.h
278+
cuda_wrappers/bits/basic_string.h
279+
cuda_wrappers/bits/basic_string.tcc
278280
)
279281

280282
set(ppc_wrapper_files
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// CUDA headers define __noinline__ which interferes with libstdc++'s use of
2+
// `__attribute((__noinline__))`. In order to avoid compilation error,
3+
// temporarily unset __noinline__ when we include affected libstdc++ header.
4+
5+
#pragma push_macro("__noinline__")
6+
#undef __noinline__
7+
#include_next "bits/basic_string.h"
8+
9+
#pragma pop_macro("__noinline__")
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// CUDA headers define __noinline__ which interferes with libstdc++'s use of
2+
// `__attribute((__noinline__))`. In order to avoid compilation error,
3+
// temporarily unset __noinline__ when we include affected libstdc++ header.
4+
5+
#pragma push_macro("__noinline__")
6+
#undef __noinline__
7+
#include_next "bits/basic_string.tcc"
8+
9+
#pragma pop_macro("__noinline__")

clang/lib/Sema/SemaChecking.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11166,12 +11166,15 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
1116611166
ImplicitMatch == ArgType::NoMatchTypeConfusion)
1116711167
Match = ImplicitMatch;
1116811168
assert(Match != ArgType::MatchPromotion);
11169+
1116911170
// Look through unscoped enums to their underlying type.
1117011171
bool IsEnum = false;
1117111172
bool IsScopedEnum = false;
11173+
QualType IntendedTy = ExprTy;
1117211174
if (auto EnumTy = ExprTy->getAs<EnumType>()) {
11175+
IntendedTy = EnumTy->getDecl()->getIntegerType();
1117311176
if (EnumTy->isUnscopedEnumerationType()) {
11174-
ExprTy = EnumTy->getDecl()->getIntegerType();
11177+
ExprTy = IntendedTy;
1117511178
// This controls whether we're talking about the underlying type or not,
1117611179
// which we only want to do when it's an unscoped enum.
1117711180
IsEnum = true;
@@ -11183,7 +11186,6 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
1118311186
// %C in an Objective-C context prints a unichar, not a wchar_t.
1118411187
// If the argument is an integer of some kind, believe the %C and suggest
1118511188
// a cast instead of changing the conversion specifier.
11186-
QualType IntendedTy = ExprTy;
1118711189
if (isObjCContext() &&
1118811190
FS.getConversionSpecifier().getKind() == ConversionSpecifier::CArg) {
1118911191
if (ExprTy->isIntegralOrUnscopedEnumerationType() &&
@@ -11219,8 +11221,10 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
1121911221
std::tie(CastTy, CastTyName) = shouldNotPrintDirectly(S.Context, IntendedTy, E);
1122011222
if (!CastTy.isNull()) {
1122111223
// %zi/%zu and %td/%tu are OK to use for NSInteger/NSUInteger of type int
11222-
// (long in ASTContext). Only complain to pedants.
11223-
if ((CastTyName == "NSInteger" || CastTyName == "NSUInteger") &&
11224+
// (long in ASTContext). Only complain to pedants or when they're the
11225+
// underlying type of a scoped enum (which always needs a cast).
11226+
if (!IsScopedEnum &&
11227+
(CastTyName == "NSInteger" || CastTyName == "NSUInteger") &&
1122411228
(AT.isSizeT() || AT.isPtrdiffT()) &&
1122511229
AT.matchesType(S.Context, CastTy))
1122611230
Match = ArgType::NoMatchPedantic;
@@ -11275,20 +11279,15 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
1127511279
// should be printed as 'long' for 64-bit compatibility.)
1127611280
// Rather than emitting a normal format/argument mismatch, we want to
1127711281
// add a cast to the recommended type (and correct the format string
11278-
// if necessary).
11282+
// if necessary). We should also do so for scoped enumerations.
1127911283
SmallString<16> CastBuf;
1128011284
llvm::raw_svector_ostream CastFix(CastBuf);
1128111285
CastFix << (S.LangOpts.CPlusPlus ? "static_cast<" : "(");
11282-
if (IsScopedEnum) {
11283-
CastFix << AT.getRepresentativeType(S.Context).getAsString(
11284-
S.Context.getPrintingPolicy());
11285-
} else {
11286-
IntendedTy.print(CastFix, S.Context.getPrintingPolicy());
11287-
}
11286+
IntendedTy.print(CastFix, S.Context.getPrintingPolicy());
1128811287
CastFix << (S.LangOpts.CPlusPlus ? ">" : ")");
1128911288

1129011289
SmallVector<FixItHint,4> Hints;
11291-
if ((!AT.matchesType(S.Context, IntendedTy) && !IsScopedEnum) ||
11290+
if (AT.matchesType(S.Context, IntendedTy) != ArgType::Match ||
1129211291
ShouldNotPrintDirectly)
1129311292
Hints.push_back(FixItHint::CreateReplacement(SpecRange, os.str()));
1129411293

@@ -11308,11 +11307,15 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
1130811307
Hints.push_back(
1130911308
FixItHint::CreateInsertion(E->getBeginLoc(), CastFix.str()));
1131011309

11311-
SourceLocation After = S.getLocForEndOfToken(E->getEndLoc());
11310+
// We don't use getLocForEndOfToken because it returns invalid source
11311+
// locations for macro expansions (by design).
11312+
SourceLocation EndLoc = S.SourceMgr.getSpellingLoc(E->getEndLoc());
11313+
SourceLocation After = EndLoc.getLocWithOffset(
11314+
Lexer::MeasureTokenLength(EndLoc, S.SourceMgr, S.LangOpts));
1131211315
Hints.push_back(FixItHint::CreateInsertion(After, ")"));
1131311316
}
1131411317

11315-
if (ShouldNotPrintDirectly) {
11318+
if (ShouldNotPrintDirectly && !IsScopedEnum) {
1131611319
// The expression has a type that should not be printed directly.
1131711320
// We extract the name from the typedef because we don't want to show
1131811321
// the underlying type in the diagnostic.

0 commit comments

Comments
 (0)