r369098 - [ASTImporter] Import ctor initializers after setting flags.

Balazs Keri via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 16 05:10:03 PDT 2019


Author: balazske
Date: Fri Aug 16 05:10:03 2019
New Revision: 369098

URL: http://llvm.org/viewvc/llvm-project?rev=369098&view=rev
Log:
[ASTImporter] Import ctor initializers after setting flags.

Summary:
Code to import "ctor initializers" at import of functions
is moved to be after the flags in the newly created function
are imported. This fixes an error when the already created but
incomplete (flags are not set) function declaration is accessed.

Reviewers: martong, shafik, a_sidorin, a.sidorin

Reviewed By: shafik

Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65935

Modified:
    cfe/trunk/lib/AST/ASTImporter.cpp
    cfe/trunk/test/Analysis/Inputs/ctu-other.cpp
    cfe/trunk/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt
    cfe/trunk/test/Analysis/ctu-main.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=369098&r1=369097&r2=369098&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Fri Aug 16 05:10:03 2019
@@ -3272,23 +3272,6 @@ ExpectedDecl ASTNodeImporter::VisitFunct
     // decl and its redeclarations may be required.
   }
 
-  // Import Ctor initializers.
-  if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
-    if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
-      SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
-      // Import first, then allocate memory and copy if there was no error.
-      if (Error Err = ImportContainerChecked(
-          FromConstructor->inits(), CtorInitializers))
-        return std::move(Err);
-      auto **Memory =
-          new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
-      std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
-      auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
-      ToCtor->setCtorInitializers(Memory);
-      ToCtor->setNumCtorInitializers(NumInitializers);
-    }
-  }
-
   ToFunction->setQualifierInfo(ToQualifierLoc);
   ToFunction->setAccess(D->getAccess());
   ToFunction->setLexicalDeclContext(LexicalDC);
@@ -3332,6 +3315,23 @@ ExpectedDecl ASTNodeImporter::VisitFunct
       return ToFTOrErr.takeError();
   }
 
+  // Import Ctor initializers.
+  if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
+    if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
+      SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
+      // Import first, then allocate memory and copy if there was no error.
+      if (Error Err = ImportContainerChecked(
+          FromConstructor->inits(), CtorInitializers))
+        return std::move(Err);
+      auto **Memory =
+          new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
+      std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
+      auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
+      ToCtor->setCtorInitializers(Memory);
+      ToCtor->setNumCtorInitializers(NumInitializers);
+    }
+  }
+
   if (D->doesThisDeclarationHaveABody()) {
     Error Err = ImportFunctionDeclBody(D, ToFunction);
 

Modified: cfe/trunk/test/Analysis/Inputs/ctu-other.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/Inputs/ctu-other.cpp?rev=369098&r1=369097&r2=369098&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/Inputs/ctu-other.cpp (original)
+++ cfe/trunk/test/Analysis/Inputs/ctu-other.cpp Fri Aug 16 05:10:03 2019
@@ -164,3 +164,14 @@ const int DefaultParmContext::I = 0;
 int DefaultParmContext::f() {
   return fDefaultParm();
 }
+
+class TestDelegateConstructor {
+public:
+  TestDelegateConstructor() : TestDelegateConstructor(2) {}
+  TestDelegateConstructor(int) {}
+};
+
+int testImportOfDelegateConstructor(int i) {
+  TestDelegateConstructor TDC;
+  return i;
+}

Modified: cfe/trunk/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt?rev=369098&r1=369097&r2=369098&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt (original)
+++ cfe/trunk/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt Fri Aug 16 05:10:03 2019
@@ -27,3 +27,4 @@ c:@extSCC ctu-other.cpp.ast
 c:@extU ctu-other.cpp.ast
 c:@S at TestAnonUnionUSR@Test ctu-other.cpp.ast
 c:@F at testImportOfIncompleteDefaultParmDuringImport#I# ctu-other.cpp.ast
+c:@F at testImportOfDelegateConstructor#I# ctu-other.cpp.ast
\ No newline at end of file

Modified: cfe/trunk/test/Analysis/ctu-main.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/ctu-main.cpp?rev=369098&r1=369097&r2=369098&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/ctu-main.cpp (original)
+++ cfe/trunk/test/Analysis/ctu-main.cpp Fri Aug 16 05:10:03 2019
@@ -127,6 +127,8 @@ public:
 
 extern int testImportOfIncompleteDefaultParmDuringImport(int);
 
+extern int testImportOfDelegateConstructor(int);
+
 int main() {
   clang_analyzer_eval(f(3) == 2); // expected-warning{{TRUE}}
   clang_analyzer_eval(f(4) == 3); // expected-warning{{TRUE}}
@@ -163,4 +165,6 @@ int main() {
   clang_analyzer_eval(TestAnonUnionUSR::Test == 5); // expected-warning{{TRUE}}
 
   clang_analyzer_eval(testImportOfIncompleteDefaultParmDuringImport(9) == 9); // expected-warning{{TRUE}}
+
+  clang_analyzer_eval(testImportOfDelegateConstructor(10) == 10); // expected-warning{{TRUE}}
 }




More information about the cfe-commits mailing list