Skip to content

Commit 4953213

Browse files
committed
Make AST reading work better with LLVM_APPEND_VC_REV=NO
With LLVM_APPEND_VC_REV=NO, Modules/merge-lifetime-extended-temporary.cpp would fail if it ran before a0f50d7 (which changed the serialization format) and then after, for these reasons: 1. With LLVM_APPEND_VC_REV=NO, the module hash before and after the change was the same. 2. Modules/merge-lifetime-extended-temporary.cpp is the only test we have that uses -fmodule-cache-path=%t that a) actually writes to the cache path b) doesn't do `rm -rf %t` at the top of the test So the old run would write a module file, and then the new run would try to load it, but the serialized format changed. Do several things to fix this: 1. Include clang::serialization::VERSION_MAJOR/VERSION_MINOR in the module hash, so that when the AST format changes (...and we remember to bump these), we use a different module cache dir. 2. Bump VERSION_MAJOR, since a0f50d7 changed the on-disk format in a way that a gch file written before that change can't be read after that change. 3. Add `rm -rf %t` to all tests that pass -fmodule-cache-path=%t. This is unnecessary from a correctness PoV after 1 and 2, but makes it so that we don't amass many cache dirs over time. (Arguably, it also makes it so that the test suite doesn't catch when we change the serialization format but don't bump clang::serialization::VERSION_MAJOR/VERSION_MINOR; oh well.) Differential Revision: https://reviews.llvm.org/D73202
1 parent af80b8c commit 4953213

File tree

7 files changed

+12
-1
lines changed

7 files changed

+12
-1
lines changed

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace serialization {
4141
/// Version 4 of AST files also requires that the version control branch and
4242
/// revision match exactly, since there is no backward compatibility of
4343
/// AST files at this time.
44-
const unsigned VERSION_MAJOR = 8;
44+
const unsigned VERSION_MAJOR = 9;
4545

4646
/// AST file minor version number supported by this version of
4747
/// Clang.

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "clang/Lex/HeaderSearchOptions.h"
4242
#include "clang/Lex/PreprocessorOptions.h"
4343
#include "clang/Sema/CodeCompleteOptions.h"
44+
#include "clang/Serialization/ASTBitCodes.h"
4445
#include "clang/Serialization/ModuleFileExtension.h"
4546
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
4647
#include "llvm/ADT/APInt.h"
@@ -3635,6 +3636,11 @@ std::string CompilerInvocation::getModuleHash() const {
36353636
// CityHash, but this will do for now.
36363637
hash_code code = hash_value(getClangFullRepositoryVersion());
36373638

3639+
// Also include the serialization version, in case LLVM_APPEND_VC_REV is off
3640+
// and getClangFullRepositoryVersion() doesn't include git revision.
3641+
code = hash_combine(code, serialization::VERSION_MAJOR,
3642+
serialization::VERSION_MINOR);
3643+
36383644
// Extend the signature with the language options
36393645
#define LANGOPT(Name, Bits, Default, Description) \
36403646
code = hash_combine(code, LangOpts->Name);

clang/test/Modules/diagnostics.modulemap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// RUN: rm -rf %t
12
// RUN: not %clang_cc1 -fmodules -fmodules-cache-path=%t -fmodule-map-file=%S/Inputs/diagnostics-aux.modulemap -fmodule-map-file=%s -fsyntax-only -x c++ /dev/null 2>&1 | FileCheck %s --implicit-check-not error:
23

34
// CHECK: In file included from {{.*}}diagnostics-aux.modulemap:3:

clang/test/Modules/exception-spec.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// RUN: rm -rf %t
12
// RUN: %clang_cc1 -x c++ -std=c++17 -fmodules -fmodules-local-submodule-visibility -fmodules-cache-path=%t %s -verify
23

34
// expected-no-diagnostics

clang/test/Modules/merge-lifetime-extended-temporary.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// RUN: rm -rf %t
12
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-lifetime-extended-temporary -verify -std=c++11 %s -DORDER=1
23
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-lifetime-extended-temporary -verify -std=c++11 %s -DORDER=2
34

clang/test/Modules/objc-method-redecl.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// RUN: rm -rf %t
12
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -x objective-c-header -emit-pch %S/Inputs/objc-method-redecl.h -o %t.pch -Wno-objc-root-class
23
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -x objective-c -include-pch %t.pch %s -verify -Wno-objc-root-class
34
// expected-no-diagnostics

clang/test/Modules/using-decl-inheritance.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// RUN: rm -rf %t
12
// RUN: %clang_cc1 -x c++ -fmodules -fmodules-local-submodule-visibility -fmodules-cache-path=%t %s -verify
23
// RUN: %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t %s -verify
34

0 commit comments

Comments
 (0)