[clang] [compiler-rt] [clang][UBSan] Add implicit conversion check for bitfields (PR #75481)
John McCall via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 13 15:51:44 PST 2024
================
@@ -1239,6 +1257,228 @@ void ScalarExprEmitter::EmitIntegerSignChangeCheck(Value *Src, QualType SrcType,
{Src, Dst});
}
+// Should be called within CodeGenFunction::SanitizerScope RAII scope.
+// Returns 'i1 false' when the truncation Src -> Dst was lossy.
+static std::pair<ScalarExprEmitter::ImplicitConversionCheckKind,
+ std::pair<llvm::Value *, SanitizerMask>>
+EmitBitfieldTruncationCheckHelper(Value *Src, QualType SrcType, Value *Dst,
+ QualType DstType, CGBuilderTy &Builder) {
+
+ llvm::Type *SrcTy = Src->getType();
+ llvm::Type *DstTy = Dst->getType();
+ (void)SrcTy; // Only used in assert()
+ (void)DstTy; // Only used in assert()
----------------
rjmccall wrote:
Then you should surround these variables with `#ifndef NDEBUG`. But mostly you don't need to do this; `CreateIntCast` will assert this for you.
https://github.com/llvm/llvm-project/pull/75481
More information about the cfe-commits
mailing list