[PATCH] D158766: [AST] TypeSourceInfo for params of inherited constructor should be null

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 24 13:08:37 PDT 2023


sammccall updated this revision to Diff 553234.
sammccall marked 2 inline comments as done.
sammccall added a comment.

address review comments, also null the TSI of the constructor itself


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158766/new/

https://reviews.llvm.org/D158766

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===================================================================
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2129,6 +2129,21 @@
       notMatches(Code, typeAliasTemplateDecl(hasName("typeAliasDecl"))));
 }
 
+TEST_P(ASTMatchersTest, TypeLocTest_DoesNotBindToSyntheticParams) {
+  if (!GetParam().isCXX11OrLater()) {
+    return;
+  }
+  EXPECT_TRUE(notMatches(
+      R"cpp(
+        struct Base { Base(int); };
+        struct Derived : Base { using Base::Base; };
+        Derived d(42); // force constructor to exist
+      )cpp",
+      cxxRecordDecl(hasAnyName("Derived"),
+                    hasDescendant(typeLoc(
+                        anyOf(loc(functionType()), loc(asString("int"))))))));
+}
+
 TEST_P(ASTMatchersTest, QualifiedTypeLocTest_BindsToConstIntVarDecl) {
   EXPECT_TRUE(matches("const int x = 0;",
                       qualifiedTypeLoc(loc(asString("const int")))));
Index: clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -13890,10 +13890,6 @@
       return cast<CXXConstructorDecl>(Ctor);
 
   DeclarationNameInfo NameInfo(Name, UsingLoc);
-  TypeSourceInfo *TInfo =
-      Context.getTrivialTypeSourceInfo(BaseCtor->getType(), UsingLoc);
-  FunctionProtoTypeLoc ProtoLoc =
-      TInfo->getTypeLoc().IgnoreParens().castAs<FunctionProtoTypeLoc>();
 
   // Check the inherited constructor is valid and find the list of base classes
   // from which it was inherited.
@@ -13905,8 +13901,9 @@
                                         false, BaseCtor, &ICI);
 
   CXXConstructorDecl *DerivedCtor = CXXConstructorDecl::Create(
-      Context, Derived, UsingLoc, NameInfo, TInfo->getType(), TInfo,
-      BaseCtor->getExplicitSpecifier(), getCurFPFeatures().isFPConstrained(),
+      Context, Derived, UsingLoc, NameInfo, BaseCtor->getType(),
+      /*TInfo=*/nullptr, BaseCtor->getExplicitSpecifier(),
+      getCurFPFeatures().isFPConstrained(),
       /*isInline=*/true,
       /*isImplicitlyDeclared=*/true,
       Constexpr ? BaseCtor->getConstexprKind() : ConstexprSpecKind::Unspecified,
@@ -13916,7 +13913,8 @@
     DerivedCtor->setInvalidDecl();
 
   // Build an unevaluated exception specification for this fake constructor.
-  const FunctionProtoType *FPT = TInfo->getType()->castAs<FunctionProtoType>();
+  const FunctionProtoType *FPT =
+      BaseCtor->getType()->castAs<FunctionProtoType>();
   FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
   EPI.ExceptionSpec.Type = EST_Unevaluated;
   EPI.ExceptionSpec.SourceDecl = DerivedCtor;
@@ -13926,18 +13924,15 @@
   // Build the parameter declarations.
   SmallVector<ParmVarDecl *, 16> ParamDecls;
   for (unsigned I = 0, N = FPT->getNumParams(); I != N; ++I) {
-    TypeSourceInfo *TInfo =
-        Context.getTrivialTypeSourceInfo(FPT->getParamType(I), UsingLoc);
     ParmVarDecl *PD = ParmVarDecl::Create(
         Context, DerivedCtor, UsingLoc, UsingLoc, /*IdentifierInfo=*/nullptr,
-        FPT->getParamType(I), TInfo, SC_None, /*DefArg=*/nullptr);
+        FPT->getParamType(I), /*TInfo=*/nullptr, SC_None, /*DefArg=*/nullptr);
     PD->setScopeInfo(0, I);
     PD->setImplicit();
     // Ensure attributes are propagated onto parameters (this matters for
     // format, pass_object_size, ...).
     mergeDeclAttributes(PD, BaseCtor->getParamDecl(I));
     ParamDecls.push_back(PD);
-    ProtoLoc.setParam(I, PD);
   }
 
   // Set up the new constructor.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158766.553234.patch
Type: text/x-patch
Size: 3621 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230824/b80d3d6e/attachment-0001.bin>


More information about the cfe-commits mailing list