Skip to content

Commit 27c9777

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:2de3d00edc614cdce4b30b68be564a7a3123dbf9 into amd-gfx:96d9808c3cce
Local branch amd-gfx 96d9808 Revert "Reapply [APInt] Enable APInt ctor assertion by default (llvm#114539)" Remote branch main 2de3d00 [mlir][tosa] Fix a crash in `PadOp::fold` (llvm#114921)
2 parents 96d9808 + 2de3d00 commit 27c9777

38 files changed

+827
-325
lines changed

clang-tools-extra/clangd/TidyProvider.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class DotClangTidyCache : private FileCache {
4646
[this](std::optional<llvm::StringRef> Data) {
4747
Value.reset();
4848
if (Data && !Data->empty()) {
49-
tidy::DiagCallback Diagnostics = [](const llvm::SMDiagnostic &D) {
49+
auto Diagnostics = [](const llvm::SMDiagnostic &D) {
5050
switch (D.getKind()) {
5151
case llvm::SourceMgr::DK_Error:
5252
elog("tidy-config error at {0}:{1}:{2}: {3}", D.getFilename(),
@@ -149,7 +149,7 @@ static void mergeCheckList(std::optional<std::string> &Checks,
149149
*Checks = llvm::join_items(",", *Checks, List);
150150
}
151151

152-
TidyProviderRef provideEnvironment() {
152+
TidyProvider provideEnvironment() {
153153
static const std::optional<std::string> User = [] {
154154
std::optional<std::string> Ret = llvm::sys::Process::GetEnv("USER");
155155
#ifdef _WIN32
@@ -167,7 +167,7 @@ TidyProviderRef provideEnvironment() {
167167
return [](tidy::ClangTidyOptions &, llvm::StringRef) {};
168168
}
169169

170-
TidyProviderRef provideDefaultChecks() {
170+
TidyProvider provideDefaultChecks() {
171171
// These default checks are chosen for:
172172
// - low false-positive rate
173173
// - providing a lot of value
@@ -251,7 +251,7 @@ TidyProvider disableUnusableChecks(llvm::ArrayRef<std::string> ExtraBadChecks) {
251251
};
252252
}
253253

254-
TidyProviderRef provideClangdConfig() {
254+
TidyProvider provideClangdConfig() {
255255
return [](tidy::ClangTidyOptions &Opts, llvm::StringRef) {
256256
const auto &CurTidyConfig = Config::current().Diagnostics.ClangTidy;
257257
if (!CurTidyConfig.Checks.empty())

clang-tools-extra/clangd/TidyProvider.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ using TidyProviderRef = llvm::function_ref<void(tidy::ClangTidyOptions &,
3030
TidyProvider combine(std::vector<TidyProvider> Providers);
3131

3232
/// Provider that just sets the defaults.
33-
TidyProviderRef provideEnvironment();
33+
TidyProvider provideEnvironment();
3434

3535
/// Provider that will enable a nice set of default checks if none are
3636
/// specified.
37-
TidyProviderRef provideDefaultChecks();
37+
TidyProvider provideDefaultChecks();
3838

3939
/// Provider the enables a specific set of checks and warnings as errors.
4040
TidyProvider addTidyChecks(llvm::StringRef Checks,
@@ -51,7 +51,7 @@ disableUnusableChecks(llvm::ArrayRef<std::string> ExtraBadChecks = {});
5151
TidyProvider provideClangTidyFiles(ThreadsafeFS &);
5252

5353
// Provider that uses clangd configuration files.
54-
TidyProviderRef provideClangdConfig();
54+
TidyProvider provideClangdConfig();
5555

5656
tidy::ClangTidyOptions getTidyOptionsForFile(TidyProviderRef Provider,
5757
llvm::StringRef Filename);

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6446,8 +6446,6 @@ bool Compiler<Emitter>::emitBuiltinBitCast(const CastExpr *E) {
64466446
QualType ToType = E->getType();
64476447
std::optional<PrimType> ToT = classify(ToType);
64486448

6449-
assert(!DiscardResult && "Implement DiscardResult mode for bitcasts.");
6450-
64516449
if (ToType->isNullPtrType()) {
64526450
if (!this->discard(SubExpr))
64536451
return false;
@@ -6463,12 +6461,24 @@ bool Compiler<Emitter>::emitBuiltinBitCast(const CastExpr *E) {
64636461
}
64646462
assert(!ToType->isReferenceType());
64656463

6464+
// Prepare storage for the result in case we discard.
6465+
if (DiscardResult && !Initializing && !ToT) {
6466+
std::optional<unsigned> LocalIndex = allocateLocal(E);
6467+
if (!LocalIndex)
6468+
return false;
6469+
if (!this->emitGetPtrLocal(*LocalIndex, E))
6470+
return false;
6471+
}
6472+
64666473
// Get a pointer to the value-to-cast on the stack.
64676474
if (!this->visit(SubExpr))
64686475
return false;
64696476

6470-
if (!ToT || ToT == PT_Ptr)
6471-
return this->emitBitCastPtr(E);
6477+
if (!ToT || ToT == PT_Ptr) {
6478+
if (!this->emitBitCastPtr(E))
6479+
return false;
6480+
return DiscardResult ? this->emitPopPtr(E) : true;
6481+
}
64726482
assert(ToT);
64736483

64746484
const llvm::fltSemantics *TargetSemantics = nullptr;

clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ using namespace clang;
2626
using namespace clang::interp;
2727

2828
/// Used to iterate over pointer fields.
29-
using DataFunc =
30-
llvm::function_ref<bool(const Pointer &P, PrimType Ty, size_t BitOffset)>;
29+
using DataFunc = llvm::function_ref<bool(const Pointer &P, PrimType Ty,
30+
size_t BitOffset, bool PackedBools)>;
3131

3232
#define BITCAST_TYPE_SWITCH(Expr, B) \
3333
do { \
@@ -89,6 +89,7 @@ struct BitcastBuffer {
8989

9090
std::byte *getBytes(unsigned BitOffset) const {
9191
assert(BitOffset % 8 == 0);
92+
assert(BitOffset < SizeInBits);
9293
return const_cast<std::byte *>(data() + (BitOffset / 8));
9394
}
9495

@@ -147,18 +148,20 @@ static bool enumerateData(const Pointer &P, const Context &Ctx, size_t Offset,
147148

148149
// Primitives.
149150
if (FieldDesc->isPrimitive())
150-
return F(P, FieldDesc->getPrimType(), Offset);
151+
return F(P, FieldDesc->getPrimType(), Offset, false);
151152

152153
// Primitive arrays.
153154
if (FieldDesc->isPrimitiveArray()) {
154155
bool BigEndianTarget = Ctx.getASTContext().getTargetInfo().isBigEndian();
155156
QualType ElemType = FieldDesc->getElemQualType();
156157
size_t ElemSizeInBits = Ctx.getASTContext().getTypeSize(ElemType);
157158
PrimType ElemT = *Ctx.classify(ElemType);
159+
// Special case, since the bools here are packed.
160+
bool PackedBools = FieldDesc->getType()->isExtVectorBoolType();
158161
bool Ok = true;
159162
for (unsigned I = 0; I != FieldDesc->getNumElems(); ++I) {
160163
unsigned Index = BigEndianTarget ? (FieldDesc->getNumElems() - 1 - I) : I;
161-
Ok = Ok && F(P.atIndex(Index), ElemT, Offset);
164+
Ok = Ok && F(P.atIndex(Index), ElemT, Offset, PackedBools);
162165
Offset += ElemSizeInBits;
163166
}
164167
return Ok;
@@ -302,7 +305,8 @@ static bool readPointerToBuffer(const Context &Ctx, const Pointer &FromPtr,
302305

303306
return enumeratePointerFields(
304307
FromPtr, Ctx,
305-
[&](const Pointer &P, PrimType T, size_t BitOffset) -> bool {
308+
[&](const Pointer &P, PrimType T, size_t BitOffset,
309+
bool PackedBools) -> bool {
306310
if (!P.isInitialized()) {
307311
assert(false && "Implement uninitialized value tracking");
308312
return ReturnOnUninit;
@@ -334,6 +338,8 @@ static bool readPointerToBuffer(const Context &Ctx, const Pointer &FromPtr,
334338
} else {
335339
if (const FieldDecl *FD = P.getField(); FD && FD->isBitField())
336340
BitWidth = FD->getBitWidthValue(ASTCtx);
341+
else if (T == PT_Bool && PackedBools)
342+
BitWidth = 1;
337343

338344
BITCAST_TYPE_SWITCH(T, {
339345
T Val = P.deref<T>();
@@ -401,7 +407,7 @@ bool clang::interp::DoBitCastPtr(InterpState &S, CodePtr OpPC,
401407
size_t BitOffset = 0;
402408
bool Success = enumeratePointerFields(
403409
ToPtr, S.getContext(),
404-
[&](const Pointer &P, PrimType T, size_t _) -> bool {
410+
[&](const Pointer &P, PrimType T, size_t _, bool PackedBools) -> bool {
405411
if (T == PT_Float) {
406412
CharUnits ObjectReprChars = ASTCtx.getTypeSizeInChars(P.getType());
407413
const auto &Semantics = ASTCtx.getFloatTypeSemantics(P.getType());

clang/lib/Sema/SemaFunctionEffects.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,7 @@ class Analyzer {
971971
PendingFunctionAnalysis &CurrentFunction;
972972
CallableInfo &CurrentCaller;
973973
ViolationSite VSite;
974+
const Expr *TrailingRequiresClause = nullptr;
974975

975976
FunctionBodyASTVisitor(Analyzer &Outer,
976977
PendingFunctionAnalysis &CurrentFunction,
@@ -985,6 +986,9 @@ class Analyzer {
985986
if (auto *Dtor = dyn_cast<CXXDestructorDecl>(CurrentCaller.CDecl))
986987
followDestructor(dyn_cast<CXXRecordDecl>(Dtor->getParent()), Dtor);
987988

989+
if (auto *FD = dyn_cast<FunctionDecl>(CurrentCaller.CDecl))
990+
TrailingRequiresClause = FD->getTrailingRequiresClause();
991+
988992
// Do an AST traversal of the function/block body
989993
TraverseDecl(const_cast<Decl *>(CurrentCaller.CDecl));
990994
}
@@ -1259,6 +1263,17 @@ class Analyzer {
12591263
return true;
12601264
}
12611265

1266+
bool TraverseStmt(Stmt *Statement) {
1267+
// If this statement is a `requires` clause from the top-level function
1268+
// being traversed, ignore it, since it's not generating runtime code.
1269+
// We skip the traversal of lambdas (beyond their captures, see
1270+
// TraverseLambdaExpr below), so just caching this from our constructor
1271+
// should suffice.
1272+
if (Statement != TrailingRequiresClause)
1273+
return Base::TraverseStmt(Statement);
1274+
return true;
1275+
}
1276+
12621277
bool TraverseConstructorInitializer(CXXCtorInitializer *Init) {
12631278
ViolationSite PrevVS = VSite;
12641279
if (Init->isAnyMemberInitializer())
@@ -1297,6 +1312,7 @@ class Analyzer {
12971312
}
12981313

12991314
bool TraverseBlockExpr(BlockExpr * /*unused*/) {
1315+
// As with lambdas, don't traverse the block's body.
13001316
// TODO: are the capture expressions (ctor call?) safe?
13011317
return true;
13021318
}

clang/test/AST/ByteCode/builtin-bit-cast.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ constexpr Init round_trip(const Init &init) {
3838
return bit_cast<Init>(bit_cast<Intermediate>(init));
3939
}
4040

41+
42+
namespace Discarding {
43+
struct S { int a; };
44+
constexpr int f = (__builtin_bit_cast(int, 2), 0);
45+
constexpr int f2 = (__builtin_bit_cast(S, 2), 0);
46+
}
47+
4148
namespace std {
4249
enum byte : unsigned char {};
4350
} // namespace std
@@ -468,8 +475,52 @@ struct ref_mem {
468475
// both-note@+1 {{bit_cast from a type with a reference member is not allowed in a constant expression}}
469476
constexpr intptr_t run_ref_mem = __builtin_bit_cast(intptr_t, ref_mem{global_int});
470477

478+
namespace test_vector {
479+
480+
typedef unsigned uint2 __attribute__((vector_size(2 * sizeof(unsigned))));
481+
typedef char byte8 __attribute__((vector_size(sizeof(unsigned long long))));
482+
483+
constexpr uint2 test_vector = { 0x0C05FEFE, 0xCAFEBABE };
484+
485+
static_assert(bit_cast<unsigned long long>(test_vector) == (LITTLE_END
486+
? 0xCAFEBABE0C05FEFE
487+
: 0x0C05FEFECAFEBABE), "");
488+
static_assert(check_round_trip<uint2>(0xCAFEBABE0C05FEFEULL), "");
489+
static_assert(check_round_trip<byte8>(0xCAFEBABE0C05FEFEULL), "");
490+
491+
typedef bool bool8 __attribute__((ext_vector_type(8)));
492+
typedef bool bool9 __attribute__((ext_vector_type(9)));
493+
typedef bool bool16 __attribute__((ext_vector_type(16)));
494+
typedef bool bool17 __attribute__((ext_vector_type(17)));
495+
typedef bool bool32 __attribute__((ext_vector_type(32)));
496+
typedef bool bool128 __attribute__((ext_vector_type(128)));
471497

498+
static_assert(bit_cast<unsigned char>(bool8{1,0,1,0,1,0,1,0}) == (LITTLE_END ? 0x55 : 0xAA), "");
499+
constexpr bool8 b8 = __builtin_bit_cast(bool8, 0x55); // both-error {{__builtin_bit_cast source size does not equal destination size (4 vs 1)}}
500+
#if 0
501+
static_assert(check_round_trip<bool8>(static_cast<unsigned char>(0)), "");
502+
static_assert(check_round_trip<bool8>(static_cast<unsigned char>(1)), "");
503+
static_assert(check_round_trip<bool8>(static_cast<unsigned char>(0x55)), "");
504+
505+
static_assert(bit_cast<unsigned short>(bool16{1,1,1,1,1,0,0,0, 1,1,1,1,0,1,0,0}) == (LITTLE_END ? 0x2F1F : 0xF8F4), "");
506+
507+
static_assert(check_round_trip<bool16>(static_cast<short>(0xCAFE)), "");
508+
static_assert(check_round_trip<bool32>(static_cast<int>(0xCAFEBABE)), "");
509+
static_assert(check_round_trip<bool128>(static_cast<__int128_t>(0xCAFEBABE0C05FEFEULL)), "");
510+
#endif
472511

512+
#if 0
513+
// expected-error@+2 {{constexpr variable 'bad_bool9_to_short' must be initialized by a constant expression}}
514+
// expected-note@+1 {{bit_cast involving type 'bool __attribute__((ext_vector_type(9)))' (vector of 9 'bool' values) is not allowed in a constant expression; element size 1 * element count 9 is not a multiple of the byte size 8}}
515+
constexpr unsigned short bad_bool9_to_short = __builtin_bit_cast(unsigned short, bool9{1,1,0,1,0,1,0,1,0});
516+
// expected-error@+2 {{constexpr variable 'bad_short_to_bool9' must be initialized by a constant expression}}
517+
// expected-note@+1 {{bit_cast involving type 'bool __attribute__((ext_vector_type(9)))' (vector of 9 'bool' values) is not allowed in a constant expression; element size 1 * element count 9 is not a multiple of the byte size 8}}
518+
constexpr bool9 bad_short_to_bool9 = __builtin_bit_cast(bool9, static_cast<unsigned short>(0));
519+
// expected-error@+2 {{constexpr variable 'bad_int_to_bool17' must be initialized by a constant expression}}
520+
// expected-note@+1 {{bit_cast involving type 'bool __attribute__((ext_vector_type(17)))' (vector of 17 'bool' values) is not allowed in a constant expression; element size 1 * element count 17 is not a multiple of the byte size 8}}
521+
constexpr bool17 bad_int_to_bool17 = __builtin_bit_cast(bool17, 0x0001CAFEU);
522+
#endif
523+
}
473524

474525
namespace test_complex {
475526
constexpr _Complex unsigned test_int_complex = { 0x0C05FEFE, 0xCAFEBABE };

clang/test/Sema/attr-nonblocking-constraints.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,51 @@ void nb26() [[clang::nonblocking]] {
388388
abort_wrapper(); // no diagnostic
389389
}
390390

391+
// --- Make sure we don't traverse a requires clause. ---
392+
393+
// Apparently some requires clauses are able to be collapsed into a constant before the nonblocking
394+
// analysis sees any function calls. This example (extracted from a real-world case where
395+
// `operator&&` in <valarray>, preceding the inclusion of <expected>) is sufficiently complex
396+
// to look like it contains function calls. There may be simpler examples.
397+
398+
namespace ExpectedTest {
399+
400+
template <class _Tp>
401+
inline constexpr bool is_copy_constructible_v = __is_constructible(_Tp, _Tp&);
402+
403+
template <bool, class _Tp = void>
404+
struct enable_if {};
405+
template <class _Tp>
406+
struct enable_if<true, _Tp> {
407+
typedef _Tp type;
408+
};
409+
410+
template <bool _Bp, class _Tp = void>
411+
using enable_if_t = typename enable_if<_Bp, _Tp>::type;
412+
413+
// Doesn't seem to matter whether the enable_if is true or false.
414+
template <class E1, class E2, enable_if_t<is_copy_constructible_v<E1>> = 0>
415+
inline bool operator&&(const E1& x, const E2& y);
416+
417+
template <class _Tp, class _Err>
418+
class expected {
419+
public:
420+
constexpr expected()
421+
{}
422+
423+
constexpr expected(const expected&)
424+
requires(is_copy_constructible_v<_Tp> && is_copy_constructible_v<_Err>)
425+
= default;
426+
};
427+
428+
void test() [[clang::nonblocking]]
429+
{
430+
expected<int, int> a;
431+
auto b = a;
432+
}
433+
434+
} // namespace ExpectedTest
435+
391436
// --- nonblocking implies noexcept ---
392437
#pragma clang diagnostic warning "-Wperf-constraint-implies-noexcept"
393438

llvm/docs/Contributing.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ of LLVM's high-level design, as well as its internals:
181181
.. _irc.oftc.net: irc://irc.oftc.net/llvm
182182
.. _good first issue: https://github.com/llvm/llvm-project/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22
183183
.. _bug tracker: https://github.com/llvm/llvm-project/issues
184-
.. _clang-format-diff.py: https://reviews.llvm.org/source/llvm-github/browse/main/clang/tools/clang-format/clang-format-diff.py
185-
.. _git-clang-format: https://reviews.llvm.org/source/llvm-github/browse/main/clang/tools/clang-format/git-clang-format
184+
.. _clang-format-diff.py: https://github.com/llvm/llvm-project/blob/main/clang/tools/clang-format/clang-format-diff.py
185+
.. _git-clang-format: https://github.com/llvm/llvm-project/blob/main/clang/tools/clang-format/git-clang-format
186186
.. _LLVM's GitHub: https://github.com/llvm/llvm-project
187187
.. _LLVM's Phabricator (read-only): https://reviews.llvm.org/
188188
.. _LLVM's Open Projects page: https://llvm.org/OpenProjects.html#what

llvm/docs/LangRef.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4386,7 +4386,7 @@ is defined inline with other types (e.g. ``[2 x {i32, i32}]``) whereas
43864386
identified types are always defined at the top level with a name.
43874387
Literal types are uniqued by their contents and can never be recursive
43884388
or opaque since there is no way to write one. Identified types can be
4389-
recursive, can be opaqued, and are never uniqued.
4389+
opaqued and are never uniqued. Identified types must not be recursive.
43904390

43914391
:Syntax:
43924392

llvm/docs/ReleaseNotes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ Makes programs 10x faster by doing Special New Thing.
5656
Changes to the LLVM IR
5757
----------------------
5858

59+
* Types are no longer allowed to be recursive.
60+
5961
* The `x86_mmx` IR type has been removed. It will be translated to
6062
the standard vector type `<1 x i64>` in bitcode upgrade.
6163
* Renamed `llvm.experimental.stepvector` intrinsic to `llvm.stepvector`.

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 517092
19+
#define LLVM_MAIN_REVISION 517104
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/include/llvm/IR/DerivedTypes.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Value;
3333
class APInt;
3434
class LLVMContext;
3535
template <typename T> class Expected;
36+
class Error;
3637

3738
/// Class to represent integer types. Note that this class is also used to
3839
/// represent the built-in integer types: Int1Ty, Int8Ty, Int16Ty, Int32Ty and
@@ -317,9 +318,18 @@ class StructType : public Type {
317318
/// suffix if there is a collision. Do not call this on an literal type.
318319
void setName(StringRef Name);
319320

320-
/// Specify a body for an opaque identified type.
321+
/// Specify a body for an opaque identified type, which must not make the type
322+
/// recursive.
321323
void setBody(ArrayRef<Type*> Elements, bool isPacked = false);
322324

325+
/// Specify a body for an opaque identified type or return an error if it
326+
/// would make the type recursive.
327+
Error setBodyOrError(ArrayRef<Type *> Elements, bool isPacked = false);
328+
329+
/// Return an error if the body for an opaque identified type would make it
330+
/// recursive.
331+
Error checkBody(ArrayRef<Type *> Elements);
332+
323333
template <typename... Tys>
324334
std::enable_if_t<are_base_of<Type, Tys...>::value, void>
325335
setBody(Type *elt1, Tys *... elts) {

0 commit comments

Comments
 (0)