Author: David Blaikie Date: 2022-04-05T17:16:42Z New Revision: bb3980ae9fa7e19540080285f2bf2d960ea802fc
URL: https://github.com/llvm/llvm-project/commit/bb3980ae9fa7e19540080285f2bf2d960ea802fc DIFF: https://github.com/llvm/llvm-project/commit/bb3980ae9fa7e19540080285f2bf2d960ea802fc.diff LOG: 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)) Added: Modified: clang/include/clang/AST/PrettyPrinter.h clang/lib/AST/TemplateBase.cpp clang/lib/CodeGen/CGDebugInfo.cpp clang/test/CodeGenCXX/debug-info-simple-template-names.cpp llvm/lib/DebugInfo/DWARF/DWARFDie.cpp llvm/test/tools/llvm-dwarfdump/X86/prettyprint_types.s llvm/test/tools/llvm-dwarfdump/X86/simplified-template-names.s Removed: ################################################################################ diff --git a/clang/include/clang/AST/PrettyPrinter.h b/clang/include/clang/AST/PrettyPrinter.h index 54cb57227f7a0..cb25b2750dd43 100644 --- a/clang/include/clang/AST/PrettyPrinter.h +++ b/clang/include/clang/AST/PrettyPrinter.h @@ -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; }; diff --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp index 3418401517c84..229a8db21ab63 100644 --- a/clang/lib/AST/TemplateBase.cpp +++ b/clang/lib/AST/TemplateBase.cpp @@ -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 diff erence 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 diff erence 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; + } } } } diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index beb640375dfba..a37dc81c4bb8f 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -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; diff --git a/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp b/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp index 00c4361e11ef4..5bf1b54b97708 100644 --- a/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp +++ b/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp @@ -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<>(); diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp index 86bf36cc457d1..1dbe22dcd1c58 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp @@ -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; } diff --git a/llvm/test/tools/llvm-dwarfdump/X86/prettyprint_types.s b/llvm/test/tools/llvm-dwarfdump/X86/prettyprint_types.s index f04e245a420b3..92010dcc14c34 100644 --- a/llvm/test/tools/llvm-dwarfdump/X86/prettyprint_types.s +++ b/llvm/test/tools/llvm-dwarfdump/X86/prettyprint_types.s @@ -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'>") diff --git a/llvm/test/tools/llvm-dwarfdump/X86/simplified-template-names.s b/llvm/test/tools/llvm-dwarfdump/X86/simplified-template-names.s index 1f522343e010e..6bca48e15a153 100644 --- a/llvm/test/tools/llvm-dwarfdump/X86/simplified-template-names.s +++ b/llvm/test/tools/llvm-dwarfdump/X86/simplified-template-names.s @@ -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: _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits