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 origin/main HEAD --extensions h,cpp,c -- 
clang/lib/AST/ASTContext.cpp clang/lib/Sema/SemaChecking.cpp 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
clang/test/Analysis/Inputs/std-c-library-functions-POSIX.h 
clang/test/Analysis/array-struct.c clang/test/Analysis/bstring.c 
clang/test/Analysis/malloc.c clang/test/Analysis/pr22954.c 
clang/test/Analysis/std-c-library-functions-POSIX.c 
clang/test/Analysis/std-c-library-functions-arg-constraints.c 
clang/test/Analysis/std-c-library-functions.c clang/test/Sema/asm-label.c 
clang/test/Sema/builtin-memcpy.c clang/test/Sema/warn-fortify-source.c 
clang/utils/TableGen/ClangBuiltinsEmitter.cpp 
compiler-rt/test/asan/TestCases/Windows/issue64990.cpp 
libcxx/test/libcxx/strings/c.strings/constexpr.cwchar.compile.pass.cpp 
--diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

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

``````````diff
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index dfb898d94..991531518 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -1308,248 +1308,251 @@ void 
Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
     DestinationSize = ComputeSizeArgument(1);
     MaxOperationSize = ComputeExplicitObjectSizeArgument(2);
   } else if (LibC == LibCDispatch::PWrite) {
-    // pwrite/pwrite64: ssize_t(int, const void buf[.count], size_t count, 
off_t);
-    // Up to count(2) bytes are read from buf(1).
+    // pwrite/pwrite64: ssize_t(int, const void buf[.count], size_t count,
+    // off_t); Up to count(2) bytes are read from buf(1).
     SourceSize = ComputeSizeArgument(1);
     MaxOperationSize = ComputeExplicitObjectSizeArgument(2);
   } else
