[clang] [clang][ExprConst] Move vector diagnostics to checkBitCastConstexprEl… (PR #119366)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 10 04:12:07 PST 2024
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/119366
…igibilityType
This is the function we use to diagnose invalid types, so use it for those checks as well.
>From 3fd250e95d6cca9bd822d516d5f6f862215dbe85 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Tue, 10 Dec 2024 13:08:39 +0100
Subject: [PATCH] [clang][ExprConst] Move vector diagnostics to
checkBitCastConstexprEligibilityType
This is the function we use to diagnose invalid types, so use it for
those checks as well.
---
clang/lib/AST/ExprConstant.cpp | 75 +++++++++++++---------------------
1 file changed, 28 insertions(+), 47 deletions(-)
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index eed277deb4ac16..0ca92c36380f81 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -7352,31 +7352,6 @@ class APValueToBufferConverter {
const VectorType *VTy = Ty->castAs<VectorType>();
QualType EltTy = VTy->getElementType();
unsigned NElts = VTy->getNumElements();
- unsigned EltSize =
- VTy->isExtVectorBoolType() ? 1 : Info.Ctx.getTypeSize(EltTy);
-
- if ((NElts * EltSize) % Info.Ctx.getCharWidth() != 0) {
- // The vector's size in bits is not a multiple of the target's byte size,
- // so its layout is unspecified. For now, we'll simply treat these cases
- // as unsupported (this should only be possible with OpenCL bool vectors
- // whose element count isn't a multiple of the byte size).
- Info.FFDiag(BCE->getBeginLoc(),
- diag::note_constexpr_bit_cast_invalid_vector)
- << Ty.getCanonicalType() << EltSize << NElts
- << Info.Ctx.getCharWidth();
- return false;
- }
-
- if (EltTy->isRealFloatingType() && &Info.Ctx.getFloatTypeSemantics(EltTy) ==
- &APFloat::x87DoubleExtended()) {
- // The layout for x86_fp80 vectors seems to be handled very inconsistently
- // by both clang and LLVM, so for now we won't allow bit_casts involving
- // it in a constexpr context.
- Info.FFDiag(BCE->getBeginLoc(),
- diag::note_constexpr_bit_cast_unsupported_type)
- << EltTy;
- return false;
- }
if (VTy->isExtVectorBoolType()) {
// Special handling for OpenCL bool vectors:
@@ -7643,28 +7618,6 @@ class BufferToAPValueConverter {
unsigned EltSize =
VTy->isExtVectorBoolType() ? 1 : Info.Ctx.getTypeSize(EltTy);
- if ((NElts * EltSize) % Info.Ctx.getCharWidth() != 0) {
- // The vector's size in bits is not a multiple of the target's byte size,
- // so its layout is unspecified. For now, we'll simply treat these cases
- // as unsupported (this should only be possible with OpenCL bool vectors
- // whose element count isn't a multiple of the byte size).
- Info.FFDiag(BCE->getBeginLoc(),
- diag::note_constexpr_bit_cast_invalid_vector)
- << QualType(VTy, 0) << EltSize << NElts << Info.Ctx.getCharWidth();
- return std::nullopt;
- }
-
- if (EltTy->isRealFloatingType() && &Info.Ctx.getFloatTypeSemantics(EltTy) ==
- &APFloat::x87DoubleExtended()) {
- // The layout for x86_fp80 vectors seems to be handled very inconsistently
- // by both clang and LLVM, so for now we won't allow bit_casts involving
- // it in a constexpr context.
- Info.FFDiag(BCE->getBeginLoc(),
- diag::note_constexpr_bit_cast_unsupported_type)
- << EltTy;
- return std::nullopt;
- }
-
SmallVector<APValue, 4> Elts;
Elts.reserve(NElts);
if (VTy->isExtVectorBoolType()) {
@@ -7793,6 +7746,34 @@ static bool checkBitCastConstexprEligibilityType(SourceLocation Loc,
Info, Ctx, CheckingDest))
return false;
+ if (const auto *VTy = Ty->getAs<VectorType>()) {
+ QualType EltTy = VTy->getElementType();
+ unsigned NElts = VTy->getNumElements();
+ unsigned EltSize =
+ VTy->isExtVectorBoolType() ? 1 : Info->Ctx.getTypeSize(EltTy);
+
+ if ((NElts * EltSize) % Info->Ctx.getCharWidth() != 0) {
+ // The vector's size in bits is not a multiple of the target's byte size,
+ // so its layout is unspecified. For now, we'll simply treat these cases
+ // as unsupported (this should only be possible with OpenCL bool vectors
+ // whose element count isn't a multiple of the byte size).
+ Info->FFDiag(Loc, diag::note_constexpr_bit_cast_invalid_vector)
+ << QualType(VTy, 0) << EltSize << NElts << Info->Ctx.getCharWidth();
+ return false;
+ }
+
+ if (EltTy->isRealFloatingType() &&
+ &Info->Ctx.getFloatTypeSemantics(EltTy) ==
+ &APFloat::x87DoubleExtended()) {
+ // The layout for x86_fp80 vectors seems to be handled very inconsistently
+ // by both clang and LLVM, so for now we won't allow bit_casts involving
+ // it in a constexpr context.
+ Info->FFDiag(Loc, diag::note_constexpr_bit_cast_unsupported_type)
+ << EltTy;
+ return false;
+ }
+ }
+
return true;
}
More information about the cfe-commits
mailing list