Skip to content

Commit 5609bd8

Browse files
committed
Revert "[clang-format] Update FormatToken::isSimpleTypeSpecifier() (#80241)"
This reverts commit 763139a. It seems that LangOpts is not initialized before use.
1 parent 9e73656 commit 5609bd8

File tree

4 files changed

+38
-7
lines changed

4 files changed

+38
-7
lines changed

clang/include/clang/Format/Format.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5175,8 +5175,6 @@ tooling::Replacements sortUsingDeclarations(const FormatStyle &Style,
51755175
ArrayRef<tooling::Range> Ranges,
51765176
StringRef FileName = "<stdin>");
51775177

5178-
extern LangOptions LangOpts;
5179-
51805178
/// Returns the ``LangOpts`` that the formatter expects you to set.
51815179
///
51825180
/// \param Style determines specific settings for lexing mode.

clang/lib/Format/FormatToken.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,41 @@ const char *getTokenTypeName(TokenType Type) {
3434
return nullptr;
3535
}
3636

37+
// FIXME: This is copy&pasted from Sema. Put it in a common place and remove
38+
// duplication.
3739
bool FormatToken::isSimpleTypeSpecifier() const {
38-
return Tok.isSimpleTypeSpecifier(LangOpts);
40+
switch (Tok.getKind()) {
41+
case tok::kw_short:
42+
case tok::kw_long:
43+
case tok::kw___int64:
44+
case tok::kw___int128:
45+
case tok::kw_signed:
46+
case tok::kw_unsigned:
47+
case tok::kw_void:
48+
case tok::kw_char:
49+
case tok::kw_int:
50+
case tok::kw_half:
51+
case tok::kw_float:
52+
case tok::kw_double:
53+
case tok::kw___bf16:
54+
case tok::kw__Float16:
55+
case tok::kw___float128:
56+
case tok::kw___ibm128:
57+
case tok::kw_wchar_t:
58+
case tok::kw_bool:
59+
#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
60+
#include "clang/Basic/TransformTypeTraits.def"
61+
case tok::annot_typename:
62+
case tok::kw_char8_t:
63+
case tok::kw_char16_t:
64+
case tok::kw_char32_t:
65+
case tok::kw_typeof:
66+
case tok::kw_decltype:
67+
case tok::kw__Atomic:
68+
return true;
69+
default:
70+
return false;
71+
}
3972
}
4073

4174
bool FormatToken::isTypeOrIdentifier() const {

clang/lib/Format/FormatTokenLexer.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,18 @@
2222
namespace clang {
2323
namespace format {
2424

25-
LangOptions LangOpts;
26-
2725
FormatTokenLexer::FormatTokenLexer(
2826
const SourceManager &SourceMgr, FileID ID, unsigned Column,
2927
const FormatStyle &Style, encoding::Encoding Encoding,
3028
llvm::SpecificBumpPtrAllocator<FormatToken> &Allocator,
3129
IdentifierTable &IdentTable)
3230
: FormatTok(nullptr), IsFirstToken(true), StateStack({LexerState::NORMAL}),
33-
Column(Column), TrailingWhitespace(0), SourceMgr(SourceMgr), ID(ID),
31+
Column(Column), TrailingWhitespace(0),
32+
LangOpts(getFormattingLangOpts(Style)), SourceMgr(SourceMgr), ID(ID),
3433
Style(Style), IdentTable(IdentTable), Keywords(IdentTable),
3534
Encoding(Encoding), Allocator(Allocator), FirstInLineIndex(0),
3635
FormattingDisabled(false), MacroBlockBeginRegex(Style.MacroBlockBegin),
3736
MacroBlockEndRegex(Style.MacroBlockEnd) {
38-
LangOpts = getFormattingLangOpts(Style);
3937
Lex.reset(new Lexer(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts));
4038
Lex->SetKeepWhitespaceMode(true);
4139

@@ -1444,6 +1442,7 @@ void FormatTokenLexer::readRawToken(FormatToken &Tok) {
14441442

14451443
void FormatTokenLexer::resetLexer(unsigned Offset) {
14461444
StringRef Buffer = SourceMgr.getBufferData(ID);
1445+
LangOpts = getFormattingLangOpts(Style);
14471446
Lex.reset(new Lexer(SourceMgr.getLocForStartOfFile(ID), LangOpts,
14481447
Buffer.begin(), Buffer.begin() + Offset, Buffer.end()));
14491448
Lex->SetKeepWhitespaceMode(true);

clang/lib/Format/FormatTokenLexer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class FormatTokenLexer {
120120
unsigned Column;
121121
unsigned TrailingWhitespace;
122122
std::unique_ptr<Lexer> Lex;
123+
LangOptions LangOpts;
123124
const SourceManager &SourceMgr;
124125
FileID ID;
125126
const FormatStyle &Style;

0 commit comments

Comments
 (0)