Skip to content

Commit 7662cb4

Browse files
committed
Merge branch 'upstream' into x86-fast-amd-shld
2 parents 14c57ed + 0237216 commit 7662cb4

File tree

133 files changed

+5563
-2291
lines changed

Some content is hidden

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

133 files changed

+5563
-2291
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,8 @@ def fhip_emit_relocatable : Flag<["-"], "fhip-emit-relocatable">,
13921392
HelpText<"Compile HIP source to relocatable">;
13931393
def fno_hip_emit_relocatable : Flag<["-"], "fno-hip-emit-relocatable">,
13941394
HelpText<"Do not override toolchain to compile HIP source to relocatable">;
1395+
def flto_partitions_EQ : Joined<["--"], "flto-partitions=">, Group<hip_Group>,
1396+
HelpText<"Number of partitions to use for parallel full LTO codegen. Use 1 to disable partitioning.">;
13951397
}
13961398

13971399
// Clang specific/exclusive options for OpenACC.

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,13 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
212212
const Pointer &A = getParam<Pointer>(Frame, 0);
213213
const Pointer &B = getParam<Pointer>(Frame, 1);
214214

215-
if (ID == Builtin::BIstrcmp || ID == Builtin::BIstrncmp)
215+
if (ID == Builtin::BIstrcmp || ID == Builtin::BIstrncmp ||
216+
ID == Builtin::BIwcscmp || ID == Builtin::BIwcsncmp)
216217
diagnoseNonConstexprBuiltin(S, OpPC, ID);
217218

218219
uint64_t Limit = ~static_cast<uint64_t>(0);
219-
if (ID == Builtin::BIstrncmp || ID == Builtin::BI__builtin_strncmp)
220+
if (ID == Builtin::BIstrncmp || ID == Builtin::BI__builtin_strncmp ||
221+
ID == Builtin::BIwcsncmp || ID == Builtin::BI__builtin_wcsncmp)
220222
Limit = peekToAPSInt(S.Stk, *S.getContext().classify(Call->getArg(2)))
221223
.getZExtValue();
222224

@@ -231,6 +233,9 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
231233
if (A.isDummy() || B.isDummy())
232234
return false;
233235

236+
bool IsWide = ID == Builtin::BIwcscmp || ID == Builtin::BIwcsncmp ||
237+
ID == Builtin::BI__builtin_wcscmp ||
238+
ID == Builtin::BI__builtin_wcsncmp;
234239
assert(A.getFieldDesc()->isPrimitiveArray());
235240
assert(B.getFieldDesc()->isPrimitiveArray());
236241

@@ -248,6 +253,21 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
248253
!CheckRange(S, OpPC, PB, AK_Read)) {
249254
return false;
250255
}
256+
257+
if (IsWide)
258+
INT_TYPE_SWITCH(
259+
*S.getContext().classify(S.getASTContext().getWCharType()), {
260+
T A = PA.deref<T>();
261+
T B = PB.deref<T>();
262+
if (A < B) {
263+
pushInteger(S, -1, Call->getType());
264+
return true;
265+
} else if (A > B) {
266+
pushInteger(S, 1, Call->getType());
267+
return true;
268+
}
269+
});
270+
251271
uint8_t CA = PA.deref<uint8_t>();
252272
uint8_t CB = PB.deref<uint8_t>();
253273

@@ -1792,6 +1812,17 @@ static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC,
17921812
return false;
17931813
}
17941814

