[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 30 17:24:35 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 8b38970811086b09752a5909d0c17de4d0cd04c3 a94835f633164a33aaf413b92ecf9ec96701add8 -- clang/test/CodeGen/integer-wrap.c clang/lib/CodeGen/CGExprScalar.cpp clang/test/Driver/fsanitize.c compiler-rt/lib/ubsan/ubsan_checks.inc
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index 74e016fe48..e6d7d94fe3 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -3430,7 +3430,7 @@ void ScalarExprEmitter::EmitUndefinedBehaviorIntegerDivAndRemCheck(
 
   const auto *BO = cast<BinaryOperator>(Ops.E);
   if (CGF.SanOpts.hasOneOf(SanitizerKind::SignedIntegerOverflow |
-      SanitizerKind::SignedIntegerWrap) &&
+                           SanitizerKind::SignedIntegerWrap) &&
       Ops.Ty->hasSignedIntegerRepresentation() &&
       !IsWidenedIntegerOp(CGF.getContext(), BO->getLHS()) &&
       Ops.mayHaveIntegerOverflow()) {
@@ -3449,7 +3449,6 @@ void ScalarExprEmitter::EmitUndefinedBehaviorIntegerDivAndRemCheck(
     if (CGF.SanOpts.has(SanitizerKind::SignedIntegerWrap))
       Checks.push_back(
           std::make_pair(NotOverflow, SanitizerKind::SignedIntegerWrap));
-
   }
 
   if (Checks.size() > 0)
@@ -3460,8 +3459,8 @@ Value *ScalarExprEmitter::EmitDiv(const BinOpInfo &Ops) {
   {
     CodeGenFunction::SanitizerScope SanScope(&CGF);
     if (CGF.SanOpts.hasOneOf(SanitizerKind::IntegerDivideByZero |
-        SanitizerKind::SignedIntegerOverflow |
-        SanitizerKind::SignedIntegerWrap) &&
+                             SanitizerKind::SignedIntegerOverflow |
+                             SanitizerKind::SignedIntegerWrap) &&
         Ops.Ty->isIntegerType() &&
         (Ops.mayHaveIntegerDivisionByZero() || Ops.mayHaveIntegerOverflow())) {
       llvm::Value *Zero = llvm::Constant::getNullValue(ConvertType(Ops.Ty));
@@ -3510,8 +3509,8 @@ Value *ScalarExprEmitter::EmitDiv(const BinOpInfo &Ops) {
 Value *ScalarExprEmitter::EmitRem(const BinOpInfo &Ops) {
   // Rem in C can't be a floating point type: C99 6.5.5p2.
   if (CGF.SanOpts.hasOneOf(SanitizerKind::IntegerDivideByZero |
-      SanitizerKind::SignedIntegerOverflow |
-      SanitizerKind::SignedIntegerWrap) &&
+                           SanitizerKind::SignedIntegerOverflow |
+                           SanitizerKind::SignedIntegerWrap) &&
       Ops.Ty->isIntegerType() &&
       (Ops.mayHaveIntegerDivisionByZero() || Ops.mayHaveIntegerOverflow())) {
     CodeGenFunction::SanitizerScope SanScope(&CGF);
@@ -3576,15 +3575,16 @@ Value *ScalarExprEmitter::EmitOverflowCheckedBinOp(const BinOpInfo &Ops) {
     // If the signed-integer-overflow or signed-integer-wrap sanitizer is
     // enabled, emit a call to its runtime. Otherwise, this is a -ftrapv check,
     // so just emit a trap.
-    if (!isSigned || CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow)
-                  || CGF.SanOpts.has(SanitizerKind::SignedIntegerWrap)) {
+    if (!isSigned || CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow) ||
+        CGF.SanOpts.has(SanitizerKind::SignedIntegerWrap)) {
       llvm::Value *NotOverflow = Builder.CreateNot(overflow);
 
       SanitizerMask Kind = SanitizerKind::UnsignedIntegerOverflow;
       if (isSigned)
         Kind = CGF.getLangOpts().getSignedOverflowBehavior() ==
-            LangOptions::SOB_Defined ? SanitizerKind::SignedIntegerWrap :
-                                       SanitizerKind::SignedIntegerOverflow;
+                       LangOptions::SOB_Defined
+                   ? SanitizerKind::SignedIntegerWrap
+                   : SanitizerKind::SignedIntegerOverflow;
 
       EmitBinOpCheck(std::make_pair(NotOverflow, Kind), Ops);
     } else
diff --git a/compiler-rt/lib/ubsan/ubsan_checks.inc b/compiler-rt/lib/ubsan/ubsan_checks.inc
index b50ba91a15..0112aeeed3 100644
--- a/compiler-rt/lib/ubsan/ubsan_checks.inc
+++ b/compiler-rt/lib/ubsan/ubsan_checks.inc
@@ -31,8 +31,7 @@ UBSAN_CHECK(AlignmentAssumption, "alignment-assumption", "alignment")
 UBSAN_CHECK(InsufficientObjectSize, "insufficient-object-size", "object-size")
 UBSAN_CHECK(SignedIntegerOverflow, "signed-integer-overflow",
             "signed-integer-overflow")
-UBSAN_CHECK(SignedIntegerWrap, "signed-integer-wrap",
-            "signed-integer-wrap")
+UBSAN_CHECK(SignedIntegerWrap, "signed-integer-wrap", "signed-integer-wrap")
 UBSAN_CHECK(UnsignedIntegerOverflow, "unsigned-integer-overflow",
             "unsigned-integer-overflow")
 UBSAN_CHECK(IntegerDivideByZero, "integer-divide-by-zero",

``````````

</details>


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


More information about the cfe-commits mailing list