Skip to content

Conversation

@ebinjose02
Copy link

Fixes #166325
Diagnose malformed '#pragma clang loop vectorize_width' lists. Avoids crash in HandlePragmaLoopHint, emit clear diagnostic and added regression test.

Diagnose malformed '#pragma clang loop vectorize_width' lists. Avoids crash in HandlePragmaLoopHint, emit clear diagnostic and added regression test.
@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Nov 25, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 25, 2025

@llvm/pr-subscribers-clang

Author: Ebin Jose (ebinjose02)

Changes

Fixes #166325
Diagnose malformed '#pragma clang loop vectorize_width' lists. Avoids crash in HandlePragmaLoopHint, emit clear diagnostic and added regression test.


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

2 Files Affected:

  • (modified) clang/lib/Parse/ParsePragma.cpp (+1-1)
  • (added) clang/test/Parser/pragma-loop-vectorize.cpp (+13)
diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index 7c2b9280f0b76..7e8b339f5be49 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -1531,7 +1531,7 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) {
         PP.Lex(Tok); // ,
 
         StateInfo = Tok.getIdentifierInfo();
-        IsScalableStr = StateInfo->getName();
+        IsScalableStr = StateInfo ? StateInfo->getName() : "";
 
         if (IsScalableStr != "scalable" && IsScalableStr != "fixed") {
           Diag(Tok.getLocation(),
diff --git a/clang/test/Parser/pragma-loop-vectorize.cpp b/clang/test/Parser/pragma-loop-vectorize.cpp
new file mode 100644
index 0000000000000..39f7e84323f5f
--- /dev/null
+++ b/clang/test/Parser/pragma-loop-vectorize.cpp
@@ -0,0 +1,13 @@
+// RUN: not %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck %s
+
+void sum_vector(unsigned int A[], unsigned int B[], unsigned int sum[]) {
+    #pragma clang loop vectorize_width(4,8,16) vectorize(assume_safety)
+    for (int k = 0; k < 64; k++) {
+        sum[k] = A[k] + 3 * B[k];
+    }
+}
+
+// CHECK: error: vectorize_width loop hint malformed; use
+// CHECK-SAME: vectorize_width(X, fixed) or vectorize_width(X, scalable) where X is an integer, or
+// CHECK-SAME: vectorize_width('fixed' or 'scalable')
+// CHECK: warning: extra tokens at end of '#pragma clang loop vectorize_width'

@zwuis
Copy link
Contributor

zwuis commented Nov 25, 2025

Thank you for your patch! Please add a release note entry to "clang/docs/ReleaseNotes.rst" so that users can know the improvement. Please read https://clang.llvm.org/docs/InternalsManual.html#testing.

Updated the test file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash in clang since clang 12 in HandlePragmaLoopHint

3 participants