Author: Jamie Schmeiser Date: 2021-05-20T12:39:04-04:00 New Revision: 136ced498ba84f6b6126051626e319f18ba740f5
URL: https://github.com/llvm/llvm-project/commit/136ced498ba84f6b6126051626e319f18ba740f5 DIFF: https://github.com/llvm/llvm-project/commit/136ced498ba84f6b6126051626e319f18ba740f5.diff LOG: When vector is found as a type or non-type id, check if it is really the altivec vector token. Summary: Call TryAltiVecVectorToken when an identifier is seen in the parser before annotating the token. This checks the next token where necessary to ensure that vector is properly handled as the altivec token. Author: Jamie Schmeiser <schme...@ca.ibm.com> Reviewed By: ZarkoCA (Zarko Todorovski) Differential Revision: https://reviews.llvm.org/D100991 Added: clang/test/Parser/altivec-non-type-vector.c clang/test/Parser/altivec-template-vector.cpp clang/test/Parser/altivec-typedef-vector.c Modified: clang/lib/Parse/Parser.cpp Removed: ################################################################################ diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 389180ea01f7..cbcbca127c9d 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -1695,6 +1695,11 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC) { break; case Sema::NC_Type: { + if (TryAltiVecVectorToken()) + // vector has been found as a type id when altivec is enabled but + // this is followed by a declaration specifier so this is really the + // altivec vector token. Leave it unannotated. + break; SourceLocation BeginLoc = NameLoc; if (SS.isNotEmpty()) BeginLoc = SS.getBeginLoc(); @@ -1736,6 +1741,11 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC) { return ANK_Success; case Sema::NC_NonType: + if (TryAltiVecVectorToken()) + // vector has been found as a non-type id when altivec is enabled but + // this is followed by a declaration specifier so this is really the + // altivec vector token. Leave it unannotated. + break; Tok.setKind(tok::annot_non_type); setNonTypeAnnotation(Tok, Classification.getNonTypeDecl()); Tok.setLocation(NameLoc); diff --git a/clang/test/Parser/altivec-non-type-vector.c b/clang/test/Parser/altivec-non-type-vector.c new file mode 100644 index 000000000000..d0868a60d0c3 --- /dev/null +++ b/clang/test/Parser/altivec-non-type-vector.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-ibm-aix-xcoff +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64le-ibm-linux-gnu +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-linux-gnu +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc-ibm-aix-xcoff +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc-linux-gnu + +int vector(); + +void test() { + vector unsigned int v = {0}; +} diff --git a/clang/test/Parser/altivec-template-vector.cpp b/clang/test/Parser/altivec-template-vector.cpp new file mode 100644 index 000000000000..f0c1d86563fe --- /dev/null +++ b/clang/test/Parser/altivec-template-vector.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-ibm-aix-xcoff +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64le-ibm-linux-gnu +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-linux-gnu +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc-ibm-aix-xcoff +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc-linux-gnu + +template <typename T> class vector { +public: + vector(int) {} +}; + +void f() { + vector int v = {0}; + vector<int> vi = {0}; +} diff --git a/clang/test/Parser/altivec-typedef-vector.c b/clang/test/Parser/altivec-typedef-vector.c new file mode 100644 index 000000000000..5e00824b4de7 --- /dev/null +++ b/clang/test/Parser/altivec-typedef-vector.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-ibm-aix-xcoff +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64le-ibm-linux-gnu +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-linux-gnu +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc-ibm-aix-xcoff +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc-linux-gnu + +typedef int vector; + +void test() { + vector unsigned int v = {0}; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits