fix PR5500: clang fails to parse inline asm with :: in C++ mode
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91802 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp
index c3595b9..9085b87 100644
--- a/lib/Parse/ParseStmt.cpp
+++ b/lib/Parse/ParseStmt.cpp
@@ -1259,18 +1259,32 @@
}
// Parse Outputs, if present.
- if (Tok.is(tok::colon)) {
+ bool AteExtraColon = false;
+ if (Tok.is(tok::colon) || Tok.is(tok::coloncolon)) {
+ // In C++ mode, parse "::" like ": :".
+ AteExtraColon = Tok.is(tok::coloncolon);
ConsumeToken();
- if (ParseAsmOperandsOpt(Names, Constraints, Exprs))
+ if (!AteExtraColon &&
+ ParseAsmOperandsOpt(Names, Constraints, Exprs))
return StmtError();
}
+
unsigned NumOutputs = Names.size();
// Parse Inputs, if present.
- if (Tok.is(tok::colon)) {
- ConsumeToken();
- if (ParseAsmOperandsOpt(Names, Constraints, Exprs))
+ if (AteExtraColon ||
+ Tok.is(tok::colon) || Tok.is(tok::coloncolon)) {
+ // In C++ mode, parse "::" like ": :".
+ if (AteExtraColon)
+ AteExtraColon = false;
+ else {
+ AteExtraColon = Tok.is(tok::coloncolon);
+ ConsumeToken();
+ }
+
+ if (!AteExtraColon &&
+ ParseAsmOperandsOpt(Names, Constraints, Exprs))
return StmtError();
}
@@ -1281,8 +1295,9 @@
unsigned NumInputs = Names.size() - NumOutputs;
// Parse the clobbers, if present.
- if (Tok.is(tok::colon)) {
- ConsumeToken();
+ if (AteExtraColon || Tok.is(tok::colon)) {
+ if (!AteExtraColon)
+ ConsumeToken();
// Parse the asm-string list for clobbers.
while (1) {
diff --git a/test/Parser/cxx-stmt.cpp b/test/Parser/cxx-stmt.cpp
index 3fd3e25..fdd573e 100644
--- a/test/Parser/cxx-stmt.cpp
+++ b/test/Parser/cxx-stmt.cpp
@@ -52,3 +52,9 @@
case Type: i = 7; break; // no error.
}
}
+
+// PR5500
+void f5() {
+ asm volatile ("":: :"memory");
+ asm volatile ("": ::"memory");
+}