[clang] beb9977 - [Clang] Improve diagnostic message for loop hint pragma

via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 28 01:51:32 PDT 2022


Author: eopXD
Date: 2022-10-28T01:51:24-07:00
New Revision: beb997799d823aece097494f156c6d277d26571c

URL: https://github.com/llvm/llvm-project/commit/beb997799d823aece097494f156c6d277d26571c
DIFF: https://github.com/llvm/llvm-project/commit/beb997799d823aece097494f156c6d277d26571c.diff

LOG: [Clang] Improve diagnostic message for loop hint pragma

Originally the loop hint is not displayed correctly in the diagnostic.
This patch fixes it.

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D136784

Added: 
    

Modified: 
    clang/lib/Parse/ParsePragma.cpp
    clang/test/Parser/pragma-loop.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index 123d94ee703f1..cddc3780133b8 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -1303,7 +1303,9 @@ struct PragmaLoopHintInfo {
 
 static std::string PragmaLoopHintString(Token PragmaName, Token Option) {
   StringRef Str = PragmaName.getIdentifierInfo()->getName();
-  std::string ClangLoopStr = (llvm::Twine("clang loop ") + Str).str();
+  std::string ClangLoopStr("clang loop ");
+  if (Str == "loop" && Option.getIdentifierInfo())
+    ClangLoopStr += Option.getIdentifierInfo()->getName();
   return std::string(llvm::StringSwitch<StringRef>(Str)
                          .Case("loop", ClangLoopStr)
                          .Case("unroll_and_jam", Str)

diff  --git a/clang/test/Parser/pragma-loop.cpp b/clang/test/Parser/pragma-loop.cpp
index 750affbddf97e..0203e90104d4f 100644
--- a/clang/test/Parser/pragma-loop.cpp
+++ b/clang/test/Parser/pragma-loop.cpp
@@ -305,34 +305,34 @@ void foo(void) {
 void foo(int *List, int Length) {
   int i;
 #pragma clang loop vectorize(enable, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - ignored}}*/ while (i-6 < Length) {
+/* expected-warning {{extra tokens at end of '#pragma clang loop vectorize' - ignored}}*/ while (i-6 < Length) {
     List[i] = i;
   }
 
 #pragma clang loop interleave(enable, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - ignored}}*/ while (i-6 < Length) {
+/* expected-warning {{extra tokens at end of '#pragma clang loop interleave' - ignored}}*/ while (i-6 < Length) {
     List[i] = i;
   }
 
 #pragma clang loop unroll(enable, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - ignored}}*/ while (i-6 < Length) {
+/* expected-warning {{extra tokens at end of '#pragma clang loop unroll' - ignored}}*/ while (i-6 < Length) {
     List[i] = i;
   }
 
 #pragma clang loop vectorize_predicate(enable, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - ignored}}*/ while (i-6 < Length) {
+/* expected-warning {{extra tokens at end of '#pragma clang loop vectorize_predicate' - ignored}}*/ while (i-6 < Length) {
     List[i] = i;
   }
 
 #pragma clang loop pipeline(disable, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - ignored}}*/ while (i-6 < Length) {
+/* expected-warning {{extra tokens at end of '#pragma clang loop pipeline' - ignored}}*/ while (i-6 < Length) {
     List[i] = i;
   }
 
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - ignored}}*/ #pragma clang loop vectorize_width(2, scalable, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - ignored}}*/ #pragma clang loop interleave_count(2, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - ignored}}*/ #pragma clang loop unroll_count(2, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - ignored}}*/ #pragma clang loop pipeline_initiation_interval(2, extra)
+/* expected-warning {{extra tokens at end of '#pragma clang loop vectorize_width' - ignored}}*/ #pragma clang loop vectorize_width(2, scalable, extra)
+/* expected-warning {{extra tokens at end of '#pragma clang loop interleave_count' - ignored}}*/ #pragma clang loop interleave_count(2, extra)
+/* expected-warning {{extra tokens at end of '#pragma clang loop unroll_count' - ignored}}*/ #pragma clang loop unroll_count(2, extra)
+/* expected-warning {{extra tokens at end of '#pragma clang loop pipeline_initiation_interval' - ignored}}*/ #pragma clang loop pipeline_initiation_interval(2, extra)
   while (i-6 < Length) {
     List[i] = i;
   }


        


More information about the cfe-commits mailing list