[clang] [clang] Fix crash in concept deprecation (PR #98622)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 12 21:13:07 PDT 2024


================
@@ -7416,10 +7416,11 @@ NamedDecl *Sema::ActOnVariableDeclarator(
     tryToFixVariablyModifiedVarType(TInfo, R, D.getIdentifierLoc(),
                                     /*DiagID=*/0);
 
-  if (const AutoType *AutoT = R->getAs<AutoType>())
-    CheckConstrainedAuto(
-        AutoT,
-        TInfo->getTypeLoc().getContainedAutoTypeLoc().getConceptNameLoc());
+  if (const AutoType *AutoT = R->getAs<AutoType>()) {
+    AutoTypeLoc Loc = TInfo->getTypeLoc().getContainedAutoTypeLoc();
----------------
mizvekov wrote:

These two lines are analyzing the type in very different ways, so there seems to be further bugs here.

`Type::getAs<AutoType>` will simply desugar a type until it finds a node with type 'AutoType'.

`getContainedAutoTypeLoc()` will dig through a certain list of type nodes until it finds an 'AutoType'.
This list includes non-sugar nodes as well.

Let's assume for now we really want `R->getAs<AutoType>()` in the if condition here, which would not find the AutoType in `auto *`. This seems wrong, as these can be constrained as well. But we can handle that as a separate issue.

So to hit your bug, you are finding an AutoType through getAs, but not finding it through getContainedAutoTypeLoc().

My first suspicion would be that the type contains a sugar node not handled by `GetContainedAutoTypeLocVisitor`, in `AST/TypeLoc.cpp`.

Can you check that?

https://github.com/llvm/llvm-project/pull/98622


More information about the cfe-commits mailing list