1815+
// Diagnose integral src/dest pointers specially.
1816+
if (SrcPtr.isIntegralPointer() || DestPtr.isIntegralPointer()) {
1817+
std::string DiagVal = "(void *)";
1818+
DiagVal += SrcPtr.isIntegralPointer()
1819+
? std::to_string(SrcPtr.getIntegerRepresentation())
1820+
: std::to_string(DestPtr.getIntegerRepresentation());
1821+
S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_memcpy_null)
1822+
<< Move << false << DestPtr.isIntegralPointer() << DiagVal;
1823+
return false;
1824+
}
1825+
17951826
// Can't read from dummy pointers.
17961827
if (DestPtr.isDummy() || SrcPtr.isDummy())
17971828
return false;
@@ -2109,6 +2140,10 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
21092140
case Builtin::BIstrcmp:
21102141
case Builtin::BI__builtin_strncmp:
21112142
case Builtin::BIstrncmp:
2143+
case Builtin::BI__builtin_wcsncmp:
2144+
case Builtin::BIwcsncmp:
2145+
case Builtin::BI__builtin_wcscmp:
2146+
case Builtin::BIwcscmp:
21122147
if (!interp__builtin_strcmp(S, OpPC, Frame, F, Call))
21132148
return false;
21142149
break;

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,11 @@ void amdgpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
630630
getToolChain().AddFilePathLibArgs(Args, CmdArgs);
631631
AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
632632
if (C.getDriver().isUsingLTO()) {
633-
addLTOOptions(getToolChain(), Args, CmdArgs, Output, Inputs[0],
634-
C.getDriver().getLTOMode() == LTOK_Thin);
633+
const bool ThinLTO = (C.getDriver().getLTOMode() == LTOK_Thin);
634+
addLTOOptions(getToolChain(), Args, CmdArgs, Output, Inputs[0], ThinLTO);
635+
636+
if (!ThinLTO)
637+
addFullLTOPartitionOption(C.getDriver(), Args, CmdArgs);
635638
} else if (Args.hasArg(options::OPT_mcpu_EQ)) {
636639
CmdArgs.push_back(Args.MakeArgString(
637640
"-plugin-opt=mcpu=" +
@@ -708,6 +711,33 @@ void amdgpu::getAMDGPUTargetFeatures(const Driver &D,
708711
options::OPT_m_amdgpu_Features_Group);
709712
}
710713

714+
static unsigned getFullLTOPartitions(const Driver &D, const ArgList &Args) {
715+
const Arg *A = Args.getLastArg(options::OPT_flto_partitions_EQ);
716+
// In the absence of an option, use 8 as the default.
717+
if (!A)
718+
return 8;
719+
int Value = 0;
720+
if (StringRef(A->getValue()).getAsInteger(10, Value) || (Value < 1)) {
721+
D.Diag(diag::err_drv_invalid_int_value)
722+
<< A->getAsString(Args) << A->getValue();
723+
return 1;
724+
}
725+
726+
return Value;
727+
}
728+
729+
void amdgpu::addFullLTOPartitionOption(const Driver &D,
730+
const llvm::opt::ArgList &Args,
731+
llvm::opt::ArgStringList &CmdArgs) {
732+
// TODO: Should this be restricted to fgpu-rdc only ? Currently we'll
733+
// also do it for non gpu-rdc LTO
734+
735+
if (unsigned NumParts = getFullLTOPartitions(D, Args); NumParts > 1) {
736+
CmdArgs.push_back(
737+
Args.MakeArgString("--lto-partitions=" + Twine(NumParts)));
738+
}
739+
}
740+
711741
/// AMDGPU Toolchain
712742
AMDGPUToolChain::AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
713743
const ArgList &Args)

clang/lib/Driver/ToolChains/AMDGPU.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ void getAMDGPUTargetFeatures(const Driver &D, const llvm::Triple &Triple,
4141
const llvm::opt::ArgList &Args,
4242
std::vector<StringRef> &Features);
4343

44+
void addFullLTOPartitionOption(const Driver &D, const llvm::opt::ArgList &Args,
45+
llvm::opt::ArgStringList &CmdArgs);
4446
} // end namespace amdgpu
4547
} // end namespace tools
4648

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9337,6 +9337,11 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
93379337
CmdArgs.push_back(
93389338
Args.MakeArgString("--device-linker=" + TC.getTripleString() + "=" +
93399339
"-lclang_rt.builtins"));
9340+
bool HasFlangRT = HasCompilerRT && C.getDriver().IsFlangMode();
9341+
if (HasFlangRT)
9342+
CmdArgs.push_back(
9343+
Args.MakeArgString("--device-linker=" + TC.getTripleString() + "=" +
9344+
"-lflang_rt.runtime"));
93409345
});
93419346
}
93429347

