r256596 - Emit a -Wmicrosoft warning when treating ^Z as EOF in MS mode.
Nico Weber via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 29 15:17:28 PST 2015
Author: nico
Date: Tue Dec 29 17:17:27 2015
New Revision: 256596
URL: http://llvm.org/viewvc/llvm-project?rev=256596&view=rev
Log:
Emit a -Wmicrosoft warning when treating ^Z as EOF in MS mode.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
cfe/trunk/lib/Lex/Lexer.cpp
cfe/trunk/test/Lexer/msdos-cpm-eof.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=256596&r1=256595&r2=256596&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Dec 29 17:17:27 2015
@@ -766,6 +766,7 @@ def MicrosoftConstInit : DiagGroup<"micr
def MicrosoftVoidPseudoDtor : DiagGroup<"microsoft-void-pseudo-dtor">;
def MicrosoftAnonTag : DiagGroup<"microsoft-anon-tag">;
def MicrosoftCommentPaste : DiagGroup<"microsoft-comment-paste">;
+def MicrosoftEndOfFile : DiagGroup<"microsoft-end-of-file">;
// Aliases.
def : DiagGroup<"msvc-include", [MicrosoftInclude]>;
// -Wmsvc-include = -Wmicrosoft-include
@@ -780,7 +781,7 @@ def Microsoft : DiagGroup<"microsoft",
MicrosoftRedeclareStatic, MicrosoftEnumForwardReference, MicrosoftGoto,
MicrosoftFlexibleArray, MicrosoftExtraQualification, MicrosoftCast,
MicrosoftConstInit, MicrosoftVoidPseudoDtor, MicrosoftAnonTag,
- MicrosoftCommentPaste]>;
+ MicrosoftCommentPaste, MicrosoftEndOfFile]>;
def ObjCNonUnifiedException : DiagGroup<"objc-nonunified-exceptions">;
Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=256596&r1=256595&r2=256596&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Tue Dec 29 17:17:27 2015
@@ -62,6 +62,9 @@ def ext_charize_microsoft : Extension<
def ext_comment_paste_microsoft : Extension<
"pasting two '/' tokens into a '//' comment token is a Microsoft extension">,
InGroup<MicrosoftCommentPaste>;
+def ext_ctrl_z_eof_microsoft : Extension<
+ "treating Ctrl-Z as end-of-file is a Microsoft extension">,
+ InGroup<MicrosoftEndOfFile>;
def ext_token_used : Extension<"extension used">,
InGroup<DiagGroup<"language-extension-token">>;
Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=256596&r1=256595&r2=256596&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Tue Dec 29 17:17:27 2015
@@ -2960,8 +2960,11 @@ LexNextToken:
case 26: // DOS & CP/M EOF: "^Z".
// If we're in Microsoft extensions mode, treat this as end of file.
- if (LangOpts.MicrosoftExt)
+ if (LangOpts.MicrosoftExt) {
+ if (!isLexingRawMode())
+ Diag(CurPtr-1, diag::ext_ctrl_z_eof_microsoft);
return LexEndOfFile(Result, CurPtr-1);
+ }
// If Microsoft extensions are disabled, this is just random garbage.
Kind = tok::unknown;
Modified: cfe/trunk/test/Lexer/msdos-cpm-eof.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/msdos-cpm-eof.c?rev=256596&r1=256595&r2=256596&view=diff
==============================================================================
--- cfe/trunk/test/Lexer/msdos-cpm-eof.c (original)
+++ cfe/trunk/test/Lexer/msdos-cpm-eof.c Tue Dec 29 17:17:27 2015
@@ -1,8 +1,8 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -fms-extensions %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -fsyntax-only -verify -fms-extensions -Wmicrosoft %s
int x;
+// expected-warning at +1 {{treating Ctrl-Z as end-of-file is a Microsoft extension">,
I am random garbage after ^Z
More information about the cfe-commits
mailing list