[llvm-branch-commits] [cfe-branch] r367681 - Merging r367530:
Hans Wennborg via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Aug 2 06:39:28 PDT 2019
Author: hans
Date: Fri Aug 2 06:39:28 2019
New Revision: 367681
URL: http://llvm.org/viewvc/llvm-project?rev=367681&view=rev
Log:
Merging r367530:
------------------------------------------------------------------------
r367530 | ibiryukov | 2019-08-01 11:10:37 +0200 (Thu, 01 Aug 2019) | 17 lines
[Preprocessor] Always discard body of #define if we failed to parse it
Summary:
Preivously we would only discard it if we failed to parse parameter lists.
If we do not consume the body, parser sees tokens inside directive. In
turn, this leads to spurious diagnostics and a crash in TokenBuffer, see
the added tests.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D65517
------------------------------------------------------------------------
Added:
cfe/branches/release_90/test/Preprocessor/stringize_skipped.c
- copied unchanged from r367530, cfe/trunk/test/Preprocessor/stringize_skipped.c
Modified:
cfe/branches/release_90/ (props changed)
cfe/branches/release_90/lib/Lex/PPDirectives.cpp
cfe/branches/release_90/unittests/Tooling/Syntax/TokensTest.cpp
Propchange: cfe/branches/release_90/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 2 06:39:28 2019
@@ -1,4 +1,4 @@
/cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:366429,366448,366457,366474,366480,366483,366511,366670,366694,366699,366878,367008,367039,367055,367103,367134,367301,367305,367323,367387
+/cfe/trunk:366429,366448,366457,366474,366480,366483,366511,366670,366694,366699,366878,367008,367039,367055,367103,367134,367301,367305,367323,367387,367530
/cfe/trunk/test:170344
/cfe/trunk/test/SemaTemplate:126920
Modified: cfe/branches/release_90/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_90/lib/Lex/PPDirectives.cpp?rev=367681&r1=367680&r2=367681&view=diff
==============================================================================
--- cfe/branches/release_90/lib/Lex/PPDirectives.cpp (original)
+++ cfe/branches/release_90/lib/Lex/PPDirectives.cpp Fri Aug 2 06:39:28 2019
@@ -33,6 +33,7 @@
#include "clang/Lex/Token.h"
#include "clang/Lex/VariadicMacroSupport.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/STLExtras.h"
@@ -2399,6 +2400,13 @@ MacroInfo *Preprocessor::ReadOptionalMac
Token Tok;
LexUnexpandedToken(Tok);
+ // Ensure we consume the rest of the macro body if errors occur.
+ auto _ = llvm::make_scope_exit([&]() {
+ // The flag indicates if we are still waiting for 'eod'.
+ if (CurLexer->ParsingPreprocessorDirective)
+ DiscardUntilEndOfDirective();
+ });
+
// Used to un-poison and then re-poison identifiers of the __VA_ARGS__ ilk
// within their appropriate context.
VariadicMacroScopeGuard VariadicMacroScopeGuard(*this);
@@ -2420,12 +2428,8 @@ MacroInfo *Preprocessor::ReadOptionalMac
} else if (Tok.is(tok::l_paren)) {
// This is a function-like macro definition. Read the argument list.
MI->setIsFunctionLike();
- if (ReadMacroParameterList(MI, LastTok)) {
- // Throw away the rest of the line.
- if (CurPPLexer->ParsingPreprocessorDirective)
- DiscardUntilEndOfDirective();
+ if (ReadMacroParameterList(MI, LastTok))
return nullptr;
- }
// If this is a definition of an ISO C/C++ variadic function-like macro (not
// using the GNU named varargs extension) inform our variadic scope guard
Modified: cfe/branches/release_90/unittests/Tooling/Syntax/TokensTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_90/unittests/Tooling/Syntax/TokensTest.cpp?rev=367681&r1=367680&r2=367681&view=diff
==============================================================================
--- cfe/branches/release_90/unittests/Tooling/Syntax/TokensTest.cpp (original)
+++ cfe/branches/release_90/unittests/Tooling/Syntax/TokensTest.cpp Fri Aug 2 06:39:28 2019
@@ -298,6 +298,21 @@ file './input.cpp'
spelled tokens:
<empty>
no mappings.
+)"},
+ // Should not crash on errors inside '#define' directives. Error is that
+ // stringification (#B) does not refer to a macro parameter.
+ {
+ R"cpp(
+a
+#define MACRO() A #B
+)cpp",
+ R"(expanded tokens:
+ a
+file './input.cpp'
+ spelled tokens:
+ a # define MACRO ( ) A # B
+ mappings:
+ ['#'_1, '<eof>'_9) => ['<eof>'_1, '<eof>'_1)
)"}};
for (auto &Test : TestCases)
EXPECT_EQ(collectAndDump(Test.first), Test.second)
More information about the llvm-branch-commits
mailing list