Skip to content

Commit

Permalink
Merged main:ee74d1b42036 into amd-gfx:c3ce838e4580
Browse files Browse the repository at this point in the history
Local branch amd-gfx c3ce838 Merged main:55ea639d3c57 into amd-gfx:2952e2d2963c
Remote branch main ee74d1b X86: use a data driven configuration of Windows x86 libcalls (NFC)
  • Loading branch information
Sw authored and Sw committed Dec 9, 2020
2 parents c3ce838 + ee74d1b commit db667e8
Show file tree
Hide file tree
Showing 56 changed files with 665 additions and 214 deletions.
11 changes: 11 additions & 0 deletions clang/include/clang/Basic/SourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,10 @@ class SourceManager : public RefCountedBase<SourceManager> {
/// data in the given source file.
void overrideFileContents(const FileEntry *SourceFile,
std::unique_ptr<llvm::MemoryBuffer> Buffer);
void overrideFileContents(FileEntryRef SourceFile,
std::unique_ptr<llvm::MemoryBuffer> Buffer) {
overrideFileContents(&SourceFile.getFileEntry(), std::move(Buffer));
}

/// Override the given source file with another one.
///
Expand Down Expand Up @@ -1029,6 +1033,13 @@ class SourceManager : public RefCountedBase<SourceManager> {
return nullptr;
}

/// Returns the FileEntryRef for the provided FileID.
Optional<FileEntryRef> getFileEntryRefForID(FileID FID) const {
if (auto *Entry = getFileEntryForID(FID))
return Entry->getLastRef();
return None;
}

/// Returns the filename for the provided FileID, unless it's a built-in
/// buffer that's not represented by a filename.
///
Expand Down
17 changes: 9 additions & 8 deletions clang/include/clang/Frontend/ASTUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -688,14 +688,15 @@ class ASTUnit {
/// lifetime is expected to extend past that of the returned ASTUnit.
///
/// \returns - The initialized ASTUnit or null if the AST failed to load.
static std::unique_ptr<ASTUnit> LoadFromASTFile(
const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
WhatToLoad ToLoad, IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
const FileSystemOptions &FileSystemOpts, bool UseDebugInfo = false,
bool OnlyLocalDecls = false, ArrayRef<RemappedFile> RemappedFiles = None,
CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
bool AllowASTWithCompilerErrors = false,
bool UserFilesAreVolatile = false);
static std::unique_ptr<ASTUnit>
LoadFromASTFile(const std::string &Filename,
const PCHContainerReader &PCHContainerRdr, WhatToLoad ToLoad,
IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
const FileSystemOptions &FileSystemOpts,
bool UseDebugInfo = false, bool OnlyLocalDecls = false,
CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
bool AllowASTWithCompilerErrors = false,
bool UserFilesAreVolatile = false);

private:
/// Helper function for \c LoadFromCompilerInvocation() and
Expand Down
25 changes: 12 additions & 13 deletions clang/lib/ARCMigrate/ObjCMT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ class ObjCMigrateASTConsumer : public ASTConsumer {
return WhiteListFilenames.find(llvm::sys::path::filename(Path))
!= WhiteListFilenames.end();
}
bool canModifyFile(const FileEntry *FE) {
bool canModifyFile(Optional<FileEntryRef> FE) {
if (!FE)
return false;
return canModifyFile(FE->getName());
}
bool canModifyFile(FileID FID) {
if (FID.isInvalid())
return false;
return canModifyFile(PP.getSourceManager().getFileEntryForID(FID));
return canModifyFile(PP.getSourceManager().getFileEntryRefForID(FID));
}

bool canModify(const Decl *D) {
Expand Down Expand Up @@ -1964,7 +1964,7 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) {
I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) {
FileID FID = I->first;
RewriteBuffer &buf = I->second;
const FileEntry *file = Ctx.getSourceManager().getFileEntryForID(FID);
Optional<FileEntryRef> file = Ctx.getSourceManager().getFileEntryRefForID(FID);
assert(file);
SmallString<512> newText;
llvm::raw_svector_ostream vecOS(newText);
Expand Down Expand Up @@ -2034,7 +2034,7 @@ MigrateSourceAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {

namespace {
struct EditEntry {
const FileEntry *File = nullptr;
Optional<FileEntryRef> File;
unsigned Offset = 0;
unsigned RemoveLen = 0;
std::string Text;
Expand Down Expand Up @@ -2127,9 +2127,8 @@ class RemapFileParser {
StringRef Val = ValueString->getValue(ValueStorage);

if (Key == "file") {
auto FE = FileMgr.getFile(Val);
if (FE)
Entry.File = *FE;
if (auto File = FileMgr.getOptionalFileRef(Val))
Entry.File = File;
else
Ignore = true;
} else if (Key == "offset") {
Expand All @@ -2155,7 +2154,7 @@ static bool reportDiag(const Twine &Err, DiagnosticsEngine &Diag) {
return true;
}

static std::string applyEditsToTemp(const FileEntry *FE,
static std::string applyEditsToTemp(FileEntryRef FE,
ArrayRef<EditEntry> Edits,
FileManager &FileMgr,
DiagnosticsEngine &Diag) {
Expand Down Expand Up @@ -2199,8 +2198,8 @@ static std::string applyEditsToTemp(const FileEntry *FE,

SmallString<64> TempPath;
int FD;
if (fs::createTemporaryFile(path::filename(FE->getName()),
path::extension(FE->getName()).drop_front(), FD,
if (fs::createTemporaryFile(path::filename(FE.getName()),
path::extension(FE.getName()).drop_front(), FD,
TempPath)) {
reportDiag("Could not create file: " + TempPath.str(), Diag);
return std::string();
Expand Down Expand Up @@ -2228,7 +2227,7 @@ bool arcmt::getFileRemappingsFromFileList(
new DiagnosticsEngine(DiagID, new DiagnosticOptions,
DiagClient, /*ShouldOwnClient=*/false));

typedef llvm::DenseMap<const FileEntry *, std::vector<EditEntry> >
typedef llvm::DenseMap<FileEntryRef, std::vector<EditEntry> >
FileEditEntriesTy;
FileEditEntriesTy FileEditEntries;

Expand All @@ -2250,7 +2249,7 @@ bool arcmt::getFileRemappingsFromFileList(
if (!Insert.second)
continue;

FileEditEntries[Entry.File].push_back(Entry);
FileEditEntries[*Entry.File].push_back(Entry);
}
}

Expand All @@ -2263,7 +2262,7 @@ bool arcmt::getFileRemappingsFromFileList(
continue;
}

remap.emplace_back(std::string(I->first->getName()), TempFile);
remap.emplace_back(std::string(I->first.getName()), TempFile);
}

return hasErrorOccurred;
Expand Down
8 changes: 2 additions & 6 deletions clang/lib/Frontend/ASTUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,9 +758,8 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
WhatToLoad ToLoad, IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
const FileSystemOptions &FileSystemOpts, bool UseDebugInfo,
bool OnlyLocalDecls, ArrayRef<RemappedFile> RemappedFiles,
CaptureDiagsKind CaptureDiagnostics, bool AllowASTWithCompilerErrors,
bool UserFilesAreVolatile) {
bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile) {
std::unique_ptr<ASTUnit> AST(new ASTUnit(true));

// Recover resources if we crash before exiting this method.
Expand Down Expand Up @@ -793,9 +792,6 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
/*Target=*/nullptr));
AST->PPOpts = std::make_shared<PreprocessorOptions>();

for (const auto &RemappedFile : RemappedFiles)
AST->PPOpts->addRemappedFile(RemappedFile.first, RemappedFile.second);

// Gather Info for preprocessor construction later on.

HeaderSearch &HeaderInfo = *AST->HeaderInfo;
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Frontend/CompilerInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,8 +891,8 @@ bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input,
}
std::unique_ptr<llvm::MemoryBuffer> SB = std::move(SBOrErr.get());

const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
SB->getBufferSize(), 0);
FileEntryRef File = FileMgr.getVirtualFileRef(SB->getBufferIdentifier(),
SB->getBufferSize(), 0);
SourceMgr.setMainFileID(
SourceMgr.createFileID(File, SourceLocation(), Kind));
SourceMgr.overrideFileContents(File, std::move(SB));
Expand Down
2 changes: 0 additions & 2 deletions clang/test/CodeGenObjC/arc.ll
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
; RUN: %clang_cc1 -triple x86_64-apple-darwin10 -Os -emit-llvm -fobjc-arc -o - %s | FileCheck %s

target triple = "x86_64-apple-darwin10"

declare i8* @llvm.objc.retain(i8*)
declare void @llvm.objc.release(i8*)

Expand Down
2 changes: 1 addition & 1 deletion clang/tools/c-index-test/core_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ static bool printSourceSymbolsFromModule(StringRef modulePath,
std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile(
std::string(modulePath), *pchRdr, ASTUnit::LoadASTOnly, Diags,
FileSystemOpts, /*UseDebugInfo=*/false,
/*OnlyLocalDecls=*/true, None, CaptureDiagsKind::None,
/*OnlyLocalDecls=*/true, CaptureDiagsKind::None,
/*AllowASTWithCompilerErrors=*/true,
/*UserFilesAreVolatile=*/false);
if (!AU) {
Expand Down
2 changes: 1 addition & 1 deletion clang/tools/libclang/CIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3475,7 +3475,7 @@ enum CXErrorCode clang_createTranslationUnit2(CXIndex CIdx,
std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile(
ast_filename, CXXIdx->getPCHContainerOperations()->getRawReader(),
ASTUnit::LoadEverything, Diags, FileSystemOpts, /*UseDebugInfo=*/false,
CXXIdx->getOnlyLocalDecls(), None, CaptureDiagsKind::All,
CXXIdx->getOnlyLocalDecls(), CaptureDiagsKind::All,
/*AllowASTWithCompilerErrors=*/true,
/*UserFilesAreVolatile=*/true);
*out_TU = MakeCXTranslationUnit(CXXIdx, std::move(AU));
Expand Down
35 changes: 35 additions & 0 deletions compiler-rt/lib/dfsan/dfsan_custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <sys/epoll.h>
#include <sys/resource.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
Expand Down Expand Up @@ -879,6 +880,26 @@ SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_nanosleep(const struct timespec *req,
return ret;
}

SANITIZER_INTERFACE_ATTRIBUTE ssize_t __dfsw_recvmsg(
int sockfd, struct msghdr *msg, int flags, dfsan_label sockfd_label,
dfsan_label msg_label, dfsan_label flags_label, dfsan_label *ret_label) {
ssize_t ret = recvmsg(sockfd, msg, flags);
if (ret >= 0) {
dfsan_set_label(0, msg, sizeof(*msg));
dfsan_set_label(0, msg->msg_name, msg->msg_namelen);
dfsan_set_label(0, msg->msg_control, msg->msg_controllen);
for (size_t remaining = ret, i = 0; remaining > 0; ++i) {
assert(i < msg->msg_iovlen);
struct iovec *iov = &msg->msg_iov[i];
size_t written = remaining < iov->iov_len ? remaining : iov->iov_len;
dfsan_set_label(0, iov->iov_base, written);
remaining -= written;
}
}
*ret_label = 0;
return ret;
}

SANITIZER_INTERFACE_ATTRIBUTE int
__dfsw_socketpair(int domain, int type, int protocol, int sv[2],
dfsan_label domain_label, dfsan_label type_label,
Expand All @@ -892,6 +913,20 @@ __dfsw_socketpair(int domain, int type, int protocol, int sv[2],
return ret;
}

SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_getsockopt(
int sockfd, int level, int optname, void *optval, socklen_t *optlen,
dfsan_label sockfd_label, dfsan_label level_label,
dfsan_label optname_label, dfsan_label optval_label,
dfsan_label optlen_label, dfsan_label *ret_label) {
int ret = getsockopt(sockfd, level, optname, optval, optlen);
if (ret != -1 && optval && optlen) {
dfsan_set_label(0, optlen, sizeof(*optlen));
dfsan_set_label(0, optval, *optlen);
}
*ret_label = 0;
return ret;
}

// Type of the trampoline function passed to the custom version of
// dfsan_set_write_callback.
typedef void (*write_trampoline_t)(
Expand Down
4 changes: 4 additions & 0 deletions compiler-rt/lib/dfsan/done_abilist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ fun:connect=discard
fun:creat=discard
fun:dladdr=discard
fun:dlclose=discard
fun:epoll_create=discard
fun:epoll_create1=discard
fun:epoll_ctl=discard
fun:fclose=discard
fun:feof=discard
Expand Down Expand Up @@ -192,9 +194,11 @@ fun:get_current_dir_name=custom
fun:gethostname=custom
fun:getrlimit=custom
fun:getrusage=custom
fun:getsockopt=custom
fun:nanosleep=custom
fun:pread=custom
fun:read=custom
fun:recvmsg=custom
fun:socketpair=custom
fun:stat=custom
fun:time=custom
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/scudo/standalone/secondary.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct Header {
uptr BlockEnd;
uptr MapBase;
uptr MapSize;
MapPlatformData Data;
[[no_unique_address]] MapPlatformData Data;
};

constexpr uptr getHeaderSize() {
Expand Down Expand Up @@ -232,7 +232,7 @@ class MapAllocatorCache {
uptr BlockEnd;
uptr MapBase;
uptr MapSize;
MapPlatformData Data;
[[no_unique_address]] MapPlatformData Data;
u64 Time;
};

Expand Down
59 changes: 59 additions & 0 deletions compiler-rt/test/dfsan/custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <sys/epoll.h>
#include <sys/resource.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
Expand Down Expand Up @@ -336,6 +337,41 @@ void test_calloc() {
free(crv);
}

void test_recvmsg() {
int sockfds[2];
int ret = socketpair(AF_UNIX, SOCK_DGRAM, 0, sockfds);
assert(ret != -1);

char sbuf[] = "abcdefghijkl";
struct iovec siovs[2] = {{&sbuf[0], 4}, {&sbuf[4], 4}};
struct msghdr smsg = {};
smsg.msg_iov = siovs;
smsg.msg_iovlen = 2;

ssize_t sent = sendmsg(sockfds[0], &smsg, 0);
assert(sent > 0);

char rbuf[128];
struct iovec riovs[2] = {{&rbuf[0], 4}, {&rbuf[4], 4}};
struct msghdr rmsg = {};
rmsg.msg_iov = riovs;
rmsg.msg_iovlen = 2;

dfsan_set_label(i_label, rbuf, sizeof(rbuf));
dfsan_set_label(i_label, &rmsg, sizeof(rmsg));

ssize_t received = recvmsg(sockfds[1], &rmsg, 0);
assert(received == sent);
assert(memcmp(sbuf, rbuf, 8) == 0);
ASSERT_ZERO_LABEL(received);
ASSERT_READ_ZERO_LABEL(&rmsg, sizeof(rmsg));
ASSERT_READ_ZERO_LABEL(&rbuf[0], 8);
ASSERT_READ_LABEL(&rbuf[8], 1, i_label);

close(sockfds[0]);
close(sockfds[1]);
}

void test_read() {
char buf[16];
dfsan_set_label(i_label, buf, 1);
Expand Down Expand Up @@ -895,6 +931,27 @@ void test_socketpair() {
ASSERT_READ_ZERO_LABEL(fd, sizeof(fd));
}

void test_getsockopt() {
int sockfd = socket(AF_UNIX, SOCK_DGRAM, 0);
assert(sockfd != -1);

int optval[2] = {-1, -1};
socklen_t optlen = sizeof(optval);
dfsan_set_label(i_label, &optval, sizeof(optval));
dfsan_set_label(i_label, &optlen, sizeof(optlen));
int ret = getsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &optval, &optlen);
assert(ret != -1);
assert(optlen == sizeof(int));
assert(optval[0] == 0);
assert(optval[1] == -1);
ASSERT_ZERO_LABEL(ret);
ASSERT_ZERO_LABEL(optlen);
ASSERT_ZERO_LABEL(optval[0]);
ASSERT_LABEL(optval[1], i_label);

close(sockfd);
}

void test_write() {
int fd = open("/dev/null", O_WRONLY);

Expand Down Expand Up @@ -1077,6 +1134,7 @@ int main(void) {
test_getpwuid_r();
test_getrlimit();
test_getrusage();
test_getsockopt();
test_gettimeofday();
test_inet_pton();
test_localtime_r();
Expand All @@ -1089,6 +1147,7 @@ int main(void) {
test_pread();
test_pthread_create();
test_read();
test_recvmsg();
test_sched_getaffinity();
test_select();
test_sigaction();
Expand Down
Loading

0 comments on commit db667e8

Please sign in to comment.