================
@@ -5571,11 +5571,50 @@ LValue CodeGenFunction::EmitBinaryOperatorLValue(const 
BinaryOperator *E) {
       break;
     }
 
-    RValue RV = EmitAnyExpr(E->getRHS());
+    llvm::Value *Previous = nullptr;
+    RValue RV;
+    QualType SrcType = E->getRHS()->getType();
+    // Check if LHS is a bitfield and sanitizer checks are enabled
+    if (E->getLHS()->refersToBitField() &&
+        SanOpts.hasOneOf(SanitizerKind::ImplicitConversion |
+                         SanitizerKind::ImplicitBitfieldConversion)) {
+      // Get the RHS before scalar conversion
+      if (auto *ICE = GetOriginalRHSForBitfieldSanitizer(E)) {
+        SrcType = ICE->getSubExpr()->getType();
+        Previous = EmitScalarExpr(ICE->getSubExpr());
+        // Pass default ScalarConversionOpts to avoid emitting
+        // integer sanitizer checks as E refers to bitfield
+        llvm::Value *RHS = EmitScalarConversion(
+            Previous, SrcType, ICE->getType(), ICE->getExprLoc());
+        RV = RValue::get(RHS);
+      }
+    }
+
+    // Otherwise, visit RHS as usual
+    if (!Previous)
+      RV = EmitAnyExpr(E->getRHS());
----------------
zygoloid wrote:

Would it be correct to do the above, more-elaborate lowering instead of this 
regardless of whether a sanitizer is enabled? I'd have more confidence that 
we're performing a correct emission if we used the same code regardless of 
sanitizer mode.

https://github.com/llvm/llvm-project/pull/75481
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to