[clang] fc78d55 - [CLANG] Resolves crash on invalid loop vectorize_width (#169473)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 11 09:18:43 PST 2025
Author: Ebin Jose
Date: 2025-12-11T12:18:35-05:00
New Revision: fc78d55398e4e8e2fabd74f0ec42f77b73f5f158
URL: https://github.com/llvm/llvm-project/commit/fc78d55398e4e8e2fabd74f0ec42f77b73f5f158
DIFF: https://github.com/llvm/llvm-project/commit/fc78d55398e4e8e2fabd74f0ec42f77b73f5f158.diff
LOG: [CLANG] Resolves crash on invalid loop vectorize_width (#169473)
Diagnose malformed '#pragma clang loop vectorize_width' lists. Avoids
crash in HandlePragmaLoopHint, emit clear diagnostic and added
regression test.
Fixes #166325
Added:
clang/test/Parser/pragma-loop-vectorize.cpp
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Parse/ParsePragma.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 899a4ee0dee0e..9a238362b4b5f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -783,6 +783,8 @@ Crash and bug fixes
- Fixed a crash when compiling ``__real__`` or ``__imag__`` unary operator on scalar value with type promotion. (#GH160583)
- Fixed a crash when parsing invalid nested name specifier sequences
containing a single colon. (#GH167905)
+- Fixed a crash when parsing malformed #pragma clang loop vectorize_width(4,8,16)
+ by diagnosing invalid comma-separated argument lists. (#GH166325)
Improvements
^^^^^^^^^^^^
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..94cc77aa37d4c
--- /dev/null
+++ b/clang/test/Parser/pragma-loop-vectorize.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+
+void sum_vector(unsigned int A[], unsigned int B[], unsigned int sum[]) {
+ #pragma clang loop vectorize_width(4,8,16) vectorize(assume_safety)
+ // expected-error at -1 {{vectorize_width loop hint malformed; use vectorize_width(X, fixed) or vectorize_width(X, scalable) where X is an integer, or vectorize_width('fixed' or 'scalable')}}
+ // expected-warning at -2 {{extra tokens at end of '#pragma clang loop vectorize_width' - ignored}}
+
+ for (int k = 0; k < 64; k++) {
+ sum[k] = A[k] + 3 * B[k];
+ }
+}
More information about the cfe-commits
mailing list