[cfe-dev] Bug 17824: parse error in typedef union with -fms-extensions
Alp Toker
alp at nuanti.com
Sun Nov 24 04:19:47 PST 2013
On 23/11/2013 21:06, Aaron Ballman wrote:
> On Fri, Nov 22, 2013 at 8:35 PM, Jeremy Fitzhardinge <jeremy at goop.org> wrote:
>> Hi all,
>>
>> I filed bug 17824 a few days ago because I'm seeing a regression in the
>> current svn clang vs previous versions with this structure in glibc's
>> /usr/include/stdlib.h when compiling with -fms-extensions:
> This is not actually a bug -- __uptr is a keyword in Microsoft mode.
>
> http://msdn.microsoft.com/en-us/library/vstudio/aa983399.aspx
>
> We don't support the full semantics for it, but you can see it
> declared as a TypeAttr in Attr.td.
Hi Aaron,
We've been good at supporting all the language standards built against
stock system headers so far because it's handy for writing quick tests
and, in this case, porting software from Windows.
The attached patch fixes -fms-extensions with GNU libc headers. Could
you give it a spin against the MS headers?
Will land and get this merged to the release branch if it works for you.
Alp.
>
> HTH!
>
> ~Aaron
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
--
http://www.nuanti.com
the browser experts
-------------- next part --------------
commit 5a42e28d24ae2ea677e31c151802512112a2b255
Author: Alp Toker <alp at nuanti.com>
Date: Sun Nov 24 12:14:09 2013 +0000
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.
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index 7185de6..1e9325b 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -4483,8 +4483,15 @@ void Parser::ParseTypeQualifierListOpt(DeclSpec &DS,
ParseOpenCLQualifiers(DS);
break;
- case tok::kw___sptr:
case tok::kw___uptr:
+ // GNU libc++ uses certain MS keywords as identifiers.
+ if (VendorAttributesAllowed && !getLangOpts().CPlusPlus &&
+ 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:
diff --git a/test/Sema/Inputs/ms-keyword-system-header.h b/test/Sema/Inputs/ms-keyword-system-header.h
new file mode 100644
index 0000000..13cfe3a
--- /dev/null
+++ b/test/Sema/Inputs/ms-keyword-system-header.h
@@ -0,0 +1,6 @@
+/* "System header" for testing GNU libc keyword conflict workarounds */
+
+typedef union {
+ union w *__uptr;
+ int *__iptr;
+} WS __attribute__((__transparent_union__));
diff --git a/test/Sema/ms-keyword-system-header.c b/test/Sema/ms-keyword-system-header.c
new file mode 100644
index 0000000..bf7a9f4
--- /dev/null
+++ b/test/Sema/ms-keyword-system-header.c
@@ -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-dev
mailing list