[clang] [clang-tools-extra] [clangd][HLSL] Separate statement and declaration attributes code complete in [...] (PR #215353)

via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 10 10:49:39 PDT 2026


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 -- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp clang/include/clang/Parse/Parser.h clang/include/clang/Sema/SemaCodeCompletion.h clang/lib/Parse/ParseDeclCXX.cpp clang/lib/Parse/ParseStmt.cpp clang/lib/Sema/SemaCodeComplete.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-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 5ca478fa9..dca5ab072 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -5179,13 +5179,17 @@ TEST(CompletionTest, HLSLBracketAttributes) {
   )hlsl");
 
   TestTU TUDecl = TestTU::withCode(DeclContext.code());
-  configureHLSL(TUDecl); 
+  configureHLSL(TUDecl);
   auto ResultsDecl = completions(TUDecl, DeclContext.point());
 
-  EXPECT_THAT(ResultsDecl.Completions, Contains(Field(&CodeCompletion::Name, "numthreads")));
-  EXPECT_THAT(ResultsDecl.Completions, Contains(Field(&CodeCompletion::Name, "WaveSize")));
-  EXPECT_THAT(ResultsDecl.Completions, Not(Contains(Field(&CodeCompletion::Name, "unroll"))));
-  EXPECT_THAT(ResultsDecl.Completions, Not(Contains(Field(&CodeCompletion::Name, "SV_Target"))));
+  EXPECT_THAT(ResultsDecl.Completions,
+              Contains(Field(&CodeCompletion::Name, "numthreads")));
+  EXPECT_THAT(ResultsDecl.Completions,
+              Contains(Field(&CodeCompletion::Name, "WaveSize")));
+  EXPECT_THAT(ResultsDecl.Completions,
+              Not(Contains(Field(&CodeCompletion::Name, "unroll"))));
+  EXPECT_THAT(ResultsDecl.Completions,
+              Not(Contains(Field(&CodeCompletion::Name, "SV_Target"))));
 
   Annotations StmtContext(R"hlsl(
     void main() {
@@ -5198,10 +5202,14 @@ TEST(CompletionTest, HLSLBracketAttributes) {
   configureHLSL(TUStmt);
   auto ResultsStmt = completions(TUStmt, StmtContext.point());
 
-  EXPECT_THAT(ResultsStmt.Completions, Contains(Field(&CodeCompletion::Name, "unroll")));
-  EXPECT_THAT(ResultsStmt.Completions, Contains(Field(&CodeCompletion::Name, "loop")));
-  EXPECT_THAT(ResultsStmt.Completions, Not(Contains(Field(&CodeCompletion::Name, "numthreads"))));
-  EXPECT_THAT(ResultsStmt.Completions, Not(Contains(Field(&CodeCompletion::Name, "SV_Target"))));
+  EXPECT_THAT(ResultsStmt.Completions,
+              Contains(Field(&CodeCompletion::Name, "unroll")));
+  EXPECT_THAT(ResultsStmt.Completions,
+              Contains(Field(&CodeCompletion::Name, "loop")));
+  EXPECT_THAT(ResultsStmt.Completions,
+              Not(Contains(Field(&CodeCompletion::Name, "numthreads"))));
+  EXPECT_THAT(ResultsStmt.Completions,
+              Not(Contains(Field(&CodeCompletion::Name, "SV_Target"))));
 }
 
 } // namespace
diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h
index 19a1c0a90..b7a311fd9 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -2337,7 +2337,8 @@ private:
     return false;
   }
 
-  bool MaybeParseMicrosoftAttributes(ParsedAttributes &Attrs, bool IsStmtContext = false) {
+  bool MaybeParseMicrosoftAttributes(ParsedAttributes &Attrs,
+                                     bool IsStmtContext = false) {
     bool AttrsParsed = false;
     if ((getLangOpts().MicrosoftExt || getLangOpts().HLSL) &&
         Tok.is(tok::l_square)) {
@@ -3133,7 +3134,8 @@ private:
   ///             ms-attribute[opt]
   ///             ms-attribute ms-attribute-seq
   /// \endverbatim
-  void ParseMicrosoftAttributes(ParsedAttributes &Attrs, bool IsStmtContext = false);
+  void ParseMicrosoftAttributes(ParsedAttributes &Attrs,
+                                bool IsStmtContext = false);
 
   void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs);
   void ParseNullabilityClassAttributes(ParsedAttributes &attrs);
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 08c5d4998..0f01b9aae 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -4921,7 +4921,8 @@ void Parser::ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs) {
                  ParsedAttr::Form::Microsoft());
 }
 
-void Parser::ParseMicrosoftAttributes(ParsedAttributes &Attrs, bool IsStmtContext) {
+void Parser::ParseMicrosoftAttributes(ParsedAttributes &Attrs,
+                                      bool IsStmtContext) {
   assert(Tok.is(tok::l_square) && "Not a Microsoft attribute list");
 
   SourceLocation StartLoc = Tok.getLocation();
@@ -4943,11 +4944,11 @@ void Parser::ParseMicrosoftAttributes(ParsedAttributes &Attrs, bool IsStmtContex
               /*RequireStmt=*/IsStmtContext,
               /*ExcludeKind=*/ParsedAttr::AT_HLSLParsedSemantic);
         } else {
-            Actions.CodeCompletion().CodeCompleteAttribute(
-                AttributeCommonInfo::AS_Microsoft,
-                SemaCodeCompletion::AttributeCompletion::Attribute,
+          Actions.CodeCompletion().CodeCompleteAttribute(
+              AttributeCommonInfo::AS_Microsoft,
+              SemaCodeCompletion::AttributeCompletion::Attribute,
               /*Scope=*/nullptr);
-          }
+        }
         break;
       }
       if (Tok.isNot(tok::identifier)) // ']', but also eof
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index 3cfbb2b74..cfca5ca71 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -10730,8 +10730,7 @@ void SemaCodeCompletion::GatherGlobalCodeCompletions(
 
 void SemaCodeCompletion::CodeCompleteHLSLAttributes(
     llvm::ArrayRef<AttributeCommonInfo::Syntax> Syntaxes,
-    std::optional<ParsedAttr::Kind> RestrictToKind,
-    bool RequireStmt,
+    std::optional<ParsedAttr::Kind> RestrictToKind, bool RequireStmt,
     std::optional<ParsedAttr::Kind> ExcludeKind) {
   ResultBuilder Results(SemaRef, CodeCompleter->getAllocator(),
                         CodeCompleter->getCodeCompletionTUInfo(),
@@ -10764,7 +10763,6 @@ void SemaCodeCompletion::CodeCompleteHLSLAttributes(
                             Results.size());
 }
 
-
 SemaCodeCompletion::SemaCodeCompletion(Sema &S,
                                        CodeCompleteConsumer *CompletionConsumer)
     : SemaBase(S), CodeCompleter(CompletionConsumer),

``````````

</details>


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


More information about the cfe-commits mailing list