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> &
}
Map &next = states[next_block];
for (auto p : ending) {
for (const auto &p : ending) {
if (next.count(p.first) == 0) {
changed = true;
if (initial) {
......@@ -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))
continue;
......
......@@ -231,7 +231,7 @@ void DefinednessBBAnalyzer::processBB(Map &starting, CFGBlock *block) const {
if (VERBOSITY("analysis") >= 2) {
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);
}
}
......@@ -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) {
results = computeFixedPoint(cfg, DefinednessBBAnalyzer(cfg, args), false);
for (auto p : results) {
for (const auto &p : results) {
RequiredSet required;
for (std::unordered_map<std::string, DefinitionLevel>::iterator it2 = p.second.begin(), end2 = p.second.end();
it2 != end2; ++it2) {
if (scope_info->refersToGlobal(it2->first))
for (const auto &p2 : p.second) {
if (scope_info->refersToGlobal(p2.first))
continue;
//printf("%d %s %d\n", p.first->idx, it2->first.c_str(), it2->second);
required.insert(it2->first);
//printf("%d %s %d\n", p.first->idx, p2.first.c_str(), p2.second);
required.insert(p2.first);
}
defined.insert(make_pair(p.first, required));
}
......@@ -275,7 +274,7 @@ PhiAnalysis::PhiAnalysis(AST_arguments* args, CFG* cfg, LivenessAnalysis *livene
const RequiredSet& defined = definedness.getDefinedNamesAt(block);
if (defined.size())
assert(block->predecessors.size());
for (auto s : defined) {
for (const auto &s : defined) {
if (liveness->isLiveAtEnd(s, block->predecessors[0])) {
required.insert(s);
}
......
......@@ -256,7 +256,7 @@ static std::vector<ScopingAnalysis::ScopeNameUsage*> sortNameUsages(ScopingAnaly
std::vector<ScopingAnalysis::ScopeNameUsage*> rtn;
std::unordered_set<ScopingAnalysis::ScopeNameUsage*> added;
for (auto p : *usages) {
for (const auto &p : *usages) {
ScopingAnalysis::ScopeNameUsage *usage = p.second;
std::vector<ScopingAnalysis::ScopeNameUsage*> traversed;
......@@ -281,7 +281,7 @@ void ScopingAnalysis::processNameUsages(ScopingAnalysis::NameUsageMap* usages) {
typedef ScopeNameUsage::StrSet StrSet;
// Resolve name lookups:
for (auto p : *usages) {
for (const auto &p : *usages) {
ScopeNameUsage *usage = p.second;
for (StrSet::iterator it2 = usage->read.begin(), end2 = usage->read.end();
it2 != end2; ++it2) {
......
......@@ -303,9 +303,9 @@ class BasicBlockTypePropagator : public ExprVisitor, public StmtVisitor {
// Get all the sub-types, even though they're not necessary to
// determine the expression type, so that things like speculations
// can be processed.
for (auto k : node->keys)
for (AST_expr* k : node->keys)
getType(k);
for (auto v : node->values)
for (AST_expr* v : node->values)
getType(v);
return DICT;
......@@ -319,7 +319,7 @@ class BasicBlockTypePropagator : public ExprVisitor, public StmtVisitor {
// Get all the sub-types, even though they're not necessary to
// determine the expression type, so that things like speculations
// can be processed.
for (auto elt : node->elts) {
for (AST_expr* elt : node->elts) {
getType(elt);
}
......@@ -449,7 +449,9 @@ class BasicBlockTypePropagator : public ExprVisitor, public StmtVisitor {
virtual void visit_pass(AST_Pass* node) {}
virtual void visit_print(AST_Print* node) {
assert(node->dest == NULL);
if (node->dest)
getType(node->dest);
if (EXPAND_UNNEEDED) {
for (int i = 0; i < node->values.size(); i++) {
getType(node->values[i]);
......@@ -571,7 +573,7 @@ class PropagatingTypeAnalysis : public TypeAnalysis {
if (VERBOSITY("types") >= 2) {
printf("before:\n");
TypeMap &starting = starting_types[block];
for (auto p : starting) {
for (const auto &p : starting) {
ASSERT(p.second, "%s", p.first.c_str());
printf("%s: %s\n", p.first.c_str(), p.second->debugName().c_str());
}
......@@ -582,12 +584,12 @@ class PropagatingTypeAnalysis : public TypeAnalysis {
if (VERBOSITY("types") >= 2) {
printf("before (after):\n");
TypeMap &starting = starting_types[block];
for (auto p : starting) {
for (const auto &p : starting) {
ASSERT(p.second, "%s", p.first.c_str());
printf("%s: %s\n", p.first.c_str(), p.second->debugName().c_str());
}
printf("after:\n");
for (auto p : ending) {
for (const auto &p : ending) {
ASSERT(p.second, "%s", p.first.c_str());
printf("%s: %s\n", p.first.c_str(), p.second->debugName().c_str());
}
......@@ -608,7 +610,7 @@ class PropagatingTypeAnalysis : public TypeAnalysis {
printf("Types at beginning of block %d:\n", b->idx);
TypeMap &starting = starting_types[b];
for (auto p : starting) {
for (const auto &p : starting) {
ASSERT(p.second, "%s", p.first.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
}
#ifndef NDEBUG
for (auto p : vars_by_location) {
for (const auto &p : vars_by_location) {
Location l = p.first;
//l.dump();
if (l.isClobberedByCall()) {
......
......@@ -47,7 +47,7 @@ void FunctionAddressRegistry::dumpPerfMap() {
char buf[80];
snprintf(buf, 80, "/tmp/perf-%d.map", getpid());
FILE *f = fopen(buf, "w");
for (auto p : functions) {
for (const auto &p : functions) {
const FuncInfo& info = p.second;
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
// Handle loading symbols from the passed osr arguments:
int arg_num = -1;
for (auto p : entry_descriptor->args) {
for (const auto &p : entry_descriptor->args) {
llvm::Value* from_arg;
arg_num++;
if (arg_num < 3) {
......@@ -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]);
for (auto p : *initial_syms) {
for (const auto &p : *initial_syms) {
delete p.second;
}
delete initial_syms;
......@@ -544,7 +544,7 @@ static void emitBBs(IRGenState* irstate, const char* bb_type, GuardList &out_gua
assert(osr_entry_block);
assert(phis);
for (auto p : entry_descriptor->args) {
for (const auto &p : entry_descriptor->args) {
ConcreteCompilerType *analyzed_type;
if (startswith(p.first, "!is_defined"))
analyzed_type = BOOL;
......@@ -569,7 +569,7 @@ static void emitBBs(IRGenState* irstate, const char* bb_type, GuardList &out_gua
}
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:
if (!source->liveness->isLiveAtEnd(s, block->predecessors[0]))
continue;
......@@ -745,7 +745,7 @@ static void emitBBs(IRGenState* irstate, const char* bb_type, GuardList &out_gua
}
if (entry_descriptor) {
for (auto p : *osr_syms) {
for (const auto &p : *osr_syms) {
delete p.second;
}
delete osr_syms;
......@@ -869,7 +869,7 @@ CompiledFunction* compileFunction(SourceInfo *source, const OSREntryDescriptor *
}
} else {
int arg_num = -1;
for (auto p : entry_descriptor->args) {
for (const auto &p : entry_descriptor->args) {
arg_num++;
//printf("Loading %s: %s\n", p.first.c_str(), p.second->debugName().c_str());
if (arg_num < 3)
......@@ -920,7 +920,7 @@ CompiledFunction* compileFunction(SourceInfo *source, const OSREntryDescriptor *
//Worklist guard_worklist;
guards.getBlocksWithGuards(deopt_full_blocks);
for (auto p : guards.exprGuards()) {
for (const auto &p : guards.exprGuards()) {
deopt_partial_blocks.insert(p.second->cfg_block);
}
......@@ -937,7 +937,7 @@ CompiledFunction* compileFunction(SourceInfo *source, const OSREntryDescriptor *
}
guards.assertGotPatched();
for (auto p : guards.exprGuards()) {
for (const auto &p : guards.exprGuards()) {
delete p.second;
}
......
......@@ -79,7 +79,7 @@ GuardList::ExprTypeGuard::ExprTypeGuard(CFGBlock *cfg_block, llvm::BranchInst* b
DupCache cache;
this->val = val->dup(cache);
for (auto p : st) {
for (const auto &p : st) {
this->st[p.first] = p.second->dup(cache);
}
}
......@@ -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) :
cfg_block(cfg_block), branch(branch) {
DupCache cache;
for (auto p : symbol_table) {
for (const auto &p : symbol_table) {
this->symbol_table[p.first] = p.second->dup(cache);
}
}
......@@ -926,7 +926,7 @@ class IRGeneratorImpl : public IRGenerator {
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());
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());
CompilerVariable *curval = symbol_table[p.first];
// I'm not sure this is necessary or even correct:
......@@ -1399,7 +1399,7 @@ class IRGeneratorImpl : public IRGenerator {
}
int arg_num = -1;
for (auto p : sorted_symbol_table) {
for (const auto &p : sorted_symbol_table) {
arg_num++;
// I don't think this can fail, but if it can we should filter out dead symbols before
// passing them on:
......
......@@ -127,20 +127,20 @@ class GuardList {
}
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);
}
}
void assertGotPatched() {
#ifndef NDEBUG
for (auto p : block_begin_guards) {
for (auto g : p.second) {
for (const auto &p : block_begin_guards) {
for (const auto g : p.second) {
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));
}
#endif
......
......@@ -206,8 +206,8 @@ void gatherInterpreterRootsForFrame(GCVisitor *visitor, void* frame_ptr) {
auto it = interpreter_roots.find(frame_ptr);
if (it == interpreter_roots.end()) {
printf("%p is not an interpreter frame; they are", frame_ptr);
for (auto it2 : interpreter_roots) {
printf(" %p", it2.first);
for (const auto &p2 : interpreter_roots) {
printf(" %p", p2.first);
}
printf("\n");
abort();
......@@ -216,8 +216,8 @@ void gatherInterpreterRootsForFrame(GCVisitor *visitor, void* frame_ptr) {
//printf("Gathering roots for frame %p\n", frame_ptr);
const SymMap* symbols = it->second;
for (auto it2 : *symbols) {
visitor->visitPotential(it2.second.o);
for (const auto &p2 : *symbols) {
visitor->visitPotential(p2.second.o);
}
}
......
......@@ -423,11 +423,11 @@ class DeadAllocsPass : public FunctionPass {
if (VERBOSITY("opt") >= 1) {
errs() << "\nFound dead alloc:" << *inst_it << '\n';
errs() << "Taking along with it:\n";
for (auto I : chain.deletions) {
for (const auto I : chain.deletions) {
errs() << *I << '\n';
}
errs() << "\nLoads that need to be remapped:\n";
for (auto I : chain.loads) {
for (const auto I : chain.loads) {
errs() << *I << '\n';
}
}
......@@ -447,7 +447,7 @@ class DeadAllocsPass : public FunctionPass {
}
sc_numdeleted.log(chain.deletions.size());
for (auto I : chain.deletions) {
for (const auto I : chain.deletions) {
I->eraseFromParent();
}
}
......
......@@ -150,7 +150,7 @@ bool EscapeAnalysis::runOnFunction(Function &F) {
{
std::deque<const BasicBlock*> queue;
for (auto I : chain->escape_points) {
for (const auto I : chain->escape_points) {
chain->bb_escapes[I->getParent()] = BBPartialEscape;
queue.insert(queue.end(), succ_begin(I->getParent()), succ_end(I->getParent()));
}
......@@ -181,10 +181,10 @@ bool EscapeAnalysis::runOnFunction(Function &F) {
void EscapeAnalysis::ChainInfo::dump() {
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';
}
for (auto ptr : derived) {
for (const auto ptr : derived) {
errs() << "Derived: " << *ptr << '\n';
}
}
......
......@@ -86,7 +86,7 @@ void processStackmap(StackMap* stackmap) {
uint8_t* start_addr = func_addr + r->offset;
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);
}
......
......@@ -45,7 +45,7 @@ void Stats::dump() {
printf("Stats:\n");
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));
}
......
......@@ -69,6 +69,10 @@ void setupSys() {
BoxedList* sys_path = new BoxedList();
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) {
std::vector<char> chars;
chars.push_back('{');
bool first = true;
for (auto p : self->d) {
for (const auto &p : self->d) {
if (!first) {
chars.push_back(',');
chars.push_back(' ');
......@@ -48,7 +48,7 @@ Box* dictRepr(BoxedDict* self) {
Box* dictItems(BoxedDict* self) {
BoxedList* rtn = new BoxedList();
for (auto p : self->d) {
for (const auto &p : self->d) {
std::vector<Box*> elts;
elts.push_back(p.first);
elts.push_back(p.second);
......@@ -61,7 +61,7 @@ Box* dictItems(BoxedDict* self) {
Box* dictValues(BoxedDict* self) {
BoxedList* rtn = new BoxedList();
for (auto p : self->d) {
for (const auto &p : self->d) {
listAppendInternal(rtn, p.second);
}
return rtn;
......@@ -69,7 +69,7 @@ Box* dictValues(BoxedDict* self) {
Box* dictKeys(BoxedDict* self) {
BoxedList* rtn = new BoxedList();
for (auto p : self->d) {
for (const auto &p : self->d) {
listAppendInternal(rtn, p.first);
}
return rtn;
......
......@@ -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
assert(new_hcls->attr_offsets[attr] == numattrs);
#ifndef NDEBUG
for (auto p : hcls->attr_offsets) {
for (const auto &p : hcls->attr_offsets) {
assert(new_hcls->attr_offsets[p.first] == p.second);
}
#endif
......
......@@ -93,8 +93,8 @@ extern "C" void typeGCHandler(GCVisitor *v, void* p) {
extern "C" void hcGCHandler(GCVisitor *v, void* p) {
HiddenClass *hc = (HiddenClass*)p;
for (auto it : hc->children) {
v->visit(it.second);
for (const auto &p : hc->children) {
v->visit(p.second);
}
}
......@@ -446,8 +446,8 @@ BoxedModule* createModule(const std::string &name, const std::string &fn) {
}
void freeHiddenClasses(HiddenClass *hcls) {
for (auto it : hcls->children) {
freeHiddenClasses(it.second);
for (const auto &p : hcls->children) {
freeHiddenClasses(p.second);
}
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