Commit 0d5ba1e2 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Be a little bit more careful about the types for range-iteration

parent 214292b4
...@@ -68,7 +68,7 @@ typename BBAnalyzer<T>::AllMap computeFixedPoint(CFG* cfg, const BBAnalyzer<T> & ...@@ -68,7 +68,7 @@ typename BBAnalyzer<T>::AllMap computeFixedPoint(CFG* cfg, const BBAnalyzer<T> &
} }
Map &next = states[next_block]; Map &next = states[next_block];
for (auto p : ending) { for (const auto &p : ending) {
if (next.count(p.first) == 0) { if (next.count(p.first) == 0) {
changed = true; changed = true;
if (initial) { if (initial) {
...@@ -87,7 +87,7 @@ typename BBAnalyzer<T>::AllMap computeFixedPoint(CFG* cfg, const BBAnalyzer<T> & ...@@ -87,7 +87,7 @@ typename BBAnalyzer<T>::AllMap computeFixedPoint(CFG* cfg, const BBAnalyzer<T> &
} }
} }
for (auto p : ending) { for (const auto &p : ending) {
if (ending.count(p.first)) if (ending.count(p.first))
continue; continue;
......
...@@ -231,7 +231,7 @@ void DefinednessBBAnalyzer::processBB(Map &starting, CFGBlock *block) const { ...@@ -231,7 +231,7 @@ void DefinednessBBAnalyzer::processBB(Map &starting, CFGBlock *block) const {
if (VERBOSITY("analysis") >= 2) { if (VERBOSITY("analysis") >= 2) {
printf("At end of block %d:\n", block->idx); printf("At end of block %d:\n", block->idx);
for (auto p : starting) { for (const auto &p : starting) {
printf("%s: %d\n", p.first.c_str(), p.second); printf("%s: %d\n", p.first.c_str(), p.second);
} }
} }
...@@ -240,15 +240,14 @@ void DefinednessBBAnalyzer::processBB(Map &starting, CFGBlock *block) const { ...@@ -240,15 +240,14 @@ void DefinednessBBAnalyzer::processBB(Map &starting, CFGBlock *block) const {
DefinednessAnalysis::DefinednessAnalysis(AST_arguments *args, CFG* cfg, ScopeInfo *scope_info) : scope_info(scope_info) { DefinednessAnalysis::DefinednessAnalysis(AST_arguments *args, CFG* cfg, ScopeInfo *scope_info) : scope_info(scope_info) {
results = computeFixedPoint(cfg, DefinednessBBAnalyzer(cfg, args), false); results = computeFixedPoint(cfg, DefinednessBBAnalyzer(cfg, args), false);
for (auto p : results) { for (const auto &p : results) {
RequiredSet required; RequiredSet required;
for (std::unordered_map<std::string, DefinitionLevel>::iterator it2 = p.second.begin(), end2 = p.second.end(); for (const auto &p2 : p.second) {
it2 != end2; ++it2) { if (scope_info->refersToGlobal(p2.first))
if (scope_info->refersToGlobal(it2->first))
continue; continue;
//printf("%d %s %d\n", p.first->idx, it2->first.c_str(), it2->second); //printf("%d %s %d\n", p.first->idx, p2.first.c_str(), p2.second);
required.insert(it2->first); required.insert(p2.first);
} }
defined.insert(make_pair(p.first, required)); defined.insert(make_pair(p.first, required));
} }
...@@ -275,7 +274,7 @@ PhiAnalysis::PhiAnalysis(AST_arguments* args, CFG* cfg, LivenessAnalysis *livene ...@@ -275,7 +274,7 @@ PhiAnalysis::PhiAnalysis(AST_arguments* args, CFG* cfg, LivenessAnalysis *livene
const RequiredSet& defined = definedness.getDefinedNamesAt(block); const RequiredSet& defined = definedness.getDefinedNamesAt(block);
if (defined.size()) if (defined.size())
assert(block->predecessors.size()); assert(block->predecessors.size());
for (auto s : defined) { for (const auto &s : defined) {
if (liveness->isLiveAtEnd(s, block->predecessors[0])) { if (liveness->isLiveAtEnd(s, block->predecessors[0])) {
required.insert(s); required.insert(s);
} }
......
...@@ -256,7 +256,7 @@ static std::vector<ScopingAnalysis::ScopeNameUsage*> sortNameUsages(ScopingAnaly ...@@ -256,7 +256,7 @@ static std::vector<ScopingAnalysis::ScopeNameUsage*> sortNameUsages(ScopingAnaly
std::vector<ScopingAnalysis::ScopeNameUsage*> rtn; std::vector<ScopingAnalysis::ScopeNameUsage*> rtn;
std::unordered_set<ScopingAnalysis::ScopeNameUsage*> added; std::unordered_set<ScopingAnalysis::ScopeNameUsage*> added;
for (auto p : *usages) { for (const auto &p : *usages) {
ScopingAnalysis::ScopeNameUsage *usage = p.second; ScopingAnalysis::ScopeNameUsage *usage = p.second;
std::vector<ScopingAnalysis::ScopeNameUsage*> traversed; std::vector<ScopingAnalysis::ScopeNameUsage*> traversed;
...@@ -281,7 +281,7 @@ void ScopingAnalysis::processNameUsages(ScopingAnalysis::NameUsageMap* usages) { ...@@ -281,7 +281,7 @@ void ScopingAnalysis::processNameUsages(ScopingAnalysis::NameUsageMap* usages) {
typedef ScopeNameUsage::StrSet StrSet; typedef ScopeNameUsage::StrSet StrSet;
// Resolve name lookups: // Resolve name lookups:
for (auto p : *usages) { for (const auto &p : *usages) {
ScopeNameUsage *usage = p.second; ScopeNameUsage *usage = p.second;
for (StrSet::iterator it2 = usage->read.begin(), end2 = usage->read.end(); for (StrSet::iterator it2 = usage->read.begin(), end2 = usage->read.end();
it2 != end2; ++it2) { it2 != end2; ++it2) {
......
...@@ -303,9 +303,9 @@ class BasicBlockTypePropagator : public ExprVisitor, public StmtVisitor { ...@@ -303,9 +303,9 @@ class BasicBlockTypePropagator : public ExprVisitor, public StmtVisitor {
// Get all the sub-types, even though they're not necessary to // Get all the sub-types, even though they're not necessary to
// determine the expression type, so that things like speculations // determine the expression type, so that things like speculations
// can be processed. // can be processed.
for (auto k : node->keys) for (AST_expr* k : node->keys)
getType(k); getType(k);
for (auto v : node->values) for (AST_expr* v : node->values)
getType(v); getType(v);
return DICT; return DICT;
...@@ -319,7 +319,7 @@ class BasicBlockTypePropagator : public ExprVisitor, public StmtVisitor { ...@@ -319,7 +319,7 @@ class BasicBlockTypePropagator : public ExprVisitor, public StmtVisitor {
// Get all the sub-types, even though they're not necessary to // Get all the sub-types, even though they're not necessary to
// determine the expression type, so that things like speculations // determine the expression type, so that things like speculations
// can be processed. // can be processed.
for (auto elt : node->elts) { for (AST_expr* elt : node->elts) {
getType(elt); getType(elt);
} }
...@@ -449,7 +449,9 @@ class BasicBlockTypePropagator : public ExprVisitor, public StmtVisitor { ...@@ -449,7 +449,9 @@ class BasicBlockTypePropagator : public ExprVisitor, public StmtVisitor {
virtual void visit_pass(AST_Pass* node) {} virtual void visit_pass(AST_Pass* node) {}
virtual void visit_print(AST_Print* node) { virtual void visit_print(AST_Print* node) {
assert(node->dest == NULL); if (node->dest)
getType(node->dest);
if (EXPAND_UNNEEDED) { if (EXPAND_UNNEEDED) {
for (int i = 0; i < node->values.size(); i++) { for (int i = 0; i < node->values.size(); i++) {
getType(node->values[i]); getType(node->values[i]);
...@@ -571,7 +573,7 @@ class PropagatingTypeAnalysis : public TypeAnalysis { ...@@ -571,7 +573,7 @@ class PropagatingTypeAnalysis : public TypeAnalysis {
if (VERBOSITY("types") >= 2) { if (VERBOSITY("types") >= 2) {
printf("before:\n"); printf("before:\n");
TypeMap &starting = starting_types[block]; TypeMap &starting = starting_types[block];
for (auto p : starting) { for (const auto &p : starting) {
ASSERT(p.second, "%s", p.first.c_str()); ASSERT(p.second, "%s", p.first.c_str());
printf("%s: %s\n", p.first.c_str(), p.second->debugName().c_str()); printf("%s: %s\n", p.first.c_str(), p.second->debugName().c_str());
} }
...@@ -582,12 +584,12 @@ class PropagatingTypeAnalysis : public TypeAnalysis { ...@@ -582,12 +584,12 @@ class PropagatingTypeAnalysis : public TypeAnalysis {
if (VERBOSITY("types") >= 2) { if (VERBOSITY("types") >= 2) {
printf("before (after):\n"); printf("before (after):\n");
TypeMap &starting = starting_types[block]; TypeMap &starting = starting_types[block];
for (auto p : starting) { for (const auto &p : starting) {
ASSERT(p.second, "%s", p.first.c_str()); ASSERT(p.second, "%s", p.first.c_str());
printf("%s: %s\n", p.first.c_str(), p.second->debugName().c_str()); printf("%s: %s\n", p.first.c_str(), p.second->debugName().c_str());
} }
printf("after:\n"); printf("after:\n");
for (auto p : ending) { for (const auto &p : ending) {
ASSERT(p.second, "%s", p.first.c_str()); ASSERT(p.second, "%s", p.first.c_str());
printf("%s: %s\n", p.first.c_str(), p.second->debugName().c_str()); printf("%s: %s\n", p.first.c_str(), p.second->debugName().c_str());
} }
...@@ -608,7 +610,7 @@ class PropagatingTypeAnalysis : public TypeAnalysis { ...@@ -608,7 +610,7 @@ class PropagatingTypeAnalysis : public TypeAnalysis {
printf("Types at beginning of block %d:\n", b->idx); printf("Types at beginning of block %d:\n", b->idx);
TypeMap &starting = starting_types[b]; TypeMap &starting = starting_types[b];
for (auto p : starting) { for (const auto &p : starting) {
ASSERT(p.second, "%s", p.first.c_str()); ASSERT(p.second, "%s", p.first.c_str());
printf("%s: %s\n", p.first.c_str(), p.second->debugName().c_str()); printf("%s: %s\n", p.first.c_str(), p.second->debugName().c_str());
} }
......
...@@ -533,7 +533,7 @@ RewriterVarUsage2 Rewriter2::call(bool can_call_into_python, void* func_addr, st ...@@ -533,7 +533,7 @@ RewriterVarUsage2 Rewriter2::call(bool can_call_into_python, void* func_addr, st
} }
#ifndef NDEBUG #ifndef NDEBUG
for (auto p : vars_by_location) { for (const auto &p : vars_by_location) {
Location l = p.first; Location l = p.first;
//l.dump(); //l.dump();
if (l.isClobberedByCall()) { if (l.isClobberedByCall()) {
......
...@@ -47,7 +47,7 @@ void FunctionAddressRegistry::dumpPerfMap() { ...@@ -47,7 +47,7 @@ void FunctionAddressRegistry::dumpPerfMap() {
char buf[80]; char buf[80];
snprintf(buf, 80, "/tmp/perf-%d.map", getpid()); snprintf(buf, 80, "/tmp/perf-%d.map", getpid());
FILE *f = fopen(buf, "w"); FILE *f = fopen(buf, "w");
for (auto p : functions) { for (const auto &p : functions) {
const FuncInfo& info = p.second; const FuncInfo& info = p.second;
fprintf(f, "%lx %x %s\n", (uintptr_t)p.first, info.length, info.name.c_str()); fprintf(f, "%lx %x %s\n", (uintptr_t)p.first, info.length, info.name.c_str());
......
...@@ -325,7 +325,7 @@ static void emitBBs(IRGenState* irstate, const char* bb_type, GuardList &out_gua ...@@ -325,7 +325,7 @@ static void emitBBs(IRGenState* irstate, const char* bb_type, GuardList &out_gua
// Handle loading symbols from the passed osr arguments: // Handle loading symbols from the passed osr arguments:
int arg_num = -1; int arg_num = -1;
for (auto p : entry_descriptor->args) { for (const auto &p : entry_descriptor->args) {
llvm::Value* from_arg; llvm::Value* from_arg;
arg_num++; arg_num++;
if (arg_num < 3) { if (arg_num < 3) {
...@@ -417,7 +417,7 @@ static void emitBBs(IRGenState* irstate, const char* bb_type, GuardList &out_gua ...@@ -417,7 +417,7 @@ static void emitBBs(IRGenState* irstate, const char* bb_type, GuardList &out_gua
} }
unbox_emitter->getBuilder()->CreateBr(llvm_entry_blocks[entry_descriptor->backedge->target]); unbox_emitter->getBuilder()->CreateBr(llvm_entry_blocks[entry_descriptor->backedge->target]);
for (auto p : *initial_syms) { for (const auto &p : *initial_syms) {
delete p.second; delete p.second;
} }
delete initial_syms; delete initial_syms;
...@@ -544,7 +544,7 @@ static void emitBBs(IRGenState* irstate, const char* bb_type, GuardList &out_gua ...@@ -544,7 +544,7 @@ static void emitBBs(IRGenState* irstate, const char* bb_type, GuardList &out_gua
assert(osr_entry_block); assert(osr_entry_block);
assert(phis); assert(phis);
for (auto p : entry_descriptor->args) { for (const auto &p : entry_descriptor->args) {
ConcreteCompilerType *analyzed_type; ConcreteCompilerType *analyzed_type;
if (startswith(p.first, "!is_defined")) if (startswith(p.first, "!is_defined"))
analyzed_type = BOOL; analyzed_type = BOOL;
...@@ -569,7 +569,7 @@ static void emitBBs(IRGenState* irstate, const char* bb_type, GuardList &out_gua ...@@ -569,7 +569,7 @@ static void emitBBs(IRGenState* irstate, const char* bb_type, GuardList &out_gua
} }
const PhiAnalysis::RequiredSet &names = source->phis->getAllDefinedAt(block); const PhiAnalysis::RequiredSet &names = source->phis->getAllDefinedAt(block);
for (auto s : names) { for (const auto &s : names) {
// TODO the list from getAllDefinedAt should come filtered: // TODO the list from getAllDefinedAt should come filtered:
if (!source->liveness->isLiveAtEnd(s, block->predecessors[0])) if (!source->liveness->isLiveAtEnd(s, block->predecessors[0]))
continue; continue;
...@@ -745,7 +745,7 @@ static void emitBBs(IRGenState* irstate, const char* bb_type, GuardList &out_gua ...@@ -745,7 +745,7 @@ static void emitBBs(IRGenState* irstate, const char* bb_type, GuardList &out_gua
} }
if (entry_descriptor) { if (entry_descriptor) {
for (auto p : *osr_syms) { for (const auto &p : *osr_syms) {
delete p.second; delete p.second;
} }
delete osr_syms; delete osr_syms;
...@@ -869,7 +869,7 @@ CompiledFunction* compileFunction(SourceInfo *source, const OSREntryDescriptor * ...@@ -869,7 +869,7 @@ CompiledFunction* compileFunction(SourceInfo *source, const OSREntryDescriptor *
} }
} else { } else {
int arg_num = -1; int arg_num = -1;
for (auto p : entry_descriptor->args) { for (const auto &p : entry_descriptor->args) {
arg_num++; arg_num++;
//printf("Loading %s: %s\n", p.first.c_str(), p.second->debugName().c_str()); //printf("Loading %s: %s\n", p.first.c_str(), p.second->debugName().c_str());
if (arg_num < 3) if (arg_num < 3)
...@@ -920,7 +920,7 @@ CompiledFunction* compileFunction(SourceInfo *source, const OSREntryDescriptor * ...@@ -920,7 +920,7 @@ CompiledFunction* compileFunction(SourceInfo *source, const OSREntryDescriptor *
//Worklist guard_worklist; //Worklist guard_worklist;
guards.getBlocksWithGuards(deopt_full_blocks); guards.getBlocksWithGuards(deopt_full_blocks);
for (auto p : guards.exprGuards()) { for (const auto &p : guards.exprGuards()) {
deopt_partial_blocks.insert(p.second->cfg_block); deopt_partial_blocks.insert(p.second->cfg_block);
} }
...@@ -937,7 +937,7 @@ CompiledFunction* compileFunction(SourceInfo *source, const OSREntryDescriptor * ...@@ -937,7 +937,7 @@ CompiledFunction* compileFunction(SourceInfo *source, const OSREntryDescriptor *
} }
guards.assertGotPatched(); guards.assertGotPatched();
for (auto p : guards.exprGuards()) { for (const auto &p : guards.exprGuards()) {
delete p.second; delete p.second;
} }
......
...@@ -79,7 +79,7 @@ GuardList::ExprTypeGuard::ExprTypeGuard(CFGBlock *cfg_block, llvm::BranchInst* b ...@@ -79,7 +79,7 @@ GuardList::ExprTypeGuard::ExprTypeGuard(CFGBlock *cfg_block, llvm::BranchInst* b
DupCache cache; DupCache cache;
this->val = val->dup(cache); this->val = val->dup(cache);
for (auto p : st) { for (const auto &p : st) {
this->st[p.first] = p.second->dup(cache); this->st[p.first] = p.second->dup(cache);
} }
} }
...@@ -87,7 +87,7 @@ GuardList::ExprTypeGuard::ExprTypeGuard(CFGBlock *cfg_block, llvm::BranchInst* b ...@@ -87,7 +87,7 @@ GuardList::ExprTypeGuard::ExprTypeGuard(CFGBlock *cfg_block, llvm::BranchInst* b
GuardList::BlockEntryGuard::BlockEntryGuard(CFGBlock *cfg_block, llvm::BranchInst* branch, const SymbolTable &symbol_table) : GuardList::BlockEntryGuard::BlockEntryGuard(CFGBlock *cfg_block, llvm::BranchInst* branch, const SymbolTable &symbol_table) :
cfg_block(cfg_block), branch(branch) { cfg_block(cfg_block), branch(branch) {
DupCache cache; DupCache cache;
for (auto p : symbol_table) { for (const auto &p : symbol_table) {
this->symbol_table[p.first] = p.second->dup(cache); this->symbol_table[p.first] = p.second->dup(cache);
} }
} }
...@@ -926,7 +926,7 @@ class IRGeneratorImpl : public IRGenerator { ...@@ -926,7 +926,7 @@ class IRGeneratorImpl : public IRGenerator {
llvm::BasicBlock *ramp_block = llvm::BasicBlock::Create(g.context, "deopt_ramp", irstate->getLLVMFunction()); llvm::BasicBlock *ramp_block = llvm::BasicBlock::Create(g.context, "deopt_ramp", irstate->getLLVMFunction());
llvm::BasicBlock *join_block = llvm::BasicBlock::Create(g.context, "deopt_join", irstate->getLLVMFunction()); llvm::BasicBlock *join_block = llvm::BasicBlock::Create(g.context, "deopt_join", irstate->getLLVMFunction());
SymbolTable joined_st; SymbolTable joined_st;
for (auto p : guard->st) { for (const auto &p : guard->st) {
//if (VERBOSITY("irgen") >= 1) printf("merging %s\n", p.first.c_str()); //if (VERBOSITY("irgen") >= 1) printf("merging %s\n", p.first.c_str());
CompilerVariable *curval = symbol_table[p.first]; CompilerVariable *curval = symbol_table[p.first];
// I'm not sure this is necessary or even correct: // I'm not sure this is necessary or even correct:
...@@ -1399,7 +1399,7 @@ class IRGeneratorImpl : public IRGenerator { ...@@ -1399,7 +1399,7 @@ class IRGeneratorImpl : public IRGenerator {
} }
int arg_num = -1; int arg_num = -1;
for (auto p : sorted_symbol_table) { for (const auto &p : sorted_symbol_table) {
arg_num++; arg_num++;
// I don't think this can fail, but if it can we should filter out dead symbols before // I don't think this can fail, but if it can we should filter out dead symbols before
// passing them on: // passing them on:
......
...@@ -127,20 +127,20 @@ class GuardList { ...@@ -127,20 +127,20 @@ class GuardList {
} }
void getBlocksWithGuards(std::unordered_set<CFGBlock*> &add_to) { void getBlocksWithGuards(std::unordered_set<CFGBlock*> &add_to) {
for (auto p : block_begin_guards) { for (const auto &p : block_begin_guards) {
add_to.insert(p.first); add_to.insert(p.first);
} }
} }
void assertGotPatched() { void assertGotPatched() {
#ifndef NDEBUG #ifndef NDEBUG
for (auto p : block_begin_guards) { for (const auto &p : block_begin_guards) {
for (auto g : p.second) { for (const auto g : p.second) {
assert(g->branch->getSuccessor(0) != g->branch->getSuccessor(1)); assert(g->branch->getSuccessor(0) != g->branch->getSuccessor(1));
} }
} }
for (auto p : expr_type_guards) { for (const auto &p : expr_type_guards) {
assert(p.second->branch->getSuccessor(0) != p.second->branch->getSuccessor(1)); assert(p.second->branch->getSuccessor(0) != p.second->branch->getSuccessor(1));
} }
#endif #endif
......
...@@ -206,8 +206,8 @@ void gatherInterpreterRootsForFrame(GCVisitor *visitor, void* frame_ptr) { ...@@ -206,8 +206,8 @@ void gatherInterpreterRootsForFrame(GCVisitor *visitor, void* frame_ptr) {
auto it = interpreter_roots.find(frame_ptr); auto it = interpreter_roots.find(frame_ptr);
if (it == interpreter_roots.end()) { if (it == interpreter_roots.end()) {
printf("%p is not an interpreter frame; they are", frame_ptr); printf("%p is not an interpreter frame; they are", frame_ptr);
for (auto it2 : interpreter_roots) { for (const auto &p2 : interpreter_roots) {
printf(" %p", it2.first); printf(" %p", p2.first);
} }
printf("\n"); printf("\n");
abort(); abort();
...@@ -216,8 +216,8 @@ void gatherInterpreterRootsForFrame(GCVisitor *visitor, void* frame_ptr) { ...@@ -216,8 +216,8 @@ void gatherInterpreterRootsForFrame(GCVisitor *visitor, void* frame_ptr) {
//printf("Gathering roots for frame %p\n", frame_ptr); //printf("Gathering roots for frame %p\n", frame_ptr);
const SymMap* symbols = it->second; const SymMap* symbols = it->second;
for (auto it2 : *symbols) { for (const auto &p2 : *symbols) {
visitor->visitPotential(it2.second.o); visitor->visitPotential(p2.second.o);
} }
} }
......
...@@ -423,11 +423,11 @@ class DeadAllocsPass : public FunctionPass { ...@@ -423,11 +423,11 @@ class DeadAllocsPass : public FunctionPass {
if (VERBOSITY("opt") >= 1) { if (VERBOSITY("opt") >= 1) {
errs() << "\nFound dead alloc:" << *inst_it << '\n'; errs() << "\nFound dead alloc:" << *inst_it << '\n';
errs() << "Taking along with it:\n"; errs() << "Taking along with it:\n";
for (auto I : chain.deletions) { for (const auto I : chain.deletions) {
errs() << *I << '\n'; errs() << *I << '\n';
} }
errs() << "\nLoads that need to be remapped:\n"; errs() << "\nLoads that need to be remapped:\n";
for (auto I : chain.loads) { for (const auto I : chain.loads) {
errs() << *I << '\n'; errs() << *I << '\n';
} }
} }
...@@ -447,7 +447,7 @@ class DeadAllocsPass : public FunctionPass { ...@@ -447,7 +447,7 @@ class DeadAllocsPass : public FunctionPass {
} }
sc_numdeleted.log(chain.deletions.size()); sc_numdeleted.log(chain.deletions.size());
for (auto I : chain.deletions) { for (const auto I : chain.deletions) {
I->eraseFromParent(); I->eraseFromParent();
} }
} }
......
...@@ -150,7 +150,7 @@ bool EscapeAnalysis::runOnFunction(Function &F) { ...@@ -150,7 +150,7 @@ bool EscapeAnalysis::runOnFunction(Function &F) {
{ {
std::deque<const BasicBlock*> queue; std::deque<const BasicBlock*> queue;
for (auto I : chain->escape_points) { for (const auto I : chain->escape_points) {
chain->bb_escapes[I->getParent()] = BBPartialEscape; chain->bb_escapes[I->getParent()] = BBPartialEscape;
queue.insert(queue.end(), succ_begin(I->getParent()), succ_end(I->getParent())); queue.insert(queue.end(), succ_begin(I->getParent()), succ_end(I->getParent()));
} }
...@@ -181,10 +181,10 @@ bool EscapeAnalysis::runOnFunction(Function &F) { ...@@ -181,10 +181,10 @@ bool EscapeAnalysis::runOnFunction(Function &F) {
void EscapeAnalysis::ChainInfo::dump() { void EscapeAnalysis::ChainInfo::dump() {
errs() << "Chain starting at " << *allocation << ":\n"; errs() << "Chain starting at " << *allocation << ":\n";
for (auto escape_point : escape_points) { for (const auto escape_point : escape_points) {
errs() << "Escapes at: " << *escape_point << '\n'; errs() << "Escapes at: " << *escape_point << '\n';
} }
for (auto ptr : derived) { for (const auto ptr : derived) {
errs() << "Derived: " << *ptr << '\n'; errs() << "Derived: " << *ptr << '\n';
} }
} }
......
...@@ -86,7 +86,7 @@ void processStackmap(StackMap* stackmap) { ...@@ -86,7 +86,7 @@ void processStackmap(StackMap* stackmap) {
uint8_t* start_addr = func_addr + r->offset; uint8_t* start_addr = func_addr + r->offset;
std::unordered_set<int> live_outs; std::unordered_set<int> live_outs;
for (auto live_out : r->live_outs) { for (const auto &live_out : r->live_outs) {
live_outs.insert(live_out.regnum); live_outs.insert(live_out.regnum);
} }
......
...@@ -45,7 +45,7 @@ void Stats::dump() { ...@@ -45,7 +45,7 @@ void Stats::dump() {
printf("Stats:\n"); printf("Stats:\n");
std::vector<std::pair<std::string, int> > pairs; std::vector<std::pair<std::string, int> > pairs;
for (auto p : *names) { for (const auto &p : *names) {
pairs.push_back(make_pair(p.second, p.first)); pairs.push_back(make_pair(p.second, p.first));
} }
......
...@@ -69,6 +69,10 @@ void setupSys() { ...@@ -69,6 +69,10 @@ void setupSys() {
BoxedList* sys_path = new BoxedList(); BoxedList* sys_path = new BoxedList();
sys_module->giveAttr("path", sys_path); sys_module->giveAttr("path", sys_path);
sys_module->giveAttr("stdout", new BoxedFile(stdout));
sys_module->giveAttr("stdin", new BoxedFile(stdin));
sys_module->giveAttr("stderr", new BoxedFile(stderr));
} }
} }
......
...@@ -27,7 +27,7 @@ Box* dictRepr(BoxedDict* self) { ...@@ -27,7 +27,7 @@ Box* dictRepr(BoxedDict* self) {
std::vector<char> chars; std::vector<char> chars;
chars.push_back('{'); chars.push_back('{');
bool first = true; bool first = true;
for (auto p : self->d) { for (const auto &p : self->d) {
if (!first) { if (!first) {
chars.push_back(','); chars.push_back(',');
chars.push_back(' '); chars.push_back(' ');
...@@ -48,7 +48,7 @@ Box* dictRepr(BoxedDict* self) { ...@@ -48,7 +48,7 @@ Box* dictRepr(BoxedDict* self) {
Box* dictItems(BoxedDict* self) { Box* dictItems(BoxedDict* self) {
BoxedList* rtn = new BoxedList(); BoxedList* rtn = new BoxedList();
for (auto p : self->d) { for (const auto &p : self->d) {
std::vector<Box*> elts; std::vector<Box*> elts;
elts.push_back(p.first); elts.push_back(p.first);
elts.push_back(p.second); elts.push_back(p.second);
...@@ -61,7 +61,7 @@ Box* dictItems(BoxedDict* self) { ...@@ -61,7 +61,7 @@ Box* dictItems(BoxedDict* self) {
Box* dictValues(BoxedDict* self) { Box* dictValues(BoxedDict* self) {
BoxedList* rtn = new BoxedList(); BoxedList* rtn = new BoxedList();
for (auto p : self->d) { for (const auto &p : self->d) {
listAppendInternal(rtn, p.second); listAppendInternal(rtn, p.second);
} }
return rtn; return rtn;
...@@ -69,7 +69,7 @@ Box* dictValues(BoxedDict* self) { ...@@ -69,7 +69,7 @@ Box* dictValues(BoxedDict* self) {
Box* dictKeys(BoxedDict* self) { Box* dictKeys(BoxedDict* self) {
BoxedList* rtn = new BoxedList(); BoxedList* rtn = new BoxedList();
for (auto p : self->d) { for (const auto &p : self->d) {
listAppendInternal(rtn, p.first); listAppendInternal(rtn, p.first);
} }
return rtn; return rtn;
......
...@@ -424,7 +424,7 @@ void HCBox::setattr(const std::string& attr, Box* val, SetattrRewriteArgs *rewri ...@@ -424,7 +424,7 @@ void HCBox::setattr(const std::string& attr, Box* val, SetattrRewriteArgs *rewri
// TODO need to make sure we don't need to rearrange the attributes // TODO need to make sure we don't need to rearrange the attributes
assert(new_hcls->attr_offsets[attr] == numattrs); assert(new_hcls->attr_offsets[attr] == numattrs);
#ifndef NDEBUG #ifndef NDEBUG
for (auto p : hcls->attr_offsets) { for (const auto &p : hcls->attr_offsets) {
assert(new_hcls->attr_offsets[p.first] == p.second); assert(new_hcls->attr_offsets[p.first] == p.second);
} }
#endif #endif
......
...@@ -93,8 +93,8 @@ extern "C" void typeGCHandler(GCVisitor *v, void* p) { ...@@ -93,8 +93,8 @@ extern "C" void typeGCHandler(GCVisitor *v, void* p) {
extern "C" void hcGCHandler(GCVisitor *v, void* p) { extern "C" void hcGCHandler(GCVisitor *v, void* p) {
HiddenClass *hc = (HiddenClass*)p; HiddenClass *hc = (HiddenClass*)p;
for (auto it : hc->children) { for (const auto &p : hc->children) {
v->visit(it.second); v->visit(p.second);
} }
} }
...@@ -446,8 +446,8 @@ BoxedModule* createModule(const std::string &name, const std::string &fn) { ...@@ -446,8 +446,8 @@ BoxedModule* createModule(const std::string &name, const std::string &fn) {
} }
void freeHiddenClasses(HiddenClass *hcls) { void freeHiddenClasses(HiddenClass *hcls) {
for (auto it : hcls->children) { for (const auto &p : hcls->children) {
freeHiddenClasses(it.second); freeHiddenClasses(p.second);
} }
rt_free(hcls); rt_free(hcls);
} }
......
# expected: fail
import sys
sys.stdout.write("hello world\n")
print >>sys.stdout, "hello world"
class StringBuf(object):
def __init__(self):
self.s = ""
def write(self, s):
self.s += s
def getvalue(self):
return self.s
sys_stdout = sys.stdout
sys.stdout = StringBuf()
print "hello world"
print >>sys_stdout, "stringio contains:", repr(sys.stdout.getvalue())
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment