Skip to content

Commit ef18e56

Browse files
committed
Merge commit '58987d2e34e67742e3a65b1bb94ec2cfebae805f' into llvmspirv_pulldown
2 parents f3ac883 + 58987d2 commit ef18e56

File tree

158 files changed

+3657
-1966
lines changed

Some content is hidden

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

158 files changed

+3657
-1966
lines changed

clang/lib/AST/ByteCode/IntegralAP.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ template <bool Signed> class IntegralAP final {
131131
if (NumBits == 0)
132132
NumBits = sizeof(T) * 8;
133133
assert(NumBits > 0);
134+
assert(APInt::getNumWords(NumBits) == 1);
134135
APInt Copy = APInt(NumBits, static_cast<uint64_t>(Value), Signed);
135-
assert(false);
136136
return IntegralAP<Signed>(Copy);
137137
}
138138

clang/lib/AST/ByteCode/Interp.h

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,7 +2713,7 @@ inline bool RVOPtr(InterpState &S, CodePtr OpPC) {
27132713
template <class LT, class RT, ShiftDir Dir>
27142714
inline bool DoShift(InterpState &S, CodePtr OpPC, LT &LHS, RT &RHS,
27152715
LT *Result) {
2716-
2716+
static_assert(!needsAlloc<LT>());
27172717
const unsigned Bits = LHS.bitWidth();
27182718

27192719
// OpenCL 6.3j: shift values are effectively % word size of LHS.
@@ -2770,7 +2770,10 @@ inline bool DoShift(InterpState &S, CodePtr OpPC, LT &LHS, RT &RHS,
27702770
LT::AsUnsigned::shiftLeft(LT::AsUnsigned::from(LHS),
27712771
LT::AsUnsigned::from(RHS, Bits), Bits, &R);
27722772
}
2773-
} else {
2773+
S.Stk.push<LT>(LT::from(R));
2774+
return true;
2775+
}
2776+
27742777
// Right shift.
27752778
if (Compare(RHS, RT::from(MaxShiftAmount, RHS.bitWidth())) ==
27762779
ComparisonCategoryResult::Greater) {
@@ -2779,51 +2782,52 @@ inline bool DoShift(InterpState &S, CodePtr OpPC, LT &LHS, RT &RHS,
27792782
// Do the shift on potentially signed LT, then convert to unsigned type.
27802783
LT A;
27812784
LT::shiftRight(LHS, LT::from(RHS, Bits), Bits, &A);
2782-
// LT::shiftRight(LHS, LT(RHSTemp), Bits, &A);
27832785
R = LT::AsUnsigned::from(A);
27842786
}
2785-
}
27862787

27872788
S.Stk.push<LT>(LT::from(R));
27882789
return true;
27892790
}
27902791

27912792
/// A version of DoShift that works on IntegralAP.
27922793
template <class LT, class RT, ShiftDir Dir>
2793-
inline bool DoShiftAP(InterpState &S, CodePtr OpPC, LT &LHS, RT &RHS,
2794-
LT *Result) {
2795-
const unsigned Bits = LHS.bitWidth();
2796-
const APSInt &LHSAP = LHS.toAPSInt();
2797-
APSInt RHSAP = RHS.toAPSInt();
2794+
inline bool DoShiftAP(InterpState &S, CodePtr OpPC, const APSInt &LHS,
2795+
APSInt RHS, LT *Result) {
2796+
const unsigned Bits = LHS.getBitWidth();
27982797

27992798
// OpenCL 6.3j: shift values are effectively % word size of LHS.
28002799
if (S.getLangOpts().OpenCL)
2801-
RHSAP &= APSInt(llvm::APInt(RHSAP.getBitWidth(),
2802-
static_cast<uint64_t>(LHSAP.getBitWidth() - 1)),
2803-
RHSAP.isUnsigned());
2800+
RHS &=
2801+
APSInt(llvm::APInt(RHS.getBitWidth(), static_cast<uint64_t>(Bits - 1)),
2802+
RHS.isUnsigned());
28042803

28052804
if (RHS.isNegative()) {
28062805
// During constant-folding, a negative shift is an opposite shift. Such a
28072806
// shift is not a constant expression.
28082807
const SourceInfo &Loc = S.Current->getSource(OpPC);
2809-
S.CCEDiag(Loc, diag::note_constexpr_negative_shift) << RHS.toAPSInt();
2808+
S.CCEDiag(Loc, diag::note_constexpr_negative_shift) << RHS; //.toAPSInt();
28102809
if (!S.noteUndefinedBehavior())
28112810
return false;
2812-
RHS = -RHS;
28132811
return DoShiftAP<LT, RT,
28142812
Dir == ShiftDir::Left ? ShiftDir::Right : ShiftDir::Left>(
2815-
S, OpPC, LHS, RHS, Result);
2813+
S, OpPC, LHS, -RHS, Result);
28162814
}
28172815

2818-
if (!CheckShift<Dir>(S, OpPC, LHS, RHS, Bits))
2816+
if (!CheckShift<Dir>(S, OpPC, static_cast<LT>(LHS), static_cast<RT>(RHS),
2817+
Bits))
28192818
return false;
28202819

2820+
unsigned SA = (unsigned)RHS.getLimitedValue(Bits - 1);
28212821
if constexpr (Dir == ShiftDir::Left) {
2822-
unsigned SA = (unsigned)RHSAP.getLimitedValue(LHS.bitWidth() - 1);
2823-
Result->copy(LHSAP << SA);
2822+
if constexpr (needsAlloc<LT>())
2823+
Result->copy(LHS << SA);
2824+
else
2825+
*Result = LT(LHS << SA);
28242826
} else {
2825-
unsigned SA = (unsigned)RHSAP.getLimitedValue(LHS.bitWidth() - 1);
2826-
Result->copy(LHSAP >> SA);
2827+
if constexpr (needsAlloc<LT>())
2828+
Result->copy(LHS >> SA);
2829+
else
2830+
*Result = LT(LHS >> SA);
28272831
}
28282832

28292833
S.Stk.push<LT>(*Result);
@@ -2837,9 +2841,12 @@ inline bool Shr(InterpState &S, CodePtr OpPC) {
28372841
auto RHS = S.Stk.pop<RT>();
28382842
auto LHS = S.Stk.pop<LT>();
28392843

2840-
if constexpr (needsAlloc<LT>()) {
2841-
LT Result = S.allocAP<LT>(LHS.bitWidth());
2842-
return DoShiftAP<LT, RT, ShiftDir::Right>(S, OpPC, LHS, RHS, &Result);
2844+
if constexpr (needsAlloc<LT>() || needsAlloc<RT>()) {
2845+
LT Result;
2846+
if constexpr (needsAlloc<LT>())
2847+
Result = S.allocAP<LT>(LHS.bitWidth());
2848+
return DoShiftAP<LT, RT, ShiftDir::Right>(S, OpPC, LHS.toAPSInt(),
2849+
RHS.toAPSInt(), &Result);
28432850
} else {
28442851
LT Result;
28452852
return DoShift<LT, RT, ShiftDir::Right>(S, OpPC, LHS, RHS, &Result);
@@ -2852,9 +2859,13 @@ inline bool Shl(InterpState &S, CodePtr OpPC) {
28522859
using RT = typename PrimConv<NameR>::T;
28532860
auto RHS = S.Stk.pop<RT>();
28542861
auto LHS = S.Stk.pop<LT>();
2855-
if constexpr (needsAlloc<LT>()) {
2856-
LT Result = S.allocAP<LT>(LHS.bitWidth());
2857-
return DoShiftAP<LT, RT, ShiftDir::Left>(S, OpPC, LHS, RHS, &Result);
2862+
2863+
if constexpr (needsAlloc<LT>() || needsAlloc<RT>()) {
2864+
LT Result;
2865+
if constexpr (needsAlloc<LT>())
2866+
Result = S.allocAP<LT>(LHS.bitWidth());
2867+
return DoShiftAP<LT, RT, ShiftDir::Left>(S, OpPC, LHS.toAPSInt(),
2868+
RHS.toAPSInt(), &Result);
28582869
} else {
28592870
LT Result;
28602871
return DoShift<LT, RT, ShiftDir::Left>(S, OpPC, LHS, RHS, &Result);

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,21 @@ static void pushInteger(InterpState &S, T Val, QualType QT) {
9696
QT);
9797
}
9898

99-
static void assignInteger(const Pointer &Dest, PrimType ValueT,
99+
static void assignInteger(InterpState &S, const Pointer &Dest, PrimType ValueT,
100100
const APSInt &Value) {
101-
INT_TYPE_SWITCH_NO_BOOL(
102-
ValueT, { Dest.deref<T>() = T::from(static_cast<T>(Value)); });
101+
102+
if (ValueT == PT_IntAPS) {
103+
Dest.deref<IntegralAP<true>>() =
104+
S.allocAP<IntegralAP<true>>(Value.getBitWidth());
105+
Dest.deref<IntegralAP<true>>().copy(Value);
106+
} else if (ValueT == PT_IntAP) {
107+
Dest.deref<IntegralAP<false>>() =
108+
S.allocAP<IntegralAP<false>>(Value.getBitWidth());
109+
Dest.deref<IntegralAP<false>>().copy(Value);
110+
} else {
111+
INT_TYPE_SWITCH_NO_BOOL(
112+
ValueT, { Dest.deref<T>() = T::from(static_cast<T>(Value)); });
113+
}
103114
}
104115

105116
static QualType getElemType(const Pointer &P) {
@@ -849,7 +860,7 @@ static bool interp__builtin_overflowop(InterpState &S, CodePtr OpPC,
849860
}
850861

851862
// Write Result to ResultPtr and put Overflow on the stack.
852-
assignInteger(ResultPtr, ResultT, Result);
863+
assignInteger(S, ResultPtr, ResultT, Result);
853864
ResultPtr.initialize();
854865
assert(Call->getDirectCallee()->getReturnType()->isBooleanType());
855866
S.Stk.push<Boolean>(Overflow);
@@ -902,7 +913,7 @@ static bool interp__builtin_carryop(InterpState &S, CodePtr OpPC,
902913

903914
QualType CarryOutType = Call->getArg(3)->getType()->getPointeeType();
904915
PrimType CarryOutT = *S.getContext().classify(CarryOutType);
905-
assignInteger(CarryOutPtr, CarryOutT, CarryOut);
916+
assignInteger(S, CarryOutPtr, CarryOutT, CarryOut);
906917
CarryOutPtr.initialize();
907918

908919
assert(Call->getType() == Call->getArg(0)->getType());
@@ -1414,7 +1425,7 @@ static bool interp__builtin_ia32_addcarry_subborrow(InterpState &S,
14141425

14151426
QualType CarryOutType = Call->getArg(3)->getType()->getPointeeType();
14161427
PrimType CarryOutT = *S.getContext().classify(CarryOutType);
1417-
assignInteger(CarryOutPtr, CarryOutT, APSInt(Result, true));
1428+
assignInteger(S, CarryOutPtr, CarryOutT, APSInt(Result, true));
14181429

14191430
pushInteger(S, CarryOut, Call->getType());
14201431

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,4 +1739,18 @@ namespace WithinLifetime {
17391739
// both-warning {{expression result unused}}
17401740
}
17411741
}
1742+
1743+
#ifdef __SIZEOF_INT128__
1744+
namespace I128Mul {
1745+
constexpr int mul() {
1746+
__int128 A = 10;
1747+
__int128 B = 10;
1748+
__int128 R;
1749+
__builtin_mul_overflow(A, B, &R);
1750+
return 1;
1751+
}
1752+
static_assert(mul() == 1);
1753+
}
1754+
#endif
1755+
17421756
#endif

clang/test/AST/ByteCode/intap.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,4 +273,18 @@ namespace IncDec {
273273
#endif
274274
}
275275

276+
#if __cplusplus >= 201402L
277+
const __int128_t a = ( (__int128_t)1 << 64 );
278+
const _BitInt(72) b = ( 1 << 72 ); // both-warning {{shift count >= width of type}}
279+
constexpr int shifts() { // both-error {{never produces a constant expression}}
280+
(void)(2 >> a); // both-warning {{shift count >= width of type}} \
281+
// both-note {{shift count 18446744073709551616 >= width of type 'int' (32 bits)}}
282+
(void)(2 >> b); // ref-warning {{shift count is negative}}
283+
(void)(2 << a); // both-warning {{shift count >= width of type}}
284+
(void)(2 << b); // ref-warning {{shift count is negative}}
285+
return 1;
286+
}
287+
#endif
288+
289+
276290
#endif

compiler-rt/lib/sanitizer_common/sanitizer_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ uptr FindAvailableMemoryRange(uptr size, uptr alignment, uptr left_padding,
166166

167167
// Used to check if we can map shadow memory to a fixed location.
168168
bool MemoryRangeIsAvailable(uptr range_start, uptr range_end);
169-
// Releases memory pages entirely within the [beg, end] address range. Noop if
169+
// Releases memory pages entirely within the [beg, end) address range. Noop if
170170
// the provided range does not contain at least one entire page.
171171
void ReleaseMemoryPagesToOS(uptr beg, uptr end);
172172
void IncreaseTotalMmap(uptr size);

compiler-rt/lib/sanitizer_common/sanitizer_linux.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ bool LibraryNameIs(const char *full_name, const char *base_name);
130130
// Call cb for each region mapped by map.
131131
void ForEachMappedRegion(link_map *map, void (*cb)(const void *, uptr));
132132

133-
// Releases memory pages entirely within the [beg, end] address range.
133+
// Releases memory pages entirely within the [beg, end) address range.
134134
// The pages no longer count toward RSS; reads are guaranteed to return 0.
135135
// Requires (but does not verify!) that pages are MAP_PRIVATE.
136136
inline void ReleaseMemoryPagesToOSAndZeroFill(uptr beg, uptr end) {

compiler-rt/lib/tsan/rtl/tsan_rtl.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ void MapShadow(uptr addr, uptr size) {
624624
static uptr mapped_meta_end = 0;
625625
uptr meta_begin = (uptr)MemToMeta(addr);
626626
uptr meta_end = (uptr)MemToMeta(addr + size);
627+
// Windows wants 64K alignment.
627628
meta_begin = RoundDownTo(meta_begin, 64 << 10);
628629
meta_end = RoundUpTo(meta_end, 64 << 10);
629630
if (!data_mapped) {
@@ -634,9 +635,6 @@ void MapShadow(uptr addr, uptr size) {
634635
Die();
635636
} else {
636637
// Mapping continuous heap.
637-
// Windows wants 64K alignment.
638-
meta_begin = RoundDownTo(meta_begin, 64 << 10);
639-
meta_end = RoundUpTo(meta_end, 64 << 10);
640638
CHECK_GT(meta_end, mapped_meta_end);
641639
if (meta_begin < mapped_meta_end)
642640
meta_begin = mapped_meta_end;

compiler-rt/lib/tsan/rtl/tsan_sync.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,14 @@ void MetaMap::MoveMemory(uptr src, uptr dst, uptr sz) {
247247
CHECK_NE(src, dst);
248248
CHECK_NE(sz, 0);
249249
uptr diff = dst - src;
250-
u32 *src_meta = MemToMeta(src);
251-
u32 *dst_meta = MemToMeta(dst);
252-
u32 *src_meta_end = MemToMeta(src + sz);
253-
uptr inc = 1;
254-
if (dst > src) {
250+
u32 *src_meta, *dst_meta, *src_meta_end;
251+
uptr inc;
252+
if (dst < src) {
253+
src_meta = MemToMeta(src);
254+
dst_meta = MemToMeta(dst);
255+
src_meta_end = MemToMeta(src + sz);
256+
inc = 1;
257+
} else {
255258
src_meta = MemToMeta(src + sz) - 1;
256259
dst_meta = MemToMeta(dst + sz) - 1;
257260
src_meta_end = MemToMeta(src) - 1;

flang/include/flang/Lower/PFTBuilder.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ static constexpr bool isExecutableDirective{common::HasMember<
184184
A, std::tuple<parser::CompilerDirective, parser::OpenACCConstruct,
185185
parser::OpenMPConstruct, parser::CUFKernelDoConstruct>>};
186186

187+
template <typename A>
188+
static constexpr bool isOpenMPDirective{
189+
common::HasMember<A, std::tuple<parser::OpenMPConstruct,
190+
parser::OpenMPDeclarativeConstruct>>};
191+
187192
template <typename A>
188193
static constexpr bool isFunctionLike{common::HasMember<
189194
A, std::tuple<parser::MainProgram, parser::FunctionSubprogram,
@@ -267,6 +272,11 @@ struct Evaluation : EvaluationVariant {
267272
return pft::isExecutableDirective<std::decay_t<decltype(r)>>;
268273
}});
269274
}
275+
constexpr bool isOpenMPDirective() const {
276+
return visit(common::visitors{[](auto &r) {
277+
return pft::isOpenMPDirective<std::decay_t<decltype(r)>>;
278+
}});
279+
}
270280

271281
/// Return the predicate: "This is a non-initial, non-terminal construct
272282
/// statement." For an IfConstruct, this is ElseIfStmt and ElseStmt.

0 commit comments

Comments
 (0)