[clang-tools-extra] [clang] [CLANG] Fix : More Detailed "No expected directives found" (PR #78338)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 16 12:00:05 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clangd

Author: Shourya Goel (Sh0g0-1758)

<details>
<summary>Changes</summary>

This pull request aims to solve the issue mentioned [here](https://github.com/llvm/llvm-project/issues/58290)
I have made the necessary changes to the best of my knowledge and updated tests for the same. 
Please do suggest changes in it. 

---
Full diff: https://github.com/llvm/llvm-project/pull/78338.diff


9 Files Affected:

- (modified) clang-tools-extra/clangd/test/indexer.test (+1-1) 
- (modified) clang/include/clang/Basic/Diagnostic.h (+3-1) 
- (modified) clang/include/clang/Basic/DiagnosticFrontendKinds.td (+1-1) 
- (modified) clang/lib/AST/ASTContext.cpp (+1-1) 
- (modified) clang/lib/Frontend/VerifyDiagnosticConsumer.cpp (+4-1) 
- (modified) clang/test/ARCMT/verify.m (+1-1) 
- (modified) clang/test/Frontend/verify.c (+1-1) 
- (modified) clang/test/Frontend/verify2.c (+1-1) 
- (modified) clang/test/Frontend/verify3.c (+2-2) 


``````````diff
diff --git a/clang-tools-extra/clangd/test/indexer.test b/clang-tools-extra/clangd/test/indexer.test
index 2f01f6c557a7de..213d33f8e2d6a5 100644
--- a/clang-tools-extra/clangd/test/indexer.test
+++ b/clang-tools-extra/clangd/test/indexer.test
@@ -5,5 +5,5 @@
 # `.ii` file and `-verify` triggers extra diagnostics generation. Clangd should
 # strip those.
 # RUN: clangd-indexer %t.cpp -- -Xclang -verify --save-temps -- 2>&1 | FileCheck %s
-# CHECK-NOT: error: no expected directives found: consider use of 'expected-no-diagnostics'
+# CHECK-NOT: error: no expected directives found: consider use of {{.*}}-no-diagnostics
 # RUN: not ls %t.ii
diff --git a/clang/include/clang/Basic/Diagnostic.h b/clang/include/clang/Basic/Diagnostic.h
index 0c7836c2ea569c..a185c75e418b58 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -9,7 +9,9 @@
 /// \file
 /// Defines the Diagnostic-related interfaces.
 //
-//===----------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//]
+
+// look into this file as well
 
 #ifndef LLVM_CLANG_BASIC_DIAGNOSTIC_H
 #define LLVM_CLANG_BASIC_DIAGNOSTIC_H
diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 568000106a84dc..42d2767af6b708 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -179,7 +179,7 @@ def err_verify_invalid_no_diags : Error<
     "%select{expected|'expected-no-diagnostics'}0 directive cannot follow "
     "%select{'expected-no-diagnostics' directive|other expected directives}0">;
 def err_verify_no_directives : Error<
-    "no expected directives found: consider use of 'expected-no-diagnostics'">;
+    "no expected directives found: consider use of '%0'-no-diagnostics">;
 def err_verify_nonconst_addrspace : Error<
   "qualifier 'const' is needed for variables in address space '%0'">;
 
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index b60dcfaabfd1a4..e3b2f1f48ed1e2 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1404,7 +1404,7 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target,
     getTranslationUnitDecl()->addDecl(MSGuidTagDecl);
   }
 }
-
+// maybe change here also.
 DiagnosticsEngine &ASTContext::getDiagnostics() const {
   return SourceMgr.getDiagnostics();
 }
diff --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
index 8a3d2286cd168c..30cd7f47a21c1f 100644
--- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
+++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
@@ -1098,7 +1098,10 @@ void VerifyDiagnosticConsumer::CheckDiagnostics() {
     // Produce an error if no expected-* directives could be found in the
     // source file(s) processed.
     if (Status == HasNoDirectives) {
-      Diags.Report(diag::err_verify_no_directives).setForceEmit();
+      // change here
+      std::string directives =
+          *Diags.getDiagnosticOptions().VerifyPrefixes.begin();
+      Diags.Report(diag::err_verify_no_directives).setForceEmit() << directives;
       ++NumErrors;
       Status = HasNoDirectivesReported;
     }
diff --git a/clang/test/ARCMT/verify.m b/clang/test/ARCMT/verify.m
index 7d245fe80575e5..13fd599f530fbe 100644
--- a/clang/test/ARCMT/verify.m
+++ b/clang/test/ARCMT/verify.m
@@ -11,7 +11,7 @@
 #error
 // expected-error at -1 {{}}
 
-//      CHECK: error: no expected directives found: consider use of 'expected-no-diagnostics'
+//      CHECK: error: no expected directives found: consider use of {{.*}}-no-diagnostics
 // CHECK-NEXT: error: 'expected-error' diagnostics seen but not expected:
 // CHECK-NEXT:   (frontend): error reading '{{.*}}verify.m.tmp.invalid'
 // CHECK-NEXT: 2 errors generated.
diff --git a/clang/test/Frontend/verify.c b/clang/test/Frontend/verify.c
index 221b715c19e416..657a9d3f2bf6bb 100644
--- a/clang/test/Frontend/verify.c
+++ b/clang/test/Frontend/verify.c
@@ -111,7 +111,7 @@ unexpected b; // expected-error at 33 1-1 {{unknown type}}
 #if 0
 // RUN: not %clang_cc1 -verify %t.invalid 2>&1 | FileCheck -check-prefix=CHECK6 %s
 
-//      CHECK6: error: no expected directives found: consider use of 'expected-no-diagnostics'
+//      CHECK6: error: no expected directives found: consider use of {{.*}}-no-diagnostics
 // CHECK6-NEXT: error: 'expected-error' diagnostics seen but not expected:
 // CHECK6-NEXT:   (frontend): error reading '{{.*}}verify.c.tmp.invalid'
 // CHECK6-NEXT: 2 errors generated.
diff --git a/clang/test/Frontend/verify2.c b/clang/test/Frontend/verify2.c
index debaeb6b498678..77510c8d9b4940 100644
--- a/clang/test/Frontend/verify2.c
+++ b/clang/test/Frontend/verify2.c
@@ -12,7 +12,7 @@
 #if 0
 // expected-error {{should be ignored}}
 
-//      CHECK: error: no expected directives found: consider use of 'expected-no-diagnostics'
+//      CHECK: error: no expected directives found: consider use of {{.*}}-no-diagnostics
 // CHECK-NEXT: error: 'expected-error' diagnostics seen but not expected:
 // CHECK-NEXT:   Line 5: header
 // CHECK-NEXT:   Line 10: source
diff --git a/clang/test/Frontend/verify3.c b/clang/test/Frontend/verify3.c
index e414c7370fad77..8924619592f583 100644
--- a/clang/test/Frontend/verify3.c
+++ b/clang/test/Frontend/verify3.c
@@ -28,7 +28,7 @@
 #ifdef TEST3
 // no directives
 
-//      CHECK3: error: no expected directives found: consider use of 'expected-no-diagnostics'
+//      CHECK3: error: no expected directives found: consider use of {{.*}}-no-diagnostics
 // CHECK3-NEXT: 1 error generated.
 #endif
 
@@ -37,5 +37,5 @@
 #warning X
 // expected-warning at -1 {{X}}
 
-// CHECK4-NOT: error: no expected directives found: consider use of 'expected-no-diagnostics'
+// CHECK4-NOT: error: no expected directives found: consider use of {{.*}}-no-diagnostics
 #endif

``````````

</details>


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


More information about the cfe-commits mailing list