[cfe-commits] r142636 - in /cfe/trunk: include/clang/Basic/TokenKinds.def include/clang/Parse/Parser.h lib/Parse/ParseStmt.cpp lib/Parse/Parser.cpp test/Sema/__try.c test/SemaCXX/MicrosoftExtensions.cpp
Douglas Gregor
dgregor at apple.com
Thu Oct 20 20:57:52 PDT 2011
Author: dgregor
Date: Thu Oct 20 22:57:52 2011
New Revision: 142636
URL: http://llvm.org/viewvc/llvm-project?rev=142636&view=rev
Log:
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>.
Modified:
cfe/trunk/include/clang/Basic/TokenKinds.def
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/test/Sema/__try.c
cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
Modified: cfe/trunk/include/clang/Basic/TokenKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=142636&r1=142635&r2=142636&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TokenKinds.def (original)
+++ cfe/trunk/include/clang/Basic/TokenKinds.def Thu Oct 20 22:57:52 2011
@@ -485,7 +485,6 @@
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)
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=142636&r1=142635&r2=142636&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Thu Oct 20 22:57:52 2011
@@ -112,6 +112,9 @@
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 @@
/// declaration is finished.
DelayedCleanupPool TopLevelDeclCleanupPool;
+ IdentifierInfo *getSEHExceptKeyword();
+
public:
Parser(Preprocessor &PP, Sema &Actions);
~Parser();
Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=142636&r1=142635&r2=142636&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Thu Oct 20 22:57:52 2011
@@ -355,7 +355,8 @@
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 @@
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);
}
Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=142636&r1=142635&r2=142636&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Thu Oct 20 22:57:52 2011
@@ -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 @@
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;
Modified: cfe/trunk/test/Sema/__try.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/__try.c?rev=142636&r1=142635&r2=142636&view=diff
==============================================================================
--- cfe/trunk/test/Sema/__try.c (original)
+++ cfe/trunk/test/Sema/__try.c Thu Oct 20 22:57:52 2011
@@ -20,7 +20,7 @@
#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 @@
} // 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}}
}
}
Modified: cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp?rev=142636&r1=142635&r2=142636&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp (original)
+++ cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp Thu Oct 20 22:57:52 2011
@@ -210,3 +210,6 @@
int array[__is_abstract(X)? 1 : -1];
};
+
+void f() { int __except = 0; }
+
More information about the cfe-commits
mailing list