Skip to content

Commit 1b09bb7

Browse files
authored
Merge branch 'main' into users/vitalybuka/spr/reapply-libc-explicitly-convert-to-masks-in-simd-code-107983
2 parents ab2eaf2 + 71d6b0b commit 1b09bb7

File tree

174 files changed

+2236
-1907
lines changed

Some content is hidden

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

174 files changed

+2236
-1907
lines changed

clang-tools-extra/clangd/tool/ClangdMain.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,13 @@ opt<std::string> FallbackStyle{
242242
init(clang::format::DefaultFallbackStyle),
243243
};
244244

245-
opt<int> EnableFunctionArgSnippets{
245+
opt<std::string> EnableFunctionArgSnippets{
246246
"function-arg-placeholders",
247247
cat(Features),
248248
desc("When disabled (0), completions contain only parentheses for "
249249
"function calls. When enabled (1), completions also contain "
250250
"placeholders for method parameters"),
251-
init(-1),
251+
init("-1"),
252252
};
253253

254254
opt<CodeCompleteOptions::IncludeInsertion> HeaderInsertion{
@@ -636,6 +636,22 @@ loadExternalIndex(const Config::ExternalIndexSpec &External,
636636
llvm_unreachable("Invalid ExternalIndexKind.");
637637
}
638638

639+
std::optional<bool> shouldEnableFunctionArgSnippets() {
640+
std::string Val = EnableFunctionArgSnippets;
641+
// Accept the same values that a bool option parser would, but also accept
642+
// -1 to indicate "unspecified", in which case the ArgumentListsPolicy
643+
// config option will be respected.
644+
if (Val == "1" || Val == "true" || Val == "True" || Val == "TRUE")
645+
return true;
646+
if (Val == "0" || Val == "false" || Val == "False" || Val == "FALSE")
647+
return false;
648+
if (Val != "-1")
649+
elog("Value specified by --function-arg-placeholders is invalid. Provide a "
650+
"boolean value or leave unspecified to use ArgumentListsPolicy from "
651+
"config instead.");
652+
return std::nullopt;
653+
}
654+
639655
class FlagsConfigProvider : public config::Provider {
640656
private:
641657
config::CompiledFragment Frag;
@@ -696,10 +712,9 @@ class FlagsConfigProvider : public config::Provider {
696712
BGPolicy = Config::BackgroundPolicy::Skip;
697713
}
698714

699-
if (EnableFunctionArgSnippets >= 0) {
700-
ArgumentLists = EnableFunctionArgSnippets
701-
? Config::ArgumentListsPolicy::FullPlaceholders
702-
: Config::ArgumentListsPolicy::Delimiters;
715+
if (std::optional<bool> Enable = shouldEnableFunctionArgSnippets()) {
716+
ArgumentLists = *Enable ? Config::ArgumentListsPolicy::FullPlaceholders
717+
: Config::ArgumentListsPolicy::Delimiters;
703718
}
704719

705720
Frag = [=](const config::Params &, Config &C) {

clang-tools-extra/docs/clang-tidy/checks/bugprone/unhandled-self-assignment.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,7 @@ temporary object into ``this`` (needs a move assignment operator):
120120
121121
.. option:: WarnOnlyIfThisHasSuspiciousField
122122

123-
When `true`, the check will warn only if the container class of the copy assignment operator
124-
has any suspicious fields (pointer or C array). This option is set to `true` by default.
123+
When `true`, the check will warn only if the container class of the copy
124+
assignment operator has any suspicious fields (pointer, C array and C++ smart
125+
pointer).
126+
This option is set to `true` by default.

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/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/Sema/SemaOverload.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6977,11 +6977,26 @@ void Sema::AddOverloadCandidate(
69776977
/// have linkage. So that all entities of the same should share one
69786978
/// linkage. But in clang, different entities of the same could have
69796979
/// different linkage.
6980-
NamedDecl *ND = Function;
6981-
if (auto *SpecInfo = Function->getTemplateSpecializationInfo())
6980+
const NamedDecl *ND = Function;
6981+
bool IsImplicitlyInstantiated = false;
6982+
if (auto *SpecInfo = Function->getTemplateSpecializationInfo()) {
69826983
ND = SpecInfo->getTemplate();
6983-
6984-
if (ND->getFormalLinkage() == Linkage::Internal) {
6984+
IsImplicitlyInstantiated = SpecInfo->getTemplateSpecializationKind() ==
6985+
TSK_ImplicitInstantiation;
6986+
}
6987+
6988+
/// Don't remove inline functions with internal linkage from the overload
6989+
/// set if they are declared in a GMF, in violation of C++ [basic.link]p17.
6990+
/// However:
6991+
/// - Inline functions with internal linkage are a common pattern in
6992+
/// headers to avoid ODR issues.
6993+
/// - The global module is meant to be a transition mechanism for C and C++
6994+
/// headers, and the current rules as written work against that goal.
6995+
const bool IsInlineFunctionInGMF =
6996+
Function->isFromGlobalModule() &&
6997+
(IsImplicitlyInstantiated || Function->isInlined());
6998+
6999+
if (ND->getFormalLinkage() == Linkage::Internal && !IsInlineFunctionInGMF) {
69857000
Candidate.Viable = false;
69867001
Candidate.FailureKind = ovl_fail_module_mismatched;
69877002
return;

clang/test/AST/ByteCode/builtin-functions.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,15 @@ namespace BuiltinMemcpy {
12441244
}
12451245
static_assert(cpyptr());
12461246

1247+
#ifndef __AVR__
1248+
constexpr int test_memmove(int a, int b, int n) {
1249+
int arr[4] = {1, 2, 3, 4};
1250+
__builtin_memmove(arr + a, arr + b, n); // both-note {{destination is not a contiguous array of at least 3 elements of type 'int'}}
1251+
return result(arr);
1252+
}
1253+
static_assert(test_memmove(2, 0, 12) == 4234); // both-error {{constant}} \
1254+
// both-note {{in call}}
1255+
#endif
12471256
}
12481257

12491258
namespace Memcmp {

clang/test/Driver/sanitizer-ld.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@
332332
// RUN: | %{filecheck} --check-prefix=CHECK-ASAN-ANDROID-SHARED-LIBASAN
333333
//
334334
// CHECK-ASAN-ANDROID-SHARED-LIBASAN-NOT: argument unused during compilation: '-shared-libsan'
335-
// CHECK-ASAN-ANDROID-SHARED-LIBASAN: libclang_rt.asan.so"
336-
// CHECK-ASAN-ANDROID-SHARED-LIBASAN: libclang_rt.asan_static.a"
335+
// CHECK-ASAN-ANDROID-SHARED-LIBASAN: libclang_rt.asan{{.*}}.so"
336+
// CHECK-ASAN-ANDROID-SHARED-LIBASAN: libclang_rt.asan_static{{.*}}.a"
337337
//
338338
// RUN: %clang -### %s 2>&1 \
339339
// RUN: --target=arm-linux-androideabi -fuse-ld=ld -fsanitize=address \
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
// RUN: split-file %s %t
4+
//
5+
// RUN: %clang -std=c++20 %t/a.cppm --precompile -o %t/a.pcm \
6+
// RUN: -DTEST_INLINE
7+
// RUN: %clang -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only -Xclang -verify \
8+
// RUN: -DTEST_INLINE
9+
//
10+
// RUN: %clang -std=c++20 %t/a.cppm --precompile -o %t/a.pcm
11+
// RUN: %clang -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only -Xclang -verify
12+
13+
//--- a.h
14+
#ifdef TEST_INLINE
15+
#define INLINE inline
16+
#else
17+
#define INLINE
18+
#endif
19+
static INLINE void func(long) {}
20+
template <typename T = long> void a() { func(T{}); }
21+
22+
//--- a.cppm
23+
module;
24+
#include "a.h"
25+
export module a;
26+
export using ::a;
27+
28+
//--- test.cc
29+
import a;
30+
auto m = (a(), 0);
31+
32+
#ifdef TEST_INLINE
33+
// expected-no-diagnostics
34+
#else
35+
// [email protected]:7 {{no matching function for call to 'func'}}
36+
// [email protected]:2 {{in instantiation of function template specialization 'a<long>' requested here}}
37+
#endif
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
// RUN: split-file %s %t
4+
//
5+
// RUN: %clang -std=c++20 %t/a.cppm --precompile -o %t/a.pcm
6+
// RUN: %clang -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only -Xclang -verify
7+
8+
//--- a.h
9+
template <typename G> static inline void func() {}
10+
template <typename T = long> void a() { func<T>(); }
11+
12+
//--- a.cppm
13+
module;
14+
#include "a.h"
15+
export module a;
16+
export using ::a;
17+
18+
//--- test.cc
19+
import a;
20+
auto m = (a(), 0);
21+
22+
// expected-no-diagnostics
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
// RUN: split-file %s %t
4+
//
5+
// RUN: %clang -std=c++20 %t/a.cppm --precompile -o %t/a.pcm
6+
// RUN: %clang -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only -Xclang -verify
7+
8+
//--- a.h
9+
namespace ns {
10+
template <typename G> static void func() {}
11+
template <typename T = long> void a() { func<T>(); }
12+
}
13+
14+
//--- a.cppm
15+
module;
16+
#include "a.h"
17+
export module a;
18+
export using ns::a;
19+
20+
//--- test.cc
21+
import a;
22+
auto m = (a(), 0);
23+
24+
// expected-no-diagnostics

0 commit comments

Comments
 (0)