Author: David Blaikie Date: 2021-09-15T13:46:37-07:00 New Revision: 40acc0adad59ac39e9a7a02fcd93161298500c00
URL: https://github.com/llvm/llvm-project/commit/40acc0adad59ac39e9a7a02fcd93161298500c00 DIFF: https://github.com/llvm/llvm-project/commit/40acc0adad59ac39e9a7a02fcd93161298500c00.diff LOG: Improve type printing of size-dependent const arrays to normalize array-of-const and const-array Follow-on from 2bd84938470bf2e337801faafb8a67710f46429d based on postcommit feedback from Richard Smith. The VariableArray case I couldn't figure out how to test/provoke - you can't write/form a variable array in any context other than a local variable that I know of, and in that case `const int x[n]` is the normalized form already (array-of-const) and you can't use typedefs (since you can't typedef int[n] with variable 'n') to force the const-array AST that would produce the undesirable type printing "int const [n]". Added: Modified: clang/lib/AST/TypePrinter.cpp clang/test/AST/ast-dump-array.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp index 251db97c7db08..749a3e25d28a4 100644 --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -242,13 +242,16 @@ bool TypePrinter::canPrefixQualifiers(const Type *T, T->isObjCQualifiedIdType() || T->isObjCQualifiedClassType(); break; + case Type::DependentSizedArray: + NeedARCStrongQualifier = true; + LLVM_FALLTHROUGH; + case Type::ConstantArray: case Type::IncompleteArray: return canPrefixQualifiers( cast<ArrayType>(UnderlyingType)->getElementType().getTypePtr(), NeedARCStrongQualifier); case Type::VariableArray: - case Type::DependentSizedArray: NeedARCStrongQualifier = true; LLVM_FALLTHROUGH; diff --git a/clang/test/AST/ast-dump-array.cpp b/clang/test/AST/ast-dump-array.cpp index fe7875ec95c90..2e94f7769e0bd 100644 --- a/clang/test/AST/ast-dump-array.cpp +++ b/clang/test/AST/ast-dump-array.cpp @@ -23,5 +23,6 @@ class array { using array_T_size = T[Size]; // CHECK: `-DependentSizedArrayType 0x{{[^ ]*}} 'T [Size]' dependent <col:25, col:30> + using const_array_T_size = const T[Size]; + // CHECK: `-DependentSizedArrayType 0x{{[^ ]*}} 'const T [Size]' dependent <col:37, col:42> }; - _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits