Skip to content

Commit 2615770

Browse files
authored
Merge branch 'main' into Vishakh2012-doc-patch
2 parents dd9d580 + 2838066 commit 2615770

File tree

72 files changed

+2497
-337
lines changed

Some content is hidden

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

72 files changed

+2497
-337
lines changed

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/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/CodeGen/AArch64/fpm-helpers.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extern "C" {
3535
//
3636
fpm_t test_init() { return __arm_fpm_init(); }
3737

38-
// CHECK-LABEL: define dso_local noundef i64 @test_src1_1(
38+
// CHECK-LABEL: define dso_local noundef range(i64 0, -6) i64 @test_src1_1(
3939
// CHECK-SAME: ) local_unnamed_addr #[[ATTR0]] {
4040
// CHECK-NEXT: [[ENTRY:.*:]]
4141
// CHECK-NEXT: ret i64 -8
@@ -44,7 +44,7 @@ fpm_t test_src1_1() {
4444
return __arm_set_fpm_src1_format(INIT_ONES, __ARM_FPM_E5M2);
4545
}
4646

47-
// CHECK-LABEL: define dso_local noundef i64 @test_src1_2(
47+
// CHECK-LABEL: define dso_local noundef range(i64 0, -6) i64 @test_src1_2(
4848
// CHECK-SAME: ) local_unnamed_addr #[[ATTR0]] {
4949
// CHECK-NEXT: [[ENTRY:.*:]]
5050
// CHECK-NEXT: ret i64 1
@@ -53,7 +53,7 @@ fpm_t test_src1_2() {
5353
return __arm_set_fpm_src1_format(INIT_ZERO, __ARM_FPM_E4M3);
5454
}
5555

56-
// CHECK-LABEL: define dso_local noundef i64 @test_src2_1(
56+
// CHECK-LABEL: define dso_local noundef range(i64 0, -48) i64 @test_src2_1(
5757
// CHECK-SAME: ) local_unnamed_addr #[[ATTR0]] {
5858
// CHECK-NEXT: [[ENTRY:.*:]]
5959
// CHECK-NEXT: ret i64 -57
@@ -62,7 +62,7 @@ fpm_t test_src2_1() {
6262
return __arm_set_fpm_src2_format(INIT_ONES, __ARM_FPM_E5M2);
6363
}
6464

65-
// CHECK-LABEL: define dso_local noundef i64 @test_src2_2(
65+
// CHECK-LABEL: define dso_local noundef range(i64 0, -48) i64 @test_src2_2(
6666
// CHECK-SAME: ) local_unnamed_addr #[[ATTR0]] {
6767
// CHECK-NEXT: [[ENTRY:.*:]]
6868
// CHECK-NEXT: ret i64 8
@@ -71,7 +71,7 @@ fpm_t test_src2_2() {
7171
return __arm_set_fpm_src2_format(INIT_ZERO, __ARM_FPM_E4M3);
7272
}
7373

74-
// CHECK-LABEL: define dso_local noundef i64 @test_dst1_1(
74+
// CHECK-LABEL: define dso_local noundef range(i64 0, -384) i64 @test_dst1_1(
7575
// CHECK-SAME: ) local_unnamed_addr #[[ATTR0]] {
7676
// CHECK-NEXT: [[ENTRY:.*:]]
7777
// CHECK-NEXT: ret i64 -449
@@ -80,7 +80,7 @@ fpm_t test_dst1_1() {
8080
return __arm_set_fpm_dst_format(INIT_ONES, __ARM_FPM_E5M2);
8181
}
8282

83-
// CHECK-LABEL: define dso_local noundef i64 @test_dst2_2(
83+
// CHECK-LABEL: define dso_local noundef range(i64 0, -384) i64 @test_dst2_2(
8484
// CHECK-SAME: ) local_unnamed_addr #[[ATTR0]] {
8585
// CHECK-NEXT: [[ENTRY:.*:]]
8686
// CHECK-NEXT: ret i64 64
@@ -139,21 +139,21 @@ fpm_t test_lscale() { return __arm_set_fpm_lscale(INIT_ZERO, 127); }
139139
//
140140
fpm_t test_lscale2() { return __arm_set_fpm_lscale2(INIT_ZERO, 63); }
141141

142-
// CHECK-LABEL: define dso_local noundef range(i64 0, 4294967296) i64 @test_nscale_1(
142+
// CHECK-LABEL: define dso_local noundef range(i64 0, 4278190081) i64 @test_nscale_1(
143143
// CHECK-SAME: ) local_unnamed_addr #[[ATTR0]] {
144144
// CHECK-NEXT: [[ENTRY:.*:]]
145145
// CHECK-NEXT: ret i64 2147483648
146146
//
147147
fpm_t test_nscale_1() { return __arm_set_fpm_nscale(INIT_ZERO, -128); }
148148

149-
// CHECK-LABEL: define dso_local noundef range(i64 0, 4294967296) i64 @test_nscale_2(
149+
// CHECK-LABEL: define dso_local noundef range(i64 0, 4278190081) i64 @test_nscale_2(
150150
// CHECK-SAME: ) local_unnamed_addr #[[ATTR0]] {
151151
// CHECK-NEXT: [[ENTRY:.*:]]
152152
// CHECK-NEXT: ret i64 2130706432
153153
//
154154
fpm_t test_nscale_2() { return __arm_set_fpm_nscale(INIT_ZERO, 127); }
155155

156-
// CHECK-LABEL: define dso_local noundef range(i64 0, 4294967296) i64 @test_nscale_3(
156+
// CHECK-LABEL: define dso_local noundef range(i64 0, 4278190081) i64 @test_nscale_3(
157157
// CHECK-SAME: ) local_unnamed_addr #[[ATTR0]] {
158158
// CHECK-NEXT: [[ENTRY:.*:]]
159159
// CHECK-NEXT: ret i64 4278190080

compiler-rt/test/builtins/Unit/truncxfhf2_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ int main() {
4848

4949
// Positive infinity
5050
if (test_truncxfhf2(UINT16_C(0x7fff), UINT64_C(0x8000000000000000),
51-
UINT16_C(0x7c00U)))
51+
UINT16_C(0x7c00)))
5252
return 1;
5353

