From 8da88ff33e3f0954e44835005486f154e737ca6f Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 29 Dec 2015 23:17:27 +0000 Subject: [PATCH] Emit a -Wmicrosoft warning when treating ^Z as EOF in MS mode. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256596 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticGroups.td | 3 ++- include/clang/Basic/DiagnosticLexKinds.td | 3 +++ lib/Lex/Lexer.cpp | 5 ++++- test/Lexer/msdos-cpm-eof.c | 4 ++-- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td index 32353b51ee..8e5f57d6d8 100644 --- a/include/clang/Basic/DiagnosticGroups.td +++ b/include/clang/Basic/DiagnosticGroups.td @@ -766,6 +766,7 @@ def MicrosoftConstInit : DiagGroup<"microsoft-const-init">; 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">; diff --git a/include/clang/Basic/DiagnosticLexKinds.td b/include/clang/Basic/DiagnosticLexKinds.td index 2ed40c0cde..bf86b7077c 100644 --- a/include/clang/Basic/DiagnosticLexKinds.td +++ b/include/clang/Basic/DiagnosticLexKinds.td @@ -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; +def ext_ctrl_z_eof_microsoft : Extension< + "treating Ctrl-Z as end-of-file is a Microsoft extension">, + InGroup; def ext_token_used : Extension<"extension used">, InGroup>; diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index 4872dee824..27b0feb482 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -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; diff --git a/test/Lexer/msdos-cpm-eof.c b/test/Lexer/msdos-cpm-eof.c index 3469b59d40..274e6305a9 100644 --- a/test/Lexer/msdos-cpm-eof.c +++ b/test/Lexer/msdos-cpm-eof.c @@ -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@+1 {{treating Ctrl-Z as end-of-file is a Microsoft extension">,  I am random garbage after ^Z -- 2.40.0