Skip to content

Commit 0c9a1d4

Browse files
committed
Blunder keep clearFlag(Token::NeedsCleaning)
at the beginning of ExpandBuiltinMacro to account for early returns (e.g..in __DATE__ or __TIME__ expansion).
1 parent bcf0381 commit 0c9a1d4

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed

clang/lib/Lex/PPMacroExpansion.cpp

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

16471647
// Set up the return result.
16481648
Tok.setIdentifierInfo(nullptr);
1649+
Tok.clearFlag(Token::NeedsCleaning);
16491650
bool IsAtStartOfLine = Tok.isAtStartOfLine();
16501651
bool HasLeadingSpace = Tok.hasLeadingSpace();
16511652

clang/test/Preprocessor/pr133574.c

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// RUN: %clang_cc1 -E -verify %s
2+
// expected-no-diagnostics
3+
4+
#define DATE_LBR __D\
5+
ATE__
6+
7+
const char* test1(void) {
8+
return __DATE\
9+
__;
10+
}
11+
const char* test2(void) {
12+
return DATE_LBR;
13+
}
14+
15+
#define TIME_LBR __TIME_\
16+
_
17+
18+
const char* test3(void) {
19+
return __TIM\
20+
E__;
21+
}
22+
23+
const char* test4(void) {
24+
return TIME_LBR;
25+
}
26+
27+
#define LINE_LBR __LI\
28+
NE__
29+
30+
int test5(void) {
31+
return _\
32+
_LINE__;
33+
}
34+
35+
int test6(void) {
36+
return LINE_LBR;
37+
}
38+
39+
#define FILE_LBR __FI\
40+
LE__
41+
42+
const char* test7(void) {
43+
return __\
44+
FILE__;
45+
}
46+
47+
const char* test8(void) {
48+
return FILE_LBR;
49+
}
50+
51+
#define FILE_NAME_LBR __FILE_NA\
52+
ME__
53+
54+
const char* test9(void) {
55+
return __FILE_NAM\
56+
E__;
57+
}
58+
59+
const char* test10(void) {
60+
return FILE_NAME_LBR;
61+
}
62+
63+
#define BASE_FILE_LBR __BASE_FIL\
64+
E__
65+
66+
const char* test11(void) {
67+
return __BASE_\
68+
FILE__;
69+
}
70+
71+
const char* test12(void) {
72+
return BASE_FILE_LBR;
73+
}
74+
75+
#define INCLUDE_LEVEL_LBR __INCLUDE\
76+
_LEVEL__
77+
78+
int test13(void) {
79+
return __IN\
80+
CLUDE_LEVEL__;
81+
}
82+
83+
int test14(void) {
84+
return INCLUDE_LEVEL_LBR;
85+
}
86+
87+
#define TIMESTAMP_LBR __TIMESTA\
88+
MP__
89+
90+
const char* test15(void) {
91+
return __TIMESTA\
92+
MP__;
93+
}
94+
95+
const char* test16(void) {
96+
return TIMESTAMP_LBR;
97+
}
98+
99+
#define FLT_EVAL_METHOD_LBR __FLT_EVAL_METH\
100+
OD__
101+
102+
int test17(void) {
103+
return __FL\
104+
T_EVAL_METHOD__;
105+
}
106+
107+
int test18(void) {
108+
return FLT_EVAL_METHOD_LBR;
109+
}
110+
111+
#define COUNTER_LBR __COUNTE\
112+
R__
113+
114+
int test19(void) {
115+
return _\
116+
_COUNTER__;
117+
}
118+
119+
int test20(void) {
120+
return COUNTER_LBR;
121+
}

0 commit comments

Comments
 (0)