Skip to content

Commit e064bfe

Browse files
authored
Merge pull request #298 from francisvm/up-to-bitstream-remarks/apple/stable/20190619
Manually merge apple/stable/20190619-> swift/master up to bitstream remarks The swift-ci build & test status was verified over at swiftlang/swift#28214
2 parents e6967ac + c555ebe commit e064bfe

File tree

183 files changed

+9284
-2838
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+9284
-2838
lines changed

clang-tools-extra/clang-doc/BitcodeReader.cpp

Lines changed: 64 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -489,24 +489,27 @@ template <typename T>
489489
llvm::Error ClangDocBitcodeReader::readRecord(unsigned ID, T I) {
490490
Record R;
491491
llvm::StringRef Blob;
492-
unsigned RecID = Stream.readRecord(ID, R, &Blob);
493-
return parseRecord(R, RecID, Blob, I);
492+
llvm::Expected<unsigned> MaybeRecID = Stream.readRecord(ID, R, &Blob);
493+
if (!MaybeRecID)
494+
return MaybeRecID.takeError();
495+
return parseRecord(R, MaybeRecID.get(), Blob, I);
494496
}
495497

496498
template <>
497499
llvm::Error ClangDocBitcodeReader::readRecord(unsigned ID, Reference *I) {
498500
Record R;
499501
llvm::StringRef Blob;
500-
unsigned RecID = Stream.readRecord(ID, R, &Blob);
501-
return parseRecord(R, RecID, Blob, I, CurrentReferenceField);
502+
llvm::Expected<unsigned> MaybeRecID = Stream.readRecord(ID, R, &Blob);
503+
if (!MaybeRecID)
504+
return MaybeRecID.takeError();
505+
return parseRecord(R, MaybeRecID.get(), Blob, I, CurrentReferenceField);
502506
}
503507

