Skip to content

Commit aa265b0

Browse files
committedOct 21, 2016
Module: correctly set the module file kind when emitting file_modified.
rdar://28503343 Differential Revision: http://reviews.llvm.org/D25806 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284899 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent c2d70a3 commit aa265b0

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed
 

‎include/clang/Basic/DiagnosticSerializationKinds.td

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ def err_fe_pch_malformed_block : Error<
2121
def err_fe_pch_file_modified : Error<
2222
"file '%0' has been modified since the precompiled header '%1' was built">,
2323
DefaultFatal;
24+
def err_fe_module_file_modified : Error<
25+
"file '%0' has been modified since the module file '%1' was built">,
26+
DefaultFatal;
27+
def err_fe_ast_file_modified : Error<
28+
"file '%0' has been modified since the AST file '%1' was built">,
29+
DefaultFatal;
2430
def err_fe_pch_file_overridden : Error<
2531
"file '%0' from the precompiled header has been overridden">;
2632
def note_pch_required_by : Note<"'%0' required by '%1'">;

‎lib/Serialization/ASTReader.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -1983,6 +1983,7 @@ ASTReader::readInputFileInfo(ModuleFile &F, unsigned ID) {
19831983
return R;
19841984
}
19851985

1986+
static unsigned moduleKindForDiagnostic(ModuleKind Kind);
19861987
InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
19871988
// If this ID is bogus, just return an empty input file.
19881989
if (ID == 0 || ID > F.InputFilesLoaded.size())
@@ -2079,7 +2080,13 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
20792080

20802081
// The top-level PCH is stale.
20812082
StringRef TopLevelPCHName(ImportStack.back()->FileName);
2082-
Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName);
2083+
unsigned DiagnosticKind = moduleKindForDiagnostic(ImportStack.back()->Kind);
2084+
if (DiagnosticKind == 0)
2085+
Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName);
2086+
else if (DiagnosticKind == 1)
2087+
Error(diag::err_fe_module_file_modified, Filename, TopLevelPCHName);
2088+
else
2089+
Error(diag::err_fe_ast_file_modified, Filename, TopLevelPCHName);
20832090

20842091
// Print the import stack.
20852092
if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) {

‎test/Modules/module-file-modified.c

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir %t
3+
// RUN: echo 'int foo = 0;' > %t/a.h
4+
// RUN: echo 'module A { header "a.h" }' > %t/m.modulemap
5+
// RUN: %clang_cc1 -fmodules -emit-module -fmodule-name=A -x c %t/m.modulemap -o %t/m.pcm
6+
// RUN: echo 'int bar;' > %t/a.h
7+
// RUN: not %clang_cc1 -fmodules -fmodule-file=%t/m.pcm -fmodule-map-file=%t/m.modulemap -x c %s -I%t -fsyntax-only 2>&1 | FileCheck %s
8+
#include "a.h"
9+
int foo = 0; // redefinition of 'foo'
10+
// CHECK: fatal error: file {{.*}} has been modified since the module file {{.*}} was built
11+
// REQUIRES: shell

0 commit comments

Comments
 (0)
Please sign in to comment.