diff options
author | Chris Lattner <sabre@nondot.org> | 2004-10-17 17:48:59 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-10-17 17:48:59 +0000 |
commit | 665825e58e5db038d5f3360b07282e21748a7189 (patch) | |
tree | 6bc28710a059b01c92b6d6e354460789027cfa15 | |
parent | 611fb259ba6e0b8964aa0f318bafee370f2ec4d8 (diff) | |
download | external_llvm-665825e58e5db038d5f3360b07282e21748a7189.zip external_llvm-665825e58e5db038d5f3360b07282e21748a7189.tar.gz external_llvm-665825e58e5db038d5f3360b07282e21748a7189.tar.bz2 |
The first hunk corrects a bug when printing undef null values. We would print
0->field, which is illegal. Now we print ((foo*)0)->field.
The second hunk is an optimization to not print undefined phi values.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17094 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Target/CBackend/CBackend.cpp | 17 | ||||
-rw-r--r-- | lib/Target/CBackend/Writer.cpp | 17 |
2 files changed, 22 insertions, 12 deletions
diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index bc3f839..96eb684 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -523,7 +523,9 @@ void CWriter::printConstant(Constant *CPV) { abort(); } } else if (isa<UndefValue>(CPV) && CPV->getType()->isFirstClassType()) { - Out << "0"; + Out << "(("; + printType(Out, CPV->getType()); + Out << ")/*UNDEF*/0)"; return; } @@ -1234,11 +1236,14 @@ void CWriter::printPHICopiesForSuccessors(BasicBlock *CurBlock, SI != E; ++SI) for (BasicBlock::iterator I = SI->begin(); isa<PHINode>(I); ++I) { PHINode *PN = cast<PHINode>(I); - // now we have to do the printing - Out << std::string(Indent, ' '); - Out << " " << Mang->getValueName(I) << "__PHI_TEMPORARY = "; - writeOperand(PN->getIncomingValue(PN->getBasicBlockIndex(CurBlock))); - Out << "; /* for PHI node */\n"; + // Now we have to do the printing. + Value *IV = PN->getIncomingValueForBlock(CurBlock); + if (!isa<UndefValue>(IV)) { + Out << std::string(Indent, ' '); + Out << " " << Mang->getValueName(I) << "__PHI_TEMPORARY = "; + writeOperand(IV); + Out << "; /* for PHI node */\n"; + } } } diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp index bc3f839..96eb684 100644 --- a/lib/Target/CBackend/Writer.cpp +++ b/lib/Target/CBackend/Writer.cpp @@ -523,7 +523,9 @@ void CWriter::printConstant(Constant *CPV) { abort(); } } else if (isa<UndefValue>(CPV) && CPV->getType()->isFirstClassType()) { - Out << "0"; + Out << "(("; + printType(Out, CPV->getType()); + Out << ")/*UNDEF*/0)"; return; } @@ -1234,11 +1236,14 @@ void CWriter::printPHICopiesForSuccessors(BasicBlock *CurBlock, SI != E; ++SI) for (BasicBlock::iterator I = SI->begin(); isa<PHINode>(I); ++I) { PHINode *PN = cast<PHINode>(I); - // now we have to do the printing - Out << std::string(Indent, ' '); - Out << " " << Mang->getValueName(I) << "__PHI_TEMPORARY = "; - writeOperand(PN->getIncomingValue(PN->getBasicBlockIndex(CurBlock))); - Out << "; /* for PHI node */\n"; + // Now we have to do the printing. + Value *IV = PN->getIncomingValueForBlock(CurBlock); + if (!isa<UndefValue>(IV)) { + Out << std::string(Indent, ' '); + Out << " " << Mang->getValueName(I) << "__PHI_TEMPORARY = "; + writeOperand(IV); + Out << "; /* for PHI node */\n"; + } } } |