504508
// Read a block of records into a single info.
505509
template <typename T>
506510
llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, T I) {
507-
if (Stream.EnterSubBlock(ID))
508-
return llvm::make_error<llvm::StringError>("Unable to enter subblock.\n",
509-
llvm::inconvertibleErrorCode());
511+
if (llvm::Error Err = Stream.EnterSubBlock(ID))
512+
return Err;
510513

511514
while (true) {
512515
unsigned BlockOrCode = 0;
@@ -519,9 +522,9 @@ llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, T I) {
519522
case Cursor::BlockEnd:
520523
return llvm::Error::success();
521524
case Cursor::BlockBegin:
522-
if (auto Err = readSubBlock(BlockOrCode, I)) {
523-
if (!Stream.SkipBlock())
524-
continue;
525+
if (llvm::Error Err = readSubBlock(BlockOrCode, I)) {
526+
if (llvm::Error Skipped = Stream.SkipBlock())
527+
return joinErrors(std::move(Err), std::move(Skipped));
525528
return Err;
526529
}
527530
continue;
@@ -603,24 +606,41 @@ ClangDocBitcodeReader::skipUntilRecordOrBlock(unsigned &BlockOrRecordID) {
603606
BlockOrRecordID = 0;
604607

605608
while (!Stream.AtEndOfStream()) {
606-
unsigned Code = Stream.ReadCode();
609+
Expected<unsigned> MaybeCode = Stream.ReadCode();
610+
if (!MaybeCode) {
611+
// FIXME this drops the error on the floor.
612+
consumeError(MaybeCode.takeError());
613+
return Cursor::BadBlock;
614+
}
607615

608-
switch ((llvm::bitc::FixedAbbrevIDs)Code) {
616+
unsigned Code = MaybeCode.get();
617+
if (Code >= static_cast<unsigned>(llvm::bitc::FIRST_APPLICATION_ABBREV)) {
618+
BlockOrRecordID = Code;
619+
return Cursor::Record;
620+
}
621+
switch (static_cast<llvm::bitc::FixedAbbrevIDs>(Code)) {
609622
case llvm::bitc::ENTER_SUBBLOCK:
610-
BlockOrRecordID = Stream.ReadSubBlockID();
623+
if (Expected<unsigned> MaybeID = Stream.ReadSubBlockID())
624+
BlockOrRecordID = MaybeID.get();
625+
else {
626+
// FIXME this drops the error on the floor.
627+
consumeError(MaybeID.takeError());
628+
}
611629
return Cursor::BlockBegin;
612630
case llvm::bitc::END_BLOCK:
613631
if (Stream.ReadBlockEnd())
614632
return Cursor::BadBlock;
615633
return Cursor::BlockEnd;
616634
case llvm::bitc::DEFINE_ABBREV:
617-
Stream.ReadAbbrevRecord();
635+
if (llvm::Error Err = Stream.ReadAbbrevRecord()) {
636+
// FIXME this drops the error on the floor.
637+
consumeError(std::move(Err));
638+
}
618639
continue;
619640
case llvm::bitc::UNABBREV_RECORD:
620641
return Cursor::BadBlock;
621-
default:
622-
BlockOrRecordID = Code;
623-
return Cursor::Record;
642+
case llvm::bitc::FIRST_APPLICATION_ABBREV:
643+
llvm_unreachable("Unexpected abbrev id.");
624644
}
625645
}
626646
llvm_unreachable("Premature stream end.");
@@ -632,17 +652,24 @@ llvm::Error ClangDocBitcodeReader::validateStream() {
632652
llvm::inconvertibleErrorCode());
633653

634654
// Sniff for the signature.
635-
if (Stream.Read(8) != BitCodeConstants::Signature[0] ||
636-
Stream.Read(8) != BitCodeConstants::Signature[1] ||
637-
Stream.Read(8) != BitCodeConstants::Signature[2] ||
638-
Stream.Read(8) != BitCodeConstants::Signature[3])
639-
return llvm::make_error<llvm::StringError>("Invalid bitcode signature.\n",
640-
llvm::inconvertibleErrorCode());
655+
for (int Idx = 0; Idx != 4; ++Idx) {
656+
Expected<llvm::SimpleBitstreamCursor::word_t> MaybeRead = Stream.Read(8);
657+
if (!MaybeRead)
658+
return MaybeRead.takeError();
659+
else if (MaybeRead.get() != BitCodeConstants::Signature[Idx])
660+
return llvm::make_error<llvm::StringError>(
661+
"Invalid bitcode signature.\n", llvm::inconvertibleErrorCode());
662+
}
641663
return llvm::Error::success();
642664
}
643665

644666
llvm::Error ClangDocBitcodeReader::readBlockInfoBlock() {
645-
BlockInfo = Stream.ReadBlockInfoBlock();
667+
Expected<Optional<llvm::BitstreamBlockInfo>> MaybeBlockInfo =
668+
Stream.ReadBlockInfoBlock();
669+
if (!MaybeBlockInfo)
670+
return MaybeBlockInfo.takeError();
671+
else
672+
BlockInfo = MaybeBlockInfo.get();
646673
if (!BlockInfo)
647674
return llvm::make_error<llvm::StringError>(
648675
"Unable to parse BlockInfoBlock.\n", llvm::inconvertibleErrorCode());
@@ -685,11 +712,16 @@ ClangDocBitcodeReader::readBitcode() {
685712

686713
// Read the top level blocks.
687714
while (!Stream.AtEndOfStream()) {
688-
unsigned Code = Stream.ReadCode();
689-
if (Code != llvm::bitc::ENTER_SUBBLOCK)
715+
Expected<unsigned> MaybeCode = Stream.ReadCode();
716+
if (!MaybeCode)
717+
return MaybeCode.takeError();
718+
if (MaybeCode.get() != llvm::bitc::ENTER_SUBBLOCK)
690719
return llvm::make_error<llvm::StringError>(
691720
"No blocks in input.\n", llvm::inconvertibleErrorCode());
692-
unsigned ID = Stream.ReadSubBlockID();
721+
Expected<unsigned> MaybeID = Stream.ReadSubBlockID();
722+
if (!MaybeID)
723+
return MaybeID.takeError();
724+
unsigned ID = MaybeID.get();
693725
switch (ID) {
694726
// NamedType and Comment blocks should not appear at the top level
695727
case BI_TYPE_BLOCK_ID:
@@ -718,8 +750,11 @@ ClangDocBitcodeReader::readBitcode() {
718750
return std::move(Err);
719751
continue;
720752
default:
721-
if (!Stream.SkipBlock())
722-
continue;
753+
if (llvm::Error Err = Stream.SkipBlock()) {
754+
// FIXME this drops the error on the floor.
755+
consumeError(std::move(Err));
756+
}
757+
continue;
723758
}
724759
}
725760
return std::move(Infos);

clang-tools-extra/clang-doc/BitcodeReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "clang/AST/AST.h"
2121
#include "llvm/ADT/Optional.h"
2222
#include "llvm/ADT/SmallVector.h"
23-
#include "llvm/Bitcode/BitstreamReader.h"
23+
#include "llvm/Bitstream/BitstreamReader.h"
2424
#include "llvm/Support/Error.h"
2525

2626
namespace clang {

clang-tools-extra/clang-doc/BitcodeWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static const std::vector<std::pair<BlockId, std::vector<RecordId>>>
213213

214214
// AbbreviationMap
215215

216-
constexpr char BitCodeConstants::Signature[];
216+
constexpr unsigned char BitCodeConstants::Signature[];
217217

218218
void ClangDocBitcodeWriter::AbbreviationMap::add(RecordId RID,
219219
unsigned AbbrevID) {

clang-tools-extra/clang-doc/BitcodeWriter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "llvm/ADT/DenseMap.h"
2121
#include "llvm/ADT/SmallVector.h"
2222
#include "llvm/ADT/StringRef.h"
23-
#include "llvm/Bitcode/BitstreamWriter.h"
23+
#include "llvm/Bitstream/BitstreamWriter.h"
2424
#include <initializer_list>
2525
#include <vector>
2626

@@ -44,7 +44,7 @@ struct BitCodeConstants {
4444
static constexpr unsigned ReferenceTypeSize = 8U;
4545
static constexpr unsigned USRLengthSize = 6U;
4646
static constexpr unsigned USRBitLengthSize = 8U;
47-
static constexpr char Signature[4] = {'D', 'O', 'C', 'S'};
47+
static constexpr unsigned char Signature[4] = {'D', 'O', 'C', 'S'};
4848
static constexpr int USRHashSize = 20;
4949
};
5050

clang-tools-extra/clang-doc/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
set(LLVM_LINK_COMPONENTS
22
support
3-
BitReader
4-
BitWriter
3+
BitstreamReader
54
)
65

76
add_clang_library(clangDoc

clang-tools-extra/clangd/ClangdUnit.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,9 @@ ParsedAST::build(std::unique_ptr<CompilerInvocation> CI,
421421
collectIWYUHeaderMaps(&CanonIncludes);
422422
Clang->getPreprocessor().addCommentHandler(IWYUHandler.get());
423423

424-
if (!Action->Execute())
425-
log("Execute() failed when building AST for {0}", MainInput.getFile());
424+
if (llvm::Error Err = Action->Execute())
425+
log("Execute() failed when building AST for {0}: {1}", MainInput.getFile(),
426+
toString(std::move(Err)));
426427

427428
std::vector<Decl *> ParsedDecls = Action->takeTopLevelDecls();
428429
// AST traversals should exclude the preamble, to avoid performance cliffs.

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,8 +1106,9 @@ bool semaCodeComplete(std::unique_ptr<CodeCompleteConsumer> Consumer,
11061106
if (Includes)
11071107
Clang->getPreprocessor().addPPCallbacks(
11081108
collectIncludeStructureCallback(Clang->getSourceManager(), Includes));
1109-
if (!Action.Execute()) {
1110-
log("Execute() failed when running codeComplete for {0}", Input.FileName);
1109+
if (llvm::Error Err = Action.Execute()) {
1110+
log("Execute() failed when running codeComplete for {0}: {1}",
1111+
Input.FileName, toString(std::move(Err)));
11111112
return false;
11121113
}
11131114
Action.EndSourceFile();

clang-tools-extra/clangd/index/Background.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,9 @@ llvm::Error BackgroundIndex::index(tooling::CompileCommand Cmd,
456456
if (!Action->BeginSourceFile(*Clang, Input))
457457
return llvm::createStringError(llvm::inconvertibleErrorCode(),
458458
"BeginSourceFile() failed");
459-
if (!Action->Execute())
460-
return llvm::createStringError(llvm::inconvertibleErrorCode(),
461-
"Execute() failed");
459+
if (llvm::Error Err = Action->Execute())
460+
return Err;
461+
462462
Action->EndSourceFile();
463463
if (Clang->hasDiagnostics() &&
464464
Clang->getDiagnostics().hasUncompilableErrorOccurred()) {

clang-tools-extra/clangd/unittests/HeadersTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class HeadersTest : public ::testing::Test {
6868
IncludeStructure Includes;
6969
Clang->getPreprocessor().addPPCallbacks(
7070
collectIncludeStructureCallback(Clang->getSourceManager(), &Includes));
71-
EXPECT_TRUE(Action.Execute());
71+
EXPECT_FALSE(Action.Execute());
7272
Action.EndSourceFile();
7373
return Includes;
7474
}

clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include "BitcodeWriter.h"
1111
#include "ClangDocTest.h"
1212
#include "Representation.h"
13-
#include "llvm/Bitcode/BitstreamReader.h"
14-
#include "llvm/Bitcode/BitstreamWriter.h"
13+
#include "llvm/Bitstream/BitstreamReader.h"
14+
#include "llvm/Bitstream/BitstreamWriter.h"
1515
#include "gtest/gtest.h"
1616

1717
namespace clang {

clang-tools-extra/unittests/clang-doc/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
set(LLVM_LINK_COMPONENTS
22
support
3-
BitReader
4-
BitWriter
3+
BitstreamReader
54
)
65

76
get_filename_component(CLANG_DOC_SOURCE_DIR

clang/docs/UsersManual.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ output format of the diagnostics that it generates.
340340

341341
``-fsave-optimization-record=yaml``: A structured YAML format.
342342

343+
- .. _opt_fsave_optimization_record_bitstream:
344+
345+
``-fsave-optimization-record=bitstream``: A binary format based on LLVM
346+
Bitstream.
347+
343348
.. _opt_foptimization-record-file:
344349

345350
**-foptimization-record-file**

clang/include/clang/Basic/Diagnostic.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/ADT/StringRef.h"
2626
#include "llvm/ADT/iterator_range.h"
2727
#include "llvm/Support/Compiler.h"
28+
#include "llvm/Support/Error.h"
2829
#include <cassert>
2930
#include <cstdint>
3031
#include <limits>
@@ -472,6 +473,9 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
472473
/// Second string argument for the delayed diagnostic.
473474
std::string DelayedDiagArg2;
474475

476+
/// Third string argument for the delayed diagnostic.
477+
std::string DelayedDiagArg3;
478+
475479
/// Optional flag value.
476480
///
477481
/// Some flags accept values, for instance: -Wframe-larger-than=<value> and
@@ -875,8 +879,12 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
875879
/// \param Arg2 A string argument that will be provided to the
876880
/// diagnostic. A copy of this string will be stored in the
877881
/// DiagnosticsEngine object itself.
882+
///
883+
/// \param Arg3 A string argument that will be provided to the
884+
/// diagnostic. A copy of this string will be stored in the
885+
/// DiagnosticsEngine object itself.
878886
void SetDelayedDiagnostic(unsigned DiagID, StringRef Arg1 = "",
879-
StringRef Arg2 = "");
887+
StringRef Arg2 = "", StringRef Arg3 = "");
880888

881889
/// Clear out the current diagnostic.
882890
void Clear() { CurDiagID = std::numeric_limits<unsigned>::max(); }
@@ -1303,6 +1311,12 @@ inline DiagnosticBuilder DiagnosticsEngine::Report(SourceLocation Loc,
13031311
return DiagnosticBuilder(this);
13041312
}
13051313

1314+
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
1315+
llvm::Error &&E) {
1316+
DB.AddString(toString(std::move(E)));
1317+
return DB;
1318+
}
1319+
13061320
inline DiagnosticBuilder DiagnosticsEngine::Report(unsigned DiagID) {
13071321
return Report(SourceLocation(), DiagID);
13081322
}

clang/include/clang/Basic/DiagnosticSerializationKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def note_module_file_imported_by : Note<
7171
"imported by %select{|module '%2' in }1'%0'">;
7272
def err_module_file_not_module : Error<
7373
"AST file '%0' was not built as a module">, DefaultFatal;
74+
def err_module_file_missing_top_level_submodule : Error<
75+
"module file '%0' is missing its top-level submodule">, DefaultFatal;
7476

7577
def remark_module_import : Remark<
7678
"importing module '%0'%select{| into '%3'}2 from '%1'">,

clang/include/clang/Frontend/FrontendAction.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "clang/Frontend/ASTUnit.h"
2424
#include "clang/Frontend/FrontendOptions.h"
2525
#include "llvm/ADT/StringRef.h"
26+
#include "llvm/Support/Error.h"
2627
#include <memory>
2728
#include <string>
2829
#include <vector>
@@ -229,7 +230,7 @@ class FrontendAction {
229230
bool BeginSourceFile(CompilerInstance &CI, const FrontendInputFile &Input);
230231

231232
/// Set the source manager's main input file, and run the action.
232-
bool Execute();
233+
llvm::Error Execute();
233234

234235
/// Perform any per-file post processing, deallocate per-file
235236
/// objects, and run statistics and output file cleanup code.

clang/include/clang/Frontend/SerializedDiagnosticPrinter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include "clang/Basic/LLVM.h"
1313
#include "clang/Frontend/SerializedDiagnostics.h"
14-
#include "llvm/Bitcode/BitstreamWriter.h"
14+
#include "llvm/Bitstream/BitstreamWriter.h"
1515

1616
namespace llvm {
1717
class raw_ostream;

clang/include/clang/Frontend/SerializedDiagnosticReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#define LLVM_CLANG_FRONTEND_SERIALIZEDDIAGNOSTICREADER_H
1111

1212
#include "clang/Basic/LLVM.h"
13-
#include "llvm/Bitcode/BitstreamReader.h"
13+
#include "llvm/Bitstream/BitstreamReader.h"
1414
#include "llvm/ADT/StringRef.h"
1515
#include "llvm/Support/ErrorOr.h"
1616
#include <system_error>

clang/include/clang/Frontend/SerializedDiagnostics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef LLVM_CLANG_FRONTEND_SERIALIZE_DIAGNOSTICS_H_
1010
#define LLVM_CLANG_FRONTEND_SERIALIZE_DIAGNOSTICS_H_
1111

12-
#include "llvm/Bitcode/BitCodes.h"
12+
#include "llvm/Bitstream/BitCodes.h"
1313

1414
namespace clang {
1515
namespace serialized_diags {

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "clang/Basic/OperatorKinds.h"
2424
#include "clang/Basic/SourceLocation.h"
2525
#include "llvm/ADT/DenseMapInfo.h"
26-
#include "llvm/Bitcode/BitCodes.h"
26+
#include "llvm/Bitstream/BitCodes.h"
2727
#include <cassert>
2828
#include <cstdint>
2929

0 commit comments

Comments
 (0)