[clang] [clang][bytecode] Fix ToType/FromType diagnostic ordering (PR #116988)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 20 07:27:20 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/116988.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp (+3-4)
- (modified) clang/test/AST/ByteCode/builtin-bit-cast.cpp (+11)
``````````diff
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);
``````````
</details>
https://github.com/llvm/llvm-project/pull/116988
More information about the cfe-commits
mailing list