-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[clang][ExprConst] Move vector diagnostics to checkBitCastConstexprEl… #119366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) Changes…igibilityType This is the function we use to diagnose invalid types, so use it for those checks as well. Full diff: https://github.com/llvm/llvm-project/pull/119366.diff 1 Files Affected:
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;
}
|
…igibilityType This is the function we use to diagnose invalid types, so use it for those checks as well.
3fd250e
to
08d3ee1
Compare
Closed
This PR is linked to this issue: #155507 |
tbaederr
added a commit
to tbaederr/llvm-project
that referenced
this pull request
Aug 27, 2025
It can be null, when called via CheckICE(). Accidentally introduced via llvm#119366 Fixes llvm#155507
tbaederr
added a commit
that referenced
this pull request
Aug 27, 2025
tru
pushed a commit
to llvmbot/llvm-project
that referenced
this pull request
Sep 3, 2025
It can be null, when called via CheckICE(). Accidentally introduced via llvm#119366 Fixes llvm#155507 (cherry picked from commit 60cdc3d)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…igibilityType
This is the function we use to diagnose invalid types, so use it for those checks as well.
NFC.