summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
diff options
context:
space:
mode:
authorDavid L. Jones <dlj@google.com>2018-06-15 06:08:54 +0000
committerDavid L. Jones <dlj@google.com>2018-06-15 06:08:54 +0000
commit5de2272174587bc8ce10a59fc20570890d0f9721 (patch)
treea4473b3da86f019287070525a4e169b64c638fd5 /clang/lib/Format
parent3c4cc0122626af9f11317a3ebeebaad0796d0655 (diff)
downloadbcm5719-llvm-5de2272174587bc8ce10a59fc20570890d0f9721.tar.gz
bcm5719-llvm-5de2272174587bc8ce10a59fc20570890d0f9721.zip
[Format] Do not use a global static value for EOF within ScopedMacroState.
ScopedMacroState injects its own EOF token under certain conditions, and the returned token may be modified in several different locations. If multiple reformat operations are started in different threads, then they will both see the same fake EOF token, and may both try to modify it. This is a data race. This bug was caught with tsan. Reviewers: klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D47759 llvm-svn: 334801
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp16
1 files changed, 4 insertions, 12 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index b257b2b74dd..e1fa72e84bd 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -83,6 +83,8 @@ public:
: Line(Line), TokenSource(TokenSource), ResetToken(ResetToken),
PreviousLineLevel(Line.Level), PreviousTokenSource(TokenSource),
Token(nullptr), PreviousToken(nullptr) {
+ FakeEOF.Tok.startToken();
+ FakeEOF.Tok.setKind(tok::eof);
TokenSource = this;
Line.Level = 0;
Line.InPPDirective = true;
@@ -102,7 +104,7 @@ public:
PreviousToken = Token;
Token = PreviousTokenSource->getNextToken();
if (eof())
- return getFakeEOF();
+ return &FakeEOF;
return Token;
}
@@ -121,17 +123,7 @@ private:
/*MinColumnToken=*/PreviousToken);
}
- FormatToken *getFakeEOF() {
- static bool EOFInitialized = false;
- static FormatToken FormatTok;
- if (!EOFInitialized) {
- FormatTok.Tok.startToken();
- FormatTok.Tok.setKind(tok::eof);
- EOFInitialized = true;
- }
- return &FormatTok;
- }
-
+ FormatToken FakeEOF;
UnwrappedLine &Line;
FormatTokenSource *&TokenSource;
FormatToken *&ResetToken;
OpenPOWER on IntegriCloud