[clang] [compiler-rt] [ubsan] Display correct runtime messages for negative _BitInt (PR #96240)
Björn Pettersson via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 21 13:00:12 PDT 2024
================
@@ -3298,22 +3315,40 @@ LValue CodeGenFunction::EmitPredefinedLValue(const PredefinedExpr *E) {
/// { i16 TypeKind, i16 TypeInfo }
/// \endcode
///
-/// followed by an array of i8 containing the type name. TypeKind is 0 for an
-/// integer, 1 for a floating point value, and -1 for anything else.
+/// followed by an array of i8 containing the type name with extra information
+/// for BitInt. TypeKind is TK_Integer(0) for an integer, TK_Float(1) for a
+/// floating point value, TK_BitInt(2) for BitInt and TK_Unknown(0xFFFF) for
+/// anything else.
llvm::Constant *CodeGenFunction::EmitCheckTypeDescriptor(QualType T) {
// Only emit each type's descriptor once.
if (llvm::Constant *C = CGM.getTypeDescriptorFromMap(T))
return C;
- uint16_t TypeKind = -1;
+ uint16_t TypeKind = TK_Unknown;
uint16_t TypeInfo = 0;
+ bool IsBitInt = false;
if (T->isIntegerType()) {
- TypeKind = 0;
+ TypeKind = TK_Integer;
TypeInfo = (llvm::Log2_32(getContext().getTypeSize(T)) << 1) |
(T->isSignedIntegerType() ? 1 : 0);
+ // Follow suggestion from discussion of issue 64100.
+ // So we can write the exact amount of bits in TypeName after '\0'
+ // making it <diagnostic-like type name>.'\0'.<32-bit width>.
+ if (T->isSignedIntegerType() && T->getAs<BitIntType>()) {
----------------
bjope wrote:
Is this whole patch limited to fixing the non-power-of-2 problem for signed BitInt? I couldn't see any test involving unsigned BitInt, and the check for signed here makes me think that we still got the same bug for type descriptors for unsigned BitInt.
If that is true, was there any specific reason for not fixing the type descriptors for unsigned BitInt as well directly?
If for example the reasoning is that the runtimes currently do not try to print the size anyway for any failures involving unsigned BitInt, maybe it had been worth mentioning that here. Because now it just looks broken to me that we still can't provide a correct type descriptor for unsigned BitInt. Right?
https://github.com/llvm/llvm-project/pull/96240
More information about the llvm-commits
mailing list