https://github.com/ChipsSpectre updated https://github.com/llvm/llvm-project/pull/74926
>From 8a3e710de9122ac74ab886f8878e01893c19ee87 Mon Sep 17 00:00:00 2001 From: ChipsSpectre <maximilian.horn...@tum.de> Date: Sun, 17 Dec 2023 10:01:39 +0100 Subject: [PATCH 1/4] [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/ParseDecl.cpp | 3 +- clang/lib/Parse/ParseDeclCXX.cpp | 2 ++ clang/test/Parser/cxx-in-c.c | 3 ++ .../Vector/Transforms/VectorTransforms.h | 10 ------ .../Transforms/LowerVectorTranspose.cpp | 34 +++++++++---------- 6 files changed, 25 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/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..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); 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()) >From a15e84572bd41df97c118c3674c2cb2e6a2f2c03 Mon Sep 17 00:00:00 2001 From: ChipsSpectre <maximilian.horn...@tum.de> Date: Sun, 17 Dec 2023 10:04:24 +0100 Subject: [PATCH 2/4] . --- .../Vector/Transforms/VectorTransforms.h | 10 ++++++ .../Transforms/LowerVectorTranspose.cpp | 34 ++++++++++--------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h b/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h index 08d3bb157a0e39..7ad410c9e825e9 100644 --- a/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h +++ b/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h @@ -59,6 +59,16 @@ 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 97f6caca1b25cc..4d43a76c4a4efc 100644 --- a/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp +++ b/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp @@ -334,22 +334,24 @@ class TransposeOpLowering : public OpRewritePattern<vector::TransposeOp> { return rewriter.notifyMatchFailure( op, "Options specifies lowering to shuffle"); - // 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 (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(); + } } if (inputType.isScalable()) >From e5e0dd731efbf986c6ad47ecc0fa6888564337c3 Mon Sep 17 00:00:00 2001 From: ChipsSpectre <maximilian.horn...@tum.de> Date: Sun, 17 Dec 2023 10:06:29 +0100 Subject: [PATCH 3/4] . --- mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h b/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h index 7ad410c9e825e9..ef405214d1b9f2 100644 --- a/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h +++ b/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h @@ -58,8 +58,7 @@ struct VectorTransformsOptions { VectorTransformsOptions &setVectorTransferSplit(VectorTransferSplit opt) { 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 >From 7d7170cdf623d950c77d6c490c8d05e2e0925943 Mon Sep 17 00:00:00 2001 From: ChipsSpectre <maximilian.horn...@tum.de> Date: Sun, 17 Dec 2023 10:08:37 +0100 Subject: [PATCH 4/4] . --- mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h b/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h index ef405214d1b9f2..41ffc929946027 100644 --- a/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h +++ b/mlir/include/mlir/Dialect/Vector/Transforms/VectorTransforms.h @@ -58,7 +58,8 @@ struct VectorTransformsOptions { VectorTransformsOptions &setVectorTransferSplit(VectorTransferSplit opt) { 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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits