[Mlir-commits] [mlir] [clang] fix issue 73559. (PR #74926)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Dec 17 00:59:26 PST 2023


Andrzej =?utf-8?q?WarzyƄski?= <andrzej.warzynski at arm.com>,ChipsSpectre
 <maximilian.hornung at tum.de>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/74926 at github.com>


https://github.com/ChipsSpectre updated https://github.com/llvm/llvm-project/pull/74926

>From dad78484118bbd0a662915df0b4ce50c24d3bf42 Mon Sep 17 00:00:00 2001
From: ChipsSpectre <maximilian.hornung at tum.de>
Date: Sat, 9 Dec 2023 12:07:02 +0100
Subject: [PATCH 1/5] fix issue 73559.

---
 clang/lib/Parse/ParseDecl.cpp    | 3 ++-
 clang/lib/Parse/ParseDeclCXX.cpp | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index ece3698967e2f6..5d1c19ae07cb54 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3483,7 +3483,8 @@ void Parser::ParseDeclarationSpecifiers(
 
     case tok::coloncolon: // ::foo::bar
       // C++ scope specifier.  Annotate and loop, or bail out on error.
-      if (TryAnnotateCXXScopeToken(EnteringContext)) {
+      if (getLangOpts().CPlusPlus &&
+          TryAnnotateCXXScopeToken(EnteringContext)) {
         if (!DS.hasTypeSpecifier())
           DS.SetTypeSpecError();
         goto DoneWithDeclSpec;
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 910112ecae964c..eba7ea65beee94 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2702,7 +2702,7 @@ Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
   bool MalformedTypeSpec = false;
   if (!TemplateInfo.Kind &&
       Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw___super)) {
-    if (TryAnnotateCXXScopeToken())
+    if (getLangOpts().CPlusPlus && TryAnnotateCXXScopeToken())
       MalformedTypeSpec = true;
 
     bool isAccessDecl;

>From a1985517ddca97dd5779014690d80caaa31f8cb4 Mon Sep 17 00:00:00 2001
From: ChipsSpectre <maximilian.hornung at tum.de>
Date: Mon, 11 Dec 2023 22:31:10 +0100
Subject: [PATCH 2/5] address review comments.

---
 clang/docs/ReleaseNotes.rst      | 2 ++
 clang/lib/Parse/ParseDeclCXX.cpp | 6 ++++--
 clang/test/Parser/cxx-in-c.c     | 1 +
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 783dc7333af7e2..59f131ea79465f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -641,6 +641,8 @@ Bug Fixes in This Version
   Fixes (`#67317 <https://github.com/llvm/llvm-project/issues/67317>`_)
 - Clang now properly diagnoses use of stand-alone OpenMP directives after a
   label (including ``case`` or ``default`` labels).
+- Fix crash when using C++ only tokens like *::* in C compiler clang.
+  Fixes (`#73559 https://github.com/llvm/llvm-project/issues/73559`_)
 
   Before:
 
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index eba7ea65beee94..89a97cc96111d8 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2678,7 +2678,9 @@ Parser::DeclGroupPtrTy
 Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
                                        ParsedAttributes &AccessAttrs,
                                        const ParsedTemplateInfo &TemplateInfo,
-                                       ParsingDeclRAIIObject *TemplateDiags) {
+                                       ParsingDeclRAIIObject *TemplateDiags) {  
+  assert(getLangOpts().CPlusPlus &&
+         "Call sites of this function should be guarded by checking for C++");                                      
   if (Tok.is(tok::at)) {
     if (getLangOpts().ObjC && NextToken().isObjCAtKeyword(tok::objc_defs))
       Diag(Tok, diag::err_at_defs_cxx);
@@ -2702,7 +2704,7 @@ Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
   bool MalformedTypeSpec = false;
   if (!TemplateInfo.Kind &&
       Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw___super)) {
-    if (getLangOpts().CPlusPlus && TryAnnotateCXXScopeToken())
+    if (TryAnnotateCXXScopeToken())
       MalformedTypeSpec = true;
 
     bool isAccessDecl;
diff --git a/clang/test/Parser/cxx-in-c.c b/clang/test/Parser/cxx-in-c.c
index f5fa39bd0cb99b..bd304260571c4d 100644
--- a/clang/test/Parser/cxx-in-c.c
+++ b/clang/test/Parser/cxx-in-c.c
@@ -3,3 +3,4 @@
 // PR9137
 void f0(int x) : {}; // expected-error{{expected function body after function declarator}}
 void f1(int x) try {}; // expected-error{{expected function body after function declarator}}
+::; // expected-error{{expected that double colon marker does not appear in c}}

>From d2de13285fdf460bd049ab7ec3bbdf5c595bb1ad Mon Sep 17 00:00:00 2001
From: ChipsSpectre <maximilian.hornung at tum.de>
Date: Mon, 11 Dec 2023 22:35:17 +0100
Subject: [PATCH 3/5] enforce coding style

---
 clang/lib/Parse/ParseDeclCXX.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 89a97cc96111d8..1cf16a752cfcdc 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2678,9 +2678,9 @@ Parser::DeclGroupPtrTy
 Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
                                        ParsedAttributes &AccessAttrs,
                                        const ParsedTemplateInfo &TemplateInfo,
-                                       ParsingDeclRAIIObject *TemplateDiags) {  
+                                       ParsingDeclRAIIObject *TemplateDiags) {
   assert(getLangOpts().CPlusPlus &&
-         "Call sites of this function should be guarded by checking for C++");                                      
+         "Call sites of this function should be guarded by checking for C++");
   if (Tok.is(tok::at)) {
     if (getLangOpts().ObjC && NextToken().isObjCAtKeyword(tok::objc_defs))
       Diag(Tok, diag::err_at_defs_cxx);

>From 2ef492222e7495c3b718f7975c40d9d27443a94e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andrzej=20Warzy=C5=84ski?= <andrzej.warzynski at arm.com>
Date: Mon, 11 Dec 2023 21:32:23 +0000
Subject: [PATCH 4/5] Revert "[mlir][vector] Make `TransposeOpLowering`
 configurable (#73915)" (#75062)

Reverting a workaround intended specifically for SPRI-V. That workaround
emerged from this discussion:

  * https://github.com/llvm/llvm-project/pull/72105

AFAIK, it hasn't been required in practice. This is based on IREE
(https://github.com/openxla/iree), which has just bumped it's fork of
LLVM without using it (*).

(*) https://github.com/openxla/iree/commit/cef31e775e03ec83420e4a7b47a992242d8df37c

This reverts commit bbd2b08b95fe76bea138c1b03c1cd42ed3ee04df.
---
 .../Vector/Transforms/VectorTransforms.h      | 10 ------
 .../Transforms/LowerVectorTranspose.cpp       | 34 +++++++++----------
 2 files changed, 16 insertions(+), 28 deletions(-)

diff --git a/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h b/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h
index 41ffc929946027..08d3bb157a0e39 100644
--- a/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h
+++ b/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h
@@ -59,16 +59,6 @@ struct VectorTransformsOptions {
     vectorTransferSplit = opt;
     return *this;
   }
-
-  /// Option to control if vector.transpose can lower to a vector.shape_cast.
-  /// TODO: ATM it's not possible to lower `vector.shape_cast` to SPIR-V
-  /// and hence the need for this opt-out. Once the missing support has been
-  /// added, this option can be removed.
-  bool useShapeCast = true;
-  VectorTransformsOptions &setUseShapeCast(bool opt = true) {
-    useShapeCast = opt;
-    return *this;
-  }
 };
 
 //===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp b/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp
index 4d43a76c4a4efc..97f6caca1b25cc 100644
--- a/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp
+++ b/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp
@@ -334,24 +334,22 @@ class TransposeOpLowering : public OpRewritePattern<vector::TransposeOp> {
       return rewriter.notifyMatchFailure(
           op, "Options specifies lowering to shuffle");
 
-    if (vectorTransformOptions.useShapeCast) {
-      // Replace:
-      //   vector.transpose %0, [1, 0] : vector<nx1x<eltty>> to
-      //                                 vector<1xnxelty>
-      // with:
-      //   vector.shape_cast %0 : vector<nx1x<eltty>> to vector<1xnxelty>
-      //
-      // Source with leading unit dim (inverse) is also replaced. Unit dim must
-      // be fixed. Non-unit can be scalable.
-      if (resType.getRank() == 2 &&
-          ((resType.getShape().front() == 1 &&
-            !resType.getScalableDims().front()) ||
-           (resType.getShape().back() == 1 &&
-            !resType.getScalableDims().back())) &&
-          transp == ArrayRef<int64_t>({1, 0})) {
-        rewriter.replaceOpWithNewOp<vector::ShapeCastOp>(op, resType, input);
-        return success();
-      }
+    // Replace:
+    //   vector.transpose %0, [1, 0] : vector<nx1x<eltty>> to
+    //                                 vector<1xnxelty>
+    // with:
+    //   vector.shape_cast %0 : vector<nx1x<eltty>> to vector<1xnxelty>
+    //
+    // Source with leading unit dim (inverse) is also replaced. Unit dim must
+    // be fixed. Non-unit can be scalable.
+    if (resType.getRank() == 2 &&
+        ((resType.getShape().front() == 1 &&
+          !resType.getScalableDims().front()) ||
+         (resType.getShape().back() == 1 &&
+          !resType.getScalableDims().back())) &&
+        transp == ArrayRef<int64_t>({1, 0})) {
+      rewriter.replaceOpWithNewOp<vector::ShapeCastOp>(op, resType, input);
+      return success();
     }
 
     if (inputType.isScalable())

>From 756295782287375054ca5ee581fa533bac3e1123 Mon Sep 17 00:00:00 2001
From: ChipsSpectre <maximilian.hornung at tum.de>
Date: Sun, 17 Dec 2023 09:58:58 +0100
Subject: [PATCH 5/5] [clang][Parse] `TryAnnotateCXXScopeToken` to be called
 only when parsing C++

Assume `TryAnnotateCXXScopeToken` to be parsing C++ code in all of its paths.

Fixes: https://github.com/llvm/llvm-project/issues/73559.
---
 clang/docs/ReleaseNotes.rst  | 2 +-
 clang/test/Parser/cxx-in-c.c | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 59f131ea79465f..92a5b5e39edbcc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -641,7 +641,7 @@ Bug Fixes in This Version
   Fixes (`#67317 <https://github.com/llvm/llvm-project/issues/67317>`_)
 - Clang now properly diagnoses use of stand-alone OpenMP directives after a
   label (including ``case`` or ``default`` labels).
-- Fix crash when using C++ only tokens like *::* in C compiler clang.
+- Fix crash when using C++ only tokens like ``::`` in C compiler clang.
   Fixes (`#73559 https://github.com/llvm/llvm-project/issues/73559`_)
 
   Before:
diff --git a/clang/test/Parser/cxx-in-c.c b/clang/test/Parser/cxx-in-c.c
index bd304260571c4d..034a44cdf12bfa 100644
--- a/clang/test/Parser/cxx-in-c.c
+++ b/clang/test/Parser/cxx-in-c.c
@@ -3,4 +3,6 @@
 // PR9137
 void f0(int x) : {}; // expected-error{{expected function body after function declarator}}
 void f1(int x) try {}; // expected-error{{expected function body after function declarator}}
-::; // expected-error{{expected that double colon marker does not appear in c}}
+
+// GH73559
+::; // expected-error{{expected identifier or '('}}



More information about the Mlir-commits mailing list