Skip to content

Commit

Permalink
Merged master:a7b209a6d40d into amd-gfx:45250cd1b7e3
Browse files Browse the repository at this point in the history
Local branch amd-gfx 45250cd Merged master:220de1f32add into amd-gfx:e5f653eaa249
Remote branch master a7b209a llvm-symbolizer: Exit non-zero when DWARF parsing errors have been rendered
  • Loading branch information
Sw authored and Sw committed Oct 15, 2020
2 parents 45250cd + a7b209a commit a59fae9
Show file tree
Hide file tree
Showing 60 changed files with 975 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ void SuspiciousSemicolonCheck::check(const MatchFinder::MatchResult &Result) {

SourceLocation LocEnd = Semicolon->getEndLoc();
FileID FID = SM.getFileID(LocEnd);
const llvm::MemoryBuffer *Buffer = SM.getBuffer(FID, LocEnd);
llvm::MemoryBufferRef Buffer = SM.getBufferOrFake(FID, LocEnd);
Lexer Lexer(SM.getLocForStartOfFile(FID), Ctxt.getLangOpts(),
Buffer->getBufferStart(), SM.getCharacterData(LocEnd) + 1,
Buffer->getBufferEnd());
Buffer.getBufferStart(), SM.getCharacterData(LocEnd) + 1,
Buffer.getBufferEnd());
if (Lexer.LexFromRawLexer(Token))
return;

Expand Down
10 changes: 5 additions & 5 deletions clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,14 +794,14 @@ static bool areExprsFromDifferentMacros(const Expr *LhsExpr,
SM.getDecomposedLoc(SM.getExpansionLoc(Lsr.getBegin()));
std::pair<FileID, unsigned> RsrLocInfo =
SM.getDecomposedLoc(SM.getExpansionLoc(Rsr.getBegin()));
const llvm::MemoryBuffer *MB = SM.getBuffer(LsrLocInfo.first);
llvm::MemoryBufferRef MB = SM.getBufferOrFake(LsrLocInfo.first);

const char *LTokenPos = MB->getBufferStart() + LsrLocInfo.second;
const char *RTokenPos = MB->getBufferStart() + RsrLocInfo.second;
const char *LTokenPos = MB.getBufferStart() + LsrLocInfo.second;
const char *RTokenPos = MB.getBufferStart() + RsrLocInfo.second;
Lexer LRawLex(SM.getLocForStartOfFile(LsrLocInfo.first), LO,
MB->getBufferStart(), LTokenPos, MB->getBufferEnd());
MB.getBufferStart(), LTokenPos, MB.getBufferEnd());
Lexer RRawLex(SM.getLocForStartOfFile(RsrLocInfo.first), LO,
MB->getBufferStart(), RTokenPos, MB->getBufferEnd());
MB.getBufferStart(), RTokenPos, MB.getBufferEnd());

