]> granicus.if.org Git - clang/commitdiff
Simplify the scheme used for keywords, and change the classification
authorEli Friedman <eli.friedman@gmail.com>
Tue, 28 Apr 2009 03:13:54 +0000 (03:13 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Tue, 28 Apr 2009 03:13:54 +0000 (03:13 +0000)
scheme to be more useful.

The new scheme introduces a set of categories that should be more
readable, and also reflects what we want to consider as an extension
more accurately.  Specifically, it makes the "what is a keyword"
determination accurately reflect whether the keyword is a GNU or
Microsoft extension.

I also introduced separate flags for keyword aliases; this is useful
because the classification of the aliases is mostly unrelated to the
classification of the original keyword.

This patch treats anything that's in the implementation
namespace (prefixed with "__", or "_X" where "X" is any upper-case
letter) as a keyword without marking it as an extension.  This is
consistent with the standards in that an implementation is allowed to define
arbitrary extensions in the implementation namespace without violating
the standard. This gets rid of all the nasty "extension used" warnings
for stuff like __attribute__ in -pedantic mode.  We still warn for
extensions outside of the the implementation namespace, like typeof.
If someone wants to implement -Wextensions or something like that, we
could add additional information to the keyword table.

This also removes processing for the unused "Boolean" language option;
such an extension isn't supported on any other C implementation, so I
don't see any point to adding it.

The changes to test/CodeGen/inline.c are required because previously, we
weren't actually disabling the "inline" keyword in -std=c89 mode.

I'll remove Boolean and NoExtensions from LangOptions in a follow-up
commit.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70281 91177308-0d34-0410-b5e6-96231b3b80d8

12 files changed:
include/clang/Basic/TokenKinds.def
lib/Basic/IdentifierTable.cpp
test/CodeGen/inline.c
test/Parser/attributes.c
test/Parser/declarators.c
test/Parser/recovery.c
test/Preprocessor/extension-warning.c
test/Sema/builtins.c
test/Sema/constant-builtins.c
test/Sema/exprs.c
test/Sema/function.c
test/Sema/i-c-e.c

index f1b6f424333e9e5fbee3e1d55561e70dafad82a8..d5575ca99ace1344763d1a847543e72c24c59a4b 100644 (file)
@@ -21,7 +21,7 @@
 #define KEYWORD(X,Y) TOK(kw_ ## X)
 #endif
 #ifndef ALIAS
-#define ALIAS(X,Y)
+#define ALIAS(X,Y,Z)
 #endif
 #ifndef PPKEYWORD
 #define PPKEYWORD(X)
@@ -173,90 +173,86 @@ TOK(at)                  // @
 
 // C99 6.4.1: Keywords.  These turn into kw_* tokens.
 // Flags allowed:
-//   NOTC90 - In C90, this token is never available.
-//   EXTC90 - In C90, this token is an extension that is enabled unless strict.
-//   NOTC99 - In C99, this token is never available.
-//   EXTC99 - In C99, this token is an extension that is enabled unless strict.
-//   NOTCPP - In C++98, this token is never available.
-//   EXTCPP - In C++98, this token is an extension that is enabled unless strict.
-//   NOTCPP0x - In C++0x, this token is never available.
-//   EXTCPP0x - In C++0x, this token is an extension that is enabled unless 
-//              strict.
+//   KEYALL   - This is a keyword in all variants of C and C++, or it
+//              is a keyword in the implementation namespace that should
+//              always be treated as a keyword
+//   KEYC99   - This is a keyword introduced to C in C99
+//   KEYCXX   - This is a C++ keyword, or a C++-specific keyword in the
+//              implementation namespace
+//   KEYCXX0X - This is a C++ keyword introduced to C++ in C++0x
+//   KEYGNU   - This is a keyword if GNU extensions are enabled
+//   KEYMS    - This is a keyword if Microsoft extensions are enabled
 //
-KEYWORD(auto                        , 0)
-KEYWORD(break                       , 0)
-KEYWORD(case                        , 0)
-KEYWORD(char                        , 0)
-KEYWORD(const                       , 0)
-KEYWORD(continue                    , 0)
-KEYWORD(default                     , 0)
-KEYWORD(do                          , 0)
-KEYWORD(double                      , 0)
-KEYWORD(else                        , 0)
-KEYWORD(enum                        , 0)
-KEYWORD(extern                      , 0)
-KEYWORD(float                       , 0)
-KEYWORD(for                         , 0)
-KEYWORD(goto                        , 0)
-KEYWORD(if                          , 0)
-KEYWORD(inline                      , EXTC90)  // Ext in C90, ok in C99/C++
-KEYWORD(int                         , 0)
-KEYWORD(long                        , 0)
-KEYWORD(register                    , 0)
-KEYWORD(restrict                    , NOTC90)    // Not in C90
-KEYWORD(return                      , 0)
-KEYWORD(short                       , 0)
-KEYWORD(signed                      , 0)
-KEYWORD(sizeof                      , 0)
-KEYWORD(static                      , 0)
-KEYWORD(struct                      , 0)
-KEYWORD(switch                      , 0)
-KEYWORD(typedef                     , 0)
-KEYWORD(union                       , 0)
-KEYWORD(unsigned                    , 0)
-KEYWORD(void                        , 0)
-KEYWORD(volatile                    , 0)
-KEYWORD(while                       , 0)
-KEYWORD(_Bool                       , EXTC90|EXTCPP|EXTCPP0x)  // C99 only
-KEYWORD(_Complex                    , EXTC90|EXTCPP|EXTCPP0x)  // C99 only
-KEYWORD(_Imaginary                  , EXTC90|NOTCPP|NOTCPP0x)  // C90 only
-
-// Special tokens to the compiler.
-KEYWORD(__func__                    , EXTC90|EXTCPP|EXTCPP0x) // Only in C99.
-KEYWORD(__FUNCTION__                , EXTC90|EXTC99|EXTCPP|EXTCPP0x) // GCC Extension.
-KEYWORD(__PRETTY_FUNCTION__         , EXTC90|EXTC99|EXTCPP|EXTCPP0x) // GCC Extension.
+KEYWORD(auto                        , KEYALL)
+KEYWORD(break                       , KEYALL)
+KEYWORD(case                        , KEYALL)
+KEYWORD(char                        , KEYALL)
+KEYWORD(const                       , KEYALL)
+KEYWORD(continue                    , KEYALL)
+KEYWORD(default                     , KEYALL)
+KEYWORD(do                          , KEYALL)
+KEYWORD(double                      , KEYALL)
+KEYWORD(else                        , KEYALL)
+KEYWORD(enum                        , KEYALL)
+KEYWORD(extern                      , KEYALL)
+KEYWORD(float                       , KEYALL)
+KEYWORD(for                         , KEYALL)
+KEYWORD(goto                        , KEYALL)
+KEYWORD(if                          , KEYALL)
+KEYWORD(inline                      , KEYC99|KEYCXX|KEYGNU)
+KEYWORD(int                         , KEYALL)
+KEYWORD(long                        , KEYALL)
+KEYWORD(register                    , KEYALL)
+KEYWORD(restrict                    , KEYC99|KEYGNU)
+KEYWORD(return                      , KEYALL)
+KEYWORD(short                       , KEYALL)
+KEYWORD(signed                      , KEYALL)
+KEYWORD(sizeof                      , KEYALL)
+KEYWORD(static                      , KEYALL)
+KEYWORD(struct                      , KEYALL)
+KEYWORD(switch                      , KEYALL)
+KEYWORD(typedef                     , KEYALL)
+KEYWORD(union                       , KEYALL)
+KEYWORD(unsigned                    , KEYALL)
+KEYWORD(void                        , KEYALL)
+KEYWORD(volatile                    , KEYALL)
+KEYWORD(while                       , KEYALL)
+KEYWORD(_Bool                       , KEYALL)
+KEYWORD(_Complex                    , KEYALL)
+KEYWORD(_Imaginary                  , KEYALL)
+KEYWORD(__func__                    , KEYALL)
 
 // C++ 2.11p1: Keywords.
-KEYWORD(asm                         , EXTC90|EXTC99) // Exts in C90/C99
-KEYWORD(bool                        , BOOLSUPPORT)
-KEYWORD(catch                       , NOTC90|NOTC99)
-KEYWORD(class                       , NOTC90|NOTC99)
-KEYWORD(const_cast                  , NOTC90|NOTC99)
-KEYWORD(delete                      , NOTC90|NOTC99)
-KEYWORD(dynamic_cast                , NOTC90|NOTC99)
-KEYWORD(explicit                    , NOTC90|NOTC99)
-KEYWORD(export                      , NOTC90|NOTC99)
-KEYWORD(false                       , BOOLSUPPORT)
-KEYWORD(friend                      , NOTC90|NOTC99)
-KEYWORD(mutable                     , NOTC90|NOTC99)
-KEYWORD(namespace                   , NOTC90|NOTC99)
-KEYWORD(new                         , NOTC90|NOTC99)
-KEYWORD(operator                    , NOTC90|NOTC99)
-KEYWORD(private                     , NOTC90|NOTC99)
-KEYWORD(protected                   , NOTC90|NOTC99)
-KEYWORD(public                      , NOTC90|NOTC99)
-KEYWORD(reinterpret_cast            , NOTC90|NOTC99)
-KEYWORD(static_cast                 , NOTC90|NOTC99)
-KEYWORD(template                    , NOTC90|NOTC99)
-KEYWORD(this                        , NOTC90|NOTC99)
-KEYWORD(throw                       , NOTC90|NOTC99)
-KEYWORD(true                        , BOOLSUPPORT)
-KEYWORD(try                         , NOTC90|NOTC99)
-KEYWORD(typename                    , NOTC90|NOTC99)
-KEYWORD(typeid                      , NOTC90|NOTC99)
-KEYWORD(using                       , NOTC90|NOTC99)
-KEYWORD(virtual                     , NOTC90|NOTC99)
-KEYWORD(wchar_t                     , NOTC90|NOTC99)
+KEYWORD(asm                         , KEYCXX|KEYGNU)
+KEYWORD(bool                        , KEYCXX)
+KEYWORD(catch                       , KEYCXX)
+KEYWORD(class                       , KEYCXX)
+KEYWORD(const_cast                  , KEYCXX)
+KEYWORD(delete                      , KEYCXX)
+KEYWORD(dynamic_cast                , KEYCXX)
+KEYWORD(explicit                    , KEYCXX)
+KEYWORD(export                      , KEYCXX)
+KEYWORD(false                       , KEYCXX)
+KEYWORD(friend                      , KEYCXX)
+KEYWORD(mutable                     , KEYCXX)
+KEYWORD(namespace                   , KEYCXX)
+KEYWORD(new                         , KEYCXX)
+KEYWORD(operator                    , KEYCXX)
+KEYWORD(private                     , KEYCXX)
+KEYWORD(protected                   , KEYCXX)
+KEYWORD(public                      , KEYCXX)
+KEYWORD(reinterpret_cast            , KEYCXX)
+KEYWORD(static_cast                 , KEYCXX)
+KEYWORD(template                    , KEYCXX)
+KEYWORD(this                        , KEYCXX)
+KEYWORD(throw                       , KEYCXX)
+KEYWORD(true                        , KEYCXX)
+KEYWORD(try                         , KEYCXX)
+KEYWORD(typename                    , KEYCXX)
+KEYWORD(typeid                      , KEYCXX)
+KEYWORD(using                       , KEYCXX)
+KEYWORD(virtual                     , KEYCXX)
+KEYWORD(wchar_t                     , KEYCXX)
 
 // C++ 2.5p2: Alternative Representations.
 CXX_KEYWORD_OPERATOR(and     , ampamp)
@@ -272,92 +268,96 @@ CXX_KEYWORD_OPERATOR(xor     , caret)
 CXX_KEYWORD_OPERATOR(xor_eq  , caretequal)
 
 // C++0x keywords
-KEYWORD(alignof                     , NOTC90|NOTC99|NOTCPP)
-KEYWORD(axiom                       , NOTC90|NOTC99|NOTCPP)
-KEYWORD(char16_t                    , NOTC90|NOTC99|NOTCPP)
-KEYWORD(char32_t                    , NOTC90|NOTC99|NOTCPP)
-KEYWORD(concept                     , NOTC90|NOTC99|NOTCPP)
-KEYWORD(concept_map                 , NOTC90|NOTC99|NOTCPP)
-KEYWORD(constexpr                   , NOTC90|NOTC99|NOTCPP)
-KEYWORD(decltype                    , NOTC90|NOTC99|NOTCPP)
-KEYWORD(late_check                  , NOTC90|NOTC99|NOTCPP)
-KEYWORD(nullptr                     , NOTC90|NOTC99|NOTCPP)
-KEYWORD(requires                    , NOTC90|NOTC99|NOTCPP)
-KEYWORD(static_assert               , NOTC90|NOTC99|NOTCPP)
-KEYWORD(thread_local                , NOTC90|NOTC99|NOTCPP)
-
-// GNU Extensions.
-KEYWORD(_Decimal32                  , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
-KEYWORD(_Decimal64                  , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
-KEYWORD(_Decimal128                 , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
-KEYWORD(typeof                      , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
-KEYWORD(__null                      , NOTC90|NOTC99|EXTCPP|EXTCPP0x) // C++-only Extensn
-KEYWORD(__alignof                   , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
-KEYWORD(__attribute                 , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
-KEYWORD(__builtin_choose_expr       , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
-KEYWORD(__builtin_offsetof          , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
-KEYWORD(__builtin_types_compatible_p, EXTC90|EXTC99|EXTCPP|EXTCPP0x)
-KEYWORD(__builtin_va_arg            , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
-KEYWORD(__extension__               , 0)     // Not treated as an extension!
-KEYWORD(__imag                      , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
-KEYWORD(__label__                   , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
-KEYWORD(__real                      , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
-KEYWORD(__thread                    , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
+KEYWORD(alignof                     , KEYCXX0X)
+KEYWORD(axiom                       , KEYCXX0X)
+KEYWORD(char16_t                    , KEYCXX0X)
+KEYWORD(char32_t                    , KEYCXX0X)
+KEYWORD(concept                     , KEYCXX0X)
+KEYWORD(concept_map                 , KEYCXX0X)
+KEYWORD(constexpr                   , KEYCXX0X)
+KEYWORD(decltype                    , KEYCXX0X)
+KEYWORD(late_check                  , KEYCXX0X)
+KEYWORD(nullptr                     , KEYCXX0X)
+KEYWORD(requires                    , KEYCXX0X)
+KEYWORD(static_assert               , KEYCXX0X)
+KEYWORD(thread_local                , KEYCXX0X)
+
+// GNU Extensions (in impl-reserved namespace)
+KEYWORD(_Decimal32                  , KEYALL)
+KEYWORD(_Decimal64                  , KEYALL)
+KEYWORD(_Decimal128                 , KEYALL)
+KEYWORD(__null                      , KEYCXX)
+KEYWORD(__alignof                   , KEYALL)
+KEYWORD(__attribute                 , KEYALL)
+KEYWORD(__builtin_choose_expr       , KEYALL)
+KEYWORD(__builtin_offsetof          , KEYALL)
+KEYWORD(__builtin_types_compatible_p, KEYALL)
+KEYWORD(__builtin_va_arg            , KEYALL)
+KEYWORD(__extension__               , KEYALL)
+KEYWORD(__imag                      , KEYALL)
+KEYWORD(__label__                   , KEYALL)
+KEYWORD(__real                      , KEYALL)
+KEYWORD(__thread                    , KEYALL)
+KEYWORD(__FUNCTION__                , KEYALL)
+KEYWORD(__PRETTY_FUNCTION__         , KEYALL)
+
+// GNU Extensions (outside impl-reserved namespace)
+KEYWORD(typeof                      , KEYGNU)
 
 // GNU and MS Type Traits
-KEYWORD(__has_nothrow_assign        , NOTC90|NOTC99)
-KEYWORD(__has_nothrow_copy          , NOTC90|NOTC99)
-KEYWORD(__has_nothrow_constructor   , NOTC90|NOTC99)
-KEYWORD(__has_trivial_assign        , NOTC90|NOTC99)
-KEYWORD(__has_trivial_copy          , NOTC90|NOTC99)
-KEYWORD(__has_trivial_constructor   , NOTC90|NOTC99)
-KEYWORD(__has_trivial_destructor    , NOTC90|NOTC99)
-KEYWORD(__has_virtual_destructor    , NOTC90|NOTC99)
-KEYWORD(__is_abstract               , NOTC90|NOTC99)
-KEYWORD(__is_base_of                , NOTC90|NOTC99)
-KEYWORD(__is_class                  , NOTC90|NOTC99)
-KEYWORD(__is_empty                  , NOTC90|NOTC99)
-KEYWORD(__is_enum                   , NOTC90|NOTC99)
-KEYWORD(__is_pod                    , NOTC90|NOTC99)
-KEYWORD(__is_polymorphic            , NOTC90|NOTC99)
-KEYWORD(__is_union                  , NOTC90|NOTC99)
+KEYWORD(__has_nothrow_assign        , KEYCXX)
+KEYWORD(__has_nothrow_copy          , KEYCXX)
+KEYWORD(__has_nothrow_constructor   , KEYCXX)
+KEYWORD(__has_trivial_assign        , KEYCXX)
+KEYWORD(__has_trivial_copy          , KEYCXX)
+KEYWORD(__has_trivial_constructor   , KEYCXX)
+KEYWORD(__has_trivial_destructor    , KEYCXX)
+KEYWORD(__has_virtual_destructor    , KEYCXX)
+KEYWORD(__is_abstract               , KEYCXX)
+KEYWORD(__is_base_of                , KEYCXX)
+KEYWORD(__is_class                  , KEYCXX)
+KEYWORD(__is_empty                  , KEYCXX)
+KEYWORD(__is_enum                   , KEYCXX)
+KEYWORD(__is_pod                    , KEYCXX)
+KEYWORD(__is_polymorphic            , KEYCXX)
+KEYWORD(__is_union                  , KEYCXX)
 // FIXME: Add MS's traits, too.
 
 // Apple Extension.
-KEYWORD(__private_extern__          , EXTC90|EXTC99|NOTCPP)
+KEYWORD(__private_extern__          , KEYALL)
 
 // Microsoft Extension.
-KEYWORD(__declspec                  , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
-KEYWORD(__cdecl                     , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
-KEYWORD(__stdcall                   , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
-KEYWORD(__fastcall                  , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
-KEYWORD(__ptr64                     , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
-KEYWORD(__w64                       , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
-KEYWORD(__forceinline               , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
+KEYWORD(__declspec                  , KEYALL)
+KEYWORD(__cdecl                     , KEYALL)
+KEYWORD(__stdcall                   , KEYALL)
+KEYWORD(__fastcall                  , KEYALL)
+KEYWORD(__ptr64                     , KEYALL)
+KEYWORD(__w64                       , KEYALL)
+KEYWORD(__forceinline               , KEYALL)
 
 // Alternate spelling for various tokens.  There are GCC extensions in all
 // languages, but should not be disabled in strict conformance mode.
-ALIAS("__attribute__", __attribute)
-ALIAS("__const"      , const      )
-ALIAS("__const__"    , const      )
-ALIAS("__alignof__"  , __alignof  )
-ALIAS("_asm"         , asm        )
-ALIAS("__asm"        , asm        )
-ALIAS("__asm__"      , asm        )
-ALIAS("__complex"    , _Complex   )
-ALIAS("__complex__"  , _Complex   )
-ALIAS("__imag__"     , __imag     )
-ALIAS("__inline"     , inline     )
-ALIAS("__inline__"   , inline     )
-ALIAS("__real__"     , __real     )
-ALIAS("__restrict"   , restrict   )
-ALIAS("__restrict__" , restrict   )
-ALIAS("__signed"     , signed     )
-ALIAS("__signed__"   , signed     )
-ALIAS("__typeof"     , typeof     )
-ALIAS("__typeof__"   , typeof     )
-ALIAS("__volatile"   , volatile   )
-ALIAS("__volatile__" , volatile   )
+ALIAS("__attribute__", __attribute, KEYALL)
+ALIAS("__const"      , const      , KEYALL)
+ALIAS("__const__"    , const      , KEYALL)
+ALIAS("__alignof__"  , __alignof  , KEYALL)
+ALIAS("_asm"         , asm        , KEYMS)
+ALIAS("__asm"        , asm        , KEYALL)
+ALIAS("__asm__"      , asm        , KEYALL)
+ALIAS("__complex"    , _Complex   , KEYALL)
+ALIAS("__complex__"  , _Complex   , KEYALL)
+ALIAS("__imag__"     , __imag     , KEYALL)
+ALIAS("__inline"     , inline     , KEYALL)
+ALIAS("__inline__"   , inline     , KEYALL)
+ALIAS("__real__"     , __real     , KEYALL)
+ALIAS("__restrict"   , restrict   , KEYALL)
+ALIAS("__restrict__" , restrict   , KEYALL)
+ALIAS("__signed"     , signed     , KEYALL)
+ALIAS("__signed__"   , signed     , KEYALL)
+ALIAS("__typeof"     , typeof     , KEYALL)
+ALIAS("__typeof__"   , typeof     , KEYALL)
+ALIAS("__volatile"   , volatile   , KEYALL)
+ALIAS("__volatile__" , volatile   , KEYALL)
 
 
 //===----------------------------------------------------------------------===//
index 69ee090b6e129257330f25d87a83949bd26bc5f9..cf78da986926042092e0e3ad8238a88b3079a222 100644 (file)
@@ -58,6 +58,18 @@ IdentifierTable::IdentifierTable(const LangOptions &LangOpts,
 // Language Keyword Implementation
 //===----------------------------------------------------------------------===//
 
+// Constants for TokenKinds.def
+namespace {
+  enum {
+    KEYALL = 1,
+    KEYC99 = 2,
+    KEYCXX = 4,
+    KEYCXX0X = 8,
+    KEYGNU = 16,
+    KEYMS = 32
+  };
+}
+
 /// AddKeyword - This method is used to associate a token ID with specific
 /// identifiers because they are language keywords.  This causes the lexer to
 /// automatically map matching identifiers to specialized token codes.
@@ -67,40 +79,24 @@ IdentifierTable::IdentifierTable(const LangOptions &LangOpts,
 /// in the specified language, and set to 2 if disabled in the
 /// specified language.
 static void AddKeyword(const char *Keyword, unsigned KWLen,
-                       tok::TokenKind TokenCode,
-                       int C90, int C99, int CXX, int CXX0x, int BoolSupport,
+                       tok::TokenKind TokenCode, unsigned Flags,
                        const LangOptions &LangOpts, IdentifierTable &Table) {
-  int Flags = 0;
-  if (BoolSupport != 0) {
-    Flags = LangOpts.CPlusPlus? 0 : LangOpts.Boolean ? BoolSupport : 2;
-  } else if (LangOpts.CPlusPlus) {
-    Flags = LangOpts.CPlusPlus0x ? CXX0x : CXX;
-  } else if (LangOpts.C99) {
-    Flags = C99;
-  } else {
-    Flags = C90;
-  }
-  
-  // Don't add this keyword if disabled in this language or if an extension
-  // and extensions are disabled.
-  if (Flags + LangOpts.NoExtensions >= 2) return;
-  
+  unsigned AddResult = 0;
+  if (Flags & KEYALL) AddResult = 2;
+  else if (LangOpts.CPlusPlus && (Flags & KEYCXX)) AddResult = 2;
+  else if (LangOpts.CPlusPlus0x && (Flags & KEYCXX0X)) AddResult = 2;
+  else if (LangOpts.C99 && (Flags & KEYC99)) AddResult = 2;
+  else if (LangOpts.GNUMode && (Flags & KEYGNU)) AddResult = 1;
+  else if (LangOpts.Microsoft && (Flags & KEYMS)) AddResult = 1;
+
+  // Don't add this keyword if disabled in this language.
+  if (AddResult == 0) return;
+
   IdentifierInfo &Info = Table.get(Keyword, Keyword+KWLen);
   Info.setTokenID(TokenCode);
-  Info.setIsExtensionToken(Flags == 1);
+  Info.setIsExtensionToken(AddResult == 1);
 }
 
-static void AddAlias(const char *Keyword, unsigned KWLen,
-                     tok::TokenKind AliaseeID,
-                     const char *AliaseeKeyword, unsigned AliaseeKWLen,
-                     const LangOptions &LangOpts, IdentifierTable &Table) {
-  IdentifierInfo &AliasInfo = Table.get(Keyword, Keyword+KWLen);
-  IdentifierInfo &AliaseeInfo = Table.get(AliaseeKeyword,
-                                          AliaseeKeyword+AliaseeKWLen);
-  AliasInfo.setTokenID(AliaseeID);
-  AliasInfo.setIsExtensionToken(AliaseeInfo.isExtensionToken());
-}  
-
 /// AddCXXOperatorKeyword - Register a C++ operator keyword alternative
 /// representations.
 static void AddCXXOperatorKeyword(const char *Keyword, unsigned KWLen,
@@ -122,35 +118,13 @@ static void AddObjCKeyword(tok::ObjCKeywordKind ObjCID,
 /// AddKeywords - Add all keywords to the symbol table.
 ///
 void IdentifierTable::AddKeywords(const LangOptions &LangOpts) {
-  enum {
-    C90Shift = 0,
-    EXTC90   = 1 << C90Shift,
-    NOTC90   = 2 << C90Shift,
-    C99Shift = 2,
-    EXTC99   = 1 << C99Shift,
-    NOTC99   = 2 << C99Shift,
-    CPPShift = 4,
-    EXTCPP   = 1 << CPPShift,
-    NOTCPP   = 2 << CPPShift,
-    CPP0xShift = 6,
-    EXTCPP0x   = 1 << CPP0xShift,
-    NOTCPP0x   = 2 << CPP0xShift,
-    BoolShift = 8,
-    BOOLSUPPORT = 1 << BoolShift,
-    Mask     = 3
-  };
-  
   // Add keywords and tokens for the current language.
 #define KEYWORD(NAME, FLAGS) \
   AddKeyword(#NAME, strlen(#NAME), tok::kw_ ## NAME,  \
-             ((FLAGS) >> C90Shift) & Mask, \
-             ((FLAGS) >> C99Shift) & Mask, \
-             ((FLAGS) >> CPPShift) & Mask, \
-             ((FLAGS) >> CPP0xShift) & Mask, \
-             ((FLAGS) >> BoolShift) & Mask, LangOpts, *this);
-#define ALIAS(NAME, TOK) \
-  AddAlias(NAME, strlen(NAME), tok::kw_ ## TOK, #TOK, strlen(#TOK),  \
-           LangOpts, *this);
+             FLAGS, LangOpts, *this);
+#define ALIAS(NAME, TOK, FLAGS) \
+  AddKeyword(NAME, strlen(NAME), tok::kw_ ## TOK,  \
+             FLAGS, LangOpts, *this);
 #define CXX_KEYWORD_OPERATOR(NAME, ALIAS) \
   if (LangOpts.CXXOperatorNames)          \
     AddCXXOperatorKeyword(#NAME, strlen(#NAME), tok::ALIAS, *this);
index 6011f42f9cf62da450401e564e06f973fc8397ca..7bdf76de19b0fb69b63e09bd15d87d8a4aa1d673 100644 (file)
 // RUN: grep "define void @_Z10gnu_inlinev()" %t &&
 // RUN: grep "define available_externally void @_Z13gnu_ei_inlinev()" %t
 
-extern inline int ei() { return 123; }
+extern __inline int ei() { return 123; }
 
-inline int foo() {
+__inline int foo() {
   return ei();
 }
 
 int bar() { return foo(); }
 
 
-inline void unreferenced1() {}
-extern inline void unreferenced2() {}
+__inline void unreferenced1() {}
+extern __inline void unreferenced2() {}
 
 __inline __attribute((__gnu_inline__)) void gnu_inline() {}
 
 // PR3988
-extern inline __attribute__((gnu_inline)) void gnu_ei_inline() {}
+extern __inline __attribute__((gnu_inline)) void gnu_ei_inline() {}
 void (*P)() = gnu_ei_inline;
 
 // <rdar://problem/6818429>
 int test1();
-inline int test1() { return 4; }
-inline int test2() { return 5; }
-inline int test2();
+__inline int test1() { return 4; }
+__inline int test2() { return 5; }
+__inline int test2();
 int test2();
 
 void test_test1() { test1(); }
 void test_test2() { test2(); }
 
 // PR3989
-extern inline void test3() __attribute__((gnu_inline));
-inline void test3()  {}
+extern __inline void test3() __attribute__((gnu_inline));
+__inline void test3()  {}
index 37fa0ca1d368d7ac79636e708aeb7415880f14c5..dc2bb02670c63a3beca411dd35cc466973838098 100644 (file)
@@ -1,57 +1,53 @@
 // RUN: clang-cc -fsyntax-only -verify %s -pedantic -std=c99
 
-int __attribute__(()) x;  // expected-warning {{extension used}}
+int __attribute__(()) x;
 
-// Hide __attribute__ behind a macro, to silence extension warnings about
-// "__attribute__ being an extension".
-#define attribute __attribute__
-
-__inline void attribute((__always_inline__, __nodebug__))
+__inline void __attribute__((__always_inline__, __nodebug__))
 foo(void) {
 }
 
 
-attribute(()) y;   // expected-warning {{defaults to 'int'}}
+__attribute__(()) y;   // expected-warning {{defaults to 'int'}}
 
 // PR2796
-int (attribute(()) *z)(long y);
+int (__attribute__(()) *z)(long y);
 
 
-void f1(attribute(()) int x);
+void f1(__attribute__(()) int x);
 
-int f2(y, attribute(()) x);     // expected-error {{expected identifier}}
+int f2(y, __attribute__(()) x);     // expected-error {{expected identifier}}
 
 // This is parsed as a normal argument list (with two args that are implicit
-// int) because the attribute is a declspec.
-void f3(attribute(()) x,  // expected-warning {{defaults to 'int'}}
+// int) because the __attribute__ is a declspec.
+void f3(__attribute__(()) x,  // expected-warning {{defaults to 'int'}}
         y);               // expected-warning {{defaults to 'int'}}
 
-void f4(attribute(()));   // expected-error {{expected parameter declarator}}
+void f4(__attribute__(()));   // expected-error {{expected parameter declarator}}
 
 
-// This is ok, the attribute applies to the pointer.
-int baz(int (attribute(()) *x)(long y));
+// This is ok, the __attribute__ applies to the pointer.
+int baz(int (__attribute__(()) *x)(long y));
 
-void g1(void (*f1)(attribute(()) int x));
-void g2(int (*f2)(y, attribute(()) x));    // expected-error {{expected identifier}}
-void g3(void (*f3)(attribute(()) x, int y));  // expected-warning {{defaults to 'int'}}
-void g4(void (*f4)(attribute(())));  // expected-error {{expected parameter declarator}}
+void g1(void (*f1)(__attribute__(()) int x));
+void g2(int (*f2)(y, __attribute__(()) x));    // expected-error {{expected identifier}}
+void g3(void (*f3)(__attribute__(()) x, int y));  // expected-warning {{defaults to 'int'}}
+void g4(void (*f4)(__attribute__(())));  // expected-error {{expected parameter declarator}}
 
 
-void (*h1)(void (*f1)(attribute(()) int x));
-void (*h2)(int (*f2)(y, attribute(()) x));    // expected-error {{expected identifier}}
+void (*h1)(void (*f1)(__attribute__(()) int x));
+void (*h2)(int (*f2)(y, __attribute__(()) x));    // expected-error {{expected identifier}}
 
-void (*h3)(void (*f3)(attribute(()) x));   // expected-warning {{defaults to 'int'}}
-void (*h4)(void (*f4)(attribute(())));  // expected-error {{expected parameter declarator}}
+void (*h3)(void (*f3)(__attribute__(()) x));   // expected-warning {{defaults to 'int'}}
+void (*h4)(void (*f4)(__attribute__(())));  // expected-error {{expected parameter declarator}}
 
 
 
 // rdar://6131260
 int foo42(void) {
-  int x, attribute((unused)) y, z;
+  int x, __attribute__((unused)) y, z;
   return 0;
 }
 
 // rdar://6096491
-void attribute((noreturn)) d0(void), attribute((noreturn)) d1(void);
+void __attribute__((noreturn)) d0(void), __attribute__((noreturn)) d1(void);
 
index a4b2aad09d88c947387a6e41f700aa73102e5933..26e8027d10782fb4f1c28c86e13007c88679d141 100644 (file)
@@ -63,4 +63,4 @@ struct xyz test8() { return a; }  // a should be be marked invalid, no diag.
 static f;      // expected-warning {{type specifier missing, defaults to 'int'}}
 static g = 4;  // expected-warning {{type specifier missing, defaults to 'int'}}
 static h        // expected-warning {{type specifier missing, defaults to 'int'}} 
-      __asm__("foo"); // expected-warning {{extension used}}
+      __asm__("foo");
index 3f2d48d0f70d97cf06e9b4f9214497676913736a..89eac564a329a614f5b58f5cc3abcf5ff7563e2d 100644 (file)
@@ -11,7 +11,7 @@ float test2241[2] = {
 static char *f (char * (*g) (char **, int), char **p, ...) {
     char *s;
     va_list v;                              // expected-error {{identifier}}
-    s = g (p, __builtin_va_arg(v, int));    // expected-error {{identifier}} expected-warning {{extension}}
+    s = g (p, __builtin_va_arg(v, int));    // expected-error {{identifier}}
 }
 
 
index 00c9b8735f346636b0b9c7aa189d29fce1f9c24c..7b5095f6e92374f531acbe87322796c49c4b47dc 100644 (file)
@@ -2,9 +2,17 @@
 
 // The preprocessor shouldn't warn about extensions within macro bodies that
 // aren't expanded.
-#define __block __attribute__((__blocks__(byref)))
+#define TY typeof
+#define TY1 typeof(1)
 
-// This warning is entirely valid.
-__block int x; // expected-warning{{extension used}}
+// But we should warn here
+TY1 x; // expected-warning {{extension}}
+TY(1) x; // FIXME: And we should warn here
+
+// Note: this warning intentionally doesn't trigger on keywords like
+// __attribute; the standard allows implementation-defined extensions
+// prefixed with "__".
+// Current list of keywords this can trigger on:
+// inline, restrict, asm, typeof, _asm
 
 void whatever() {}
index 0781abc7b9e05b56003d202609096208f76ab022..ce7c3484fd856100248682ac35a56dcf490a002c 100644 (file)
@@ -32,7 +32,7 @@ void cfstring() {
 }
 
 
-typedef __attribute__(( ext_vector_type(16) )) unsigned char uchar16;  // expected-warning {{extension}}
+typedef __attribute__(( ext_vector_type(16) )) unsigned char uchar16;
 
 // rdar://5905347
 unsigned char foo( short v ) {
index 3914641751d90bfebfb43333879248f9f6e379cc..f8cea33d6762637c7342e8e327a0c1bb4943fc96 100644 (file)
@@ -13,7 +13,7 @@ long double  g5 = __builtin_infl();
 
 extern int f();
 
-int h0 = __builtin_types_compatible_p(int,float); // expected-warning {{extension}}
+int h0 = __builtin_types_compatible_p(int,float);
 //int h1 = __builtin_choose_expr(1, 10, f());
 //int h2 = __builtin_expect(0, 0);
 
index d92141ce1df44f2c98e18decb05583cbfc781392..f85e2fc4141d8cdd8466e9b10e412cf416dcb872 100644 (file)
@@ -51,7 +51,7 @@ void test7(int *P, _Complex float Gamma) {
 // rdar://6095061
 int test8(void) {
   int i;
-  __builtin_choose_expr (0, 42, i) = 10;  // expected-warning {{extension used}}
+  __builtin_choose_expr (0, 42, i) = 10;
   return i;
 }
 
@@ -60,8 +60,8 @@ int test8(void) {
 struct f { int x : 4;  float y[]; };
 int test9(struct f *P) {
   int R;
-  R = __alignof(P->x);  // expected-error {{invalid application of '__alignof' to bitfield}} expected-warning {{extension used}}
-  R = __alignof(P->y);   // ok. expected-warning {{extension used}}
+  R = __alignof(P->x);  // expected-error {{invalid application of '__alignof' to bitfield}}
+  R = __alignof(P->y);   // ok.
   R = sizeof(P->x); // expected-error {{invalid application of 'sizeof' to bitfield}}
   return R;
 }
@@ -98,8 +98,8 @@ void test13(
 // rdar://6326239 - Vector comparisons are not fully trusted yet, until the
 // backend is known to work, just unconditionally reject them.
 void test14() {
-  typedef long long __m64 __attribute__((__vector_size__(8))); // expected-warning {{extension used}}
-  typedef short __v4hi __attribute__((__vector_size__(8))); // expected-warning {{extension used}}
+  typedef long long __m64 __attribute__((__vector_size__(8)));
+  typedef short __v4hi __attribute__((__vector_size__(8)));
 
   __v4hi a;
   __m64 mask = (__m64)((__v4hi)a >  // expected-error {{comparison of vector types ('__v4hi' and '__v4hi') not supported yet}}
index 8b5c8572076072cde4a9c47d9409fce67f2a4303..c9d8630c47f6ba47921bd5bcf76af30ce29064d7 100644 (file)
@@ -64,11 +64,11 @@ struct incomplete_test a(void) {} // expected-error{{incomplete result type 'str
 
 
 extern __inline
-__attribute__((__gnu_inline__))  // expected-warning{{extension used}}
+__attribute__((__gnu_inline__))
 void gnu_inline1() {}
 
 void
-__attribute__((__gnu_inline__)) // expected-warning {{'gnu_inline' attribute requires function to be marked 'inline', attribute ignored}} expected-warning{{extension used}}
+__attribute__((__gnu_inline__)) // expected-warning {{'gnu_inline' attribute requires function to be marked 'inline', attribute ignored}}
 gnu_inline2() {}
 
 
index 6afe035e1cf312b1e08a2306cda6e804ae759481..de279669922b0586150f0090055e71bd5c309c66 100644 (file)
@@ -61,6 +61,6 @@ int illegaldiv1[1 || 1/0];
 int illegaldiv2[1/0]; // expected-error {{variable length array declaration not allowed at file scope}}
 int illegaldiv3[INT_MIN / -1]; // expected-error {{variable length array declaration not allowed at file scope}}
 
-int chooseexpr[__builtin_choose_expr(1, 1, expr)]; // expected-warning {{extension used}}
-int realop[(__real__ 4) == 4 ? 1 : -1]; // expected-warning {{extension used}}
-int imagop[(__imag__ 4) == 0 ? 1 : -1]; // expected-warning {{extension used}}
+int chooseexpr[__builtin_choose_expr(1, 1, expr)];
+int realop[(__real__ 4) == 4 ? 1 : -1];
+int imagop[(__imag__ 4) == 0 ? 1 : -1];