[PATCH] D65935: [ASTImporter] Import ctor initializers after setting flags.
Balázs Kéri via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 8 03:27:07 PDT 2019
balazske created this revision.
Herald added subscribers: cfe-commits, gamesh411, Szelethus, dkrupp.
Herald added a reviewer: martong.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: clang.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D65935
Files:
clang/lib/AST/ASTImporter.cpp
clang/test/Analysis/Inputs/ctu-other.cpp
clang/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt
clang/test/Analysis/ctu-main.cpp
Index: clang/test/Analysis/ctu-main.cpp
===================================================================
--- clang/test/Analysis/ctu-main.cpp
+++ clang/test/Analysis/ctu-main.cpp
@@ -125,6 +125,8 @@
static const int Test;
};
+extern int testImportOfDelegateConstructor(int);
+
int main() {
clang_analyzer_eval(f(3) == 2); // expected-warning{{TRUE}}
clang_analyzer_eval(f(4) == 3); // expected-warning{{TRUE}}
@@ -158,4 +160,6 @@
// clang_analyzer_eval(extSCC.a == 7); // TODO
clang_analyzer_eval(extU.a == 4); // expected-warning{{TRUE}}
clang_analyzer_eval(TestAnonUnionUSR::Test == 5); // expected-warning{{TRUE}}
+
+ clang_analyzer_eval(testImportOfDelegateConstructor(10) == 10); // expected-warning{{TRUE}}
}
Index: clang/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt
===================================================================
--- clang/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt
+++ clang/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt
@@ -26,3 +26,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 testImportOfDelegateConstructor#I# ctu-other.cpp.ast
Index: clang/test/Analysis/Inputs/ctu-other.cpp
===================================================================
--- clang/test/Analysis/Inputs/ctu-other.cpp
+++ clang/test/Analysis/Inputs/ctu-other.cpp
@@ -145,3 +145,14 @@
static const int Test;
};
const int TestAnonUnionUSR::Test = 5;
+
+class TestDelegateConstructor {
+public:
+ TestDelegateConstructor() : TestDelegateConstructor(2) {}
+ TestDelegateConstructor(int) {}
+};
+
+int testImportOfDelegateConstructor(int i) {
+ TestDelegateConstructor TDC;
+ return i;
+}
Index: clang/lib/AST/ASTImporter.cpp
===================================================================
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -3265,23 +3265,6 @@
// 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);
@@ -3307,6 +3290,23 @@
}
}
+ // 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 (usedDifferentExceptionSpec) {
// Update FunctionProtoType::ExtProtoInfo.
if (ExpectedType TyOrErr = import(D->getType()))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65935.214099.patch
Type: text/x-patch
Size: 3938 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190808/ea823fb2/attachment-0001.bin>
More information about the cfe-commits
mailing list