================
@@ -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();
----------------
Sirraide wrote:

I don’t think we should use `getLocalQualifiers()` for anything derived from 
the type of the initialiser here. For reference, `getLocalQualifiers()` returns 
`const` if the type is e.g. `const int`, but _no qualifiers_ if it’s e.g. `foo` 
defined as `using foo = const int`.

It’s fine to use it for the `auto` type because `auto` can’t appear in a 
typedef.

https://github.com/llvm/llvm-project/pull/188196
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to