Token LTok, RTok;
do { // Compare the expressions token-by-token.
Expand Down
3 changes: 2 additions & 1 deletion clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ SourceLocation StaticAssertCheck::getLastParenLoc(const ASTContext *ASTCtx,
const LangOptions &Opts = ASTCtx->getLangOpts();
const SourceManager &SM = ASTCtx->getSourceManager();

const llvm::MemoryBuffer *Buffer = SM.getBuffer(SM.getFileID(AssertLoc));
llvm::Optional<llvm::MemoryBufferRef> Buffer =
SM.getBufferOrNone(SM.getFileID(AssertLoc));
if (!Buffer)
return SourceLocation();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ bool MagicNumbersCheck::isSyntheticValue(const SourceManager *SourceManager,
return false;

const StringRef BufferIdentifier =
SourceManager->getBuffer(FileOffset.first)->getBufferIdentifier();
SourceManager->getBufferOrFake(FileOffset.first).getBufferIdentifier();

return BufferIdentifier.empty();
}
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/ParsedAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class ReplayPreamble : private PPCallbacks {
SrcMgr::CharacteristicKind Kind, FileID PrevFID) override {
// It'd be nice if there was a better way to identify built-in headers...
if (Reason == FileChangeReason::ExitFile &&
SM.getBuffer(PrevFID)->getBufferIdentifier() == "<built-in>")
SM.getBufferOrFake(PrevFID).getBufferIdentifier() == "<built-in>")
replay();
}

Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/SemanticHighlighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class HighlightingsBuilder {
TokRef = TokRef.drop_front(Conflicting.size());
}
const auto &SM = AST.getSourceManager();
StringRef MainCode = SM.getBuffer(SM.getMainFileID())->getBuffer();
StringRef MainCode = SM.getBufferOrFake(SM.getMainFileID()).getBuffer();

// Merge token stream with "inactive line" markers.
std::vector<HighlightingToken> WithInactiveLines;
Expand Down
7 changes: 3 additions & 4 deletions clang-tools-extra/clangd/SourceCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,8 @@ llvm::Optional<SourceRange> toHalfOpenFileRange(const SourceManager &SM,

llvm::StringRef toSourceCode(const SourceManager &SM, SourceRange R) {
assert(isValidFileRange(SM, R));
bool Invalid = false;
auto *Buf = SM.getBuffer(SM.getFileID(R.getBegin()), &Invalid);
assert(!Invalid);
auto Buf = SM.getBufferOrNone(SM.getFileID(R.getBegin()));
assert(Buf);

size_t BeginOffset = SM.getFileOffset(R.getBegin());
size_t EndOffset = SM.getFileOffset(R.getEnd());
Expand All @@ -456,7 +455,7 @@ llvm::StringRef toSourceCode(const SourceManager &SM, SourceRange R) {

llvm::Expected<SourceLocation> sourceLocationInMainFile(const SourceManager &SM,
Position P) {
llvm::StringRef Code = SM.getBuffer(SM.getMainFileID())->getBuffer();
llvm::StringRef Code = SM.getBufferOrFake(SM.getMainFileID()).getBuffer();
auto Offset =
positionToOffset(Code, P, /*AllowColumnBeyondLineLength=*/false);
if (!Offset)
Expand Down
15 changes: 8 additions & 7 deletions clang-tools-extra/modularize/PreprocessorTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,10 @@ static std::string getSourceString(clang::Preprocessor &PP,
// Retrieve source line from file image given a location.
static std::string getSourceLine(clang::Preprocessor &PP,
clang::SourceLocation Loc) {
const llvm::MemoryBuffer *MemBuffer =
PP.getSourceManager().getBuffer(PP.getSourceManager().getFileID(Loc));
const char *Buffer = MemBuffer->getBufferStart();
const char *BufferEnd = MemBuffer->getBufferEnd();
llvm::MemoryBufferRef MemBuffer = PP.getSourceManager().getBufferOrFake(
PP.getSourceManager().getFileID(Loc));
const char *Buffer = MemBuffer.getBufferStart();
const char *BufferEnd = MemBuffer.getBufferEnd();
const char *BeginPtr = PP.getSourceManager().getCharacterData(Loc);
const char *EndPtr = BeginPtr;
while (BeginPtr > Buffer) {
Expand All @@ -338,9 +338,10 @@ static std::string getSourceLine(clang::Preprocessor &PP,
// Retrieve source line from file image given a file ID and line number.
static std::string getSourceLine(clang::Preprocessor &PP, clang::FileID FileID,
int Line) {
const llvm::MemoryBuffer *MemBuffer = PP.getSourceManager().getBuffer(FileID);
const char *Buffer = MemBuffer->getBufferStart();
const char *BufferEnd = MemBuffer->getBufferEnd();
llvm::MemoryBufferRef MemBuffer =
PP.getSourceManager().getBufferOrFake(FileID);
const char *Buffer = MemBuffer.getBufferStart();
const char *BufferEnd = MemBuffer.getBufferEnd();
const char *BeginPtr = Buffer;
const char *EndPtr = BufferEnd;
int LineCounter = 1;
Expand Down
11 changes: 11 additions & 0 deletions clang/include/clang/Basic/SourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,17 @@ class SourceManager : public RefCountedBase<SourceManager> {
Diag, getFileManager(), Loc);
}

/// Return the buffer for the specified FileID.
///
/// If there is an error opening this buffer the first time, this
/// manufactures a temporary buffer and returns it.
llvm::MemoryBufferRef
getBufferOrFake(FileID FID, SourceLocation Loc = SourceLocation()) const {
if (auto B = getBufferOrNone(FID, Loc))
return *B;
return getFakeBufferForRecovery()->getMemBufferRef();
}

/// Return the buffer for the specified FileID.
///
/// If there is an error opening this buffer the first time, this
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Basic/Diagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ void DiagnosticsEngine::DiagStateMap::dump(SourceManager &SrcMgr,
PrintedOuterHeading = true;

llvm::errs() << "File " << &File << " <FileID " << ID.getHashValue()
<< ">: " << SrcMgr.getBuffer(ID)->getBufferIdentifier();
<< ">: " << SrcMgr.getBufferOrFake(ID).getBufferIdentifier();

if (F.second.Parent) {
std::pair<FileID, unsigned> Decomp =
SrcMgr.getDecomposedIncludedLoc(ID);
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Basic/SourceLocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ const char *FullSourceLoc::getCharacterData(bool *Invalid) const {

StringRef FullSourceLoc::getBufferData(bool *Invalid) const {
assert(isValid());
return SrcMgr->getBuffer(SrcMgr->getFileID(*this), Invalid)->getBuffer();
return SrcMgr->getBufferData(SrcMgr->getFileID(*this), Invalid);
}

std::pair<FileID, unsigned> FullSourceLoc::getDecomposedLoc() const {
Expand Down
16 changes: 9 additions & 7 deletions clang/lib/Basic/SourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1228,12 +1228,11 @@ const char *SourceManager::getCharacterData(SourceLocation SL,
/// this is significantly cheaper to compute than the line number.
unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos,
bool *Invalid) const {
bool MyInvalid = false;
const llvm::MemoryBuffer *MemBuf = getBuffer(FID, &MyInvalid);
llvm::Optional<llvm::MemoryBufferRef> MemBuf = getBufferOrNone(FID);
if (Invalid)
*Invalid = MyInvalid;
*Invalid = !MemBuf;

if (MyInvalid)
if (!MemBuf)
return 1;

// It is okay to request a position just past the end of the buffer.
Expand Down Expand Up @@ -1509,7 +1508,10 @@ StringRef SourceManager::getBufferName(SourceLocation Loc,
bool *Invalid) const {
if (isInvalid(Loc, Invalid)) return "<invalid loc>";

return getBuffer(getFileID(Loc), Invalid)->getBufferIdentifier();
auto B = getBufferOrNone(getFileID(Loc));
if (Invalid)
*Invalid = !B;
return B ? B->getBufferIdentifier() : "<invalid buffer>";
}

/// getPresumedLoc - This method returns the "presumed" location of a
Expand Down Expand Up @@ -2047,8 +2049,8 @@ bool SourceManager::isBeforeInTranslationUnit(SourceLocation LHS,
// If we arrived here, the location is either in a built-ins buffer or
// associated with global inline asm. PR5662 and PR22576 are examples.

StringRef LB = getBuffer(LOffs.first)->getBufferIdentifier();
StringRef RB = getBuffer(ROffs.first)->getBufferIdentifier();
StringRef LB = getBufferOrFake(LOffs.first).getBufferIdentifier();
StringRef RB = getBufferOrFake(ROffs.first).getBufferIdentifier();
bool LIsBuiltins = LB == "<built-in>";
bool RIsBuiltins = RB == "<built-in>";
// Sort built-in before non-built-in.
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,8 @@ CGDebugInfo::computeChecksum(FileID FID, SmallString<32> &Checksum) const {
return None;

SourceManager &SM = CGM.getContext().getSourceManager();
bool Invalid;
const llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, &Invalid);
if (Invalid)
Optional<llvm::MemoryBufferRef> MemBuffer = SM.getBufferOrNone(FID);
if (!MemBuffer)
return None;

llvm::MD5 Hash;
Expand Down
8 changes: 3 additions & 5 deletions clang/lib/CodeGen/CodeGenAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,11 +1122,10 @@ void CodeGenAction::ExecuteAction() {
if (BA != Backend_EmitNothing && !OS)
return;

bool Invalid;
SourceManager &SM = CI.getSourceManager();
FileID FID = SM.getMainFileID();
const llvm::MemoryBuffer *MainFile = SM.getBuffer(FID, &Invalid);
if (Invalid)
Optional<MemoryBufferRef> MainFile = SM.getBufferOrNone(FID);
if (!MainFile)
return;

TheModule = loadModule(*MainFile);
Expand All @@ -1141,8 +1140,7 @@ void CodeGenAction::ExecuteAction() {
TheModule->setTargetTriple(TargetOpts.Triple);
}

EmbedBitcode(TheModule.get(), CodeGenOpts,
MainFile->getMemBufferRef());
EmbedBitcode(TheModule.get(), CodeGenOpts, *MainFile);

LLVMContext &Ctx = TheModule->getContext();
Ctx.setInlineAsmDiagnosticHandler(BitcodeInlineAsmDiagHandler,
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Frontend/FrontendAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ static bool loadModuleMapForModuleBuild(CompilerInstance &CI, bool IsSystem,
PresumedModuleMapFile))
return true;

if (SrcMgr.getBuffer(ModuleMapID)->getBufferSize() == Offset)
if (SrcMgr.getBufferOrFake(ModuleMapID).getBufferSize() == Offset)
Offset = 0;

return false;
Expand Down
10 changes: 4 additions & 6 deletions clang/lib/Frontend/FrontendActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,11 +805,9 @@ void PrintPreprocessedAction::ExecuteAction() {
// concern, so if we scan for too long, we'll just assume the file should
// be opened in binary mode.
bool BinaryMode = true;
bool InvalidFile = false;
const SourceManager& SM = CI.getSourceManager();
const llvm::MemoryBuffer *Buffer = SM.getBuffer(SM.getMainFileID(),
&InvalidFile);
if (!InvalidFile) {
if (llvm::Optional<llvm::MemoryBufferRef> Buffer =
SM.getBufferOrNone(SM.getMainFileID())) {
const char *cur = Buffer->getBufferStart();
const char *end = Buffer->getBufferEnd();
const char *next = (cur != end) ? cur + 1 : end;
Expand Down Expand Up @@ -937,12 +935,12 @@ void DumpCompilerOptionsAction::ExecuteAction() {
void PrintDependencyDirectivesSourceMinimizerAction::ExecuteAction() {
CompilerInstance &CI = getCompilerInstance();
SourceManager &SM = CI.getPreprocessor().getSourceManager();
const llvm::MemoryBuffer *FromFile = SM.getBuffer(SM.getMainFileID());
llvm::MemoryBufferRef FromFile = SM.getBufferOrFake(SM.getMainFileID());

llvm::SmallString<1024> Output;
llvm::SmallVector<minimize_source_to_dependency_directives::Token, 32> Toks;
if (minimizeSourceToDependencyDirectives(
FromFile->getBuffer(), Output, Toks, &CI.getDiagnostics(),
FromFile.getBuffer(), Output, Toks, &CI.getDiagnostics(),
SM.getLocForStartOfFile(SM.getMainFileID()))) {
assert(CI.getDiagnostics().hasErrorOccurred() &&
"no errors reported for failure");
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Frontend/Rewrite/HTMLPrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void HTMLPrinter::HandleTranslationUnit(ASTContext &Ctx) {
if (Entry)
Name = Entry->getName();
else
Name = R.getSourceMgr().getBuffer(FID)->getBufferIdentifier();
Name = R.getSourceMgr().getBufferOrFake(FID).getBufferIdentifier();

html::AddLineNumbers(R, FID);
html::AddHeaderFooterInternalBuiltinCSS(R, FID, Name);
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,9 @@ void RewriteModernObjC::InitializeCommon(ASTContext &context) {

// Get the ID and start/end of the main file.
MainFileID = SM->getMainFileID();
const llvm::MemoryBuffer *MainBuf = SM->getBuffer(MainFileID);
MainFileStart = MainBuf->getBufferStart();
MainFileEnd = MainBuf->getBufferEnd();
llvm::MemoryBufferRef MainBuf = SM->getBufferOrFake(MainFileID);
MainFileStart = MainBuf.getBufferStart();
MainFileEnd = MainBuf.getBufferEnd();

Rewrite.setSourceMgr(Context->getSourceManager(), Context->getLangOpts());
}
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Frontend/Rewrite/RewriteObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,9 +631,9 @@ void RewriteObjC::InitializeCommon(ASTContext &context) {

// Get the ID and start/end of the main file.
MainFileID = SM->getMainFileID();
const llvm::MemoryBuffer *MainBuf = SM->getBuffer(MainFileID);
MainFileStart = MainBuf->getBufferStart();
MainFileEnd = MainBuf->getBufferEnd();
llvm::MemoryBufferRef MainBuf = SM->getBufferOrFake(MainFileID);
MainFileStart = MainBuf.getBufferStart();
MainFileEnd = MainBuf.getBufferEnd();

Rewrite.setSourceMgr(Context->getSourceManager(), Context->getLangOpts());
}
Expand Down
16 changes: 14 additions & 2 deletions clang/lib/Sema/SemaExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7249,8 +7249,8 @@ ExprResult Sema::ActOnStartCXXMemberReference(Scope *S, Expr *Base,
return Base;
}

static bool CheckArrow(Sema& S, QualType& ObjectType, Expr *&Base,
tok::TokenKind& OpKind, SourceLocation OpLoc) {
static bool CheckArrow(Sema &S, QualType &ObjectType, Expr *&Base,
tok::TokenKind &OpKind, SourceLocation OpLoc) {
if (Base->hasPlaceholderType()) {
ExprResult result = S.CheckPlaceholderExpr(Base);
if (result.isInvalid()) return true;
Expand All @@ -7265,6 +7265,18 @@ static bool CheckArrow(Sema& S, QualType& ObjectType, Expr *&Base,
// Note that this is rather different from the normal handling for the
// arrow operator.
if (OpKind == tok::arrow) {
// The operator requires a prvalue, so perform lvalue conversions.
// Only do this if we might plausibly end with a pointer, as otherwise
// this was likely to be intended to be a '.'.
if (ObjectType->isPointerType() || ObjectType->isArrayType() ||
ObjectType->isFunctionType()) {
ExprResult BaseResult = S.DefaultFunctionArrayLvalueConversion(Base);
if (BaseResult.isInvalid())
return true;
Base = BaseResult.get();
ObjectType = Base->getType();
}

if (const PointerType *Ptr = ObjectType->getAs<PointerType>()) {
ObjectType = Ptr->getPointeeType();
} else if (!Base->isTypeDependent()) {
Expand Down
7 changes: 3 additions & 4 deletions clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1141,10 +1141,9 @@ void EmptyLocalizationContextChecker::MethodCrawler::VisitObjCMessageExpr(
SE = Mgr.getSourceManager().getSLocEntry(SLInfo.first);
}

bool Invalid = false;
const llvm::MemoryBuffer *BF =
Mgr.getSourceManager().getBuffer(SLInfo.first, SL, &Invalid);
if (Invalid)
llvm::Optional<llvm::MemoryBufferRef> BF =
Mgr.getSourceManager().getBufferOrNone(SLInfo.first, SL);
if (!BF)
return;

Lexer TheLexer(SL, LangOptions(), BF->getBufferStart(),
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/StaticAnalyzer/Core/BugReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1570,9 +1570,8 @@ static Optional<size_t> getLengthOnSingleLine(const SourceManager &SM,
if (FID != SM.getFileID(ExpansionRange.getEnd()))
return None;

bool Invalid;
const llvm::MemoryBuffer *Buffer = SM.getBuffer(FID, &Invalid);
if (Invalid)
Optional<MemoryBufferRef> Buffer = SM.getBufferOrNone(FID);
if (!Buffer)
return None;

unsigned BeginOffset = SM.getFileOffset(ExpansionRange.getBegin());
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,8 @@ void HTMLDiagnostics::HandlePiece(Rewriter &R, FileID BugFileID,
if (LPosInfo.first != BugFileID)
return;

const llvm::MemoryBuffer *Buf = SM.getBuffer(LPosInfo.first);
const char* FileStart = Buf->getBufferStart();
llvm::MemoryBufferRef Buf = SM.getBufferOrFake(LPosInfo.first);
const char *FileStart = Buf.getBufferStart();

// Compute the column number. Rewind from the current position to the start
// of the line.
Expand All @@ -797,7 +797,7 @@ void HTMLDiagnostics::HandlePiece(Rewriter &R, FileID BugFileID,

// Compute LineEnd.
const char *LineEnd = TokInstantiationPtr;
const char* FileEnd = Buf->getBufferEnd();
const char *FileEnd = Buf.getBufferEnd();
while (*LineEnd != '\n' && LineEnd != FileEnd)
++LineEnd;

Expand Down
Loading

0 comments on commit a59fae9

Please sign in to comment.