Skip to content

Commit 3e78303

Browse files
authored
Merge pull request llvm#589 from AMD-Lightning-Internal/upstream_merge_202502101140
merge main into amd-staging
2 parents 8d13721 + 93bf5bd commit 3e78303

File tree

123 files changed

+5093
-1681
lines changed

Some content is hidden

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

123 files changed

+5093
-1681
lines changed

clang/docs/BoundsSafety.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,13 +777,13 @@ the transformed pseudo code of function ``alloc_buf()`` in the example below.
777777
size_t count;
778778
} sized_buf_t;
779779
780-
void alloc_buf(sized_buf_t *sbuf, sized_t nelems) {
780+
void alloc_buf(sized_buf_t *sbuf, size_t nelems) {
781781
sbuf->buf = (int *)malloc(sizeof(int) * nelems);
782782
sbuf->count = nelems;
783783
}
784784
785785
// Transformed pseudo code:
786-
void alloc_buf(sized_buf_t *sbuf, sized_t nelems) {
786+
void alloc_buf(sized_buf_t *sbuf, size_t nelems) {
787787
// Materialize RHS values:
788788
int *tmp_ptr = (int *)malloc(sizeof(int) * nelems);
789789
int tmp_count = nelems;

clang/docs/BoundsSafetyImplPlans.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ same basic block and without side effect in between.
134134
int *__counted_by(count) buf; size_t count;
135135
} sized_buf_t;
136136
137-
void alloc_buf(sized_buf_t *sbuf, sized_t nelems) {
137+
void alloc_buf(sized_buf_t *sbuf, size_t nelems) {
138138
sbuf->buf = (int *)malloc(sizeof(int) * nelems);
139139
sbuf->count = nelems;
140140
}

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 116 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3370,15 +3370,23 @@ bool Compiler<Emitter>::VisitCXXNewExpr(const CXXNewExpr *E) {
33703370

33713371
PrimType SizeT = classifyPrim(Stripped->getType());
33723372

3373+
// Save evaluated array size to a variable.
3374+
unsigned ArrayLen = allocateLocalPrimitive(
3375+
Stripped, SizeT, /*IsConst=*/false, /*IsExtended=*/false);
3376+
if (!this->visit(Stripped))
3377+
return false;
3378+
if (!this->emitSetLocal(SizeT, ArrayLen, E))
3379+
return false;
3380+
33733381
if (PlacementDest) {
33743382
if (!this->visit(PlacementDest))
33753383
return false;
3376-
if (!this->visit(Stripped))
3384+
if (!this->emitGetLocal(SizeT, ArrayLen, E))
33773385
return false;
33783386
if (!this->emitCheckNewTypeMismatchArray(SizeT, E, E))
33793387
return false;
33803388
} else {
3381-
if (!this->visit(Stripped))
3389+
if (!this->emitGetLocal(SizeT, ArrayLen, E))
33823390
return false;
33833391

33843392
if (ElemT) {
@@ -3392,10 +3400,113 @@ bool Compiler<Emitter>::VisitCXXNewExpr(const CXXNewExpr *E) {
33923400
}
33933401
}
33943402

3395-
if (Init && !this->visitInitializer(Init))
3396-
return false;
3403+
if (Init) {
3404+
QualType InitType = Init->getType();
3405+
size_t StaticInitElems = 0;
3406+
const Expr *DynamicInit = nullptr;
3407+
if (const ConstantArrayType *CAT =
3408+
Ctx.getASTContext().getAsConstantArrayType(InitType)) {
3409+
StaticInitElems = CAT->getZExtSize();
3410+
if (!this->visitInitializer(Init))
3411+
return false;
33973412

3398-
} else {
3413+
if (const auto *ILE = dyn_cast<InitListExpr>(Init);
3414+
ILE && ILE->hasArrayFiller())
3415+
DynamicInit = ILE->getArrayFiller();
3416+
}
3417+
3418+
// The initializer initializes a certain number of elements, S.
3419+
// However, the complete number of elements, N, might be larger than that.
3420+
// In this case, we need to get an initializer for the remaining elements.
3421+
// There are to cases:
3422+
// 1) For the form 'new Struct[n];', the initializer is a
3423+
// CXXConstructExpr and its type is an IncompleteArrayType.
3424+
// 2) For the form 'new Struct[n]{1,2,3}', the initializer is an
3425+
// InitListExpr and the initializer for the remaining elements
3426+
// is the array filler.
3427+
3428+
if (DynamicInit || InitType->isIncompleteArrayType()) {
3429+
const Function *CtorFunc = nullptr;
3430+
if (const auto *CE = dyn_cast<CXXConstructExpr>(Init)) {
3431+
CtorFunc = getFunction(CE->getConstructor());
3432+
if (!CtorFunc)
3433+
return false;
3434+
}
3435+
3436+
LabelTy EndLabel = this->getLabel();
3437+
LabelTy StartLabel = this->getLabel();
3438+
3439+
// In the nothrow case, the alloc above might have returned nullptr.
3440+
// Don't call any constructors that case.
3441+
if (IsNoThrow) {
3442+
if (!this->emitDupPtr(E))
3443+
return false;
3444+
if (!this->emitNullPtr(0, nullptr, E))
3445+
return false;
3446+
if (!this->emitEQPtr(E))
3447+
return false;
3448+
if (!this->jumpTrue(EndLabel))
3449+
return false;
3450+
}
3451+
3452+
// Create loop variables.
3453+
unsigned Iter = allocateLocalPrimitive(
3454+
Stripped, SizeT, /*IsConst=*/false, /*IsExtended=*/false);
3455+
if (!this->emitConst(StaticInitElems, SizeT, E))
3456+
return false;
3457+
if (!this->emitSetLocal(SizeT, Iter, E))
3458+
return false;
3459+
3460+
this->fallthrough(StartLabel);
3461+
this->emitLabel(StartLabel);
3462+
// Condition. Iter < ArrayLen?
3463+
if (!this->emitGetLocal(SizeT, Iter, E))
3464+
return false;
3465+
if (!this->emitGetLocal(SizeT, ArrayLen, E))
3466+
return false;
3467+
if (!this->emitLT(SizeT, E))
3468+
return false;
3469+
if (!this->jumpFalse(EndLabel))
3470+
return false;
3471+
3472+
// Pointer to the allocated array is already on the stack.
3473+
if (!this->emitGetLocal(SizeT, Iter, E))
3474+
return false;
3475+
if (!this->emitArrayElemPtr(SizeT, E))
3476+
return false;
3477+
3478+
if (DynamicInit) {
3479+
if (std::optional<PrimType> InitT = classify(DynamicInit)) {
3480+
if (!this->visit(DynamicInit))
3481+
return false;
3482+
if (!this->emitStorePop(*InitT, E))
3483+
return false;
3484+
} else {
3485+
if (!this->visitInitializer(DynamicInit))
3486+
return false;
3487+
if (!this->emitPopPtr(E))
3488+
return false;
3489+
}
3490+
} else {
3491+
assert(CtorFunc);
3492+
if (!this->emitCall(CtorFunc, 0, E))
3493+
return false;
3494+
}
3495+
3496+
// ++Iter;
3497+
if (!this->emitGetPtrLocal(Iter, E))
3498+
return false;
3499+
if (!this->emitIncPop(SizeT, E))
3500+
return false;
3501+
3502+
if (!this->jump(StartLabel))
3503+
return false;
3504+
3505+
this->fallthrough(EndLabel);
3506+
this->emitLabel(EndLabel);
3507+
}
3508+
}
3509+
} else { // Non-array.
33993510
if (PlacementDest) {
34003511
if (!this->visit(PlacementDest))
34013512
return false;

clang/lib/AST/ByteCode/Interp.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,10 @@ bool InitThisBitField(InterpState &S, CodePtr OpPC, const Record::Field *F,
14841484
template <PrimType Name, class T = typename PrimConv<Name>::T>
14851485
bool InitField(InterpState &S, CodePtr OpPC, uint32_t I) {
14861486
const T &Value = S.Stk.pop<T>();
1487-
const Pointer &Field = S.Stk.peek<Pointer>().atField(I);
1487+
const Pointer &Ptr = S.Stk.peek<Pointer>();
1488+
if (!CheckRange(S, OpPC, Ptr, CSK_Field))
1489+
return false;
1490+
const Pointer &Field = Ptr.atField(I);
14881491
Field.deref<T>() = Value;
14891492
Field.activate();
14901493
Field.initialize();

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,21 +1070,23 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
10701070
ArgM = ArgMD;
10711071

10721072
if (ArgM) {
1073-
// Determine the output location.
1074-
const char *DepFile;
1075-
if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
1076-
DepFile = MF->getValue();
1077-
C.addFailureResultFile(DepFile, &JA);
1078-
} else if (Output.getType() == types::TY_Dependencies) {
1079-
DepFile = Output.getFilename();
1080-
} else if (!ArgMD) {
1081-
DepFile = "-";
1082-
} else {
1083-
DepFile = getDependencyFileName(Args, Inputs);
1084-
C.addFailureResultFile(DepFile, &JA);
1073+
if (!JA.isDeviceOffloading(Action::OFK_HIP)) {
1074+
// Determine the output location.
1075+
const char *DepFile;
1076+
if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
1077+
DepFile = MF->getValue();
1078+
C.addFailureResultFile(DepFile, &JA);
1079+
} else if (Output.getType() == types::TY_Dependencies) {
1080+
DepFile = Output.getFilename();
1081+
} else if (!ArgMD) {
1082+
DepFile = "-";
1083+
} else {
1084+
DepFile = getDependencyFileName(Args, Inputs);
1085+
C.addFailureResultFile(DepFile, &JA);
1086+
}
1087+
CmdArgs.push_back("-dependency-file");
1088+
CmdArgs.push_back(DepFile);
10851089
}
1086-
CmdArgs.push_back("-dependency-file");
1087-
CmdArgs.push_back(DepFile);
10881090

10891091
bool HasTarget = false;
10901092
for (const Arg *A : Args.filtered(options::OPT_MT, options::OPT_MQ)) {
@@ -9429,24 +9431,13 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
94299431
for (StringRef Arg : LinkerArgs)
94309432
CmdArgs.push_back(Args.MakeArgString(
94319433
"--device-linker=" + TC->getTripleString() + "=" + Arg));
9432-
9433-
// Forward the LTO mode relying on the Driver's parsing.
9434-
if (C.getDriver().getOffloadLTOMode() == LTOK_Full)
9435-
CmdArgs.push_back(Args.MakeArgString(
9436-
"--device-compiler=" + TC->getTripleString() + "=-flto=full"));
9437-
else if (C.getDriver().getOffloadLTOMode() == LTOK_Thin)
9438-
CmdArgs.push_back(Args.MakeArgString(
9439-
"--device-compiler=" + TC->getTripleString() + "=-flto=thin"));
94409434
}
94419435
}
94429436

94439437
CmdArgs.push_back(
94449438
Args.MakeArgString("--host-triple=" + getToolChain().getTripleString()));
94459439
if (Args.hasArg(options::OPT_v))
94469440
CmdArgs.push_back("--wrapper-verbose");
9447-
if (Arg *A = Args.getLastArg(options::OPT_cuda_path_EQ))
9448-
CmdArgs.push_back(
9449-
Args.MakeArgString(Twine("--cuda-path=") + A->getValue()));
94509441

94519442
// Construct the link job so we can wrap around it.
94529443
Linker->ConstructJob(C, JA, Output, Inputs, Args, LinkingOutput);

clang/lib/Headers/avx10_2_512convertintrin.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,19 +213,19 @@ _mm512_maskz_cvts2ph_hf8(__mmask64 __U, __m512h __A, __m512h __B) {
213213
(__v64qi)(__m512i)_mm512_setzero_si512());
214214
}
215215

216-
static __inline__ __m512h __DEFAULT_FN_ATTRS512 _mm512_cvthf8(__m256i __A) {
216+
static __inline__ __m512h __DEFAULT_FN_ATTRS512 _mm512_cvthf8_ph(__m256i __A) {
217217
return (__m512h)__builtin_ia32_vcvthf8_2ph512_mask(
218218
(__v32qi)__A, (__v32hf)(__m512h)_mm512_undefined_ph(), (__mmask32)-1);
219219
}
220220

221221
static __inline__ __m512h __DEFAULT_FN_ATTRS512
222-
_mm512_mask_cvthf8(__m512h __W, __mmask32 __U, __m256i __A) {
222+
_mm512_mask_cvthf8_ph(__m512h __W, __mmask32 __U, __m256i __A) {
223223
return (__m512h)__builtin_ia32_vcvthf8_2ph512_mask(
224224
(__v32qi)__A, (__v32hf)(__m512h)__W, (__mmask32)__U);
225225
}
226226

227227
static __inline__ __m512h __DEFAULT_FN_ATTRS512
228-
_mm512_maskz_cvthf8(__mmask32 __U, __m256i __A) {
228+
_mm512_maskz_cvthf8_ph(__mmask32 __U, __m256i __A) {
229229
return (__m512h)__builtin_ia32_vcvthf8_2ph512_mask(
230230
(__v32qi)__A, (__v32hf)(__m512h)_mm512_setzero_ph(), (__mmask32)__U);
231231
}

clang/lib/Headers/avx10_2convertintrin.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -381,37 +381,36 @@ _mm256_maskz_cvts2ph_hf8(__mmask32 __U, __m256h __A, __m256h __B) {
381381
(__v32qi)(__m256i)_mm256_setzero_si256());
382382
}
383383

384-
static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_cvthf8(__m128i __A) {
384+
static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_cvthf8_ph(__m128i __A) {
385385
return (__m128h)__builtin_ia32_vcvthf8_2ph128_mask(
386386
(__v16qi)__A, (__v8hf)(__m128h)_mm_undefined_ph(), (__mmask8)-1);
387387
}
388388

389-
static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_mask_cvthf8(__m128h __W,
390-
__mmask8 __U,
391-
__m128i __A) {
389+
static __inline__ __m128h __DEFAULT_FN_ATTRS128
390+
_mm_mask_cvthf8_ph(__m128h __W, __mmask8 __U, __m128i __A) {
392391
return (__m128h)__builtin_ia32_vcvthf8_2ph128_mask(
393392
(__v16qi)__A, (__v8hf)(__m128h)__W, (__mmask8)__U);
394393
}
395394

396-
static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_maskz_cvthf8(__mmask8 __U,
397-
__m128i __A) {
395+
static __inline__ __m128h __DEFAULT_FN_ATTRS128
396+
_mm_maskz_cvthf8_ph(__mmask8 __U, __m128i __A) {
398397
return (__m128h)__builtin_ia32_vcvthf8_2ph128_mask(
399398
(__v16qi)__A, (__v8hf)(__m128h)_mm_setzero_ph(), (__mmask8)__U);
400399
}
401400

402-
static __inline__ __m256h __DEFAULT_FN_ATTRS256 _mm256_cvthf8(__m128i __A) {
401+
static __inline__ __m256h __DEFAULT_FN_ATTRS256 _mm256_cvthf8_ph(__m128i __A) {
403402
return (__m256h)__builtin_ia32_vcvthf8_2ph256_mask(
404403
(__v16qi)__A, (__v16hf)(__m256h)_mm256_undefined_ph(), (__mmask16)-1);
405404
}
406405

407406
static __inline__ __m256h __DEFAULT_FN_ATTRS256
408-
_mm256_mask_cvthf8(__m256h __W, __mmask16 __U, __m128i __A) {
407+
_mm256_mask_cvthf8_ph(__m256h __W, __mmask16 __U, __m128i __A) {
409408
return (__m256h)__builtin_ia32_vcvthf8_2ph256_mask(
410409
(__v16qi)__A, (__v16hf)(__m256h)__W, (__mmask16)__U);
411410
}
412411

413412
static __inline__ __m256h __DEFAULT_FN_ATTRS256
414-
_mm256_maskz_cvthf8(__mmask16 __U, __m128i __A) {
413+
_mm256_maskz_cvthf8_ph(__mmask16 __U, __m128i __A) {
415414
return (__m256h)__builtin_ia32_vcvthf8_2ph256_mask(
416415
(__v16qi)__A, (__v16hf)(__m256h)_mm256_setzero_ph(), (__mmask16)__U);
417416
}

clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp renamed to clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//== ArrayBoundCheckerV2.cpp ------------------------------------*- C++ -*--==//
1+
//== ArrayBoundChecker.cpp -------------------------------------------------==//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -11,12 +11,6 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
// NOTE: The name of this file ends with "V2" because previously
15-
// "ArrayBoundChecker.cpp" contained the implementation of another (older and
16-
// simpler) checker that was called `alpha.security.ArrayBound`.
17-
// TODO: Rename this file to "ArrayBoundChecker.cpp" when it won't be confused
18-
// with that older file.
19-
2014
#include "clang/AST/CharUnits.h"
2115
#include "clang/AST/ParentMapContext.h"
2216
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
@@ -297,7 +291,8 @@ static std::pair<ProgramStateRef, ProgramStateRef>
297291
compareValueToThreshold(ProgramStateRef State, NonLoc Value, NonLoc Threshold,
298292
SValBuilder &SVB, bool CheckEquality = false) {
299293
if (auto ConcreteThreshold = Threshold.getAs<nonloc::ConcreteInt>()) {
300-
std::tie(Value, Threshold) = getSimplifiedOffsets(Value, *ConcreteThreshold, SVB);
294+
std::tie(Value, Threshold) =
295+
getSimplifiedOffsets(Value, *ConcreteThreshold, SVB);
301296
}
302297

303298
// We want to perform a _mathematical_ comparison between the numbers `Value`

clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set(LLVM_LINK_COMPONENTS
77
add_clang_library(clangStaticAnalyzerCheckers
88
AnalysisOrderChecker.cpp
99
AnalyzerStatsChecker.cpp
10-
ArrayBoundCheckerV2.cpp
10+
ArrayBoundChecker.cpp
1111
BasicObjCFoundationChecks.cpp
1212
BitwiseShiftChecker.cpp
1313
BlockInCriticalSectionChecker.cpp

0 commit comments

Comments
 (0)