From 3acdc6773444b0dea84a69e99024e07ebabc0c98 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Tue, 27 Feb 2018 22:08:15 +0000 Subject: [CodeView] Lower __restrict and other pointer qualifiers correctly Qualifiers on a pointer or reference type may apply to either the pointee or the pointer itself. Consider 'const char *' and 'char * const'. In the first example, the pointee data may not be modified without casts, and in the second example, the pointer may not be updated to point to new data. In the general case, qualifiers are applied to types with LF_MODIFIER records, which support the usual const and volatile qualifiers as well as the __unaligned extension qualifier. However, LF_POINTER records, which are used for pointers, references, and member pointers, have flags for qualifiers applying to the *pointer*. In fact, this is the only way to represent the restrict qualifier, which can only apply to pointers, and cannot qualify regular data types. This patch causes LLVM to correctly fold 'const' and 'volatile' pointer qualifiers into the pointer record, as well as adding support for '__restrict' qualifiers in the same place. Based on a patch from Aaron Smith Differential Revision: https://reviews.llvm.org/D43060 llvm-svn: 326260 --- llvm/lib/DebugInfo/CodeView/RecordName.cpp | 18 +++++++++++------- llvm/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'llvm/lib/DebugInfo/CodeView') diff --git a/llvm/lib/DebugInfo/CodeView/RecordName.cpp b/llvm/lib/DebugInfo/CodeView/RecordName.cpp index 4e17e9e5193..e6fd7cd3d28 100644 --- a/llvm/lib/DebugInfo/CodeView/RecordName.cpp +++ b/llvm/lib/DebugInfo/CodeView/RecordName.cpp @@ -167,13 +167,6 @@ Error TypeNameComputer::visitKnownRecord(CVType &CVR, PointerRecord &Ptr) { StringRef Class = Types.getTypeName(MI.getContainingType()); Name = formatv("{0} {1}::*", Pointee, Class); } else { - if (Ptr.isConst()) - Name.append("const "); - if (Ptr.isVolatile()) - Name.append("volatile "); - if (Ptr.isUnaligned()) - Name.append("__unaligned "); - Name.append(Types.getTypeName(Ptr.getReferentType())); if (Ptr.getMode() == PointerMode::LValueReference) @@ -182,6 +175,17 @@ Error TypeNameComputer::visitKnownRecord(CVType &CVR, PointerRecord &Ptr) { Name.append("&&"); else if (Ptr.getMode() == PointerMode::Pointer) Name.append("*"); + + // Qualifiers in pointer records apply to the pointer, not the pointee, so + // they go on the right. + if (Ptr.isConst()) + Name.append(" const"); + if (Ptr.isVolatile()) + Name.append(" volatile"); + if (Ptr.isUnaligned()) + Name.append(" __unaligned"); + if (Ptr.isRestrict()) + Name.append(" __restrict"); } return Error::success(); } diff --git a/llvm/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp b/llvm/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp index e7998b8732f..2482c9ef332 100644 --- a/llvm/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp +++ b/llvm/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp @@ -370,6 +370,7 @@ Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, PointerRecord &Ptr) { W->printNumber("IsConst", Ptr.isConst()); W->printNumber("IsVolatile", Ptr.isVolatile()); W->printNumber("IsUnaligned", Ptr.isUnaligned()); + W->printNumber("IsRestrict", Ptr.isRestrict()); W->printNumber("SizeOf", Ptr.getSize()); if (Ptr.isPointerToMember()) { -- cgit v1.2.3