[Mlir-commits] [mlir] [clang] fix issue 73559. (PR #74926)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Dec 17 01:01:05 PST 2023
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/2] 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 84b14beea4c2a106c656058efc72aec6afb36853 Mon Sep 17 00:00:00 2001
From: ChipsSpectre <maximilian.hornung at tum.de>
Date: Sun, 17 Dec 2023 10:00:31 +0100
Subject: [PATCH 2/2] [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/lib/Parse/ParseDeclCXX.cpp | 4 ++-
clang/test/Parser/cxx-in-c.c | 3 ++
.../Vector/Transforms/VectorTransforms.h | 10 ------
.../Transforms/LowerVectorTranspose.cpp | 34 +++++++++----------
5 files changed, 24 insertions(+), 29 deletions(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 783dc7333af7e2..92a5b5e39edbcc 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..1cf16a752cfcdc 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2679,6 +2679,8 @@ Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
ParsedAttributes &AccessAttrs,
const ParsedTemplateInfo &TemplateInfo,
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..034a44cdf12bfa 100644
--- a/clang/test/Parser/cxx-in-c.c
+++ b/clang/test/Parser/cxx-in-c.c
@@ -3,3 +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}}
+
+// GH73559
+::; // expected-error{{expected identifier or '('}}
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())
More information about the Mlir-commits
mailing list