[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


================
@@ -5570,11 +5570,44 @@ LValue CodeGenFunction::EmitBinaryOperatorLValue(const BinaryOperator *E) {
       break;
     }
 
-    RValue RV = EmitAnyExpr(E->getRHS());
+    llvm::Value *Previous = nullptr;
+    RValue RV;
+    QualType SrcType = E->getRHS()->getType();
+    // If LHS refers to a bitfield we want to retrieve the value before
+    // implicit conversion between the bitfield type and the RHS type
+    // and evaluate RHS without integer sanitizer checks (if passed)
+    if (auto *ICE = RetrieveImplicitCastExprForBitfieldSanitizer(E)) {
----------------
rjmccall wrote:

When we say "conversion between A and B", it typically means A is being converted to B, but I think you're actually talking about the reverse here.

Please pull the basic conditions for whether to emit this check into this function (LHS is a bit-field + the sanitizer option); it will make the data flow much clearer.  You can just evaluate them once and then check it again below.

Please test for a bit-field LHS before checking for the sanitizer option.

The function call here should be something like `getOriginalRHSForBitfieldSanitizer`.

https://github.com/llvm/llvm-project/pull/75481


More information about the cfe-commits mailing list