[clang] [NFC][Clang][ubsan] Rename BackupT/T in EmitCheckTypeDescriptor (PR #242168)
Vitaly Buka via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 12 20:51:11 PST 2026
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/242168
Keep T for the original QualType and name the unwrapped enum type
UnderlyingT, as suggested in review.
Follow-up to #216460.
Assisted-by: Gemini
>From d47aa72ceb2834bc721115b788d675aee9142ca3 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Thu, 12 Nov 2026 20:50:59 -0800
Subject: [PATCH] [spr] update
Created using spr 2.0.0-beta.2
---
clang/lib/CodeGen/CGExpr.cpp | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 5075292d3d45a..935a86c932578 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -4060,23 +4060,24 @@ llvm::Constant *CodeGenFunction::EmitCheckTypeDescriptor(QualType T) {
// isIntegerType() never holds for scoped enums, and getAs<BitIntType> can't
// see through the EnumType node to a __BitInt underlying type even for
// unscoped enums.
- QualType BackupT = T;
+ QualType UnderlyingT = T;
if (const EnumType *ET = T->getAs<EnumType>())
if (ET->getDecl()->isComplete())
- T = ET->getDecl()->getIntegerType();
+ UnderlyingT = ET->getDecl()->getIntegerType();
- if (T->isIntegerType()) {
+ if (UnderlyingT->isIntegerType()) {
TypeKind = TK_Integer;
- TypeInfo = (llvm::Log2_32(getContext().getTypeSize(T)) << 1) |
- (T->isSignedIntegerType() ? 1 : 0);
+ TypeInfo = (llvm::Log2_32(getContext().getTypeSize(UnderlyingT)) << 1) |
+ (UnderlyingT->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>()) {
+ if (UnderlyingT->isSignedIntegerType() &&
+ UnderlyingT->getAs<BitIntType>()) {
// Do a sanity checks as we are using 32-bit type to store bit length.
- assert(getContext().getTypeSize(T) > 0 &&
+ assert(getContext().getTypeSize(UnderlyingT) > 0 &&
" non positive amount of bits in __BitInt type");
- assert(getContext().getTypeSize(T) <= 0xFFFFFFFF &&
+ assert(getContext().getTypeSize(UnderlyingT) <= 0xFFFFFFFF &&
" too many bits in __BitInt type");
// Redefine TypeKind with the actual __BitInt type if we have signed
@@ -4084,23 +4085,23 @@ llvm::Constant *CodeGenFunction::EmitCheckTypeDescriptor(QualType T) {
TypeKind = TK_BitInt;
IsBitInt = true;
}
- } else if (T->isFloatingType()) {
+ } else if (UnderlyingT->isFloatingType()) {
TypeKind = TK_Float;
- TypeInfo = getContext().getTypeSize(T);
+ TypeInfo = getContext().getTypeSize(UnderlyingT);
}
// Format the type name as if for a diagnostic, including quotes and
// optionally an 'aka'.
SmallString<32> Buffer;
CGM.getDiags().ConvertArgToString(DiagnosticsEngine::ak_qualtype,
- (intptr_t)BackupT.getAsOpaquePtr(),
- StringRef(), StringRef(), {}, Buffer, {});
+ (intptr_t)T.getAsOpaquePtr(), StringRef(),
+ StringRef(), {}, Buffer, {});
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>();
+ const auto *EIT = UnderlyingT->castAs<BitIntType>();
uint32_t Bits = EIT->getNumBits();
llvm::support::endian::write32(S + 1, Bits,
getTarget().isBigEndian()
@@ -4123,7 +4124,7 @@ llvm::Constant *CodeGenFunction::EmitCheckTypeDescriptor(QualType T) {
CGM.getSanitizerMetadata()->disableSanitizerForGlobal(GV);
// Remember the descriptor for this type.
- CGM.setTypeDescriptorInMap(BackupT, GV);
+ CGM.setTypeDescriptorInMap(T, GV);
return GV;
}
More information about the cfe-commits
mailing list