5454
// Negative infinity
5555
if (test_truncxfhf2(UINT16_C(0xffff), UINT64_C(0x8000000000000000),
56-
UINT16_C(0xfc00U)))
56+
UINT16_C(0xfc00)))
5757
return 1;
5858

5959
// NaN
6060
if (test_truncxfhf2(UINT16_C(0x7fff), UINT64_C(0xc000000000000000),
61-
UINT16_C(0x7e00U)))
61+
UINT16_C(0x7e00)))
6262
return 1;
6363

6464
return 0;

libc/src/compiler/generic/__stack_chk_fail.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
#include "src/compiler/__stack_chk_fail.h"
1010
#include "src/__support/OSUtil/io.h"
1111
#include "src/stdlib/abort.h"
12+
#include <stdint.h> // For uintptr_t
1213

1314
extern "C" {
1415

16+
uintptr_t __stack_chk_guard = static_cast<uintptr_t>(0xa9fff01234);
17+
1518
void __stack_chk_fail(void) {
1619
LIBC_NAMESPACE::write_to_stderr("stack smashing detected\n");
1720
LIBC_NAMESPACE::abort();

lld/MachO/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1842,7 +1842,7 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
18421842
args.hasArg(OPT_irpgo_profile_sort_eq))
18431843
warn("--irpgo-profile-sort is deprecated. Please use "
18441844
"--bp-startup-sort=function");
1845-
if (const Arg *arg = args.getLastArg(OPT_irpgo_profile_eq))
1845+
if (const Arg *arg = args.getLastArg(OPT_irpgo_profile))
18461846
config->irpgoProfilePath = arg->getValue();
18471847

18481848
if (const Arg *arg = args.getLastArg(OPT_irpgo_profile_sort)) {

lld/MachO/Options.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,10 @@ def no_call_graph_profile_sort : Flag<["--"], "no-call-graph-profile-sort">,
126126
def print_symbol_order_eq: Joined<["--"], "print-symbol-order=">,
127127
HelpText<"Print a symbol order specified by --call-graph-profile-sort into the specified file">,
128128
Group<grp_lld>;
129+
def irpgo_profile: Separate<["--"], "irpgo-profile">, Group<grp_lld>;
129130
def irpgo_profile_eq: Joined<["--"], "irpgo-profile=">,
130-
HelpText<"Read the IRPGO profile for use with -bp-startup-sort and other profile-guided optimizations">,
131+
Alias<!cast<Separate>(irpgo_profile)>, MetaVarName<"<profile>">,
132+
HelpText<"Read the IRPGO <profile> for use with -bp-startup-sort and other profile-guided optimizations">,
131133
Group<grp_lld>;
132134
def bp_startup_sort: Joined<["--"], "bp-startup-sort=">,
133135
MetaVarName<"[none,function]">,

lld/test/MachO/bp-section-orderer-errs.s

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
# RUN: not %lld -o /dev/null --bp-compression-sort-startup-functions 2>&1 | FileCheck %s --check-prefix=STARTUP
1515
# STARTUP: --bp-compression-sort-startup-functions must be used with --bp-startup-sort=function
1616

17+
# RUN: not %lld -o /dev/null --irpgo-profile %s --bp-startup-sort=function --call-graph-profile-sort 2>&1 | FileCheck %s --check-prefix=IRPGO-STARTUP
1718
# RUN: not %lld -o /dev/null --irpgo-profile=%s --bp-startup-sort=function --call-graph-profile-sort 2>&1 | FileCheck %s --check-prefix=IRPGO-STARTUP
1819
# IRPGO-STARTUP: --bp-startup-sort= is incompatible with --call-graph-profile-sort
1920

2021
# RUN: not %lld -o /dev/null --bp-startup-sort=function 2>&1 | FileCheck %s --check-prefix=STARTUP-COMPRESSION
21-
# STARTUP-COMPRESSION: --bp-startup-sort=function must be used with --irpgo-profile
22+
# STARTUP-COMPRESSION: --bp-startup-sort=function must be used with --irpgo-profile

lld/test/MachO/bp-section-orderer.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# RUN: %no-fatal-warnings-lld -arch arm64 -lSystem -e _main -o %t/a.out %t/a.o --irpgo-profile-sort=%t/a.profdata --verbose-bp-section-orderer 2>&1 | FileCheck %s --check-prefix=STARTUP
88
# RUN: %no-fatal-warnings-lld -arch arm64 -lSystem -e _main -o %t/a.out %t/a.o --irpgo-profile-sort=%t/a.profdata --verbose-bp-section-orderer --icf=all --compression-sort=none 2>&1 | FileCheck %s --check-prefix=STARTUP
99

10-
# RUN: %lld -arch arm64 -lSystem -e _main -o %t/a.out %t/a.o --irpgo-profile=%t/a.profdata --bp-startup-sort=function --verbose-bp-section-orderer 2>&1 | FileCheck %s --check-prefix=STARTUP
10+
# RUN: %lld -arch arm64 -lSystem -e _main -o %t/a.out %t/a.o --irpgo-profile %t/a.profdata --bp-startup-sort=function --verbose-bp-section-orderer 2>&1 | FileCheck %s --check-prefix=STARTUP
1111
# RUN: %lld -arch arm64 -lSystem -e _main -o %t/a.out %t/a.o --irpgo-profile=%t/a.profdata --bp-startup-sort=function --verbose-bp-section-orderer --icf=all --bp-compression-sort=none 2>&1 | FileCheck %s --check-prefix=STARTUP
1212
# STARTUP: Ordered 3 sections using balanced partitioning
1313

0 commit comments

Comments
 (0)