Skip to content

Commit c68b8c8

Browse files
committed
[Lex] Make sure to notify MultipleIncludeOpt for "read tokens" during fast dependency directive lexing
Otherwise a header may be erroneously marked as having a header macro guard and won't get re-included. Differential Revision: https://reviews.llvm.org/D128772
1 parent 6fa65f8 commit c68b8c8

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

clang/lib/Lex/Lexer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4248,6 +4248,10 @@ bool Lexer::LexDependencyDirectiveToken(Token &Result) {
42484248

42494249
const dependency_directives_scan::Token &DDTok =
42504250
DepDirectives.front().Tokens[NextDepDirectiveTokenIndex++];
4251+
if (NextDepDirectiveTokenIndex > 1 || DDTok.Kind != tok::hash) {
4252+
// Read something other than a preprocessor directive hash.
4253+
MIOpt.ReadToken();
4254+
}
42514255

42524256
const char *TokPtr = convertDependencyDirectiveToken(DDTok, Result);
42534257

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
4+
5+
// RUN: clang-scan-deps -compilation-database %t/cdb.json | FileCheck %s
6+
7+
// CHECK: t.c
8+
// CHECK: top.h
9+
// CHECK: n1.h
10+
// CHECK: n2.h
11+
// CHECK: n3.h
12+
13+
//--- cdb.json.template
14+
[
15+
{
16+
"directory": "DIR",
17+
"command": "clang -fsyntax-only DIR/t.c",
18+
"file": "DIR/t.c"
19+
}
20+
]
21+
22+
//--- t.c
23+
24+
#include "top.h"
25+
#define INCLUDE_N3
26+
#include "top.h"
27+
28+
//--- top.h
29+
#ifndef _TOP_H_
30+
#define _TOP_H_
31+
32+
#include "n1.h"
33+
34+
#endif
35+
36+
// More stuff after following '#endif', should invalidate the macro guard optimization,
37+
// and allow `top.h` to get re-included.
38+
#include "n2.h"
39+
40+
//--- n1.h
41+
42+
//--- n2.h
43+
#ifdef INCLUDE_N3
44+
#include "n3.h"
45+
#endif
46+
47+
//--- n3.h

0 commit comments

Comments
 (0)