Skip to content

Commit 20a3fb9

Browse files
committed
[Clang] Fix how ReadMacroParameterList handles comments in macro parameter-list when in -CC mode
Currently when in -CC mode when processing a function like macro ReadMacroParameterList(...) does not handle the case where there is a comment embedded in the parameter-list. Instead of using LexUnexpandedToken(...) I switched to using LexUnexpandedNonComment(...) which eats comments while lexing. Fixes: llvm#60887 Differential Revision: https://reviews.llvm.org/D144511
1 parent a3252d1 commit 20a3fb9

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

clang/docs/ReleaseNotes.rst

+3
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ Bug Fixes in This Version
254254
requires on lambdas when not allowed, which we previously missed.
255255
(`#61748 <https://github.com/llvm/llvm-project/issues/61748>`_)
256256
- Fix confusing diagnostic for incorrect use of qualified concepts names.
257+
- Fix handling of comments in function like macros so they are ignored in -CC
258+
mode.
259+
(`#60887 <https://github.com/llvm/llvm-project/issues/60887>`_)
257260

258261

259262
Bug Fixes to Compiler Builtins

clang/lib/Lex/PPDirectives.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -2643,7 +2643,7 @@ bool Preprocessor::ReadMacroParameterList(MacroInfo *MI, Token &Tok) {
26432643
SmallVector<IdentifierInfo*, 32> Parameters;
26442644

26452645
while (true) {
2646-
LexUnexpandedToken(Tok);
2646+
LexUnexpandedNonComment(Tok);
26472647
switch (Tok.getKind()) {
26482648
case tok::r_paren:
26492649
// Found the end of the parameter list.
@@ -2664,7 +2664,7 @@ bool Preprocessor::ReadMacroParameterList(MacroInfo *MI, Token &Tok) {
26642664
}
26652665

26662666
// Lex the token after the identifier.
2667-
LexUnexpandedToken(Tok);
2667+
LexUnexpandedNonComment(Tok);
26682668
if (Tok.isNot(tok::r_paren)) {
26692669
Diag(Tok, diag::err_pp_missing_rparen_in_macro_def);
26702670
return true;
@@ -2698,7 +2698,7 @@ bool Preprocessor::ReadMacroParameterList(MacroInfo *MI, Token &Tok) {
26982698
Parameters.push_back(II);
26992699

27002700
// Lex the token after the identifier.
2701-
LexUnexpandedToken(Tok);
2701+
LexUnexpandedNonComment(Tok);
27022702

27032703
switch (Tok.getKind()) {
27042704
default: // #define X(A B
@@ -2714,7 +2714,7 @@ bool Preprocessor::ReadMacroParameterList(MacroInfo *MI, Token &Tok) {
27142714
Diag(Tok, diag::ext_named_variadic_macro);
27152715

27162716
// Lex the token after the identifier.
2717-
LexUnexpandedToken(Tok);
2717+
LexUnexpandedNonComment(Tok);
27182718
if (Tok.isNot(tok::r_paren)) {
27192719
Diag(Tok, diag::err_pp_missing_rparen_in_macro_def);
27202720
return true;
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
// RUN: %clang_cc1 -E -C %s | FileCheck -check-prefix=CHECK-C -strict-whitespace %s
22
// CHECK-C: boo bork bar // zot
3+
// CHECK-C: ( 0 );
4+
// CHECK-C: ( 0,1,2 );
5+
// CHECK-C: ( 0,1,2 );
36

47
// RUN: %clang_cc1 -E -CC %s | FileCheck -check-prefix=CHECK-CC -strict-whitespace %s
58
// CHECK-CC: boo bork /* blah*/ bar // zot
9+
// CHECK-CC: (/**/0/**/);
10+
// CHECK-CC: (/**/0,1,2/**/);
11+
// CHECK-CC: (/**/0,1,2/**/);
612

713
// RUN: %clang_cc1 -E %s | FileCheck -strict-whitespace %s
814
// CHECK: boo bork bar
15+
// CHECK: ( 0 );
16+
// CHECK: ( 0,1,2 );
17+
// CHECK: ( 0,1,2 );
918

1019

1120
#define FOO bork // blah
1221
boo FOO bar // zot
22+
#define M(/**/x/**/) (/**/x/**/)
23+
M(0);
24+
#define M2(/**/.../**/) (/**/__VA_ARGS__/**/)
25+
M2(0,1,2);
26+
#define M3(/**/x.../**/) (/**/x/**/)
27+
M3(0,1,2);
1328

0 commit comments

Comments
 (0)