Index: include/clang/AST/PrettyPrinter.h =================================================================== --- include/clang/AST/PrettyPrinter.h +++ include/clang/AST/PrettyPrinter.h @@ -51,7 +51,8 @@ TerseOutput(false), PolishForDeclaration(false), Half(LO.Half), MSWChar(LO.MicrosoftExt && !LO.WChar), IncludeNewlines(true), MSVCFormatting(false), - ConstantsAsWritten(false), SuppressImplicitBase(false) { } + ConstantsAsWritten(false), SuppressImplicitBase(false), + ABICompatibleFormatting(false) { } /// \brief Adjust this printing policy for cases where it's known that /// we're printing C++ code (for instance, if AST dumping reaches a @@ -64,7 +65,7 @@ } /// \brief The number of spaces to use to indent each line. - unsigned Indentation : 8; + unsigned Indentation : 7; /// \brief Whether we should suppress printing of the actual specifiers for /// the given type or declaration. @@ -222,6 +223,13 @@ /// \brief When true, don't print the implicit 'self' or 'this' expressions. bool SuppressImplicitBase : 1; + + /// \brief Use formatting compatible with ABI specification. It is necessary for + /// saving entities into debug tables which have to be compatible with + /// the representation, described in ABI specification. In particular, this forces + /// templates parametrized with enums to be represented as "T<(Enum)0>" instead of + /// "T". + bool ABICompatibleFormatting : 1; }; } // end namespace clang Index: lib/AST/TemplateBase.cpp =================================================================== --- lib/AST/TemplateBase.cpp +++ lib/AST/TemplateBase.cpp @@ -41,14 +41,22 @@ const llvm::APSInt &Val = TemplArg.getAsIntegral(); if (const EnumType *ET = T->getAs()) { - 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.ABICompatibleFormatting) { + Out << "("; + ET->getDecl()->getNameForDiagnostic(Out, Policy, true); + Out << ")"; + Out << Val; + return; + } else { + 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; + } } } } Index: lib/CodeGen/CGDebugInfo.cpp =================================================================== --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -234,6 +234,7 @@ if (CGM.getCodeGenOpts().EmitCodeView) PP.MSVCFormatting = true; + PP.ABICompatibleFormatting = true; return PP; }