Skip to content

Commit dc75f74

Browse files
committed
[clang][deps] Respect Lexer::cutOffLexing() (llvm#134404)
This is crucial when recovering from fatal loader errors. Without it, the `Lexer` keeps yielding more tokens and the compiler may access invalid `ASTReader` state. rdar://133388373 (cherry picked from commit cde90e6)
1 parent fdb2d70 commit dc75f74

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

clang/lib/Lex/Lexer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4545,6 +4545,9 @@ bool Lexer::LexDependencyDirectiveToken(Token &Result) {
45454545

45464546
using namespace dependency_directives_scan;
45474547

4548+
if (BufferPtr == BufferEnd)
4549+
return LexEndOfFile(Result, BufferPtr);
4550+
45484551
while (NextDepDirectiveTokenIndex == DepDirectives.front().Tokens.size()) {
45494552
if (DepDirectives.front().Kind == pp_eof)
45504553
return LexEndOfFile(Result, BufferEnd);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// This test checks that we don't crash when we load two conflicting PCM files
2+
// and instead emit the appropriate diagnostics.
3+
4+
// RUN: rm -rf %t
5+
// RUN: split-file %s %t
6+
7+
// RUN: mkdir %t/frameworks1
8+
9+
// RUN: clang-scan-deps -format experimental-full -o %t/deps1.json -- \
10+
// RUN: %clang -fmodules -fmodules-cache-path=%t/cache \
11+
// RUN: -F %t/frameworks1 -F %t/frameworks2 \
12+
// RUN: -c %t/tu1.m -o %t/tu1.o
13+
14+
// RUN: cp -r %t/frameworks2/A.framework %t/frameworks1
15+
16+
// RUN: not clang-scan-deps -format experimental-full -o %t/deps2.json -- \
17+
// RUN: %clang -fmodules -fmodules-cache-path=%t/cache \
18+
// RUN: -F %t/frameworks1 -F %t/frameworks2 \
19+
// RUN: -c %t/tu2.m -o %t/tu2.o \
20+
// RUN: 2>&1 | FileCheck %s
21+
22+
// CHECK: fatal error: module 'A' is defined in both '{{.*}}.pcm' and '{{.*}}.pcm'
23+
24+
//--- frameworks2/A.framework/Modules/module.modulemap
25+
framework module A { header "A.h" }
26+
//--- frameworks2/A.framework/Headers/A.h
27+
#define MACRO_A 1
28+
29+
//--- frameworks2/B.framework/Modules/module.modulemap
30+
framework module B { header "B.h" }
31+
//--- frameworks2/B.framework/Headers/B.h
32+
#include <A/A.h>
33+
34+
//--- tu1.m
35+
#include <B/B.h>
36+
37+
//--- tu2.m
38+
#include <A/A.h>
39+
#include <B/B.h> // This results in a conflict and a fatal loader error.
40+
41+
#if MACRO_A // This crashes with lexer that does not respect `cutOfLexing()`.
42+
#endif

0 commit comments

Comments
 (0)