r195710 - Unbreak -fms-extensions with GNU libc headers

Alp Toker alp at nuanti.com
Mon Nov 25 17:30:11 PST 2013


Author: alp
Date: Mon Nov 25 19:30:10 2013
New Revision: 195710

URL: http://llvm.org/viewvc/llvm-project?rev=195710&view=rev
Log:
Unbreak -fms-extensions with GNU libc headers

GNU libc uses '__uptr' as a member name in C mode, conflicting with the
eponymous MSVC pointer modifier keyword.

Detect and mark the token as an identifier when these specific conditions are
met. __uptr will continue to work as a keyword for the remainder of the
translation unit.

Fixes PR17824.

Added:
    cfe/trunk/test/Sema/Inputs/ms-keyword-system-header.h
    cfe/trunk/test/Sema/ms-keyword-system-header.c
Modified:
    cfe/trunk/include/clang/Parse/Parser.h
    cfe/trunk/lib/Parse/ParseDecl.cpp

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=195710&r1=195709&r2=195710&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Mon Nov 25 19:30:10 2013
@@ -2072,7 +2072,8 @@ private:
 
   void ParseTypeQualifierListOpt(DeclSpec &DS, bool GNUAttributesAllowed = true,
                                  bool CXX11AttributesAllowed = true,
-                                 bool AtomicAllowed = true);
+                                 bool AtomicAllowed = true,
+                                 bool IdentifierRequired = false);
   void ParseDirectDeclarator(Declarator &D);
   void ParseParenDeclarator(Declarator &D);
   void ParseFunctionDeclarator(Declarator &D,

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=195710&r1=195709&r2=195710&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon Nov 25 19:30:10 2013
@@ -4429,7 +4429,8 @@ bool Parser::isConstructorDeclarator() {
 void Parser::ParseTypeQualifierListOpt(DeclSpec &DS,
                                        bool VendorAttributesAllowed,
                                        bool CXX11AttributesAllowed,
-                                       bool AtomicAllowed) {
+                                       bool AtomicAllowed,
+                                       bool IdentifierRequired) {
   if (getLangOpts().CPlusPlus11 && CXX11AttributesAllowed &&
       isCXX11AttributeSpecifier()) {
     ParsedAttributesWithRange attrs(AttrFactory);
@@ -4483,8 +4484,16 @@ void Parser::ParseTypeQualifierListOpt(D
       ParseOpenCLQualifiers(DS);
       break;
 
-    case tok::kw___sptr:
     case tok::kw___uptr:
+      // GNU libc headers in C mode use '__uptr' as an identifer which conflicts
+      // with the MS modifier keyword.
+      if (VendorAttributesAllowed && !getLangOpts().CPlusPlus &&
+          IdentifierRequired && DS.isEmpty() && NextToken().is(tok::semi) &&
+          PP.getSourceManager().isInSystemHeader(Loc)) {
+        Tok.setKind(tok::identifier);
+        continue;
+      }
+    case tok::kw___sptr:
     case tok::kw___w64:
     case tok::kw___ptr64:
     case tok::kw___ptr32:
@@ -4640,7 +4649,7 @@ void Parser::ParseDeclaratorInternal(Dec
     DeclSpec DS(AttrFactory);
 
     // FIXME: GNU attributes are not allowed here in a new-type-id.
-    ParseTypeQualifierListOpt(DS);
+    ParseTypeQualifierListOpt(DS, true, true, true, !D.mayOmitIdentifier());
     D.ExtendWithDeclSpec(DS);
 
     // Recursively parse the declarator.

Added: cfe/trunk/test/Sema/Inputs/ms-keyword-system-header.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/Inputs/ms-keyword-system-header.h?rev=195710&view=auto
==============================================================================
--- cfe/trunk/test/Sema/Inputs/ms-keyword-system-header.h (added)
+++ cfe/trunk/test/Sema/Inputs/ms-keyword-system-header.h Mon Nov 25 19:30:10 2013
@@ -0,0 +1,6 @@
+/* "System header" for testing GNU libc keyword conflict workarounds */
+
+typedef union {
+  union w *__uptr;
+  int *__iptr;
+} WS __attribute__((__transparent_union__));

Added: cfe/trunk/test/Sema/ms-keyword-system-header.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/ms-keyword-system-header.c?rev=195710&view=auto
==============================================================================
--- cfe/trunk/test/Sema/ms-keyword-system-header.c (added)
+++ cfe/trunk/test/Sema/ms-keyword-system-header.c Mon Nov 25 19:30:10 2013
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fms-extensions -D MS -isystem %S/Inputs %s -fsyntax-only -verify
+// RUN: %clang_cc1 -isystem %S/Inputs %s -fsyntax-only -verify
+
+// PR17824: GNU libc uses MS keyword __uptr as an identifier in C mode
+#include <ms-keyword-system-header.h>
+
+void fn() {
+  WS ws;
+  ws.__uptr = 0;
+#ifdef MS
+  // expected-error at -2 {{expected identifier}}
+#else
+  // expected-no-diagnostics
+#endif
+}





More information about the cfe-commits mailing list