Handle qualified constants that are directly folded by FE.

PR 7920.

llvm-svn: 111820
This commit is contained in:
Devang Patel 2010-08-23 18:25:56 +00:00
parent 620b68e883
commit a8652674e0
3 changed files with 32 additions and 6 deletions

View File

@ -290,6 +290,9 @@ namespace llvm {
unsigned getEncoding() const { return getUnsignedField(9); } unsigned getEncoding() const { return getUnsignedField(9); }
/// Verify - Verify that a basic type descriptor is well formed.
bool Verify() const;
/// print - print basic type. /// print - print basic type.
void print(raw_ostream &OS) const; void print(raw_ostream &OS) const;
@ -313,6 +316,9 @@ namespace llvm {
/// return base type size. /// return base type size.
uint64_t getOriginalTypeSize() const; uint64_t getOriginalTypeSize() const;
/// Verify - Verify that a derived type descriptor is well formed.
bool Verify() const;
/// print - print derived type. /// print - print derived type.
void print(raw_ostream &OS) const; void print(raw_ostream &OS) const;

View File

@ -303,6 +303,16 @@ bool DIType::Verify() const {
return true; return true;
} }
/// Verify - Verify that a basic type descriptor is well formed.
bool DIBasicType::Verify() const {
return isBasicType();
}
/// Verify - Verify that a derived type descriptor is well formed.
bool DIDerivedType::Verify() const {
return isDerivedType();
}
/// Verify - Verify that a composite type descriptor is well formed. /// Verify - Verify that a composite type descriptor is well formed.
bool DICompositeType::Verify() const { bool DICompositeType::Verify() const {
if (!DbgNode) if (!DbgNode)

View File

@ -1861,6 +1861,21 @@ CompileUnit *DwarfDebug::getCompileUnit(const MDNode *N) const {
return I->second; return I->second;
} }
/// isUnsignedDIType - Return true if type encoding is unsigned.
static bool isUnsignedDIType(DIType Ty) {
DIDerivedType DTy(Ty);
if (DTy.Verify())
return isUnsignedDIType(DTy.getTypeDerivedFrom());
DIBasicType BTy(Ty);
if (BTy.Verify()) {
unsigned Encoding = BTy.getEncoding();
if (Encoding == dwarf::DW_ATE_unsigned ||
Encoding == dwarf::DW_ATE_unsigned_char)
return true;
}
return false;
}
/// constructGlobalVariableDIE - Construct global variable DIE. /// constructGlobalVariableDIE - Construct global variable DIE.
void DwarfDebug::constructGlobalVariableDIE(const MDNode *N) { void DwarfDebug::constructGlobalVariableDIE(const MDNode *N) {
@ -1930,17 +1945,12 @@ void DwarfDebug::constructGlobalVariableDIE(const MDNode *N) {
} }
} else if (Constant *C = GV.getConstant()) { } else if (Constant *C = GV.getConstant()) {
if (ConstantInt *CI = dyn_cast<ConstantInt>(C)) { if (ConstantInt *CI = dyn_cast<ConstantInt>(C)) {
DIBasicType BTy(GTy); if (isUnsignedDIType(GTy))
if (BTy.Verify()) {
unsigned Encoding = BTy.getEncoding();
if (Encoding == dwarf::DW_ATE_unsigned ||
Encoding == dwarf::DW_ATE_unsigned_char)
addUInt(VariableDIE, dwarf::DW_AT_const_value, dwarf::DW_FORM_udata, addUInt(VariableDIE, dwarf::DW_AT_const_value, dwarf::DW_FORM_udata,
CI->getZExtValue()); CI->getZExtValue());
else else
addSInt(VariableDIE, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata, addSInt(VariableDIE, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata,
CI->getSExtValue()); CI->getSExtValue());
}
} }
} }
return; return;