Skip to content

Commit e5b8fac

Browse files
authored
Merge branch 'main' into harrison/mlir
2 parents 5e07a46 + 5d39e0c commit e5b8fac

File tree

35 files changed

+1300
-2177
lines changed

35 files changed

+1300
-2177
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/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 };

flang/lib/Optimizer/Passes/Pipelines.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,10 @@ void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
264264
addNestedPassToAllTopLevelOperations(pm, fir::createAbstractResultOpt);
265265
fir::addCodeGenRewritePass(
266266
pm, (config.DebugInfo != llvm::codegenoptions::NoDebugInfo));
267-
fir::addTargetRewritePass(pm);
268-
fir::addCompilerGeneratedNamesConversionPass(pm);
269267
fir::addExternalNameConversionPass(pm, config.Underscoring);
270268
fir::createDebugPasses(pm, config.DebugInfo, config.OptLevel, inputFilename);
269+
fir::addTargetRewritePass(pm);
270+
fir::addCompilerGeneratedNamesConversionPass(pm);
271271

272272
if (config.VScaleMin != 0)
273273
pm.addPass(fir::createVScaleAttr({{config.VScaleMin, config.VScaleMax}}));

flang/test/Driver/mlir-debug-pass-pipeline.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@
111111

112112
! ALL-NEXT: CodeGenRewrite
113113
! ALL-NEXT: (S) 0 num-dce'd - Number of operations eliminated
114-
! ALL-NEXT: TargetRewrite
115-
! ALL-NEXT: CompilerGeneratedNamesConversion
116114
! ALL-NEXT: ExternalNameConversion
117115
! DEBUG-NEXT: AddDebugInfo
118116
! NO-DEBUG-NOT: AddDebugInfo
117+
! ALL-NEXT: TargetRewrite
118+
! ALL-NEXT: CompilerGeneratedNamesConversion
119119
! ALL: FIRToLLVMLowering
120120
! ALL-NOT: LLVMIRLoweringPass

flang/test/Driver/mlir-pass-pipeline.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@
120120

121121
! ALL-NEXT: CodeGenRewrite
122122
! ALL-NEXT: (S) 0 num-dce'd - Number of operations eliminated
123+
! ALL-NEXT: ExternalNameConversion
123124
! ALL-NEXT: TargetRewrite
124125
! ALL-NEXT: CompilerGeneratedNamesConversion
125-
! ALL-NEXT: ExternalNameConversion
126126
! ALL-NEXT: FIRToLLVMLowering
127127
! ALL-NOT: LLVMIRLoweringPass
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck %s
2+
3+
! Test that complex return type is correctly represented in debug.
4+
complex function fn(a)
5+
complex, intent(in) :: a
6+
fn = a
7+
end function
8+
9+
! CHECK-DAG: ![[CMPLX:.*]] = !DIBasicType(name: "complex", size: 64, encoding: DW_ATE_complex_float)
10+
! CHECK-DAG: ![[SR_TY:.*]] = !DISubroutineType(cc: DW_CC_normal, types: ![[TYPES:.*]])
11+
! CHECK-DAG: ![[TYPES]] = !{![[CMPLX]], ![[CMPLX]]}
12+
! CHECK-DAG: !DISubprogram(name: "fn"{{.*}}type: ![[SR_TY]]{{.*}})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck %s
2+
3+
! Test that correct linkage name is generated in the debug info.
4+
subroutine sub(a)
5+
integer :: a
6+
return a+1
7+
end
8+
9+
!CHECK: !DISubprogram(name: "sub", linkageName: "sub_"{{.*}})
10+

0 commit comments

Comments
 (0)