forked from OSchip/llvm-project
DebugInfo: Don't use enumerators in template names for debug info as they are not canonical
Since enumerators may not be available in every translation unit they can't be reliably used to name entities. (this also makes simplified template name roundtripping infeasible - since the expected name could only be rebuilt if the enumeration definition could be found (or only if it couldn't be found, depending on the context of the original name))
This commit is contained in:
parent
6efda5e6d6
commit
bb3980ae9f
|
@ -74,7 +74,8 @@ struct PrintingPolicy {
|
|||
SuppressImplicitBase(false), FullyQualifiedName(false),
|
||||
PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true),
|
||||
UsePreferredNames(true), AlwaysIncludeTypeForTemplateArgument(false),
|
||||
CleanUglifiedParameters(false), EntireContentsOfLargeArray(true) {}
|
||||
CleanUglifiedParameters(false), EntireContentsOfLargeArray(true),
|
||||
UseEnumerators(true) {}
|
||||
|
||||
/// Adjust this printing policy for cases where it's known that we're
|
||||
/// printing C++ code (for instance, if AST dumping reaches a C++-only
|
||||
|
@ -290,6 +291,10 @@ struct PrintingPolicy {
|
|||
/// template parameters, no matter how many elements there are.
|
||||
unsigned EntireContentsOfLargeArray : 1;
|
||||
|
||||
/// Whether to print enumerator non-type template parameters with a matching
|
||||
/// enumerator name or via cast of an integer.
|
||||
unsigned UseEnumerators : 1;
|
||||
|
||||
/// Callbacks to use to allow the behavior of printing to be customized.
|
||||
const PrintingCallbacks *Callbacks = nullptr;
|
||||
};
|
||||
|
|
|
@ -59,15 +59,17 @@ static void printIntegral(const TemplateArgument &TemplArg, raw_ostream &Out,
|
|||
const Type *T = TemplArg.getIntegralType().getTypePtr();
|
||||
const llvm::APSInt &Val = TemplArg.getAsIntegral();
|
||||
|
||||
if (const EnumType *ET = T->getAs<EnumType>()) {
|
||||
for (const EnumConstantDecl* ECD : ET->getDecl()->enumerators()) {
|
||||
// In Sema::CheckTemplateArugment, enum template arguments value are
|
||||
// extended to the size of the integer underlying the enum type. This
|
||||
// may create a size difference between the enum value and template
|
||||
// argument value, requiring isSameValue here instead of operator==.
|
||||
if (llvm::APSInt::isSameValue(ECD->getInitVal(), Val)) {
|
||||
ECD->printQualifiedName(Out, Policy);
|
||||
return;
|
||||
if (Policy.UseEnumerators) {
|
||||
if (const EnumType *ET = T->getAs<EnumType>()) {
|
||||
for (const EnumConstantDecl *ECD : ET->getDecl()->enumerators()) {
|
||||
// In Sema::CheckTemplateArugment, enum template arguments value are
|
||||
// extended to the size of the integer underlying the enum type. This
|
||||
// may create a size difference between the enum value and template
|
||||
// argument value, requiring isSameValue here instead of operator==.
|
||||
if (llvm::APSInt::isSameValue(ECD->getInitVal(), Val)) {
|
||||
ECD->printQualifiedName(Out, Policy);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -248,6 +248,7 @@ PrintingPolicy CGDebugInfo::getPrintingPolicy() const {
|
|||
PP.PrintCanonicalTypes = true;
|
||||
PP.UsePreferredNames = false;
|
||||
PP.AlwaysIncludeTypeForTemplateArgument = true;
|
||||
PP.UseEnumerators = false;
|
||||
|
||||
// Apply -fdebug-prefix-map.
|
||||
PP.Callbacks = &PrintCB;
|
||||
|
|
|
@ -31,7 +31,7 @@ struct t4 {
|
|||
};
|
||||
|
||||
t4 v1;
|
||||
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "t3<(anonymous namespace)::LocalEnum, (anonymous namespace)::LocalEnum1>"
|
||||
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "t3<(anonymous namespace)::LocalEnum, ((anonymous namespace)::LocalEnum)0>"
|
||||
void f() {
|
||||
// Basic examples of simplifiable/rebuildable names
|
||||
f1<>();
|
||||
|
|
|
@ -397,27 +397,10 @@ struct DWARFTypePrinter {
|
|||
DWARFDie T = resolveReferencedType(C);
|
||||
Sep();
|
||||
if (T.getTag() == DW_TAG_enumeration_type) {
|
||||
auto V = C.find(DW_AT_const_value);
|
||||
bool FoundEnumerator = false;
|
||||
for (const DWARFDie &Enumerator : T) {
|
||||
auto EV = Enumerator.find(DW_AT_const_value);
|
||||
if (V && EV &&
|
||||
V->getAsSignedConstant() == EV->getAsSignedConstant()) {
|
||||
if (T.find(DW_AT_enum_class)) {
|
||||
appendQualifiedName(T);
|
||||
OS << "::";
|
||||
} else
|
||||
appendScopes(T.getParent());
|
||||
OS << Enumerator.getShortName();
|
||||
FoundEnumerator = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (FoundEnumerator)
|
||||
continue;
|
||||
OS << '(';
|
||||
appendQualifiedName(T);
|
||||
OS << ')';
|
||||
auto V = C.find(DW_AT_const_value);
|
||||
OS << to_string(*V->getAsSignedConstant());
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -140,9 +140,9 @@
|
|||
# CHECK: DW_AT_type{{.*}}"t2<t2<int> >"
|
||||
|
||||
# enum literals
|
||||
# CHECK: DW_AT_type{{.*}}"tv<e1, E1>")
|
||||
# CHECK: DW_AT_type{{.*}}"tv<e1, (e1)0>")
|
||||
# CHECK: DW_AT_type{{.*}}"tv<e1, (e1)1>")
|
||||
# CHECK: DW_AT_type{{.*}}"tv<e2, e2::E2>")
|
||||
# CHECK: DW_AT_type{{.*}}"tv<e2, (e2)0>")
|
||||
|
||||
# char literals
|
||||
# CHECK: DW_AT_type{{.*}}"tv<unsigned char, (unsigned char)'x'>")
|
||||
|
|
|
@ -12600,15 +12600,15 @@ i:
|
|||
.Linfo_string195:
|
||||
.asciz "_Z2f3IN2ns11EnumerationEJLS1_1ELS1_2EEEvv" # string offset=2877
|
||||
.Linfo_string196:
|
||||
.asciz "_STNf3|<ns::Enumeration, ns::Enumerator2, (ns::Enumeration)2>" # string offset=2919
|
||||
.asciz "_STNf3|<ns::Enumeration, (ns::Enumeration)1, (ns::Enumeration)2>" # string offset=2919
|
||||
.Linfo_string197:
|
||||
.asciz "_Z2f3IN2ns16EnumerationClassEJLS1_1ELS1_2EEEvv" # string offset=2981
|
||||
.Linfo_string198:
|
||||
.asciz "_STNf3|<ns::EnumerationClass, ns::EnumerationClass::Enumerator2, (ns::EnumerationClass)2>" # string offset=3028
|
||||
.asciz "_STNf3|<ns::EnumerationClass, (ns::EnumerationClass)1, (ns::EnumerationClass)2>" # string offset=3028
|
||||
.Linfo_string199:
|
||||
.asciz "_Z2f3IN2ns16EnumerationSmallEJLS1_255EEEvv" # string offset=3118
|
||||
.Linfo_string200:
|
||||
.asciz "_STNf3|<ns::EnumerationSmall, ns::kNeg>" # string offset=3161
|
||||
.asciz "_STNf3|<ns::EnumerationSmall, (ns::EnumerationSmall)255>" # string offset=3161
|
||||
.Linfo_string201:
|
||||
.asciz "_Z2f3IN2ns3$_0EJLS1_1ELS1_2EEEvv" # string offset=3201
|
||||
.Linfo_string202:
|
||||
|
|
Loading…
Reference in New Issue