aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-10-21 03:57:52 +0000
committerDouglas Gregor <dgregor@apple.com>2011-10-21 03:57:52 +0000
commitb57791e5b40afa6691063c83d0e95c416fb19fde (patch)
treed78816125dc3762c59239aa6630851f0c0b77ef3
parent258f9a2c33b010ddeca6902012461cdd4d5f14ef (diff)
Treat the Microsoft/Borland keyword "__except" as a context-sensitive
keyword, because both libstdc++ and libc++ use "__except" as an identifier. Fixes <rdar://problem/10322555>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142636 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/TokenKinds.def1
-rw-r--r--include/clang/Parse/Parser.h5
-rw-r--r--lib/Parse/ParseStmt.cpp10
-rw-r--r--lib/Parse/Parser.cpp10
-rw-r--r--test/Sema/__try.c5
-rw-r--r--test/SemaCXX/MicrosoftExtensions.cpp3
6 files changed, 28 insertions, 6 deletions
diff --git a/include/clang/Basic/TokenKinds.def b/include/clang/Basic/TokenKinds.def
index cd0cd06a61..de345af701 100644
--- a/include/clang/Basic/TokenKinds.def
+++ b/include/clang/Basic/TokenKinds.def
@@ -485,7 +485,6 @@ KEYWORD(__ptr32 , KEYMS)
KEYWORD(__w64 , KEYMS)
KEYWORD(__uuidof , KEYMS | KEYBORLAND)
KEYWORD(__try , KEYMS | KEYBORLAND)
-KEYWORD(__except , KEYMS | KEYBORLAND)
KEYWORD(__finally , KEYMS | KEYBORLAND)
KEYWORD(__leave , KEYMS | KEYBORLAND)
KEYWORD(__int64 , KEYMS)
diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h
index e28bcf2001..5cd6e44870 100644
--- a/include/clang/Parse/Parser.h
+++ b/include/clang/Parse/Parser.h
@@ -112,6 +112,9 @@ class Parser : public CodeCompletionHandler {
IdentifierInfo *Ident__exception_info, *Ident___exception_info, *Ident_GetExceptionInfo; // __except filter expression
IdentifierInfo *Ident__abnormal_termination, *Ident___abnormal_termination, *Ident_AbnormalTermination; // __finally
+ /// Contextual keywords for Microsoft extensions.
+ IdentifierInfo *Ident__except;
+
/// Ident_super - IdentifierInfo for "super", to support fast
/// comparison.
IdentifierInfo *Ident_super;
@@ -179,6 +182,8 @@ class Parser : public CodeCompletionHandler {
/// declaration is finished.
DelayedCleanupPool TopLevelDeclCleanupPool;
+ IdentifierInfo *getSEHExceptKeyword();
+
public:
Parser(Preprocessor &PP, Sema &Actions);
~Parser();
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp
index 3df761af44..8968a43480 100644
--- a/lib/Parse/ParseStmt.cpp
+++ b/lib/Parse/ParseStmt.cpp
@@ -355,7 +355,8 @@ StmtResult Parser::ParseSEHTryBlockCommon(SourceLocation TryLoc) {
return move(TryBlock);
StmtResult Handler;
- if(Tok.is(tok::kw___except)) {
+ if (Tok.is(tok::identifier) &&
+ Tok.getIdentifierInfo() == getSEHExceptKeyword()) {
SourceLocation Loc = ConsumeToken();
Handler = ParseSEHExceptBlock(Loc);
} else if (Tok.is(tok::kw___finally)) {
@@ -2037,10 +2038,13 @@ StmtResult Parser::ParseCXXTryBlockCommon(SourceLocation TryLoc) {
return move(TryBlock);
// Borland allows SEH-handlers with 'try'
- if(Tok.is(tok::kw___except) || Tok.is(tok::kw___finally)) {
+
+ if((Tok.is(tok::identifier) &&
+ Tok.getIdentifierInfo() == getSEHExceptKeyword()) ||
+ Tok.is(tok::kw___finally)) {
// TODO: Factor into common return ParseSEHHandlerCommon(...)
StmtResult Handler;
- if(Tok.is(tok::kw___except)) {
+ if(Tok.getIdentifierInfo() == getSEHExceptKeyword()) {
SourceLocation Loc = ConsumeToken();
Handler = ParseSEHExceptBlock(Loc);
}
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp
index 2e0c46dbdb..2face304c0 100644
--- a/lib/Parse/Parser.cpp
+++ b/lib/Parse/Parser.cpp
@@ -23,6 +23,14 @@
#include "clang/AST/ASTConsumer.h"
using namespace clang;
+IdentifierInfo *Parser::getSEHExceptKeyword() {
+ // __except is accepted as a (contextual) keyword
+ if (!Ident__except && (getLang().MicrosoftExt || getLang().Borland))
+ Ident__except = PP.getIdentifierInfo("__except");
+
+ return Ident__except;
+}
+
Parser::Parser(Preprocessor &pp, Sema &actions)
: PP(pp), Actions(actions), Diags(PP.getDiagnostics()),
GreaterThanIsOperator(true), ColonIsSacred(false),
@@ -431,6 +439,8 @@ void Parser::Initialize() {
Ident_obsoleted = 0;
Ident_unavailable = 0;
+ Ident__except = 0;
+
Ident__exception_code = Ident__exception_info = Ident__abnormal_termination = 0;
Ident___exception_code = Ident___exception_info = Ident___abnormal_termination = 0;
Ident_GetExceptionCode = Ident_GetExceptionInfo = Ident_AbnormalTermination = 0;
diff --git a/test/Sema/__try.c b/test/Sema/__try.c
index 5490aea539..1641402e7e 100644
--- a/test/Sema/__try.c
+++ b/test/Sema/__try.c
@@ -20,7 +20,7 @@ void __abnormal_termination();
#pragma sysheader end
-DWORD FilterExpression(int);
+DWORD FilterExpression(int); // expected-note{{declared here}}
DWORD FilterExceptionInformation(struct EXCEPTION_INFO*);
const char * NotFilterExpression();
@@ -47,7 +47,8 @@ void TEST() {
} // expected-error{{expected '__except' or '__finally' block}}
void TEST() {
- __except ( FilterExpression() ) { // expected-error{{}}
+ __except ( FilterExpression() ) { // expected-warning{{implicit declaration of function '__except' is invalid in C99}} \
+ // expected-error{{too few arguments to function call, expected 1, have 0}}
}
}
diff --git a/test/SemaCXX/MicrosoftExtensions.cpp b/test/SemaCXX/MicrosoftExtensions.cpp
index ddf5d9d6a1..62f4f61471 100644
--- a/test/SemaCXX/MicrosoftExtensions.cpp
+++ b/test/SemaCXX/MicrosoftExtensions.cpp
@@ -210,3 +210,6 @@ struct PR11150 {
int array[__is_abstract(X)? 1 : -1];
};
+
+void f() { int __except = 0; }
+