Skip to content

Commit

Permalink
When vector is found as a type or non-type id, check if it is really the
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jamieschmeiser committed Apr 21, 2021
1 parent 35c564d commit 3733420
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions clang/lib/Parse/Parser.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions 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};
}
11 changes: 11 additions & 0 deletions 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};
}
7 changes: 7 additions & 0 deletions 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};
}

0 comments on commit 3733420

Please sign in to comment.