4141#include " llvm/IR/MatrixBuilder.h"
4242#include " llvm/Passes/OptimizationLevel.h"
4343#include " llvm/Support/ConvertUTF.h"
44- #include " llvm/Support/Endian.h"
4544#include " llvm/Support/MathExtras.h"
4645#include " llvm/Support/Path.h"
4746#include " llvm/Support/SaveAndRestore.h"
@@ -65,22 +64,6 @@ static llvm::cl::opt<bool> ClSanitizeGuardChecks(
6564 " ubsan-guard-checks" , llvm::cl::Optional,
6665 llvm::cl::desc (" Guard UBSAN checks with `llvm.allow.ubsan.check()`." ));
6766
68- // ===--------------------------------------------------------------------===//
69- // Defines for metadata
70- // ===--------------------------------------------------------------------===//
71-
72- // Those values are crucial to be the SAME as in ubsan runtime library.
73- enum VariableTypeDescriptorKind : uint16_t {
74- // / An integer type.
75- TK_Integer = 0x0000 ,
76- // / A floating-point type.
77- TK_Float = 0x0001 ,
78- // / An _BitInt(N) type.
79- TK_BitInt = 0x0002 ,
80- // / Any other type. The value representation is unspecified.
81- TK_Unknown = 0xffff
82- };
83-
8467// ===--------------------------------------------------------------------===//
8568// Miscellaneous Helper Methods
8669// ===--------------------------------------------------------------------===//
@@ -3315,40 +3298,22 @@ LValue CodeGenFunction::EmitPredefinedLValue(const PredefinedExpr *E) {
33153298// / { i16 TypeKind, i16 TypeInfo }
33163299// / \endcode
33173300// /
3318- // / followed by an array of i8 containing the type name with extra information
3319- // / for BitInt. TypeKind is TK_Integer(0) for an integer, TK_Float(1) for a
3320- // / floating point value, TK_BitInt(2) for BitInt and TK_Unknown(0xFFFF) for
3321- // / anything else.
3301+ // / followed by an array of i8 containing the type name. TypeKind is 0 for an
3302+ // / integer, 1 for a floating point value, and -1 for anything else.
33223303llvm::Constant *CodeGenFunction::EmitCheckTypeDescriptor (QualType T) {
33233304 // Only emit each type's descriptor once.
33243305 if (llvm::Constant *C = CGM.getTypeDescriptorFromMap (T))
33253306 return C;
33263307
3327- uint16_t TypeKind = TK_Unknown ;
3308+ uint16_t TypeKind = - 1 ;
33283309 uint16_t TypeInfo = 0 ;
3329- bool IsBitInt = false ;
33303310
33313311 if (T->isIntegerType ()) {
3332- TypeKind = TK_Integer ;
3312+ TypeKind = 0 ;
33333313 TypeInfo = (llvm::Log2_32 (getContext ().getTypeSize (T)) << 1 ) |
33343314 (T->isSignedIntegerType () ? 1 : 0 );
3335- // Follow suggestion from https://github.com/llvm/llvm-project/issues/64100
3336- // So we can write the exact amount of bits in TypeName after '\0'
3337- // making it <diagnostic-like type name>.'\0'.<32-bit width>.
3338- if (T->isSignedIntegerType () && T->getAs <BitIntType>()) {
3339- // Do a sanity checks as we are using 32-bit type to store bit length.
3340- assert ((getContext ().getTypeSize (T) > 0 ) &&
3341- " non positive amount of bits in __BitInt type" );
3342- assert ((getContext ().getTypeSize (T) <= 0xFFFFFFFF ) &&
3343- " too many bits in __BitInt type" );
3344-
3345- // Redefine TypeKind with the actual __BitInt type if we have signed
3346- // BitInt.
3347- TypeKind = TK_BitInt;
3348- IsBitInt = true ;
3349- }
33503315 } else if (T->isFloatingType ()) {
3351- TypeKind = TK_Float ;
3316+ TypeKind = 1 ;
33523317 TypeInfo = getContext ().getTypeSize (T);
33533318 }
33543319
@@ -3359,20 +3324,6 @@ llvm::Constant *CodeGenFunction::EmitCheckTypeDescriptor(QualType T) {
33593324 DiagnosticsEngine::ak_qualtype, (intptr_t )T.getAsOpaquePtr (), StringRef (),
33603325 StringRef (), std::nullopt , Buffer, std::nullopt );
33613326
3362- if (IsBitInt) {
3363- // The Structure is: 0 to end the string, 32 bit unsigned integer in target
3364- // endianness, zero.
3365- char S[6 ] = {' \0 ' , ' \0 ' , ' \0 ' , ' \0 ' , ' \0 ' , ' \0 ' };
3366- const auto *EIT = T->castAs <BitIntType>();
3367- uint32_t Bits = EIT->getNumBits ();
3368- llvm::support::endian::write32 (S + 1 , Bits,
3369- getTarget ().isBigEndian ()
3370- ? llvm::endianness::big
3371- : llvm::endianness::little);
3372- StringRef str = StringRef (S, sizeof (S) / sizeof (decltype (S[0 ])));
3373- Buffer.append (str);
3374- }
3375-
33763327 llvm::Constant *Components[] = {
33773328 Builder.getInt16 (TypeKind), Builder.getInt16 (TypeInfo),
33783329 llvm::ConstantDataArray::getString (getLLVMContext (), Buffer)
0 commit comments