From a9d12c0a56e60a331af3ef6209d754f0c12e8bab Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 16 Oct 2004 18:12:13 +0000 Subject: [PATCH] Add support for unreachable and undef git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17048 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/CBackend/CBackend.cpp | 12 ++++++++++-- lib/Target/CBackend/Writer.cpp | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index c4d8c464837..bc3f839409c 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -174,6 +174,7 @@ namespace { void visitUnwindInst(UnwindInst &I) { assert(0 && "Lowerinvoke pass didn't work!"); } + void visitUnreachableInst(UnreachableInst &I); void visitPHINode(PHINode &I); void visitBinaryOperator(Instruction &I); @@ -521,6 +522,9 @@ void CWriter::printConstant(Constant *CPV) { << *CE << "\n"; abort(); } + } else if (isa(CPV) && CPV->getType()->isFirstClassType()) { + Out << "0"; + return; } switch (CPV->getType()->getTypeID()) { @@ -606,7 +610,7 @@ void CWriter::printConstant(Constant *CPV) { } case Type::ArrayTyID: - if (isa(CPV)) { + if (isa(CPV) || isa(CPV)) { const ArrayType *AT = cast(CPV->getType()); Out << "{"; if (AT->getNumElements()) { @@ -625,7 +629,7 @@ void CWriter::printConstant(Constant *CPV) { break; case Type::StructTyID: - if (isa(CPV)) { + if (isa(CPV) || isa(CPV)) { const StructType *ST = cast(CPV->getType()); Out << "{"; if (ST->getNumElements()) { @@ -1205,6 +1209,10 @@ void CWriter::visitSwitchInst(SwitchInst &SI) { Out << " }\n"; } +void CWriter::visitUnreachableInst(UnreachableInst &I) { + Out << " /*UNREACHABLE*/\n"; +} + bool CWriter::isGotoCodeNecessary(BasicBlock *From, BasicBlock *To) { /// FIXME: This should be reenabled, but loop reordering safe!! return true; diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp index c4d8c464837..bc3f839409c 100644 --- a/lib/Target/CBackend/Writer.cpp +++ b/lib/Target/CBackend/Writer.cpp @@ -174,6 +174,7 @@ namespace { void visitUnwindInst(UnwindInst &I) { assert(0 && "Lowerinvoke pass didn't work!"); } + void visitUnreachableInst(UnreachableInst &I); void visitPHINode(PHINode &I); void visitBinaryOperator(Instruction &I); @@ -521,6 +522,9 @@ void CWriter::printConstant(Constant *CPV) { << *CE << "\n"; abort(); } + } else if (isa(CPV) && CPV->getType()->isFirstClassType()) { + Out << "0"; + return; } switch (CPV->getType()->getTypeID()) { @@ -606,7 +610,7 @@ void CWriter::printConstant(Constant *CPV) { } case Type::ArrayTyID: - if (isa(CPV)) { + if (isa(CPV) || isa(CPV)) { const ArrayType *AT = cast(CPV->getType()); Out << "{"; if (AT->getNumElements()) { @@ -625,7 +629,7 @@ void CWriter::printConstant(Constant *CPV) { break; case Type::StructTyID: - if (isa(CPV)) { + if (isa(CPV) || isa(CPV)) { const StructType *ST = cast(CPV->getType()); Out << "{"; if (ST->getNumElements()) { @@ -1205,6 +1209,10 @@ void CWriter::visitSwitchInst(SwitchInst &SI) { Out << " }\n"; } +void CWriter::visitUnreachableInst(UnreachableInst &I) { + Out << " /*UNREACHABLE*/\n"; +} + bool CWriter::isGotoCodeNecessary(BasicBlock *From, BasicBlock *To) { /// FIXME: This should be reenabled, but loop reordering safe!! return true;