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 cpp -- 
clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp
 clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp 
clang/lib/Sema/SemaDeclAttr.cpp 
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.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/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp 
b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
index 9545fbf09..95fd74a32 100644
--- a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -12,8 +12,8 @@
 
//===----------------------------------------------------------------------===//
 
 #include "clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h"
-#include "clang/AST/Attr.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/Attr.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
@@ -239,7 +239,9 @@ AST_MATCHER(CXXOperatorCallExpr, 
hasOptionalOperatorObjectType) {
   return hasReceiverTypeDesugaringToOptional(Node.getArg(0));
 }
 
-static bool hasAnalyzeAsMethodNameHelper (const NamedDecl &Node, std::string 
MethodName, std::string Label) {
+static bool hasAnalyzeAsMethodNameHelper(const NamedDecl &Node,
+                                         std::string MethodName,
+                                         std::string Label) {
   if (const auto *MD = dyn_cast<CXXMethodDecl>(&Node)) {
     if (const auto *Attr = MD->getAttr<AnalyzeAsMethodAttr>()) {
       StringRef AttrValue = Attr->getMethodName();
@@ -250,7 +252,8 @@ static bool hasAnalyzeAsMethodNameHelper (const NamedDecl 
&Node, std::string Met
   return false;
 }
 
-AST_MATCHER_P2(NamedDecl, hasAnalyzeAsMethodNameAndLabel, std::string, 
MethodName, std::string, Label) {
+AST_MATCHER_P2(NamedDecl, hasAnalyzeAsMethodNameAndLabel, std::string,
+               MethodName, std::string, Label) {
   return hasAnalyzeAsMethodNameHelper(Node, MethodName, Label);
 }
 
@@ -258,12 +261,10 @@ AST_MATCHER_P(NamedDecl, hasAnalyzeAsMethodName, 
std::string, MethodName) {
   return hasAnalyzeAsMethodNameHelper(Node, MethodName, "");
 }
 
-auto isOptionalOperatorCallWithLabelMatcher(std::string operatorName, 
std::string label)
-{
-      return cxxOperatorCallExpr(
-            callee(
-              cxxMethodDecl(
-                hasAnalyzeAsMethodNameAndLabel(operatorName, label))));
+auto isOptionalOperatorCallWithLabelMatcher(std::string operatorName,
+                                            std::string label) {
+  return cxxOperatorCallExpr(callee(
+      cxxMethodDecl(hasAnalyzeAsMethodNameAndLabel(operatorName, label))));
 }
 
 auto isOptionalMemberCallWithNameMatcher(
@@ -403,10 +404,12 @@ auto isValueOrStringEmptyCall() {
   return cxxMemberCallExpr(
       callee(cxxMethodDecl(hasName("empty"))),
       onImplicitObjectArgument(ignoringImplicit(
-          cxxMemberCallExpr(on(expr(unless(cxxThisExpr()))),
-                            callee(cxxMethodDecl(anyOf(hasName("value_or"), 
hasAnalyzeAsMethodName("value_or")),
-                                                 ofClass(optionalClass()))),
-                            hasArgument(0, stringLiteral(hasSize(0))))
+          cxxMemberCallExpr(
+              on(expr(unless(cxxThisExpr()))),
+              callee(cxxMethodDecl(anyOf(hasName("value_or"),
+                                         hasAnalyzeAsMethodName("value_or")),
+                                   ofClass(optionalClass()))),
+              hasArgument(0, stringLiteral(hasSize(0))))
               .bind(ValueOrCallID))));
 }
 
@@ -496,11 +499,11 @@ void setHasValue(RecordStorageLocation &OptionalLoc, 
BoolValue &HasValueVal,
   Env.setValue(locForHasValue(OptionalLoc), HasValueVal);
 }
 
-static void setHasValueHelper (const CXXMemberCallExpr *E, 
LatticeTransferState &State, bool objectValue)
-{
-  if( RecordStorageLocation *Loc = getImplicitObjectLocation(*E, State.Env)) {
-              setHasValue(*Loc, State.Env.getBoolLiteralValue(objectValue), 
State.Env);
-            }
+static void setHasValueHelper(const CXXMemberCallExpr *E,
+                              LatticeTransferState &State, bool objectValue) {
+  if (RecordStorageLocation *Loc = getImplicitObjectLocation(*E, State.Env)) {
+    setHasValue(*Loc, State.Env.getBoolLiteralValue(objectValue), State.Env);
+  }
 }
 
 /// Returns the symbolic value that represents the "has_value" property of the
@@ -1105,12 +1108,15 @@ auto buildTransferMatchSwitch() {
 
       // optional::operator=
       .CaseOfCFGStmt<CXXOperatorCallExpr>(
-        isOptionalOperatorCallWithLabelMatcher("operator=", "null"),
-        transferNulloptAssignment)
+          isOptionalOperatorCallWithLabelMatcher("operator=", "null"),
+          transferNulloptAssignment)
       .CaseOfCFGStmt<CXXMemberCallExpr>(
-        
isOptionalMemberCallWithNameMatcher(hasAnalyzeAsMethodNameAndLabel("operator=", 
"null")),
-        [](const CXXMemberCallExpr *E, const MatchFinder::MatchResult &, 
LatticeTransferState &State)
-        {setHasValueHelper(E, State, false);})
+          isOptionalMemberCallWithNameMatcher(
+              hasAnalyzeAsMethodNameAndLabel("operator=", "null")),
+          [](const CXXMemberCallExpr *E, const MatchFinder::MatchResult &,
+             LatticeTransferState &State) {
+            setHasValueHelper(E, State, false);
+          })
       .CaseOfCFGStmt<CXXOperatorCallExpr>(
           isOptionalValueOrConversionAssignment(),
           transferValueOrConversionAssignment)
@@ -1149,7 +1155,7 @@ auto buildTransferMatchSwitch() {
       .CaseOfCFGStmt<CXXMemberCallExpr>(
           isOptionalMemberCallWithNameMatcher(
               anyOf(hasAnyName("has_value", "hasValue"),
-              hasAnalyzeAsMethodName("has_value"))),
+                    hasAnalyzeAsMethodName("has_value"))),
           transferOptionalHasValueCall)
 
       // optional::operator bool
@@ -1158,18 +1164,17 @@ auto buildTransferMatchSwitch() {
           transferOptionalHasValueCall)
 
       // this code could be removed if NullableValue used
-      // [[clang::analyze_as_inverse_method("std::optional::has_value")]] on 
isNull() *NYI
-      // NullableValue::isNull
-      // Only NullableValue has isNull
+      // [[clang::analyze_as_inverse_method("std::optional::has_value")]] on
+      // isNull() *NYI NullableValue::isNull Only NullableValue has isNull
       .CaseOfCFGStmt<CXXMemberCallExpr>(
           isOptionalMemberCallWithNameMatcher(hasName("isNull")),
           transferOptionalIsNullCall)
 
       // this code could be removed if NullableValue used
-      // [[clang::analyze_as_method("emplace")]] on makeValue() and 
makeValueInplace()
-      // NullableValue::makeValue, NullableValue::makeValueInplace
-      // Only NullableValue has these methods, but this
-      // will also pass for other types
+      // [[clang::analyze_as_method("emplace")]] on makeValue() and
+      // makeValueInplace() NullableValue::makeValue,
+      // NullableValue::makeValueInplace Only NullableValue has these methods,
+      // but this will also pass for other types
       .CaseOfCFGStmt<CXXMemberCallExpr>(
           isOptionalMemberCallWithNameMatcher(
               hasAnyName("makeValue", "makeValueInplace")),
@@ -1183,7 +1188,8 @@ auto buildTransferMatchSwitch() {
 
       // optional::emplace
       .CaseOfCFGStmt<CXXMemberCallExpr>(
-          isOptionalMemberCallWithNameMatcher(anyOf(hasName("emplace"), 
hasAnalyzeAsMethodName("emplace"))),
+          isOptionalMemberCallWithNameMatcher(
+              anyOf(hasName("emplace"), hasAnalyzeAsMethodName("emplace"))),
           [](const CXXMemberCallExpr *E, const MatchFinder::MatchResult &,
              LatticeTransferState &State) {
             if (RecordStorageLocation *Loc =
@@ -1194,7 +1200,8 @@ auto buildTransferMatchSwitch() {
 
       // optional::reset
       .CaseOfCFGStmt<CXXMemberCallExpr>(
-          isOptionalMemberCallWithNameMatcher(anyOf(hasName("reset"), 
hasAnalyzeAsMethodName("reset"))),
+          isOptionalMemberCallWithNameMatcher(
+              anyOf(hasName("reset"), hasAnalyzeAsMethodName("reset"))),
           [](const CXXMemberCallExpr *E, const MatchFinder::MatchResult &,
              LatticeTransferState &State) {
             if (RecordStorageLocation *Loc =
@@ -1206,7 +1213,8 @@ auto buildTransferMatchSwitch() {
 
       // optional::swap
       .CaseOfCFGStmt<CXXMemberCallExpr>(
-          isOptionalMemberCallWithNameMatcher(anyOf(hasName("swap"), 
hasAnalyzeAsMethodName("swap"))),
+          isOptionalMemberCallWithNameMatcher(
+              anyOf(hasName("swap"), hasAnalyzeAsMethodName("swap"))),
           transferSwapCall)
 
       // std::swap
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index b8a498d88..4a6cb5235 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6711,10 +6711,11 @@ static void handleAnalyzeAsClass(Sema &S, Decl *D, 
const ParsedAttr &AL) {
 }
 
 // for now this only handles std::optional (POC)
-static bool isValidAnalyzeAsMethodAttr(Decl *D, StringRef MethodName, 
StringRef Label) {
-  // no validation is done currently.  if someone writes something with a 
nonsense name,
-  // it simply won't be validated but also no warning will be emitted
-  // would be nice to do something smarter in the real implementation
+static bool isValidAnalyzeAsMethodAttr(Decl *D, StringRef MethodName,
+                                       StringRef Label) {
+  // no validation is done currently.  if someone writes something with a
+  // nonsense name, it simply won't be validated but also no warning will be
+  // emitted would be nice to do something smarter in the real implementation
   return true;
 }
 
@@ -6731,11 +6732,12 @@ static void handleAnalyzeAsMethod(Sema &S, Decl *D, 
const ParsedAttr &AL) {
     return;
   }
 
-  if(AL.isArgExpr(1) && AL.getArgAsExpr(1) &&
+  if (AL.isArgExpr(1) && AL.getArgAsExpr(1) &&
       !S.checkStringLiteralArgumentAttr(AL, 1, Label))
     return;
 
-  D->addAttr(::new (S.Context) AnalyzeAsMethodAttr(S.Context, AL, MethodName, 
Label));
+  D->addAttr(::new (S.Context)
+                 AnalyzeAsMethodAttr(S.Context, AL, MethodName, Label));
 }
 
 static bool hasBTFDeclTagAttr(Decl *D, StringRef Tag) {

``````````

</details>


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

Reply via email to