llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

Reject bitcasts to non-byte sized `_BitInt` for now.

---
Full diff: https://github.com/llvm/llvm-project/pull/243401.diff


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Interp.h (+6) 
- (modified) clang/test/AST/ByteCode/builtin-bit-cast.cpp (+7) 


``````````diff
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 18c2421a67231..4a967192de0b2 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -4076,6 +4076,12 @@ inline bool BitCastPrim(InterpState &S, CodePtr OpPC, 
bool TargetIsUCharOrByte,
     bool HasIndeterminateBits = false;
 
     Bits FullBitWidth(ResultBitWidth);
+
+    // FIXME: Since we support bitcasts of bitfields, we should also support
+    // this.
+    if (!FullBitWidth.isFullByte())
+      return false;
+
     Bits BitWidth = FullBitWidth;
 
     if constexpr (std::is_same_v<T, Floating>) {
diff --git a/clang/test/AST/ByteCode/builtin-bit-cast.cpp 
b/clang/test/AST/ByteCode/builtin-bit-cast.cpp
index 8588b4217a4d9..7bf169ae15855 100644
--- a/clang/test/AST/ByteCode/builtin-bit-cast.cpp
+++ b/clang/test/AST/ByteCode/builtin-bit-cast.cpp
@@ -624,3 +624,10 @@ namespace nullptrToArray {
                                                                // both-note 
{{read of uninitialized object}} \
                                                                // both-note 
{{temporary created here}}
 }
+
+namespace BitInt20 {
+  constexpr _BitInt(32) BI = ~0;
+  constexpr unsigned int I = __builtin_bit_cast(unsigned int, BI);
+  constexpr _BitInt(32) IB = __builtin_bit_cast(_BitInt(20), I); // both-error 
{{must be initialized by a constant expression}} \
+                                                                 // ref-note 
{{constexpr bit cast involving type '_BitInt(20)' is not yet supported}}
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/243401
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to