Skip to content

Commit 49a65e8

Browse files
authored
Merge branch 'main' into VariableTemplates
2 parents b4244b9 + cd23949 commit 49a65e8

File tree

109 files changed

+3079
-683
lines changed

Some content is hidden

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

109 files changed

+3079
-683
lines changed

clang/docs/ClangFormat.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ names. It has the following format:
150150
* Patterns follow the rules specified in `POSIX 2.13.1, 2.13.2, and Rule 1 of
151151
2.13.3 <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/
152152
V3_chap02.html#tag_18_13>`_.
153+
* Bash globstar (``**``) is supported.
153154
* A pattern is negated if it starts with a bang (``!``).
154155

155156
To match all files in a directory, use e.g. ``foo/bar/*``. To match all files in

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,7 @@ Bug Fixes to C++ Support
886886
out of a module (which is the case e.g. in MSVC's implementation of ``std`` module). (#GH118218)
887887
- Fixed a pack expansion issue in checking unexpanded parameter sizes. (#GH17042)
888888
- Fixed a bug where captured structured bindings were modifiable inside non-mutable lambda (#GH95081)
889+
- Fixed an issue while resolving type of expression indexing into a pack of values of non-dependent type (#GH121242)
889890

890891
Bug Fixes to AST Handling
891892
^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1125,6 +1126,7 @@ clang-format
11251126
- Adds ``KeepFormFeed`` option and set it to ``true`` for ``GNU`` style.
11261127
- Adds ``AllowShortNamespacesOnASingleLine`` option.
11271128
- Adds ``VariableTemplates`` option.
1129+
- Adds support for bash globstar in ``.clang-format-ignore``.
11281130

11291131
libclang
11301132
--------

clang/include/clang/Frontend/Utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class DependencyFileGenerator : public DependencyCollector {
120120
private:
121121
void outputDependencyFile(DiagnosticsEngine &Diags);
122122

123+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS;
123124
std::string OutputFile;
124125
std::vector<std::string> Targets;
125126
bool IncludeSystemHeaders;

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "clang/Basic/Builtins.h"
1818
#include "clang/Basic/TargetBuiltins.h"
1919
#include "clang/Basic/TargetInfo.h"
20+
#include "llvm/ADT/StringExtras.h"
2021
#include "llvm/Support/SipHash.h"
2122

2223
namespace clang {
@@ -1837,6 +1838,7 @@ static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC,
18371838
assert(Call->getNumArgs() == 3);
18381839
unsigned ID = Func->getBuiltinID();
18391840
Pointer DestPtr = getParam<Pointer>(Frame, 0);
1841+
const ASTContext &ASTCtx = S.getASTContext();
18401842
const Pointer &SrcPtr = getParam<Pointer>(Frame, 1);
18411843
const APSInt &Size =
18421844
peekToAPSInt(S.Stk, *S.getContext().classify(Call->getArg(2)));
@@ -1857,34 +1859,55 @@ static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC,
18571859
Pointer DiagPtr = (SrcPtr.isZero() ? SrcPtr : DestPtr);
18581860
S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_memcpy_null)
18591861
<< /*IsMove=*/Move << /*IsWchar=*/false << !SrcPtr.isZero()
1860-
<< DiagPtr.toDiagnosticString(S.getASTContext());
1862+
<< DiagPtr.toDiagnosticString(ASTCtx);
18611863
return false;
18621864
}
18631865

1864-
QualType ElemType;
1865-
if (DestPtr.getFieldDesc()->isArray())
1866-
ElemType = DestPtr.getFieldDesc()->getElemQualType();
1867-
else
1868-
ElemType = DestPtr.getType();
1866+
QualType DestElemType;
1867+
size_t RemainingDestElems;
1868+
if (DestPtr.getFieldDesc()->isArray()) {
1869+
DestElemType = DestPtr.getFieldDesc()->getElemQualType();
1870+
RemainingDestElems = (DestPtr.getNumElems() - DestPtr.getIndex());
1871+
} else {
1872+
DestElemType = DestPtr.getType();
1873+
RemainingDestElems = 1;
1874+
}
1875+
unsigned DestElemSize = ASTCtx.getTypeSizeInChars(DestElemType).getQuantity();
18691876

