Skip to content

Commit 4021a18

Browse files
authored
Merge branch 'main' into tablegen/decoder/filter-known-bits
2 parents abc9cf7 + 1d05d69 commit 4021a18

File tree

77 files changed

+419
-254
lines changed

Some content is hidden

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

77 files changed

+419
-254
lines changed

clang/include/clang/Basic/AllDiagnostics.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@
2323
#include "clang/Basic/DiagnosticInstallAPI.h"
2424
#include "clang/Basic/DiagnosticLex.h"
2525
#include "clang/Basic/DiagnosticParse.h"
26+
#include "clang/Basic/DiagnosticRefactoring.h"
2627
#include "clang/Basic/DiagnosticSema.h"
2728
#include "clang/Basic/DiagnosticSerialization.h"
28-
#include "clang/Basic/DiagnosticRefactoring.h"
2929

3030
namespace clang {
31-
template <size_t SizeOfStr, typename FieldType>
32-
class StringSizerHelper {
31+
template <size_t SizeOfStr, typename FieldType> class StringSizerHelper {
3332
static_assert(SizeOfStr <= FieldType(~0U), "Field too small!");
33+
3434
public:
3535
enum { Size = SizeOfStr };
3636
};
3737
} // end namespace clang
3838

39-
#define STR_SIZE(str, fieldTy) clang::StringSizerHelper<sizeof(str)-1, \
40-
fieldTy>::Size
39+
#define STR_SIZE(str, fieldTy) \
40+
clang::StringSizerHelper<sizeof(str) - 1, fieldTy>::Size
4141

4242
#endif

clang/include/clang/Basic/DiagnosticIDs.h

Lines changed: 75 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -23,76 +23,78 @@
2323
#include <vector>
2424

2525
namespace clang {
26-
class DiagnosticsEngine;
27-
class DiagnosticBuilder;
28-
class LangOptions;
29-
class SourceLocation;
30-
31-
// Import the diagnostic enums themselves.
32-
namespace diag {
33-
enum class Group;
34-
35-
// Size of each of the diagnostic categories.
36-
enum {
37-
DIAG_SIZE_COMMON = 300,
38-
DIAG_SIZE_DRIVER = 400,
39-
DIAG_SIZE_FRONTEND = 200,
40-
DIAG_SIZE_SERIALIZATION = 120,
41-
DIAG_SIZE_LEX = 500,
42-
DIAG_SIZE_PARSE = 800,
43-
DIAG_SIZE_AST = 300,
44-
DIAG_SIZE_COMMENT = 100,
45-
DIAG_SIZE_CROSSTU = 100,
46-
DIAG_SIZE_SEMA = 5000,
47-
DIAG_SIZE_ANALYSIS = 100,
48-
DIAG_SIZE_REFACTORING = 1000,
49-
DIAG_SIZE_INSTALLAPI = 100,
50-
};
51-
// Start position for diagnostics.
52-
enum {
53-
DIAG_START_COMMON = 0,
54-
DIAG_START_DRIVER = DIAG_START_COMMON + static_cast<int>(DIAG_SIZE_COMMON),
55-
DIAG_START_FRONTEND = DIAG_START_DRIVER + static_cast<int>(DIAG_SIZE_DRIVER),
56-
DIAG_START_SERIALIZATION = DIAG_START_FRONTEND + static_cast<int>(DIAG_SIZE_FRONTEND),
57-
DIAG_START_LEX = DIAG_START_SERIALIZATION + static_cast<int>(DIAG_SIZE_SERIALIZATION),
58-
DIAG_START_PARSE = DIAG_START_LEX + static_cast<int>(DIAG_SIZE_LEX),
59-
DIAG_START_AST = DIAG_START_PARSE + static_cast<int>(DIAG_SIZE_PARSE),
60-
DIAG_START_COMMENT = DIAG_START_AST + static_cast<int>(DIAG_SIZE_AST),
61-
DIAG_START_CROSSTU = DIAG_START_COMMENT + static_cast<int>(DIAG_SIZE_COMMENT),
62-
DIAG_START_SEMA = DIAG_START_CROSSTU + static_cast<int>(DIAG_SIZE_CROSSTU),
63-
DIAG_START_ANALYSIS = DIAG_START_SEMA + static_cast<int>(DIAG_SIZE_SEMA),
64-
DIAG_START_REFACTORING = DIAG_START_ANALYSIS + static_cast<int>(DIAG_SIZE_ANALYSIS),
65-
DIAG_START_INSTALLAPI = DIAG_START_REFACTORING + static_cast<int>(DIAG_SIZE_REFACTORING),
66-
DIAG_UPPER_LIMIT = DIAG_START_INSTALLAPI + static_cast<int>(DIAG_SIZE_INSTALLAPI)
67-
};
68-
69-
class CustomDiagInfo;
70-
71-
/// All of the diagnostics that can be emitted by the frontend.
72-
typedef unsigned kind;
73-
74-
/// Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs
75-
/// to either Ignore (nothing), Remark (emit a remark), Warning
76-
/// (emit a warning) or Error (emit as an error). It allows clients to
77-
/// map ERRORs to Error or Fatal (stop emitting diagnostics after this one).
78-
enum class Severity : uint8_t {
79-
// NOTE: 0 means "uncomputed".
80-
Ignored = 1, ///< Do not present this diagnostic, ignore it.
81-
Remark = 2, ///< Present this diagnostic as a remark.
82-
Warning = 3, ///< Present this diagnostic as a warning.
83-
Error = 4, ///< Present this diagnostic as an error.
84-
Fatal = 5 ///< Present this diagnostic as a fatal error.
85-
};
86-
87-
/// Flavors of diagnostics we can emit. Used to filter for a particular
88-
/// kind of diagnostic (for instance, for -W/-R flags).
89-
enum class Flavor {
90-
WarningOrError, ///< A diagnostic that indicates a problem or potential
91-
///< problem. Can be made fatal by -Werror.
92-
Remark ///< A diagnostic that indicates normal progress through
93-
///< compilation.
94-
};
95-
} // end namespace diag
26+
class DiagnosticsEngine;
27+
class DiagnosticBuilder;
28+
class LangOptions;
29+
class SourceLocation;
30+
31+
// Import the diagnostic enums themselves.
32+
namespace diag {
33+
enum class Group;
34+
35+
// Size of each of the diagnostic categories.
36+
enum {
37+
DIAG_SIZE_COMMON = 300,
38+
DIAG_SIZE_DRIVER = 400,
39+
DIAG_SIZE_FRONTEND = 200,
40+
DIAG_SIZE_SERIALIZATION = 120,
41+
DIAG_SIZE_LEX = 500,
42+
DIAG_SIZE_PARSE = 800,
43+
DIAG_SIZE_AST = 300,
44+
DIAG_SIZE_COMMENT = 100,
45+
DIAG_SIZE_CROSSTU = 100,
46+
DIAG_SIZE_SEMA = 5000,
47+
DIAG_SIZE_ANALYSIS = 100,
48+
DIAG_SIZE_REFACTORING = 1000,
49+
DIAG_SIZE_INSTALLAPI = 100,
50+
};
51+
// Start position for diagnostics.
52+
// clang-format off
53+
enum {
54+
DIAG_START_COMMON = 0,
55+
DIAG_START_DRIVER = DIAG_START_COMMON + static_cast<int>(DIAG_SIZE_COMMON),
56+
DIAG_START_FRONTEND = DIAG_START_DRIVER + static_cast<int>(DIAG_SIZE_DRIVER),
57+
DIAG_START_SERIALIZATION = DIAG_START_FRONTEND + static_cast<int>(DIAG_SIZE_FRONTEND),
58+
DIAG_START_LEX = DIAG_START_SERIALIZATION + static_cast<int>(DIAG_SIZE_SERIALIZATION),
59+
DIAG_START_PARSE = DIAG_START_LEX + static_cast<int>(DIAG_SIZE_LEX),
60+
DIAG_START_AST = DIAG_START_PARSE + static_cast<int>(DIAG_SIZE_PARSE),
61+
DIAG_START_COMMENT = DIAG_START_AST + static_cast<int>(DIAG_SIZE_AST),
62+
DIAG_START_CROSSTU = DIAG_START_COMMENT + static_cast<int>(DIAG_SIZE_COMMENT),
63+
DIAG_START_SEMA = DIAG_START_CROSSTU + static_cast<int>(DIAG_SIZE_CROSSTU),
64+
DIAG_START_ANALYSIS = DIAG_START_SEMA + static_cast<int>(DIAG_SIZE_SEMA),
65+
DIAG_START_REFACTORING = DIAG_START_ANALYSIS + static_cast<int>(DIAG_SIZE_ANALYSIS),
66+
DIAG_START_INSTALLAPI = DIAG_START_REFACTORING + static_cast<int>(DIAG_SIZE_REFACTORING),
67+
DIAG_UPPER_LIMIT = DIAG_START_INSTALLAPI + static_cast<int>(DIAG_SIZE_INSTALLAPI)
68+
};
69+
// clang-format on
70+
71+
class CustomDiagInfo;
72+
73+
/// All of the diagnostics that can be emitted by the frontend.
74+
typedef unsigned kind;
75+
76+
/// Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs
77+
/// to either Ignore (nothing), Remark (emit a remark), Warning
78+
/// (emit a warning) or Error (emit as an error). It allows clients to
79+
/// map ERRORs to Error or Fatal (stop emitting diagnostics after this one).
80+
enum class Severity : uint8_t {
81+
// NOTE: 0 means "uncomputed".
82+
Ignored = 1, ///< Do not present this diagnostic, ignore it.
83+
Remark = 2, ///< Present this diagnostic as a remark.
84+
Warning = 3, ///< Present this diagnostic as a warning.
85+
Error = 4, ///< Present this diagnostic as an error.
86+
Fatal = 5 ///< Present this diagnostic as a fatal error.
87+
};
88+
89+
/// Flavors of diagnostics we can emit. Used to filter for a particular
90+
/// kind of diagnostic (for instance, for -W/-R flags).
91+
enum class Flavor {
92+
WarningOrError, ///< A diagnostic that indicates a problem or potential
93+
///< problem. Can be made fatal by -Werror.
94+
Remark ///< A diagnostic that indicates normal progress through
95+
///< compilation.
96+
};
97+
} // end namespace diag
9698
} // end namespace clang
9799

98100
// This has to be included *after* the DIAG_START_ enums above are defined.
@@ -173,7 +175,8 @@ class DiagnosticMapping {
173175

174176
/// Used for handling and querying diagnostic IDs.
175177
///
176-
/// Can be used and shared by multiple Diagnostics for multiple translation units.
178+
/// Can be used and shared by multiple Diagnostics for multiple translation
179+
/// units.
177180
class DiagnosticIDs : public RefCountedBase<DiagnosticIDs> {
178181
public:
179182
/// The level of the diagnostic, after it has been through mapping.
@@ -498,6 +501,6 @@ class DiagnosticIDs : public RefCountedBase<DiagnosticIDs> {
498501
friend class DiagnosticsEngine;
499502
};
500503

501-
} // end namespace clang
504+
} // end namespace clang
502505

503506
#endif

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 83 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,54 @@ Address CIRGenFunction::emitPointerWithAlignment(const Expr *expr,
7373

7474
// Casts:
7575
if (auto const *ce = dyn_cast<CastExpr>(expr)) {
76-
if (isa<ExplicitCastExpr>(ce)) {
77-
cgm.errorNYI(expr->getSourceRange(),
78-
"emitPointerWithAlignment: explicit cast");
79-
return Address::invalid();
80-
}
76+
if (const auto *ece = dyn_cast<ExplicitCastExpr>(ce))
77+
cgm.emitExplicitCastExprType(ece);
8178

8279
switch (ce->getCastKind()) {
8380
// Non-converting casts (but not C's implicit conversion from void*).
8481
case CK_BitCast:
8582
case CK_NoOp:
8683
case CK_AddressSpaceConversion: {
87-
cgm.errorNYI(expr->getSourceRange(),
88-
"emitPointerWithAlignment: noop cast");
89-
return Address::invalid();
90-
} break;
84+
if (const auto *ptrTy =
85+
ce->getSubExpr()->getType()->getAs<PointerType>()) {
86+
if (ptrTy->getPointeeType()->isVoidType())
87+
break;
88+
89+
LValueBaseInfo innerBaseInfo;
90+
assert(!cir::MissingFeatures::opTBAA());
91+
Address addr =
92+
emitPointerWithAlignment(ce->getSubExpr(), &innerBaseInfo);
93+
if (baseInfo)
94+
*baseInfo = innerBaseInfo;
95+
96+
if (isa<ExplicitCastExpr>(ce)) {
97+
LValueBaseInfo targetTypeBaseInfo;
98+
99+
const QualType pointeeType = expr->getType()->getPointeeType();
100+
const CharUnits align =
101+
cgm.getNaturalTypeAlignment(pointeeType, &targetTypeBaseInfo);
102+
103+
// If the source l-value is opaque, honor the alignment of the
104+
// casted-to type.
105+
if (innerBaseInfo.getAlignmentSource() != AlignmentSource::Decl) {
106+
if (baseInfo)
107+
baseInfo->mergeForCast(targetTypeBaseInfo);
108+
addr = Address(addr.getPointer(), addr.getElementType(), align);
109+
}
110+
}
111+
112+
assert(!cir::MissingFeatures::sanitizers());
113+
114+
const mlir::Type eltTy =
115+
convertTypeForMem(expr->getType()->getPointeeType());
116+
addr = getBuilder().createElementBitCast(getLoc(expr->getSourceRange()),
117+
addr, eltTy);
118+
assert(!cir::MissingFeatures::addressSpace());
119+
120+
return addr;
121+
}
122+
break;
123+
}
91124

92125
// Array-to-pointer decay. TODO(cir): BaseInfo and TBAAInfo.
93126
case CK_ArrayToPointerDecay:
@@ -551,6 +584,37 @@ RValue CIRGenFunction::emitLoadOfLValue(LValue lv, SourceLocation loc) {
551584
return RValue::get(nullptr);
552585
}
553586

587+
static cir::FuncOp emitFunctionDeclPointer(CIRGenModule &cgm, GlobalDecl gd) {
588+
assert(!cir::MissingFeatures::weakRefReference());
589+
return cgm.getAddrOfFunction(gd);
590+
}
591+
592+
static LValue emitFunctionDeclLValue(CIRGenFunction &cgf, const Expr *e,
593+
GlobalDecl gd) {
594+
const FunctionDecl *fd = cast<FunctionDecl>(gd.getDecl());
595+
cir::FuncOp funcOp = emitFunctionDeclPointer(cgf.cgm, gd);
596+
mlir::Location loc = cgf.getLoc(e->getSourceRange());
597+
CharUnits align = cgf.getContext().getDeclAlign(fd);
598+
599+
assert(!cir::MissingFeatures::sanitizers());
600+
601+
mlir::Type fnTy = funcOp.getFunctionType();
602+
mlir::Type ptrTy = cir::PointerType::get(fnTy);
603+
mlir::Value addr = cgf.getBuilder().create<cir::GetGlobalOp>(
604+
loc, ptrTy, funcOp.getSymName());
605+
606+
if (funcOp.getFunctionType() != cgf.convertType(fd->getType())) {
607+
fnTy = cgf.convertType(fd->getType());
608+
ptrTy = cir::PointerType::get(fnTy);
609+
610+
addr = cir::CastOp::create(cgf.getBuilder(), addr.getLoc(), ptrTy,
611+
cir::CastKind::bitcast, addr);
612+
}
613+
614+
return cgf.makeAddrLValue(Address(addr, fnTy, align), e->getType(),
615+
AlignmentSource::Decl);
616+
}
617+
554618
LValue CIRGenFunction::emitDeclRefLValue(const DeclRefExpr *e) {
555619
const NamedDecl *nd = e->getDecl();
556620
QualType ty = e->getType();
@@ -607,6 +671,16 @@ LValue CIRGenFunction::emitDeclRefLValue(const DeclRefExpr *e) {
607671
return emitLValue(bd->getBinding());
608672
}
609673

674+
if (const auto *fd = dyn_cast<FunctionDecl>(nd)) {
675+
LValue lv = emitFunctionDeclLValue(*this, e, fd);
676+
677+
// Emit debuginfo for the function declaration if the target wants to.
678+
if (getContext().getTargetInfo().allowDebugInfoForExternalRef())
679+
assert(!cir::MissingFeatures::generateDebugInfo());
680+
681+
return lv;
682+
}
683+
610684
cgm.errorNYI(e->getSourceRange(), "emitDeclRefLValue: unhandled decl type");
611685
return LValue();
612686
}
@@ -1401,11 +1475,6 @@ RValue CIRGenFunction::emitAnyExpr(const Expr *e, AggValueSlot aggSlot) {
14011475
llvm_unreachable("bad evaluation kind");
14021476
}
14031477

1404-
static cir::FuncOp emitFunctionDeclPointer(CIRGenModule &cgm, GlobalDecl gd) {
1405-
assert(!cir::MissingFeatures::weakRefReference());
1406-
return cgm.getAddrOfFunction(gd);
1407-
}
1408-
14091478
// Detect the unusual situation where an inline version is shadowed by a
14101479
// non-inline version. In that case we should pick the external one
14111480
// everywhere. That's GCC behavior too.

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,6 +1905,8 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *ce) {
19051905
cgf.getLoc(subExpr->getSourceRange()), cgf.convertType(destTy),
19061906
Visit(subExpr));
19071907
}
1908+
case CK_FunctionToPointerDecay:
1909+
return cgf.emitLValue(subExpr).getPointer();
19081910

19091911
default:
19101912
cgf.getCIRGenModule().errorNYI(subExpr->getSourceRange(),

clang/lib/Sema/SemaChecking.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5601,8 +5601,10 @@ ExprResult Sema::BuiltinShuffleVector(CallExpr *TheCall) {
56015601
TheCall->getArg(1)->getEndLoc()));
56025602
} else if (numElements != numResElements) {
56035603
QualType eltType = LHSType->castAs<VectorType>()->getElementType();
5604-
resType =
5605-
Context.getVectorType(eltType, numResElements, VectorKind::Generic);
5604+
resType = resType->isExtVectorType()
5605+
? Context.getExtVectorType(eltType, numResElements)
5606+
: Context.getVectorType(eltType, numResElements,
5607+
VectorKind::Generic);
56065608
}
56075609
}
56085610

clang/test/AST/ByteCode/constexpr-vectors.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ using FourFloatsExtVec __attribute__((ext_vector_type(4))) = float;
1515
using FourDoublesExtVec __attribute__((ext_vector_type(4))) = double;
1616
using FourI128ExtVec __attribute__((ext_vector_type(4))) = __int128;
1717

18-
1918
// Next a series of tests to make sure these operations are usable in
2019
// constexpr functions. Template instantiations don't emit Winvalid-constexpr,
2120
// so we have to do these as macros.
@@ -875,3 +874,9 @@ void BoolVecUsage() {
875874
constexpr auto k = ~FourBoolsExtVec{true, false, true, false};
876875
static_assert(k[0] == false && k[1] == true && k[2] == false && k[3] == true, "");
877876
}
877+
878+
using EightBoolsExtVec __attribute__((ext_vector_type(8))) = bool;
879+
void BoolVecShuffle() {
880+
constexpr EightBoolsExtVec a = __builtin_shufflevector(
881+
FourBoolsExtVec{}, FourBoolsExtVec{}, 0, 1, 2, 3, 4, 5, 6, 7);
882+
}

0 commit comments

Comments
 (0)