diff options
| author | earnol <earnol@users.noreply.github.com> | 2024-06-21 08:33:46 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-21 08:33:46 -0400 |
| commit | 138ea7d1fb82c2525da8dcc2f8ea73eae7b25f25 (patch) | |
| tree | eecbaa97f7a54642bada380277a05fae3014a3a8 /clang/lib/CodeGen/CGExpr.cpp | |
| parent | 8cf39881d17becb1afef85190a602c4f76fe70d4 (diff) | |
Revert "[ubsan] Display correct runtime messages for negative _BitInt" (#96239)
Reverts llvm/llvm-project#93612 due to the issues with ppc64le platform.
Diffstat (limited to 'clang/lib/CodeGen/CGExpr.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 59 |
1 files changed, 5 insertions, 54 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 55b2b4337fab..3dfe5e09c778 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -41,7 +41,6 @@ #include "llvm/IR/MatrixBuilder.h" #include "llvm/Passes/OptimizationLevel.h" #include "llvm/Support/ConvertUTF.h" -#include "llvm/Support/Endian.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/Path.h" #include "llvm/Support/SaveAndRestore.h" @@ -66,22 +65,6 @@ static llvm::cl::opt<bool> ClSanitizeGuardChecks( llvm::cl::desc("Guard UBSAN checks with `llvm.allow.ubsan.check()`.")); //===--------------------------------------------------------------------===// -// Defines for metadata -//===--------------------------------------------------------------------===// - -// Those values are crucial to be the SAME as in ubsan runtime library. -enum VariableTypeDescriptorKind : uint16_t { - /// An integer type. - TK_Integer = 0x0000, - /// A floating-point type. - TK_Float = 0x0001, - /// An _BitInt(N) type. - TK_BitInt = 0x0002, - /// Any other type. The value representation is unspecified. - TK_Unknown = 0xffff -}; - -//===--------------------------------------------------------------------===// // Miscellaneous Helper Methods //===--------------------------------------------------------------------===// @@ -3315,40 +3298,22 @@ LValue CodeGenFunction::EmitPredefinedLValue(const PredefinedExpr *E) { /// { i16 TypeKind, i16 TypeInfo } /// \endcode /// -/// 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. +/// 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. 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 = TK_Unknown; + uint16_t TypeKind = -1; uint16_t TypeInfo = 0; - bool IsBitInt = false; if (T->isIntegerType()) { - TypeKind = TK_Integer; + TypeKind = 0; TypeInfo = (llvm::Log2_32(getContext().getTypeSize(T)) << 1) | (T->isSignedIntegerType() ? 1 : 0); - // Follow suggestion from https://github.com/llvm/llvm-project/issues/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>()) { - // Do a sanity checks as we are using 32-bit type to store bit length. - assert((getContext().getTypeSize(T) > 0) && - " non positive amount of bits in __BitInt type"); - assert((getContext().getTypeSize(T) <= 0xFFFFFFFF) && - " too many bits in __BitInt type"); - - // Redefine TypeKind with the actual __BitInt type if we have signed - // BitInt. - TypeKind = TK_BitInt; - IsBitInt = true; - } } else if (T->isFloatingType()) { - TypeKind = TK_Float; + TypeKind = 1; TypeInfo = getContext().getTypeSize(T); } @@ -3359,20 +3324,6 @@ llvm::Constant *CodeGenFunction::EmitCheckTypeDescriptor(QualType T) { DiagnosticsEngine::ak_qualtype, (intptr_t)T.getAsOpaquePtr(), StringRef(), StringRef(), std::nullopt, Buffer, std::nullopt); - if (IsBitInt) { - // The Structure is: 0 to end the string, 32 bit unsigned integer in target - // endianness, zero. - char S[6] = {'\0', '\0', '\0', '\0', '\0', '\0'}; - const auto *EIT = T->castAs<BitIntType>(); - uint32_t Bits = EIT->getNumBits(); - llvm::support::endian::write32(S + 1, Bits, - getTarget().isBigEndian() - ? llvm::endianness::big - : llvm::endianness::little); - StringRef str = StringRef(S, sizeof(S) / sizeof(decltype(S[0]))); - Buffer.append(str); - } - llvm::Constant *Components[] = { Builder.getInt16(TypeKind), Builder.getInt16(TypeInfo), llvm::ConstantDataArray::getString(getLLVMContext(), Buffer) |
