Author: Timm Baeder Date: 2024-11-21T07:54:38+01:00 New Revision: 476b208e0115e766605e9f850982996a1d51c287
URL: https://github.com/llvm/llvm-project/commit/476b208e0115e766605e9f850982996a1d51c287 DIFF: https://github.com/llvm/llvm-project/commit/476b208e0115e766605e9f850982996a1d51c287.diff LOG: [clang][bytecode] Fix ToType/FromType diagnostic ordering (#116988) We need to check the ToType first, then the FromType. Additionally, remove qualifiers from the parent type of the field we're emitting a note for. Added: Modified: clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp clang/test/AST/ByteCode/builtin-bit-cast.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp index 7e8853d3469317..b1230f92ddf1d4 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp @@ -254,7 +254,7 @@ static bool CheckBitcastType(InterpState &S, CodePtr OpPC, QualType T, }; auto note = [&](int Construct, QualType NoteType, SourceRange NoteRange) { S.Note(NoteRange.getBegin(), diag::note_constexpr_bit_cast_invalid_subtype) - << NoteType << Construct << T << NoteRange; + << NoteType << Construct << T.getUnqualifiedType() << NoteRange; return false; }; @@ -388,11 +388,10 @@ bool clang::interp::DoBitCastPtr(InterpState &S, CodePtr OpPC, QualType FromType = FromPtr.getType(); QualType ToType = ToPtr.getType(); - if (!CheckBitcastType(S, OpPC, FromType, /*IsToType=*/false)) - return false; - if (!CheckBitcastType(S, OpPC, ToType, /*IsToType=*/true)) return false; + if (!CheckBitcastType(S, OpPC, FromType, /*IsToType=*/false)) + return false; BitcastBuffer Buffer; readPointerToBuffer(S.getContext(), FromPtr, Buffer, diff --git a/clang/test/AST/ByteCode/builtin-bit-cast.cpp b/clang/test/AST/ByteCode/builtin-bit-cast.cpp index 60e8c3a615c5e6..3c6cd0aa36e7fe 100644 --- a/clang/test/AST/ByteCode/builtin-bit-cast.cpp +++ b/clang/test/AST/ByteCode/builtin-bit-cast.cpp @@ -145,6 +145,17 @@ namespace Fail { // both-note {{initializer of 'a' is not a constant expression}} } +namespace ToPtr { + struct S { + const int *p = nullptr; + }; + struct P { + const int *p; // both-note {{invalid type 'const int *' is a member of 'ToPtr::P'}} + }; + constexpr P p = __builtin_bit_cast(P, S{}); // both-error {{must be initialized by a constant expression}} \ + // both-note {{bit_cast to a pointer type is not allowed in a constant expression}} +} + namespace NullPtr { constexpr nullptr_t N = __builtin_bit_cast(nullptr_t, (intptr_t)1u); static_assert(N == nullptr); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits