Skip to content

Commit dd54aa5

Browse files
committed
[clang] Clear NeedsCleaning flag after ExpandBuiltinMacro
After builtin macro expansion in `Preprocessor::ExpandBuiltinMacro` the result token may have the `Token::NeedsCleaning` flag set which causes an assertion failure later on when the lexer retrives the spelling of the token in `getSpellingSlow` in Lexer.cpp.
1 parent 6c68cc4 commit dd54aa5

File tree

6 files changed

+129
-1
lines changed

6 files changed

+129
-1
lines changed

clang/lib/Lex/PPMacroExpansion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,6 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
16461646

16471647
// Set up the return result.
16481648
Tok.setIdentifierInfo(nullptr);
1649-
Tok.clearFlag(Token::NeedsCleaning);
16501649
bool IsAtStartOfLine = Tok.isAtStartOfLine();
16511650
bool HasLeadingSpace = Tok.hasLeadingSpace();
16521651

@@ -2089,6 +2088,7 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
20892088
CreateString(OS.str(), Tok, Tok.getLocation(), Tok.getLocation());
20902089
Tok.setFlagValue(Token::StartOfLine, IsAtStartOfLine);
20912090
Tok.setFlagValue(Token::LeadingSpace, HasLeadingSpace);
2091+
Tok.clearFlag(Token::NeedsCleaning);
20922092
}
20932093

20942094
void Preprocessor::markMacroAsUsed(MacroInfo *MI) {

clang/test/Preprocessor/embed___has_embed.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,22 @@ unsigned char buffer[] = {
5858
#else
5959
#error 17
6060
#endif
61+
62+
#if __has_embed(__FILE__\
63+
)
64+
#else
65+
#error 18
66+
#endif
67+
68+
#define F __FI\
69+
LE__
70+
#if __has_embed(F)
71+
#else
72+
#error 19
73+
#endif
74+
75+
#if __has_embed(F\
76+
)
77+
#else
78+
#error 20
79+
#endif

clang/test/Preprocessor/has_attribute.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,23 @@ int has_no_volatile_attribute();
6868
int has_fallthrough;
6969
#endif
7070
// CHECK: int has_fallthrough;
71+
72+
#if __has_attribute(F\
73+
)
74+
int has_fallthrough_2;
75+
#endif
76+
// CHECK: int has_fallthrough_2;
77+
78+
#define F_2 fall\
79+
through
80+
81+
#if __has_attribute(F_2)
82+
int has_fallthrough_3;
83+
#endif
84+
// CHECK: int has_fallthrough_3;
85+
86+
#if __has_attribute(F_2\
87+
)
88+
int has_fallthrough_4;
89+
#endif
90+
// CHECK: int has_fallthrough_4;

clang/test/Preprocessor/has_attribute.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,26 @@ int funclike_1;
116116
int funclike_2;
117117
#endif
118118
// CHECK: int funclike_2;
119+
120+
#if __has_cpp_attribute(CF\
121+
)
122+
int has_clang_falthrough_5;
123+
#endif
124+
// CHECK: int has_clang_falthrough_5;
125+
126+
#define CF_2 clang::\
127+
fallthrough
128+
129+
#if __has_cpp_attribute(CF_2)
130+
int has_clang_falthrough_6;
131+
#endif
132+
// CHECK: int has_clang_falthrough_6;
133+
134+
#if __has_cpp_attribute(CF_2\
135+
)
136+
int has_clang_falthrough_7;
137+
#endif
138+
// CHECK: int has_clang_falthrough_7;
119139
}
120140

121141
// Test for Microsoft __declspec attributes

clang/test/Preprocessor/has_c_attribute.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,23 @@ int funclike_1;
8484
int funclike_2;
8585
#endif
8686
// CHECK: int funclike_2;
87+
88+
#if __has_c_attribute(CL\
89+
)
90+
int has_clang_likely_5;
91+
#endif
92+
// CHECK: int has_clang_likely_5;
93+
94+
#define CL_2 clang::\
95+
likely
96+
97+
#if __has_c_attribute(CL_2)
98+
int has_clang_likely_6;
99+
#endif
100+
// CHECK: int has_clang_likely_6;
101+
102+
#if __has_c_attribute(CL_2\
103+
)
104+
int has_clang_likely_7;
105+
#endif
106+
// CHECK: int has_clang_likely_7;

clang/test/Preprocessor/has_include.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,52 @@ __has_include
197197
#ifdef FOO
198198
#elif __has_include(<foo>)
199199
#endif
200+
201+
#if __has_include(<stdint.h>\
202+
)
203+
#else
204+
#error "__has_include failed (10)."
205+
#endif
206+
207+
#define MACRO6 <stdint.h>
208+
#if __has_include(MACRO6\
209+
)
210+
#else
211+
#error "__has_include failed (11)."
212+
#endif
213+
214+
#if __has_include_next(<stdint.h>/*expected-warning {{#include_next in primary source file}}*/\
215+
)
216+
#else
217+
#error "__has_include_next failed (9)."
218+
#endif
219+
220+
#if __has_include_next(MACRO6/*expected-warning {{#include_next in primary source file}}*/\
221+
)
222+
#else
223+
#error "__has_include_next failed (10)."
224+
#endif
225+
226+
#define MACRO7 <std\
227+
int.h>
228+
#if __has_include(MACRO7)
229+
#else
230+
#error "__has_include failed (12)."
231+
#endif
232+
233+
#if __has_include(MACRO7\
234+
)
235+
#else
236+
#error "__has_include failed (13)."
237+
#endif
238+
239+
#if __has_include_next(MACRO7) //expected-warning {{#include_next in primary source file}}
240+
#else
241+
#error "__has_include_next failed (11)."
242+
#endif
243+
244+
#if __has_include_next(MACRO7/*expected-warning {{#include_next in primary source file}}*/\
245+
)
246+
#else
247+
#error "__has_include_next failed (12)."
248+
#endif

0 commit comments

Comments
 (0)