From 0a88921083656be573ac2532877961e358c2137d Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Thu, 11 Feb 2016 18:54:02 +0000 Subject: [PATCH] [Modules] Early-exit if ReadOptionsBlock fails to avoid crashing If we didn't tell ReadOptionsBlock to allow failures then we can't assume that the stream is not in the middle of a block if it returns out-of-date. This was causing a crash when we tried to continue reading. Also, it's just generally a good idea to early-exit if we're doing implicit module builds, since we will want to immediately rebuild this module anyway and there's no reason to waste time continuing after failure. rdar://problem/24114938 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@260563 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Serialization/ASTReader.cpp | 7 ++++--- test/Modules/implicit-build-config-out-of-date.m | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 test/Modules/implicit-build-config-out-of-date.m diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index b2f59d1fa6..ac78da2614 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -2269,9 +2269,10 @@ ASTReader::ReadControlBlock(ModuleFile &F, (AllowConfigurationMismatch && Result == ConfigurationMismatch)) Result = Success; - // If we've diagnosed a problem, we're done. - if (Result != Success && - isDiagnosedResult(Result, ClientLoadCapabilities)) + // If we can't load the module, exit early since we likely + // will rebuild the module anyway. The stream may be in the + // middle of a block. + if (Result != Success) return Result; } else if (Stream.SkipBlock()) { Error("malformed block record in AST file"); diff --git a/test/Modules/implicit-build-config-out-of-date.m b/test/Modules/implicit-build-config-out-of-date.m new file mode 100644 index 0000000000..c8c02ff0a8 --- /dev/null +++ b/test/Modules/implicit-build-config-out-of-date.m @@ -0,0 +1,6 @@ +// RUN: rm -rf %t +// Use -DA=0 so that there is at least one preprocessor option serialized after the diagnostic options. +// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fimplicit-module-maps -I %S/Inputs %s -DA=0 -Rmodule-build -verify +// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fimplicit-module-maps -I %S/Inputs %s -DA=0 -Werror -Rmodule-build -verify + +@import category_top; // expected-remark {{building module}} expected-remark {{finished building}} -- 2.40.0