clang/lib/Driver/ToolChains/HIPAMD.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, const JobAction &JA,
116116

117117
addLinkerCompressDebugSectionsOption(TC, Args, LldArgs);
118118

119+
amdgpu::addFullLTOPartitionOption(D, Args, LldArgs);
120+
119121
// Given that host and device linking happen in separate processes, the device
120122
// linker doesn't always have the visibility as to which device symbols are
121123
// needed by a program, especially for the device symbol dependencies that are

clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,11 @@ void ContainerModeling::checkPostCall(const CallEvent &Call,
157157
if (Func->isOverloadedOperator()) {
158158
const auto Op = Func->getOverloadedOperator();
159159
if (Op == OO_Equal) {
160-
// Overloaded 'operator=' must be a non-static member function.
161-
const auto *InstCall = cast<CXXInstanceCall>(&Call);
160+
// Only handle the assignment operator with implicit this
161+
const auto *InstCall = dyn_cast<CXXInstanceCall>(&Call);
162+
if (!InstCall)
163+
return;
164+
162165
if (cast<CXXMethodDecl>(Func)->isMoveAssignmentOperator()) {
163166
handleAssignment(C, InstCall->getCXXThisVal(), Call.getOriginExpr(),
164167
Call.getArgSVal(0));

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ extern "C" {
2222
extern char *strchr(const char *s, int c);
2323
extern wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n);
2424
extern wchar_t *wcschr(const wchar_t *s, wchar_t c);
25+
extern int wcscmp(const wchar_t *s1, const wchar_t *s2);
26+
extern int wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n);
2527
}
2628

2729
namespace strcmp {
@@ -66,6 +68,50 @@ namespace strcmp {
6668
static_assert(__builtin_strncmp("abab\0banana", "abab\0canada", 100) == 0);
6769
}
6870

71+
namespace WcsCmp {
72+
constexpr wchar_t kFoobar[6] = {L'f',L'o',L'o',L'b',L'a',L'r'};
73+
constexpr wchar_t kFoobazfoobar[12] = {L'f',L'o',L'o',L'b',L'a',L'z',L'f',L'o',L'o',L'b',L'a',L'r'};
74+
75+
static_assert(__builtin_wcscmp(L"abab", L"abab") == 0);
76+
static_assert(__builtin_wcscmp(L"abab", L"abba") == -1);
77+
static_assert(__builtin_wcscmp(L"abab", L"abaa") == 1);
78+
static_assert(__builtin_wcscmp(L"ababa", L"abab") == 1);
79+
static_assert(__builtin_wcscmp(L"abab", L"ababa") == -1);
80+
static_assert(__builtin_wcscmp(L"abab\0banana", L"abab") == 0);
81+
static_assert(__builtin_wcscmp(L"abab", L"abab\0banana") == 0);
82+
static_assert(__builtin_wcscmp(L"abab\0banana", L"abab\0canada") == 0);
83+
#if __WCHAR_WIDTH__ == 32
84+
static_assert(__builtin_wcscmp(L"a\x83838383", L"a") == (wchar_t)-1U >> 31);
85+
#endif
86+
static_assert(__builtin_wcscmp(0, L"abab") == 0); // both-error {{not an integral constant}} \
87+
// both-note {{dereferenced null}}
88+
static_assert(__builtin_wcscmp(L"abab", 0) == 0); // both-error {{not an integral constant}} \
89+
// both-note {{dereferenced null}}
90+
91+
static_assert(__builtin_wcscmp(kFoobar, kFoobazfoobar) == -1);
92+
static_assert(__builtin_wcscmp(kFoobar, kFoobazfoobar + 6) == 0); // both-error {{not an integral constant}} \
93+
// both-note {{dereferenced one-past-the-end}}
94+
95+
static_assert(__builtin_wcsncmp(L"abaa", L"abba", 5) == -1);
96+
static_assert(__builtin_wcsncmp(L"abaa", L"abba", 4) == -1);
97+
static_assert(__builtin_wcsncmp(L"abaa", L"abba", 3) == -1);
98+
static_assert(__builtin_wcsncmp(L"abaa", L"abba", 2) == 0);
99+
static_assert(__builtin_wcsncmp(L"abaa", L"abba", 1) == 0);
100+
static_assert(__builtin_wcsncmp(L"abaa", L"abba", 0) == 0);
101+
static_assert(__builtin_wcsncmp(0, 0, 0) == 0);
102+
static_assert(__builtin_wcsncmp(L"abab\0banana", L"abab\0canada", 100) == 0);
103+
#if __WCHAR_WIDTH__ == 32
104+
static_assert(__builtin_wcsncmp(L"a\x83838383", L"aa", 2) ==
105+
(wchar_t)-1U >> 31);
106+
#endif
107+
108+
static_assert(__builtin_wcsncmp(kFoobar, kFoobazfoobar, 6) == -1);
109+
static_assert(__builtin_wcsncmp(kFoobar, kFoobazfoobar, 7) == -1);
110+
static_assert(__builtin_wcsncmp(kFoobar, kFoobazfoobar + 6, 6) == 0);
111+
static_assert(__builtin_wcsncmp(kFoobar, kFoobazfoobar + 6, 7) == 0); // both-error {{not an integral constant}} \
112+
// both-note {{dereferenced one-past-the-end}}
113+
}
114+
69115
/// Copied from constant-expression-cxx11.cpp
70116
namespace strlen {
71117
constexpr const char *a = "foo\0quux";
@@ -1290,6 +1336,12 @@ namespace BuiltinMemcpy {
12901336
return Result1 && Result2;
12911337
}
12921338
static_assert(memmoveOverlapping());
1339+
1340+
#define fold(x) (__builtin_constant_p(0) ? (x) : (x))
1341+
static_assert(__builtin_memcpy(&global, fold((wchar_t*)123), sizeof(wchar_t))); // both-error {{not an integral constant expression}} \
1342+
// both-note {{source of 'memcpy' is (void *)123}}
1343+
static_assert(__builtin_memcpy(fold(reinterpret_cast<wchar_t*>(123)), &global, sizeof(wchar_t))); // both-error {{not an integral constant expression}} \
1344+
// both-note {{destination of 'memcpy' is (void *)123}}
12931345
}
12941346

12951347
namespace Memcmp {

clang/test/Analysis/invalidated-iterator.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.InvalidatedIterator -analyzer-config aggressive-binary-operation-simplification=true -analyzer-config c++-container-inlining=false %s -verify
22
// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.InvalidatedIterator -analyzer-config aggressive-binary-operation-simplification=true -analyzer-config c++-container-inlining=true -DINLINE=1 %s -verify
3+
// RUN: %clang_analyze_cc1 -std=c++23 -analyzer-checker=core,cplusplus,alpha.cplusplus.InvalidatedIterator -analyzer-config aggressive-binary-operation-simplification=true -analyzer-config c++-container-inlining=true -DINLINE=1 %s -verify
34

45
#include "Inputs/system-header-simulator-cxx.h"
56

@@ -204,4 +205,26 @@ void invalidated_subscript_end_ptr_iterator(cont_with_ptr_iterator<int> &C) {
204205
auto i = C.begin();
205206
C.erase(i);
206207
(void) i[1]; // expected-warning{{Invalidated iterator accessed}}
207-
}
208+
}
209+
210+
#if __cplusplus >= 202302L
211+
namespace GH116372 {
212+
class ExplicitThis {
213+
int f = 0;
214+
public:
215+
ExplicitThis();
216+
ExplicitThis(ExplicitThis& other);
217+
218+
ExplicitThis& operator=(this ExplicitThis& self, ExplicitThis const& other) { // no crash
219+
self.f = other.f;
220+
return self;
221+
}
222+
223+
~ExplicitThis();
224+
};
225+
226+
void func(ExplicitThis& obj1) {
227+
obj1 = obj1;
228+
}
229+
}
230+
#endif

0 commit comments

Comments
 (0)