Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit fe90708

Browse files
author
Mark Seaborn
committed
Fix PNaCl-local files after merging LLVM 3.4
These are mostly compile fixes: * Update for interface changes: * readBytes() (unused arg was removed) * tool_output_file takes different flags * Materialize() uses error_code instead of bool + string * Remove uses of case ranges, which were removed in 3.4 * pnacl-llc: Some TargetOptions fields were removed in 3.4 Also update test expectations. LLVM's 'not' tool now treats crashes as a failure unless '--crash' is passed. BUG=https://code.google.com/p/nativeclient/issues/detail?id=3757 TEST=PNaCl toolchain trybots Review URL: https://codereview.chromium.org/180483005/
1 parent 811bc0f commit fe90708

File tree

17 files changed

+59
-61
lines changed

17 files changed

+59
-61
lines changed

include/llvm/Bitcode/NaCl/NaClBitstreamReader.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,7 @@ class NaClBitstreamCursor {
363363
// Read the next word from the stream.
364364
uint8_t Array[sizeof(word_t)] = {0};
365365

366-
BitStream->getBitcodeBytes().readBytes(NextChar, sizeof(Array),
367-
Array, NULL);
366+
BitStream->getBitcodeBytes().readBytes(NextChar, sizeof(Array), Array);
368367

369368
// Handle big-endian byte-swapping if necessary.
370369
support::detail::packed_endian_specific_integral

lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,6 @@ const char *PNaClABIVerifyFunctions::checkInstruction(const Instruction *Inst) {
466466
// value, so check all the cases too.
467467
for (SwitchInst::ConstCaseIt Case = Switch->case_begin(),
468468
E = Switch->case_end(); Case != E; ++Case) {
469-
// This check will go away when we merge upstream's r190328,
470-
// which removes all case range support.
471-
if (!Case.getCaseValueEx().isSingleNumber())
472-
return "case range in switch instruction";
473-
474469
if (!isValidScalarOperand(Case.getCaseValue()))
475470
return "bad switch case";
476471
}

lib/Bitcode/NaCl/Reader/NaClBitcodeHeader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,14 @@ bool NaClBitcodeHeader::Read(StreamableMemoryObject *Bytes) {
199199
unsigned NumBytes;
200200
{
201201
unsigned char Buffer[2 * WordSize];
202-
if (Bytes->readBytes(0, sizeof(Buffer), Buffer, NULL))
202+
if (Bytes->readBytes(0, sizeof(Buffer), Buffer))
203203
return UnsupportedError("Bitcode read failure");
204204
if (ReadPrefix(Buffer, Buffer + sizeof(Buffer), NumFields, NumBytes))
205205
return true; // ReadPrefix sets UnsupportedMessage
206206
}
207207
uint8_t *Header = new uint8_t[NumBytes];
208208
bool failed =
209-
Bytes->readBytes(2 * WordSize, NumBytes, Header, NULL) ||
209+
Bytes->readBytes(2 * WordSize, NumBytes, Header) ||
210210
ReadFields(Header, Header + NumBytes, NumFields, NumBytes);
211211
delete[] Header;
212212
if (failed)

lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,24 +1490,34 @@ bool NaClBitcodeReader::isMaterializable(const GlobalValue *GV) const {
14901490
return false;
14911491
}
14921492

1493-
bool NaClBitcodeReader::Materialize(GlobalValue *GV, std::string *ErrInfo) {
1493+
error_code NaClBitcodeReader::Materialize(GlobalValue *GV) {
14941494
Function *F = dyn_cast<Function>(GV);
14951495
// If it's not a function or is already material, ignore the request.
1496-
if (!F || !F->isMaterializable()) return false;
1496+
if (!F || !F->isMaterializable())
1497+
return error_code::success();
14971498

14981499
DenseMap<Function*, uint64_t>::iterator DFII = DeferredFunctionInfo.find(F);
14991500
assert(DFII != DeferredFunctionInfo.end() && "Deferred function not found!");
15001501
// If its position is recorded as 0, its body is somewhere in the stream
15011502
// but we haven't seen it yet.
1502-
if (DFII->second == 0)
1503-
if (LazyStreamer && FindFunctionInStream(F, DFII)) return true;
1503+
if (DFII->second == 0) {
1504+
if (FindFunctionInStream(F, DFII)) {
1505+
// Refactoring upstream in LLVM 3.4 means we can no longer
1506+
// return an error string here, so return a catch-all error
1507+
// code.
1508+
// TODO(mseaborn): Clean up the reader to return a more
1509+
// meaningful error_code here.
1510+
return make_error_code(errc::invalid_argument);
1511+
}
1512+
}
15041513

15051514
// Move the bit stream to the saved position of the deferred function body.
15061515
Stream.JumpToBit(DFII->second);
15071516

15081517
if (ParseFunctionBody(F)) {
1509-
if (ErrInfo) *ErrInfo = ErrorString;
1510-
return true;
1518+
// TODO(mseaborn): Clean up the reader to return a more meaningful
1519+
// error_code instead of a catch-all.
1520+
return make_error_code(errc::invalid_argument);
15111521
}
15121522

15131523
// Upgrade any old intrinsic calls in the function.
@@ -1522,7 +1532,7 @@ bool NaClBitcodeReader::Materialize(GlobalValue *GV, std::string *ErrInfo) {
15221532
}
15231533
}
15241534

1525-
return false;
1535+
return error_code::success();
15261536
}
15271537

15281538
bool NaClBitcodeReader::isDematerializable(const GlobalValue *GV) const {
@@ -1545,16 +1555,18 @@ void NaClBitcodeReader::Dematerialize(GlobalValue *GV) {
15451555
}
15461556

15471557

1548-
bool NaClBitcodeReader::MaterializeModule(Module *M, std::string *ErrInfo) {
1558+
error_code NaClBitcodeReader::MaterializeModule(Module *M) {
15491559
assert(M == TheModule &&
15501560
"Can only Materialize the Module this NaClBitcodeReader is attached to.");
15511561
// Iterate over the module, deserializing any functions that are still on
15521562
// disk.
15531563
for (Module::iterator F = TheModule->begin(), E = TheModule->end();
1554-
F != E; ++F)
1555-
if (F->isMaterializable() &&
1556-
Materialize(F, ErrInfo))
1557-
return true;
1564+
F != E; ++F) {
1565+
if (F->isMaterializable()) {
1566+
if (error_code EC = Materialize(F))
1567+
return EC;
1568+
}
1569+
}
15581570

15591571
// At this point, if there are any function bodies, the current bit is
15601572
// pointing to the END_BLOCK record after them. Now make sure the rest
@@ -1581,7 +1593,7 @@ bool NaClBitcodeReader::MaterializeModule(Module *M, std::string *ErrInfo) {
15811593
}
15821594
std::vector<std::pair<Function*, Function*> >().swap(UpgradedIntrinsics);
15831595

1584-
return false;
1596+
return error_code::success();
15851597
}
15861598

15871599
bool NaClBitcodeReader::InitStream() {

lib/Bitcode/NaCl/Reader/NaClBitcodeReader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ class NaClBitcodeReader : public GVMaterializer {
225225

226226
virtual bool isMaterializable(const GlobalValue *GV) const;
227227
virtual bool isDematerializable(const GlobalValue *GV) const;
228-
virtual bool Materialize(GlobalValue *GV, std::string *ErrInfo = 0);
229-
virtual bool MaterializeModule(Module *M, std::string *ErrInfo = 0);
228+
virtual error_code Materialize(GlobalValue *GV);
229+
virtual error_code MaterializeModule(Module *M);
230230
virtual void Dematerialize(GlobalValue *GV);
231231

232232
bool Error(const std::string &Str) {

lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -695,11 +695,6 @@ static bool WriteInstruction(const Instruction &I, unsigned InstID,
695695
Vals64.push_back(SI.getNumCases());
696696
for (SwitchInst::ConstCaseIt i = SI.case_begin(), e = SI.case_end();
697697
i != e; ++i) {
698-
// This check will go away when we merge upstream's r190328,
699-
// which removes all case range support.
700-
if (!i.getCaseValueEx().isSingleNumber())
701-
report_fatal_error("Case ranges are not supported in PNaCl bitcode");
702-
703698
// The PNaCl bitcode format has vestigial support for case
704699
// ranges, but we no longer support reading or writing them,
705700
// so the next two fields always have the same values.

lib/Support/Unix/RWMutex.inc

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,36 @@
1616
//=== is guaranteed to work on *all* UNIX variants.
1717
//===----------------------------------------------------------------------===//
1818

19+
#include "llvm/Support/Mutex.h"
20+
1921
namespace llvm {
2022

2123
using namespace sys;
2224

23-
RWMutexImpl::RWMutexImpl() { }
25+
// This naive implementation treats readers the same as writers. This
26+
// will therefore deadlock if a thread tries to acquire a read lock
27+
// multiple times.
28+
29+
RWMutexImpl::RWMutexImpl() : data_(new Mutex(false)) { }
2430

25-
RWMutexImpl::~RWMutexImpl() { }
31+
RWMutexImpl::~RWMutexImpl() {
32+
delete static_cast<Mutex *>(data_);
33+
}
2634

2735
bool RWMutexImpl::reader_acquire() {
28-
return true;
36+
return static_cast<Mutex *>(data_)->acquire();
2937
}
3038

3139
bool RWMutexImpl::reader_release() {
32-
return true;
40+
return static_cast<Mutex *>(data_)->release();
3341
}
3442

3543
bool RWMutexImpl::writer_acquire() {
36-
return true;
44+
return static_cast<Mutex *>(data_)->acquire();
3745
}
3846

3947
bool RWMutexImpl::writer_release() {
40-
return true;
48+
return static_cast<Mutex *>(data_)->release();
4149
}
4250

4351
}

lib/Target/X86/MCTargetDesc/X86MCNaCl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ unsigned DemoteRegTo32_(unsigned RegIn);
5656
static MCSymbol *CreateTempLabel(MCContext &Context, const char *Prefix) {
5757
SmallString<128> NameSV;
5858
raw_svector_ostream(NameSV)
59-
<< Context.getAsmInfo().getPrivateGlobalPrefix() // get internal label
59+
<< Context.getAsmInfo()->getPrivateGlobalPrefix() // get internal label
6060
<< Prefix << Context.getUniqueSymbolID();
6161
return Context.GetOrCreateSymbol(NameSV);
6262
}

lib/Transforms/NaCl/PromoteIntegers.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -551,12 +551,6 @@ static void convertInstruction(Instruction *Inst, ConversionState &State) {
551551
for (SwitchInst::CaseIt I = Switch->case_begin(),
552552
E = Switch->case_end();
553553
I != E; ++I) {
554-
// This sanity check should never trigger because no-one
555-
// generates case ranges. It will go away when we merge
556-
// upstream's r190328, which removes all case range support.
557-
if (!I.getCaseValueEx().isSingleNumber())
558-
report_fatal_error("Case ranges are not supported in PNaCl");
559-
560554
NewInst->addCase(cast<ConstantInt>(convertConstant(I.getCaseValue())),
561555
I.getCaseSuccessor());
562556
}

test/CodeGen/ARM/varargs-spill-stack-align-nacl.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@ define void @varargs_func(i32 %arg1, ...) {
2727
; CHECK: sub sp, sp, #12
2828
; Calculate the address of the varargs save area and save varargs
2929
; arguments into it.
30-
; CHECK-NEXT: add r0, sp, #20
30+
; @LOCALMOD: Adjust test expectation, removing NEXT to allow CFI
31+
; directive to intervene in the output.
32+
; CHECK: add r0, sp, #20
3133
; CHECK-NEXT: stm r0, {r1, r2, r3}

test/NaCl/PNaClLLC/test-runs-verify.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: not pnacl-llc -mtriple=i386-unknown-nacl -filetype=asm %s -o - 2>&1 | FileCheck %s
1+
; RUN: not --crash pnacl-llc -mtriple=i386-unknown-nacl -filetype=asm %s -o - 2>&1 | FileCheck %s
22

33
; Test that the Verifier pass is running in pnacl-llc.
44

tools/pnacl-bccompress/pnacl-bccompress.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ static bool CopyBitcode(OwningPtr<MemoryBuffer> &MemBuf,
14151415
std::string ErrorInfo;
14161416
OwningPtr<tool_output_file> OutFile(
14171417
new tool_output_file(OutputFilename.c_str(), ErrorInfo,
1418-
raw_fd_ostream::F_Binary));
1418+
sys::fs::F_Binary));
14191419
if (!ErrorInfo.empty())
14201420
return Error(ErrorInfo);
14211421

tools/pnacl-freeze/pnacl-freeze.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static void WriteOutputFile(const Module *M) {
4141
std::string ErrorInfo;
4242
OwningPtr<tool_output_file> Out
4343
(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
44-
raw_fd_ostream::F_Binary));
44+
sys::fs::F_Binary));
4545
if (!ErrorInfo.empty()) {
4646
errs() << ErrorInfo << '\n';
4747
exit(1);

tools/pnacl-llc/ThreadedStreamingCache.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,16 @@ ThreadedStreamingCache::ThreadedStreamingCache(
2525

2626
int ThreadedStreamingCache::fetchCacheLine(uint64_t address) const {
2727
uint64_t Base = address & kCacheSizeMask;
28-
uint64_t Copied;
2928
int Ret;
3029
ScopedLock L(StreamerLock);
3130
if (Streamer->isValidAddress(Base + kCacheSize - 1)) {
32-
Ret = Streamer->readBytes(Base, kCacheSize, &Cache[0], &Copied);
33-
assert(Copied == kCacheSize);
31+
Ret = Streamer->readBytes(Base, kCacheSize, &Cache[0]);
3432
assert(Ret == 0);
3533
MinObjectSize = Base + kCacheSize;
3634
} else {
3735
uint64_t End = Streamer->getExtent();
3836
assert(End > address && End <= Base + kCacheSize);
39-
Ret = Streamer->readBytes(Base, End - Base, &Cache[0], &Copied);
40-
assert(Copied == End - Base);
37+
Ret = Streamer->readBytes(Base, End - Base, &Cache[0]);
4138
assert(Ret == 0);
4239
MinObjectSize = End;
4340
}
@@ -56,7 +53,7 @@ int ThreadedStreamingCache::readByte(
5653
}
5754

5855
int ThreadedStreamingCache::readBytes(
59-
uint64_t address, uint64_t size, uint8_t* buf, uint64_t* copied) const {
56+
uint64_t address, uint64_t size, uint8_t* buf) const {
6057
// To keep the cache fetch simple, we currently require that no request cross
6158
// the cache line. This isn't a problem for the bitcode reader because it only
6259
// fetches a byte or a word at a time.
@@ -66,7 +63,6 @@ int ThreadedStreamingCache::readBytes(
6663
if(fetchCacheLine(address))
6764
return -1;
6865
}
69-
if (copied) *copied = size;
7066
memcpy(buf, &Cache[address - CacheBase], size);
7167
return 0;
7268
}

tools/pnacl-llc/ThreadedStreamingCache.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ class ThreadedStreamingCache : public llvm::StreamableMemoryObject {
2929
virtual int readByte(uint64_t address, uint8_t* ptr) const LLVM_OVERRIDE;
3030
virtual int readBytes(uint64_t address,
3131
uint64_t size,
32-
uint8_t* buf,
33-
uint64_t* copied) const LLVM_OVERRIDE;
32+
uint8_t* buf) const LLVM_OVERRIDE;
3433
virtual const uint8_t *getPointer(uint64_t address,
3534
uint64_t size) const LLVM_OVERRIDE {
3635
// This could be fixed by ensuring the bytes are fetched and making a copy,

tools/pnacl-llc/pnacl-llc.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,9 @@ static tool_output_file *GetOutputStream(const char *TargetName,
205205

206206
// Open the file.
207207
std::string error;
208-
unsigned OpenFlags = 0;
209-
if (Binary) OpenFlags |= raw_fd_ostream::F_Binary;
208+
sys::fs::OpenFlags OpenFlags = sys::fs::F_None;
209+
if (Binary)
210+
OpenFlags |= sys::fs::F_Binary;
210211
OwningPtr<tool_output_file> FDOut(
211212
new tool_output_file(Filename.c_str(), error, OpenFlags));
212213
if (!error.empty()) {
@@ -602,7 +603,6 @@ static int compileModule(StringRef ProgramName) {
602603
TargetOptions Options;
603604
Options.LessPreciseFPMADOption = EnableFPMAD;
604605
Options.NoFramePointerElim = DisableFPElim;
605-
Options.NoFramePointerElimNonLeaf = DisableFPElimNonLeaf;
606606
Options.AllowFPOpFusion = FuseFPOps;
607607
Options.UnsafeFPMath = EnableUnsafeFPMath;
608608
Options.NoInfsFPMath = EnableNoInfsFPMath;
@@ -616,12 +616,10 @@ static int compileModule(StringRef ProgramName) {
616616
Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
617617
Options.DisableTailCalls = DisableTailCalls;
618618
Options.StackAlignmentOverride = OverrideStackAlignment;
619-
Options.RealignStack = EnableRealignStack;
620619
Options.TrapFuncName = TrapFuncName;
621620
Options.PositionIndependentExecutable = EnablePIE;
622621
Options.EnableSegmentedStacks = SegmentedStacks;
623622
Options.UseInitArray = UseInitArray;
624-
Options.SSPBufferSize = SSPBufferSize;
625623

626624
if (GenerateSoftFloatCalls)
627625
FloatABIForCalls = FloatABI::Soft;

tools/pnacl-thaw/pnacl-thaw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static void WriteOutputFile(const Module *M) {
4141
std::string ErrorInfo;
4242
OwningPtr<tool_output_file> Out
4343
(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
44-
raw_fd_ostream::F_Binary));
44+
sys::fs::F_Binary));
4545
if (!ErrorInfo.empty()) {
4646
errs() << ErrorInfo << '\n';
4747
exit(1);

0 commit comments

Comments
 (0)