-  switch (BuiltinID) {
-  default:
-    return;
-  case Builtin::BI__builtin_strcat:
-  case Builtin::BIstrcat:
-  case Builtin::BI__builtin_stpcpy:
-  case Builtin::BIstpcpy:
-  case Builtin::BI__builtin_strcpy:
-  case Builtin::BIstrcpy: {
-    DiagOverflowID = diag::warn_fortify_strlen_overflow;
-    MinOperationSize = ComputeStrLenArgument(1);
-    DestinationSize = ComputeSizeArgument(0);
-    break;
-  }
-
-  case Builtin::BI__builtin___strcat_chk:
-  case Builtin::BI__builtin___stpcpy_chk:
-  case Builtin::BI__builtin___strcpy_chk: {
-    DiagOverflowID = diag::warn_fortify_strlen_overflow;
-    MinOperationSize = ComputeStrLenArgument(1);
-    DestinationSize = ComputeExplicitObjectSizeArgument(2);
-    IsChkVariant = true;
-    break;
-  }
-
-  case Builtin::BIscanf:
-  case Builtin::BIfscanf:
-  case Builtin::BIsscanf: {
-    unsigned FormatIndex = 1;
-    unsigned DataIndex = 2;
-    if (BuiltinID == Builtin::BIscanf) {
-      FormatIndex = 0;
-      DataIndex = 1;
+    switch (BuiltinID) {
+    default:
+      return;
+    case Builtin::BI__builtin_strcat:
+    case Builtin::BIstrcat:
+    case Builtin::BI__builtin_stpcpy:
+    case Builtin::BIstpcpy:
+    case Builtin::BI__builtin_strcpy:
+    case Builtin::BIstrcpy: {
+      DiagOverflowID = diag::warn_fortify_strlen_overflow;
+      MinOperationSize = ComputeStrLenArgument(1);
+      DestinationSize = ComputeSizeArgument(0);
+      break;
     }
 
-    const auto *FormatExpr =
-        TheCall->getArg(FormatIndex)->IgnoreParenImpCasts();
+    case Builtin::BI__builtin___strcat_chk:
+    case Builtin::BI__builtin___stpcpy_chk:
+    case Builtin::BI__builtin___strcpy_chk: {
+      DiagOverflowID = diag::warn_fortify_strlen_overflow;
+      MinOperationSize = ComputeStrLenArgument(1);
+      DestinationSize = ComputeExplicitObjectSizeArgument(2);
+      IsChkVariant = true;
+      break;
+    }
 
-    StringRef FormatStrRef;
-    size_t StrLen;
-    if (!ProcessFormatStringLiteral(FormatExpr, FormatStrRef, StrLen, Context))
-      return;
+    case Builtin::BIscanf:
+    case Builtin::BIfscanf:
+    case Builtin::BIsscanf: {
+      unsigned FormatIndex = 1;
+      unsigned DataIndex = 2;
+      if (BuiltinID == Builtin::BIscanf) {
+        FormatIndex = 0;
+        DataIndex = 1;
+      }
 
-    auto Diagnose = [&](unsigned ArgIndex, unsigned DestSize,
-                        unsigned SourceSize) {
-      unsigned Index = ArgIndex + DataIndex;
-      std::string FunctionName = GetFunctionName();
-      DiagRuntimeBehavior(TheCall->getArg(Index)->getBeginLoc(), TheCall,
-                          PDiag(diag::warn_fortify_scanf_overflow)
-                              << FunctionName << (Index + 1) << DestSize
-                              << SourceSize);
-    };
+      const auto *FormatExpr =
+          TheCall->getArg(FormatIndex)->IgnoreParenImpCasts();
 
-    auto ShiftedComputeSizeArgument = [&](unsigned Index) {
-      return ComputeSizeArgument(Index + DataIndex);
-    };
-    ScanfDiagnosticFormatHandler H(ShiftedComputeSizeArgument, Diagnose);
-    const char *FormatBytes = FormatStrRef.data();
-    analyze_format_string::ParseScanfString(H, FormatBytes,
-                                            FormatBytes + StrLen, 
getLangOpts(),
-                                            Context.getTargetInfo());
-
-    // Unlike the other cases, in this one we have already issued the 
diagnostic
-    // here, so no need to continue (because unlike the other cases, here the
-    // diagnostic refers to the argument number).
-    return;
-  }
+      StringRef FormatStrRef;
+      size_t StrLen;
+      if (!ProcessFormatStringLiteral(FormatExpr, FormatStrRef, StrLen,
+                                      Context))
+        return;
 
-  case Builtin::BIsprintf:
-  case Builtin::BI__builtin___sprintf_chk: {
-    size_t FormatIndex = BuiltinID == Builtin::BIsprintf ? 1 : 3;
-    auto *FormatExpr = TheCall->getArg(FormatIndex)->IgnoreParenImpCasts();
+      auto Diagnose = [&](unsigned ArgIndex, unsigned DestSize,
+                          unsigned SourceSize) {
+        unsigned Index = ArgIndex + DataIndex;
+        std::string FunctionName = GetFunctionName();
+        DiagRuntimeBehavior(TheCall->getArg(Index)->getBeginLoc(), TheCall,
+                            PDiag(diag::warn_fortify_scanf_overflow)
+                                << FunctionName << (Index + 1) << DestSize
+                                << SourceSize);
+      };
 
-    StringRef FormatStrRef;
-    size_t StrLen;
-    if (ProcessFormatStringLiteral(FormatExpr, FormatStrRef, StrLen, Context)) 
{
-      EstimateSizeFormatHandler H(FormatStrRef);
+      auto ShiftedComputeSizeArgument = [&](unsigned Index) {
+        return ComputeSizeArgument(Index + DataIndex);
+      };
+      ScanfDiagnosticFormatHandler H(ShiftedComputeSizeArgument, Diagnose);
       const char *FormatBytes = FormatStrRef.data();
-      if (!analyze_format_string::ParsePrintfString(
-              H, FormatBytes, FormatBytes + StrLen, getLangOpts(),
-              Context.getTargetInfo(), false)) {
-        DiagOverflowID = H.isKernelCompatible()
-                             ? diag::warn_format_overflow
-                             : diag::warn_format_overflow_non_kprintf;
-        MinOperationSize = llvm::APSInt::getUnsigned(H.getSizeLowerBound())
-                               .extOrTrunc(SizeTypeWidth);
-        if (BuiltinID == Builtin::BI__builtin___sprintf_chk) {
-          DestinationSize = ComputeExplicitObjectSizeArgument(2);
-          IsChkVariant = true;
-        } else {
-          DestinationSize = ComputeSizeArgument(0);
+      analyze_format_string::ParseScanfString(
+          H, FormatBytes, FormatBytes + StrLen, getLangOpts(),
+          Context.getTargetInfo());
+
+      // Unlike the other cases, in this one we have already issued the
+      // diagnostic here, so no need to continue (because unlike the other
+      // cases, here the diagnostic refers to the argument number).
+      return;
+    }
+
+    case Builtin::BIsprintf:
+    case Builtin::BI__builtin___sprintf_chk: {
+      size_t FormatIndex = BuiltinID == Builtin::BIsprintf ? 1 : 3;
+      auto *FormatExpr = TheCall->getArg(FormatIndex)->IgnoreParenImpCasts();
+
+      StringRef FormatStrRef;
+      size_t StrLen;
+      if (ProcessFormatStringLiteral(FormatExpr, FormatStrRef, StrLen,
+                                     Context)) {
+        EstimateSizeFormatHandler H(FormatStrRef);
+        const char *FormatBytes = FormatStrRef.data();
+        if (!analyze_format_string::ParsePrintfString(
+                H, FormatBytes, FormatBytes + StrLen, getLangOpts(),
+                Context.getTargetInfo(), false)) {
+          DiagOverflowID = H.isKernelCompatible()
+                               ? diag::warn_format_overflow
+                               : diag::warn_format_overflow_non_kprintf;
+          MinOperationSize = llvm::APSInt::getUnsigned(H.getSizeLowerBound())
+                                 .extOrTrunc(SizeTypeWidth);
+          if (BuiltinID == Builtin::BI__builtin___sprintf_chk) {
+            DestinationSize = ComputeExplicitObjectSizeArgument(2);
+            IsChkVariant = true;
+          } else {
+            DestinationSize = ComputeSizeArgument(0);
+          }
+          break;
         }
-        break;
       }
+      return;
     }
-    return;
-  }
 
-  case Builtin::BI__builtin___memcpy_chk:
-  case Builtin::BI__builtin___memmove_chk:
-  case Builtin::BI__builtin___memset_chk:
-  case Builtin::BI__builtin___strlcat_chk:
-  case Builtin::BI__builtin___strlcpy_chk:
-  case Builtin::BI__builtin___strncat_chk:
-  case Builtin::BI__builtin___strncpy_chk:
-  case Builtin::BI__builtin___stpncpy_chk:
-  case Builtin::BI__builtin___memccpy_chk:
-  case Builtin::BI__builtin___mempcpy_chk: {
-    DiagOverflowID = diag::warn_builtin_chk_overflow;
-    MinOperationSize =
-        ComputeExplicitObjectSizeArgument(TheCall->getNumArgs() - 2);
-    DestinationSize =
-        ComputeExplicitObjectSizeArgument(TheCall->getNumArgs() - 1);
-    IsChkVariant = true;
-    break;
-  }
+    case Builtin::BI__builtin___memcpy_chk:
+    case Builtin::BI__builtin___memmove_chk:
+    case Builtin::BI__builtin___memset_chk:
+    case Builtin::BI__builtin___strlcat_chk:
+    case Builtin::BI__builtin___strlcpy_chk:
+    case Builtin::BI__builtin___strncat_chk:
+    case Builtin::BI__builtin___strncpy_chk:
+    case Builtin::BI__builtin___stpncpy_chk:
+    case Builtin::BI__builtin___memccpy_chk:
+    case Builtin::BI__builtin___mempcpy_chk: {
+      DiagOverflowID = diag::warn_builtin_chk_overflow;
+      MinOperationSize =
+          ComputeExplicitObjectSizeArgument(TheCall->getNumArgs() - 2);
+      DestinationSize =
+          ComputeExplicitObjectSizeArgument(TheCall->getNumArgs() - 1);
+      IsChkVariant = true;
+      break;
+    }
 
-  case Builtin::BI__builtin___snprintf_chk:
-  case Builtin::BI__builtin___vsnprintf_chk: {
-    DiagOverflowID = diag::warn_builtin_chk_overflow;
-    MinOperationSize = ComputeExplicitObjectSizeArgument(1);
-    DestinationSize = ComputeExplicitObjectSizeArgument(3);
-    IsChkVariant = true;
-    break;
-  }
+    case Builtin::BI__builtin___snprintf_chk:
+    case Builtin::BI__builtin___vsnprintf_chk: {
+      DiagOverflowID = diag::warn_builtin_chk_overflow;
+      MinOperationSize = ComputeExplicitObjectSizeArgument(1);
+      DestinationSize = ComputeExplicitObjectSizeArgument(3);
+      IsChkVariant = true;
+      break;
+    }
 
-  case Builtin::BIstrncat:
-  case Builtin::BI__builtin_strncat:
-  case Builtin::BIstrncpy:
-  case Builtin::BI__builtin_strncpy:
-  case Builtin::BIstpncpy:
-  case Builtin::BI__builtin_stpncpy: {
-    // Whether these functions overflow depends on the runtime strlen of the
-    // string, not just the buffer size, so emitting the "always overflow"
-    // diagnostic isn't quite right. We should still diagnose passing a buffer
-    // size larger than the destination buffer though; this is a runtime abort
-    // in _FORTIFY_SOURCE mode, and is quite suspicious otherwise.
-    MaxOperationSize =
-        ComputeExplicitObjectSizeArgument(TheCall->getNumArgs() - 1);
-    DestinationSize = ComputeSizeArgument(0);
-    break;
-  }
+    case Builtin::BIstrncat:
+    case Builtin::BI__builtin_strncat:
+    case Builtin::BIstrncpy:
+    case Builtin::BI__builtin_strncpy:
+    case Builtin::BIstpncpy:
+    case Builtin::BI__builtin_stpncpy: {
+      // Whether these functions overflow depends on the runtime strlen of the
+      // string, not just the buffer size, so emitting the "always overflow"
+      // diagnostic isn't quite right. We should still diagnose passing a 
buffer
+      // size larger than the destination buffer though; this is a runtime 
abort
+      // in _FORTIFY_SOURCE mode, and is quite suspicious otherwise.
+      MaxOperationSize =
+          ComputeExplicitObjectSizeArgument(TheCall->getNumArgs() - 1);
+      DestinationSize = ComputeSizeArgument(0);
+      break;
+    }
 
-  case Builtin::BImemset:
-  case Builtin::BI__builtin_memset:
-  case Builtin::BIbzero:
-  case Builtin::BI__builtin_bzero: {
-    MinOperationSize = MaxOperationSize =
-        ComputeExplicitObjectSizeArgument(TheCall->getNumArgs() - 1);
-    DestinationSize = ComputeSizeArgument(0);
-    break;
-  }
+    case Builtin::BImemset:
+    case Builtin::BI__builtin_memset:
+    case Builtin::BIbzero:
+    case Builtin::BI__builtin_bzero: {
+      MinOperationSize = MaxOperationSize =
+          ComputeExplicitObjectSizeArgument(TheCall->getNumArgs() - 1);
+      DestinationSize = ComputeSizeArgument(0);
+      break;
+    }
 
-  case Builtin::BImemcpy:
-  case Builtin::BI__builtin_memcpy:
-  case Builtin::BImemmove:
-  case Builtin::BI__builtin_memmove:
-  case Builtin::BImempcpy:
-  case Builtin::BI__builtin_mempcpy: {
-    MinOperationSize = MaxOperationSize =
-        ComputeExplicitObjectSizeArgument(TheCall->getNumArgs() - 1);
-    DestinationSize = ComputeSizeArgument(0);
-    SourceSize = ComputeSizeArgument(1);
-    break;
-  }
-  case Builtin::BIbcopy:
-  case Builtin::BI__builtin_bcopy: {
-    MinOperationSize = MaxOperationSize =
-        ComputeExplicitObjectSizeArgument(TheCall->getNumArgs() - 1);
-    SourceSize = ComputeSizeArgument(0);
-    DestinationSize = ComputeSizeArgument(1);
-    break;
-  }
+    case Builtin::BImemcpy:
+    case Builtin::BI__builtin_memcpy:
+    case Builtin::BImemmove:
+    case Builtin::BI__builtin_memmove:
+    case Builtin::BImempcpy:
+    case Builtin::BI__builtin_mempcpy: {
+      MinOperationSize = MaxOperationSize =
+          ComputeExplicitObjectSizeArgument(TheCall->getNumArgs() - 1);
+      DestinationSize = ComputeSizeArgument(0);
+      SourceSize = ComputeSizeArgument(1);
+      break;
+    }
+    case Builtin::BIbcopy:
+    case Builtin::BI__builtin_bcopy: {
+      MinOperationSize = MaxOperationSize =
+          ComputeExplicitObjectSizeArgument(TheCall->getNumArgs() - 1);
+      SourceSize = ComputeSizeArgument(0);
+      DestinationSize = ComputeSizeArgument(1);
+      break;
+    }
 
-  case Builtin::BIread:
-  case Builtin::BI__builtin_read:
-  case Builtin::BIreadlink:
-  case Builtin::BI__builtin_readlink:
-  case Builtin::BIreadlinkat:
-  case Builtin::BI__builtin_readlinkat:
-  case Builtin::BIgetcwd:
-  case Builtin::BI__builtin_getcwd: {
-    DestinationSize = ComputeSizeArgument(TheCall->getNumArgs() - 2);
-    MaxOperationSize =
-        ComputeExplicitObjectSizeArgument(TheCall->getNumArgs() - 1);
-    break;
-  }
+    case Builtin::BIread:
+    case Builtin::BI__builtin_read:
+    case Builtin::BIreadlink:
+    case Builtin::BI__builtin_readlink:
+    case Builtin::BIreadlinkat:
+    case Builtin::BI__builtin_readlinkat:
+    case Builtin::BIgetcwd:
+    case Builtin::BI__builtin_getcwd: {
+      DestinationSize = ComputeSizeArgument(TheCall->getNumArgs() - 2);
+      MaxOperationSize =
+          ComputeExplicitObjectSizeArgument(TheCall->getNumArgs() - 1);
+      break;
+    }
 
-  case Builtin::BIwrite:
-  case Builtin::BI__builtin_write: {
-    SourceSize = ComputeSizeArgument(TheCall->getNumArgs() - 2);
-    MaxOperationSize =
-        ComputeExplicitObjectSizeArgument(TheCall->getNumArgs() - 1);
-    break;
-  }
+    case Builtin::BIwrite:
+    case Builtin::BI__builtin_write: {
+      SourceSize = ComputeSizeArgument(TheCall->getNumArgs() - 2);
+      MaxOperationSize =
+          ComputeExplicitObjectSizeArgument(TheCall->getNumArgs() - 1);
+      break;
+    }
 
-  case Builtin::BIsnprintf:
-  case Builtin::BI__builtin_snprintf:
-  case Builtin::BIvsnprintf:
-  case Builtin::BI__builtin_vsnprintf: {
-    MaxOperationSize = ComputeExplicitObjectSizeArgument(1);
-    const auto *FormatExpr = TheCall->getArg(2)->IgnoreParenImpCasts();
-    StringRef FormatStrRef;
-    size_t StrLen;
-    if (MaxOperationSize &&
-        ProcessFormatStringLiteral(FormatExpr, FormatStrRef, StrLen, Context)) 
{
-      EstimateSizeFormatHandler H(FormatStrRef);
-      const char *FormatBytes = FormatStrRef.data();
-      if (!analyze_format_string::ParsePrintfString(
-              H, FormatBytes, FormatBytes + StrLen, getLangOpts(),
-              Context.getTargetInfo(), /*isFreeBSDKPrintf=*/false)) {
-        llvm::APSInt FormatSize =
-            llvm::APSInt::getUnsigned(H.getSizeLowerBound())
-                .extOrTrunc(SizeTypeWidth);
-        if (FormatSize > *MaxOperationSize && *MaxOperationSize != 0) {
-          unsigned TruncationDiagID =
-              H.isKernelCompatible() ? diag::warn_format_truncation
-                                     : 
diag::warn_format_truncation_non_kprintf;
-          SmallString<16> SpecifiedSizeStr;
-          SmallString<16> FormatSizeStr;
-          MaxOperationSize->toString(SpecifiedSizeStr, /*Radix=*/10);
-          FormatSize.toString(FormatSizeStr, /*Radix=*/10);
-          DiagRuntimeBehavior(TheCall->getBeginLoc(), TheCall,
-                              PDiag(TruncationDiagID)
-                                  << GetFunctionName() << SpecifiedSizeStr
-                                  << FormatSizeStr);
+    case Builtin::BIsnprintf:
+    case Builtin::BI__builtin_snprintf:
+    case Builtin::BIvsnprintf:
+    case Builtin::BI__builtin_vsnprintf: {
+      MaxOperationSize = ComputeExplicitObjectSizeArgument(1);
+      const auto *FormatExpr = TheCall->getArg(2)->IgnoreParenImpCasts();
+      StringRef FormatStrRef;
+      size_t StrLen;
+      if (MaxOperationSize && ProcessFormatStringLiteral(
+                                  FormatExpr, FormatStrRef, StrLen, Context)) {
+        EstimateSizeFormatHandler H(FormatStrRef);
+        const char *FormatBytes = FormatStrRef.data();
+        if (!analyze_format_string::ParsePrintfString(
+                H, FormatBytes, FormatBytes + StrLen, getLangOpts(),
+                Context.getTargetInfo(), /*isFreeBSDKPrintf=*/false)) {
+          llvm::APSInt FormatSize =
+              llvm::APSInt::getUnsigned(H.getSizeLowerBound())
+                  .extOrTrunc(SizeTypeWidth);
+          if (FormatSize > *MaxOperationSize && *MaxOperationSize != 0) {
+            unsigned TruncationDiagID =
+                H.isKernelCompatible()
+                    ? diag::warn_format_truncation
+                    : diag::warn_format_truncation_non_kprintf;
+            SmallString<16> SpecifiedSizeStr;
+            SmallString<16> FormatSizeStr;
+            MaxOperationSize->toString(SpecifiedSizeStr, /*Radix=*/10);
+            FormatSize.toString(FormatSizeStr, /*Radix=*/10);
+            DiagRuntimeBehavior(TheCall->getBeginLoc(), TheCall,
+                                PDiag(TruncationDiagID)
+                                    << GetFunctionName() << SpecifiedSizeStr
+                                    << FormatSizeStr);
+          }
         }
       }
+      DestinationSize = ComputeSizeArgument(0);
+      const Expr *LenArg = TheCall->getArg(1)->IgnoreCasts();
+      const Expr *Dest = TheCall->getArg(0)->IgnoreCasts();
+      IdentifierInfo *FnInfo = FD->getIdentifier();
+      CheckSizeofMemaccessArgument(LenArg, Dest, FnInfo);
+      break;
+    }
     }
-    DestinationSize = ComputeSizeArgument(0);
-    const Expr *LenArg = TheCall->getArg(1)->IgnoreCasts();
-    const Expr *Dest = TheCall->getArg(0)->IgnoreCasts();
-    IdentifierInfo *FnInfo = FD->getIdentifier();
-    CheckSizeofMemaccessArgument(LenArg, Dest, FnInfo);
-    break;
-  }
-  }
 
   std::string FunctionName = GetFunctionName();
   SmallString<16> MaxOpStr;

``````````

</details>


https://github.com/llvm/llvm-project/pull/196499
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to