1870-
unsigned ElemSize =
1871-
S.getASTContext().getTypeSizeInChars(ElemType).getQuantity();
1872-
if (Size.urem(ElemSize) != 0) {
1877+
if (Size.urem(DestElemSize) != 0) {
18731878
S.FFDiag(S.Current->getSource(OpPC),
18741879
diag::note_constexpr_memcpy_unsupported)
1875-
<< Move << /*IsWchar=*/false << 0 << ElemType << Size << ElemSize;
1880+
<< Move << /*IsWchar=*/false << 0 << DestElemType << Size
1881+
<< DestElemSize;
18761882
return false;
18771883
}
18781884

18791885
QualType SrcElemType;
1880-
if (SrcPtr.getFieldDesc()->isArray())
1886+
size_t RemainingSrcElems;
1887+
if (SrcPtr.getFieldDesc()->isArray()) {
18811888
SrcElemType = SrcPtr.getFieldDesc()->getElemQualType();
1882-
else
1889+
RemainingSrcElems = (SrcPtr.getNumElems() - SrcPtr.getIndex());
1890+
} else {
18831891
SrcElemType = SrcPtr.getType();
1892+
RemainingSrcElems = 1;
1893+
}
1894+
unsigned SrcElemSize = ASTCtx.getTypeSizeInChars(SrcElemType).getQuantity();
18841895

1885-
if (!S.getASTContext().hasSameUnqualifiedType(ElemType, SrcElemType)) {
1896+
if (!ASTCtx.hasSameUnqualifiedType(DestElemType, SrcElemType)) {
18861897
S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_memcpy_type_pun)
1887-
<< Move << SrcElemType << ElemType;
1898+
<< Move << SrcElemType << DestElemType;
1899+
return false;
1900+
}
1901+
1902+
// Check if we have enough elements to read from and write to/
1903+
size_t RemainingDestBytes = RemainingDestElems * DestElemSize;
1904+
size_t RemainingSrcBytes = RemainingSrcElems * SrcElemSize;
1905+
if (Size.ugt(RemainingDestBytes) || Size.ugt(RemainingSrcBytes)) {
1906+
APInt N = Size.udiv(DestElemSize);
1907+
S.FFDiag(S.Current->getSource(OpPC),
1908+
diag::note_constexpr_memcpy_unsupported)
1909+
<< Move << /*IsWChar*/ false << (Size.ugt(RemainingSrcBytes) ? 1 : 2)
1910+
<< DestElemType << toString(N, 10, /*Signed=*/false);
18881911
return false;
18891912
}
18901913

@@ -1905,7 +1928,7 @@ static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC,
19051928
// As a last resort, reject dummy pointers.
19061929
if (DestPtr.isDummy() || SrcPtr.isDummy())
19071930
return false;
1908-
assert(Size.getZExtValue() % ElemSize == 0);
1931+
assert(Size.getZExtValue() % DestElemSize == 0);
19091932
if (!DoMemcpy(S, OpPC, SrcPtr, DestPtr, Bytes(Size.getZExtValue()).toBits()))
19101933
return false;
19111934

clang/lib/AST/ExprCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ PackIndexingExpr *PackIndexingExpr::Create(
17221722
if (Index && FullySubstituted && !SubstitutedExprs.empty())
17231723
Type = SubstitutedExprs[*Index]->getType();
17241724
else
1725-
Type = Context.DependentTy;
1725+
Type = PackIdExpr->getType();
17261726

17271727
void *Storage =
17281728
Context.Allocate(totalSizeToAlloc<Expr *>(SubstitutedExprs.size()));

clang/lib/CodeGen/Targets/AArch64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ bool AArch64ABIInfo::isZeroLengthBitfieldPermittedInHomogeneousAggregate()
662662

663663
bool AArch64ABIInfo::passAsAggregateType(QualType Ty) const {
664664
if (Kind == AArch64ABIKind::AAPCS && Ty->isSVESizelessBuiltinType()) {
665-
const auto *BT = Ty->getAs<BuiltinType>();
665+
const auto *BT = Ty->castAs<BuiltinType>();
666666
return !BT->isSVECount() &&
667667
getContext().getBuiltinVectorTypeInfo(BT).NumVectors > 1;
668668
}

clang/lib/Driver/ToolChains/OHOS.cpp

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#include "llvm/ProfileData/InstrProf.h"
2020
#include "llvm/Support/FileSystem.h"
2121
#include "llvm/Support/Path.h"
22-
#include "llvm/Support/VirtualFileSystem.h"
2322
#include "llvm/Support/ScopedPrinter.h"
23+
#include "llvm/Support/VirtualFileSystem.h"
2424

2525
using namespace clang::driver;
2626
using namespace clang::driver::toolchains;
@@ -58,11 +58,9 @@ static bool findOHOSMuslMultilibs(const Driver &D,
5858
return false;
5959
}
6060

61-
static bool findOHOSMultilibs(const Driver &D,
62-
const ToolChain &TC,
63-
const llvm::Triple &TargetTriple,
64-
StringRef Path, const ArgList &Args,
65-
DetectedMultilibs &Result) {
61+
static bool findOHOSMultilibs(const Driver &D, const ToolChain &TC,
62+
const llvm::Triple &TargetTriple, StringRef Path,
63+
const ArgList &Args, DetectedMultilibs &Result) {
6664
Multilib::flags_list Flags;
6765
bool IsA7 = false;
6866
if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
@@ -172,8 +170,7 @@ OHOS::OHOS(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
172170
Paths);
173171
}
174172

175-
ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(
176-
const ArgList &Args) const {
173+
ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(const ArgList &Args) const {
177174
if (Arg *A = Args.getLastArg(clang::driver::options::OPT_rtlib_EQ)) {
178175
StringRef Value = A->getValue();
179176
if (Value != "compiler-rt")
@@ -184,20 +181,19 @@ ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(
184181
return ToolChain::RLT_CompilerRT;
185182
}
186183

187-
ToolChain::CXXStdlibType
188-
OHOS::GetCXXStdlibType(const ArgList &Args) const {
184+
ToolChain::CXXStdlibType OHOS::GetCXXStdlibType(const ArgList &Args) const {
189185
if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
190186
StringRef Value = A->getValue();
191187
if (Value != "libc++")
192188
getDriver().Diag(diag::err_drv_invalid_stdlib_name)
193-
<< A->getAsString(Args);
189+
<< A->getAsString(Args);
194190
}
195191

196192
return ToolChain::CST_Libcxx;
197193
}
198194

199195
void OHOS::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
200-
ArgStringList &CC1Args) const {
196+
ArgStringList &CC1Args) const {
201197
const Driver &D = getDriver();
202198
const llvm::Triple &Triple = getTriple();
203199
std::string SysRoot = computeSysRoot();
@@ -258,7 +254,7 @@ void OHOS::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
258254
}
259255

260256
void OHOS::AddCXXStdlibLibArgs(const ArgList &Args,
261-
ArgStringList &CmdArgs) const {
257+
ArgStringList &CmdArgs) const {
262258
switch (GetCXXStdlibType(Args)) {
263259
case ToolChain::CST_Libcxx:
264260
CmdArgs.push_back("-lc++");
@@ -291,7 +287,8 @@ ToolChain::path_list OHOS::getRuntimePaths() const {
291287

292288
// First try the triple passed to driver as --target=<triple>.
293289
P.assign(D.ResourceDir);
294-
llvm::sys::path::append(P, "lib", D.getTargetTriple(), SelectedMultilib.gccSuffix());
290+
llvm::sys::path::append(P, "lib", D.getTargetTriple(),
291+
SelectedMultilib.gccSuffix());
295292
Paths.push_back(P.c_str());
296293

297294
// Second try the normalized triple.
@@ -340,26 +337,20 @@ std::string OHOS::getDynamicLinker(const ArgList &Args) const {
340337

341338
std::string OHOS::getCompilerRT(const ArgList &Args, StringRef Component,
342339
FileType Type) const {
340+
std::string CRTBasename =
341+
buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false);
342+
343343
SmallString<128> Path(getDriver().ResourceDir);
344344
llvm::sys::path::append(Path, "lib", getMultiarchTriple(getTriple()),
345-
SelectedMultilib.gccSuffix());
346-
const char *Prefix =
347-
Type == ToolChain::FT_Object ? "" : "lib";
348-
const char *Suffix;
349-
switch (Type) {
350-
case ToolChain::FT_Object:
351-
Suffix = ".o";
352-
break;
353-
case ToolChain::FT_Static:
354-
Suffix = ".a";
355-
break;
356-
case ToolChain::FT_Shared:
357-
Suffix = ".so";
358-
break;
359-
}
360-
llvm::sys::path::append(
361-
Path, Prefix + Twine("clang_rt.") + Component + Suffix);
362-
return static_cast<std::string>(Path.str());
345+
SelectedMultilib.gccSuffix(), CRTBasename);
346+
if (getVFS().exists(Path))
347+
return std::string(Path);
348+
349+
std::string NewPath = ToolChain::getCompilerRT(Args, Component, Type);
350+
if (getVFS().exists(NewPath))
351+
return NewPath;
352+
353+
return std::string(Path);
363354
}
364355

365356
void OHOS::addExtraOpts(llvm::opt::ArgStringList &CmdArgs) const {
@@ -396,7 +387,7 @@ SanitizerMask OHOS::getSupportedSanitizers() const {
396387

397388
// TODO: Make a base class for Linux and OHOS and move this there.
398389
void OHOS::addProfileRTLibs(const llvm::opt::ArgList &Args,
399-
llvm::opt::ArgStringList &CmdArgs) const {
390+
llvm::opt::ArgStringList &CmdArgs) const {
400391
// Add linker option -u__llvm_profile_runtime to cause runtime
401392
// initialization module to be linked in.
402393
if (needsProfileRT(Args))
@@ -413,7 +404,8 @@ ToolChain::path_list OHOS::getArchSpecificLibPaths() const {
413404
return Paths;
414405
}
415406

416-
ToolChain::UnwindLibType OHOS::GetUnwindLibType(const llvm::opt::ArgList &Args) const {
407+
ToolChain::UnwindLibType
408+
OHOS::GetUnwindLibType(const llvm::opt::ArgList &Args) const {
417409
if (Args.getLastArg(options::OPT_unwindlib_EQ))
418410
return Generic_ELF::GetUnwindLibType(Args);
419411
return GetDefaultUnwindLibType();

clang/lib/Format/MatchFilePath.cpp

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ bool matchFilePath(StringRef Pattern, StringRef FilePath) {
2525
assert(!Pattern.empty());
2626
assert(!FilePath.empty());
2727

28+
const auto FilePathBack = FilePath.back();
29+
2830
// No match if `Pattern` ends with a non-meta character not equal to the last
2931
// character of `FilePath`.
30-
if (const auto C = Pattern.back(); !strchr("?*]", C) && C != FilePath.back())
32+
if (const auto C = Pattern.back(); !strchr("?*]", C) && C != FilePathBack)
3133
return false;
3234

3335
constexpr auto Separator = '/';
@@ -49,25 +51,37 @@ bool matchFilePath(StringRef Pattern, StringRef FilePath) {
4951
return false;
5052
break;
5153
case '*': {
52-
while (++I < EOP && Pattern[I] == '*') { // Skip consecutive stars.
54+
bool Globstar = I == 0 || Pattern[I - 1] == Separator;
55+
int StarCount = 1;
56+
for (; ++I < EOP && Pattern[I] == '*'; ++StarCount) {
57+
// Skip consecutive stars.
5358
}
59+
if (StarCount != 2)
60+
Globstar = false;
5461
const auto K = FilePath.find(Separator, J); // Index of next `Separator`.
5562
const bool NoMoreSeparatorsInFilePath = K == StringRef::npos;
5663
if (I == EOP) // `Pattern` ends with a star.
57-
return NoMoreSeparatorsInFilePath;
58-
// `Pattern` ends with a lone backslash.
59-
if (Pattern[I] == '\\' && ++I == EOP)
60-
return false;
64+
return Globstar || NoMoreSeparatorsInFilePath;
65+
if (Pattern[I] != Separator) {
66+
Globstar = false;
67+
// `Pattern` ends with a lone backslash.
68+
if (Pattern[I] == '\\' && ++I == EOP)
69+
return false;
70+
}
6171
// The star is followed by a (possibly escaped) `Separator`.
6272
if (Pattern[I] == Separator) {
63-
if (NoMoreSeparatorsInFilePath)
64-
return false;
65-
J = K; // Skip to next `Separator` in `FilePath`.
66-
break;
73+
if (!Globstar) {
74+
if (NoMoreSeparatorsInFilePath)
75+
return false;
76+
J = K; // Skip to next `Separator` in `FilePath`.
77+
break;
78+
}
79+
if (++I == EOP)
80+
return FilePathBack == Separator;
6781
}
6882
// Recurse.
69-
for (auto Pat = Pattern.substr(I); J < End && FilePath[J] != Separator;
70-
++J) {
83+
for (auto Pat = Pattern.substr(I);
84+
J < End && (Globstar || FilePath[J] != Separator); ++J) {
7185
if (matchFilePath(Pat, FilePath.substr(J)))
7286
return true;
7387
}

0 commit comments

Comments
 (0)