[llvm-branch-commits] [clang] 3733420 - When vector is found as a type or non-type id, check if it is really the

Jamie Schmeiser via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Apr 21 12:42:07 PDT 2021


Author: Jamie Schmeiser
Date: 2021-04-21T14:36:00-04:00
New Revision: 3733420a974201b8439f83441aaa8bcf3610fab6

URL: https://github.com/llvm/llvm-project/commit/3733420a974201b8439f83441aaa8bcf3610fab6
DIFF: https://github.com/llvm/llvm-project/commit/3733420a974201b8439f83441aaa8bcf3610fab6.diff

LOG: When vector is found as a type or non-type id, check if it is really the
altivec vector token.

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.

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 b178b56e967c6..c4f5f5d3c49d0 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 0000000000000..38e170da62a99
--- /dev/null
+++ b/clang/test/Parser/altivec-non-type-vector.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s
+
+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 0000000000000..3b349e778e1ff
--- /dev/null
+++ b/clang/test/Parser/altivec-template-vector.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -target-feature +altivec %s
+
+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 0000000000000..e94d332b5d79e
--- /dev/null
+++ b/clang/test/Parser/altivec-typedef-vector.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s
+
+typedef int vector;
+
+void test() {
+  vector unsigned int v = {0};
+}


        


More information about the llvm-branch-commits mailing list