Skip to content

Commit 502c08e

Browse files
authored
[clang][ExprConst] Move vector diagnostics to checkBitCastConstexprEl… (#119366)
…igibilityType This is the function we use to diagnose invalid types, so use it for those checks as well. NFC.
1 parent 28a0ad0 commit 502c08e

File tree

1 file changed

+26
-47
lines changed

1 file changed

+26
-47
lines changed

clang/lib/AST/ExprConstant.cpp

+26-47
Original file line numberDiff line numberDiff line change
@@ -7352,31 +7352,6 @@ class APValueToBufferConverter {
73527352
const VectorType *VTy = Ty->castAs<VectorType>();
73537353
QualType EltTy = VTy->getElementType();
73547354
unsigned NElts = VTy->getNumElements();
7355-
unsigned EltSize =
7356-
VTy->isExtVectorBoolType() ? 1 : Info.Ctx.getTypeSize(EltTy);
7357-
7358-
if ((NElts * EltSize) % Info.Ctx.getCharWidth() != 0) {
7359-
// The vector's size in bits is not a multiple of the target's byte size,
7360-
// so its layout is unspecified. For now, we'll simply treat these cases
7361-
// as unsupported (this should only be possible with OpenCL bool vectors
7362-
// whose element count isn't a multiple of the byte size).
7363-
Info.FFDiag(BCE->getBeginLoc(),
7364-
diag::note_constexpr_bit_cast_invalid_vector)
7365-
<< Ty.getCanonicalType() << EltSize << NElts
7366-
<< Info.Ctx.getCharWidth();
7367-
return false;
7368-
}
7369-
7370-
if (EltTy->isRealFloatingType() && &Info.Ctx.getFloatTypeSemantics(EltTy) ==
7371-
&APFloat::x87DoubleExtended()) {
7372-
// The layout for x86_fp80 vectors seems to be handled very inconsistently
7373-
// by both clang and LLVM, so for now we won't allow bit_casts involving
7374-
// it in a constexpr context.
7375-
Info.FFDiag(BCE->getBeginLoc(),
7376-
diag::note_constexpr_bit_cast_unsupported_type)
7377-
<< EltTy;
7378-
return false;
7379-
}
73807355

73817356
if (VTy->isExtVectorBoolType()) {
73827357
// Special handling for OpenCL bool vectors:
@@ -7643,28 +7618,6 @@ class BufferToAPValueConverter {
76437618
unsigned EltSize =
76447619
VTy->isExtVectorBoolType() ? 1 : Info.Ctx.getTypeSize(EltTy);
76457620

7646-
if ((NElts * EltSize) % Info.Ctx.getCharWidth() != 0) {
7647-
// The vector's size in bits is not a multiple of the target's byte size,
7648-
// so its layout is unspecified. For now, we'll simply treat these cases
7649-
// as unsupported (this should only be possible with OpenCL bool vectors
7650-
// whose element count isn't a multiple of the byte size).
7651-
Info.FFDiag(BCE->getBeginLoc(),
7652-
diag::note_constexpr_bit_cast_invalid_vector)
7653-
<< QualType(VTy, 0) << EltSize << NElts << Info.Ctx.getCharWidth();
7654-
return std::nullopt;
7655-
}
7656-
7657-
if (EltTy->isRealFloatingType() && &Info.Ctx.getFloatTypeSemantics(EltTy) ==
7658-
&APFloat::x87DoubleExtended()) {
7659-
// The layout for x86_fp80 vectors seems to be handled very inconsistently
7660-
// by both clang and LLVM, so for now we won't allow bit_casts involving
7661-
// it in a constexpr context.
7662-
Info.FFDiag(BCE->getBeginLoc(),
7663-
diag::note_constexpr_bit_cast_unsupported_type)
7664-
<< EltTy;
7665-
return std::nullopt;
7666-
}
7667-
76687621
SmallVector<APValue, 4> Elts;
76697622
Elts.reserve(NElts);
76707623
if (VTy->isExtVectorBoolType()) {
@@ -7793,6 +7746,32 @@ static bool checkBitCastConstexprEligibilityType(SourceLocation Loc,
77937746
Info, Ctx, CheckingDest))
77947747
return false;
77957748

7749+
if (const auto *VTy = Ty->getAs<VectorType>()) {
7750+
QualType EltTy = VTy->getElementType();
7751+
unsigned NElts = VTy->getNumElements();
7752+
unsigned EltSize = VTy->isExtVectorBoolType() ? 1 : Ctx.getTypeSize(EltTy);
7753+
7754+
if ((NElts * EltSize) % Ctx.getCharWidth() != 0) {
7755+
// The vector's size in bits is not a multiple of the target's byte size,
7756+
// so its layout is unspecified. For now, we'll simply treat these cases
7757+
// as unsupported (this should only be possible with OpenCL bool vectors
7758+
// whose element count isn't a multiple of the byte size).
7759+
Info->FFDiag(Loc, diag::note_constexpr_bit_cast_invalid_vector)
7760+
<< QualType(VTy, 0) << EltSize << NElts << Ctx.getCharWidth();
7761+
return false;
7762+
}
7763+
7764+
if (EltTy->isRealFloatingType() &&
7765+
&Ctx.getFloatTypeSemantics(EltTy) == &APFloat::x87DoubleExtended()) {
7766+
// The layout for x86_fp80 vectors seems to be handled very inconsistently
7767+
// by both clang and LLVM, so for now we won't allow bit_casts involving
7768+
// it in a constexpr context.
7769+
Info->FFDiag(Loc, diag::note_constexpr_bit_cast_unsupported_type)
7770+
<< EltTy;
7771+
return false;
7772+
}
7773+
}
7774+
77967775
return true;
77977776
}
77987777

0 commit comments

Comments
 (0)