Skip to content

Commit a9becbe

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merge llvm/main into amd-debug
2 parents ccb4647 + bddac5e commit a9becbe

File tree

105 files changed

+1279
-955
lines changed

Some content is hidden

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

105 files changed

+1279
-955
lines changed

clang/lib/AST/ByteCode/Descriptor.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,25 @@ static void dtorRecord(Block *B, std::byte *Ptr, const Descriptor *D) {
246246
destroyBase(B, Ptr, F.Desc, F.Offset);
247247
}
248248

249+
/// Whether a record needs its descriptor dtor function called.
250+
static bool needsRecordDtor(const Record *R) {
251+
for (const auto &B : R->bases()) {
252+
if (B.Desc->DtorFn)
253+
return true;
254+
}
255+
256+
for (const auto &F : R->fields()) {
257+
if (F.Desc->DtorFn)
258+
return true;
259+
}
260+
261+
for (const auto &V : R->virtual_bases()) {
262+
if (V.Desc->DtorFn)
263+
return true;
264+
}
265+
return false;
266+
}
267+
249268
static BlockCtorFn getCtorPrim(PrimType Type) {
250269
// Floating types are special. They are primitives, but need their
251270
// constructor called.
@@ -336,7 +355,7 @@ Descriptor::Descriptor(const DeclTy &D, const Type *SourceTy,
336355
AllocSize(std::max<size_t>(alignof(void *), Size) + MDSize),
337356
ElemDesc(Elem), IsConst(IsConst), IsMutable(IsMutable),
338357
IsTemporary(IsTemporary), IsArray(true), CtorFn(ctorArrayDesc),
339-
DtorFn(dtorArrayDesc) {
358+
DtorFn(Elem->DtorFn ? dtorArrayDesc : nullptr) {
340359
assert(Source && "Missing source");
341360
}
342361

@@ -347,7 +366,7 @@ Descriptor::Descriptor(const DeclTy &D, const Descriptor *Elem, MetadataSize MD,
347366
Size(UnknownSizeMark), MDSize(MD.value_or(0)),
348367
AllocSize(MDSize + alignof(void *)), ElemDesc(Elem), IsConst(true),
349368
IsMutable(false), IsTemporary(IsTemporary), IsArray(true),
350-
CtorFn(ctorArrayDesc), DtorFn(dtorArrayDesc) {
369+
CtorFn(ctorArrayDesc), DtorFn(Elem->DtorFn ? dtorArrayDesc : nullptr) {
351370
assert(Source && "Missing source");
352371
}
353372

@@ -359,7 +378,7 @@ Descriptor::Descriptor(const DeclTy &D, const Record *R, MetadataSize MD,
359378
Size(ElemSize), MDSize(MD.value_or(0)), AllocSize(Size + MDSize),
360379
ElemRecord(R), IsConst(IsConst), IsMutable(IsMutable),
361380
IsTemporary(IsTemporary), IsVolatile(IsVolatile), CtorFn(ctorRecord),
362-
DtorFn(dtorRecord) {
381+
DtorFn(needsRecordDtor(R) ? dtorRecord : nullptr) {
363382
assert(Source && "Missing source");
364383
}
365384

clang/lib/AST/ByteCode/Integral.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,11 @@ template <unsigned Bits, bool Signed> class Integral final {
318318
template <typename T> static bool CheckMulUB(T A, T B, T &R) {
319319
if constexpr (std::is_signed_v<T>) {
320320
return llvm::MulOverflow<T>(A, B, R);
321+
} else if constexpr (sizeof(T) < sizeof(int)) {
322+
// Silly integer promotion rules will convert both A and B to int,
323+
// even it T is unsigned. Prevent that by manually casting to uint first.
324+
R = static_cast<T>(static_cast<unsigned>(A) * static_cast<unsigned>(B));
325+
return false;
321326
} else {
322327
R = A * B;
323328
return false;

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,17 +1207,15 @@ static bool runRecordDestructor(InterpState &S, CodePtr OpPC,
12071207
}
12081208

12091209
// Destructor of this record.
1210-
if (const CXXDestructorDecl *Dtor = R->getDestructor();
1211-
Dtor && !Dtor->isTrivial()) {
1212-
const Function *DtorFunc = S.getContext().getOrCreateFunction(Dtor);
1213-
if (!DtorFunc)
1214-
return false;
1210+
const CXXDestructorDecl *Dtor = R->getDestructor();
1211+
assert(Dtor);
1212+
assert(!Dtor->isTrivial());
1213+
const Function *DtorFunc = S.getContext().getOrCreateFunction(Dtor);
1214+
if (!DtorFunc)
1215+
return false;
12151216

1216-
S.Stk.push<Pointer>(BasePtr);
1217-
if (!Call(S, OpPC, DtorFunc, 0))
1218-
return false;
1219-
}
1220-
return true;
1217+
S.Stk.push<Pointer>(BasePtr);
1218+
return Call(S, OpPC, DtorFunc, 0);
12211219
}
12221220

12231221
static bool RunDestructors(InterpState &S, CodePtr OpPC, const Block *B) {
@@ -1229,6 +1227,9 @@ static bool RunDestructors(InterpState &S, CodePtr OpPC, const Block *B) {
12291227

12301228
assert(Desc->isRecord() || Desc->isCompositeArray());
12311229

1230+
if (Desc->hasTrivialDtor())
1231+
return true;
1232+
12321233
if (Desc->isCompositeArray()) {
12331234
unsigned N = Desc->getNumElems();
12341235
if (N == 0)

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,9 +2514,9 @@ static bool interp__builtin_is_within_lifetime(InterpState &S, CodePtr OpPC,
25142514
return true;
25152515
}
25162516

2517-
static bool interp__builtin_elementwise_sat(InterpState &S, CodePtr OpPC,
2518-
const CallExpr *Call,
2519-
unsigned BuiltinID) {
2517+
static bool interp__builtin_elementwise_int_binop(InterpState &S, CodePtr OpPC,
2518+
const CallExpr *Call,
2519+
unsigned BuiltinID) {
25202520
assert(Call->getNumArgs() == 2);
25212521

25222522
// Single integer case.
@@ -2553,6 +2553,8 @@ static bool interp__builtin_elementwise_sat(InterpState &S, CodePtr OpPC,
25532553
const Pointer &LHS = S.Stk.pop<Pointer>();
25542554
const Pointer &Dst = S.Stk.peek<Pointer>();
25552555
PrimType ElemT = *S.getContext().classify(VT->getElementType());
2556+
bool DestUnsigned =
2557+
VT->getElementType()->isUnsignedIntegerOrEnumerationType();
25562558
unsigned NumElems = VT->getNumElements();
25572559
for (unsigned I = 0; I != NumElems; ++I) {
25582560
APSInt Elem1;
@@ -2586,6 +2588,34 @@ static bool interp__builtin_elementwise_sat(InterpState &S, CodePtr OpPC,
25862588
Result = APSInt(llvm::APIntOps::mulhs(Elem1, Elem2),
25872589
/*isUnsigned=*/false);
25882590
break;
2591+
case clang::X86::BI__builtin_ia32_psllv2di:
2592+
case clang::X86::BI__builtin_ia32_psllv4di:
2593+
case clang::X86::BI__builtin_ia32_psllv4si:
2594+
case clang::X86::BI__builtin_ia32_psllv8si:
2595+
if (Elem2.uge(Elem2.getBitWidth())) {
2596+
Result = APSInt(APInt::getZero(Elem2.getBitWidth()), DestUnsigned);
2597+
break;
2598+
}
2599+
Result = APSInt(Elem1.shl(Elem2.getZExtValue()), DestUnsigned);
2600+
break;
2601+
case clang::X86::BI__builtin_ia32_psrav4si:
2602+
case clang::X86::BI__builtin_ia32_psrav8si:
2603+
if (Elem2.uge(Elem2.getBitWidth())) {
2604+
Result = APSInt(Elem1.ashr(Elem2.getBitWidth() - 1), DestUnsigned);
2605+
break;
2606+
}
2607+
Result = APSInt(Elem1.ashr(Elem2.getZExtValue()), DestUnsigned);
2608+
break;
2609+
case clang::X86::BI__builtin_ia32_psrlv2di:
2610+
case clang::X86::BI__builtin_ia32_psrlv4di:
2611+
case clang::X86::BI__builtin_ia32_psrlv4si:
2612+
case clang::X86::BI__builtin_ia32_psrlv8si:
2613+
if (Elem2.uge(Elem2.getBitWidth())) {
2614+
Result = APSInt(APInt::getZero(Elem2.getBitWidth()), DestUnsigned);
2615+
break;
2616+
}
2617+
Result = APSInt(Elem1.lshr(Elem2.getZExtValue()), DestUnsigned);
2618+
break;
25892619
default:
25902620
llvm_unreachable("Wrong builtin ID");
25912621
}
@@ -3232,7 +3262,17 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
32323262
case clang::X86::BI__builtin_ia32_pmulhw128:
32333263
case clang::X86::BI__builtin_ia32_pmulhw256:
32343264
case clang::X86::BI__builtin_ia32_pmulhw512:
3235-
return interp__builtin_elementwise_sat(S, OpPC, Call, BuiltinID);
3265+
case clang::X86::BI__builtin_ia32_psllv2di:
3266+
case clang::X86::BI__builtin_ia32_psllv4di:
3267+
case clang::X86::BI__builtin_ia32_psllv4si:
3268+
case clang::X86::BI__builtin_ia32_psllv8si:
3269+
case clang::X86::BI__builtin_ia32_psrav4si:
3270+
case clang::X86::BI__builtin_ia32_psrav8si:
3271+
case clang::X86::BI__builtin_ia32_psrlv2di:
3272+
case clang::X86::BI__builtin_ia32_psrlv4di:
3273+
case clang::X86::BI__builtin_ia32_psrlv4si:
3274+
case clang::X86::BI__builtin_ia32_psrlv8si:
3275+
return interp__builtin_elementwise_int_binop(S, OpPC, Call, BuiltinID);
32363276

32373277
case Builtin::BI__builtin_elementwise_max:
32383278
case Builtin::BI__builtin_elementwise_min:

clang/lib/AST/ByteCode/Program.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ unsigned Program::createGlobalString(const StringLiteral *S, const Expr *Base) {
101101
}
102102
}
103103
}
104-
Ptr.initialize();
104+
Ptr.initializeAllElements();
105105

106106
return GlobalIndex;
107107
}

clang/test/CodeGen/X86/avx2-builtins.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +avx2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=CHECK,X86
88
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +avx2 -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=CHECK,X86
99

10+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx2 -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s --check-prefixes=CHECK,X64
11+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx2 -fno-signed-char -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s --check-prefixes=CHECK,X64
12+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +avx2 -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s --check-prefixes=CHECK,X86
13+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +avx2 -fno-signed-char -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s --check-prefixes=CHECK,X86
14+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx2 -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s --check-prefixes=CHECK,X64
15+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx2 -fno-signed-char -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s --check-prefixes=CHECK,X64
16+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +avx2 -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s --check-prefixes=CHECK,X86
17+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +avx2 -fno-signed-char -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s --check-prefixes=CHECK,X86
1018

1119
#include <immintrin.h>
1220
#include "builtin_test_helpers.h"

flang/include/flang/Parser/parse-tree.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4893,8 +4893,11 @@ struct OpenMPSectionsConstruct {
48934893
CharBlock source;
48944894
// Each of the OpenMPConstructs in the list below contains an
48954895
// OpenMPSectionConstruct. This is guaranteed by the parser.
4896+
// The end sections directive is optional here because it is difficult to
4897+
// generate helpful error messages for a missing end directive within the
4898+
// parser. Semantics will generate an error if this is absent.
48964899
std::tuple<OmpBeginSectionsDirective, std::list<OpenMPConstruct>,
4897-
OmpEndSectionsDirective>
4900+
std::optional<OmpEndSectionsDirective>>
48984901
t;
48994902
};
49004903

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3979,9 +3979,12 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
39793979
List<Clause> clauses = makeClauses(
39803980
std::get<parser::OmpClauseList>(beginSectionsDirective.t), semaCtx);
39813981
const auto &endSectionsDirective =
3982-
std::get<parser::OmpEndSectionsDirective>(sectionsConstruct.t);
3982+
std::get<std::optional<parser::OmpEndSectionsDirective>>(
3983+
sectionsConstruct.t);
3984+
assert(endSectionsDirective &&
3985+
"Missing end section directive should have been handled in semantics");
39833986
clauses.append(makeClauses(
3984-
std::get<parser::OmpClauseList>(endSectionsDirective.t), semaCtx));
3987+
std::get<parser::OmpClauseList>(endSectionsDirective->t), semaCtx));
39853988
mlir::Location currentLocation = converter.getCurrentLocation();
39863989

39873990
llvm::omp::Directive directive =

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1921,7 +1921,7 @@ TYPE_PARSER(sourced(construct<OpenMPSectionsConstruct>(
19211921
construct<OpenMPSectionConstruct>(maybe(sectionDir), block))),
19221922
many(construct<OpenMPConstruct>(
19231923
sourced(construct<OpenMPSectionConstruct>(sectionDir, block))))),
1924-
Parser<OmpEndSectionsDirective>{} / endOmpLine)))
1924+
maybe(Parser<OmpEndSectionsDirective>{} / endOmpLine))))
19251925

19261926
static bool IsExecutionPart(const OmpDirectiveName &name) {
19271927
return name.IsExecutionPart();

flang/lib/Parser/unparse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2788,7 +2788,7 @@ class UnparseVisitor {
27882788
Walk(std::get<std::list<OpenMPConstruct>>(x.t), "");
27892789
BeginOpenMP();
27902790
Word("!$OMP END ");
2791-
Walk(std::get<OmpEndSectionsDirective>(x.t));
2791+
Walk(std::get<std::optional<OmpEndSectionsDirective>>(x.t));
27922792
Put("\n");
27932793
EndOpenMP();
27942794
}

0 commit comments

Comments
 (0)