================
@@ -5262,7 +5270,59 @@ Sema::DeduceAutoType(TypeLoc Type, Expr *Init, QualType
&Result,
DeducedType = getDecltypeForExpr(Init);
assert(!DeducedType.isNull());
- } else {
+ } else if (CanTryFastPath) {
+ // Fast-path a subset of `auto` deduction for non-init-list cases in
+ // non-ObjC and non-OpenCL language modes. For these cases, the deduced
+ // type can be computed directly from the initializer type by removing
+ // references, applying array/function decay, and dropping top-level
+ // cv-qualifiers. For single-level `auto*` declarators, the deduced type
+ // is the pointee type of the processed initializer type.
+
+ QualType DeclaredTy = Type.getType();
+ bool IsPlainOrTopLevelCvAuto = Context.hasSameType(
+ DeclaredTy.getLocalUnqualifiedType(), Context.getAutoDeductType());
+ bool IsSimpleAutoStar =
+ DeclaredTy->isPointerType() &&
+ Context.hasSameType(
+ DeclaredTy->getPointeeType().getLocalUnqualifiedType(),
+ Context.getAutoDeductType());
+
+ QualType ProcessedInitTy = Init->getType().getNonReferenceType();
+ if (ProcessedInitTy->isArrayType() || ProcessedInitTy->isFunctionType())
+ ProcessedInitTy = Context.getDecayedType(ProcessedInitTy);
+
+ ProcessedInitTy = ProcessedInitTy.getUnqualifiedType();
+ bool CanUsePointerFastPath =
+ IsSimpleAutoStar && ProcessedInitTy->isPointerType();
+
+ if (IsPlainOrTopLevelCvAuto) {
+ DeducedType = ProcessedInitTy;
+#ifndef NDEBUG
+ FastPathUsed = true;
+#endif
+ } else if (CanUsePointerFastPath) {
+ DeducedType = ProcessedInitTy->getPointeeType();
+ Qualifiers ProcessedInitQuals = DeducedType.getLocalQualifiers();
+ Qualifiers TypeQuals = DeclaredTy->getPointeeType().getLocalQualifiers();
+ ProcessedInitQuals.removeCVRQualifiers(TypeQuals.getCVRQualifiers());
+ DeducedType = Context.getQualifiedType(
+ DeducedType.getLocalUnqualifiedType(), ProcessedInitQuals);
----------------
Sirraide wrote:
I don’t quite understand why we’re calling `removeCVRQualifiers()` here;
shouldn’t we be merging them?
https://github.com/llvm/llvm-project/pull/188196
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits